dMZX Forums: shot detection - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

shot detection

#1 User is offline   Mr Goof 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 14-June 05

Posted 25 February 2024 - 02:58 AM

Hi Everyone,

Wondering I have checked the command reference and I did not see a command for what I am looking for. Id like to have a bot shoot the player and be able to detect if its shot actually hit the player. Not sure if there is a command for this or some type of coding to use. Any advice is greatly appreciated :D
0

#2 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,943
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 25 February 2024 - 05:11 AM

There's nothing direct. How feasible this is depends on what else is going on on the board at the same time.

For example, if there's no other source of player-hurting bullets on the board, just use the :playerhit label

However, once a robot has fired a bullet, there is nothing unique about that bullet tying it to the robot in question - it just becomes a plain, neutral bullet with a given direction. There's some nasty shit you could do to try and make a guess - for example, use code to follow the bullet's path, make sure it's still there. If the bullet disappears and the player is in the right location to be hit by it and the player's health is reduced in that same cycle, chances are very good your bullet hurt the player - but nothing is certain.

Another alternative is that you could simulate a bullet, using a sprite or overlay to draw it, and just reproduce in robotic all the usual bullet handling (what happens when it hits various creatures etc.), except for a special case when hitting the player. However other code potentially on the board, such as code checking for the presence of a bullet in a given location, or if any bullet etc. will not work.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#3 User is offline   Joseph Collins 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 31
  • Joined: 10-October 02
  • Gender:Not Telling
  • Location:United States

Posted 25 February 2024 - 02:30 PM

View PostDr Lancer-X, on 25 February 2024 - 12:11 AM, said:

[…] for example, use code to follow the bullet's path, make sure it's still there. If the bullet disappears and the player is in the right location to be hit by it and the player's health is reduced in that same cycle, chances are very good your bullet hurt the player - but nothing is certain.

Basically this. Or, alternately, have the Robot "pay attention" for a few cycles to see what happens to the bullet. I recently made a "short-ranged bullet" engine for my game where a 'bot makes its won bullets disappear in 20 cycles through the use of "copy block". I'm sure the problems are apparent just from that statement alone, but it works for my purposes.

Anyway, if you don't have multiple 'bots on the same axes of the player, you could combine an "if "HORIZPLD"" or "if "VERTPLD"" statement with ":playerhit" or something. It's more prone to trigger false positives if there are multiple sources of damage on the same board, but it would probably be the simplest solution for what's needed. Maybe.

Quote

Another alternative is that you could simulate a bullet, using a sprite or overlay to draw it, and just reproduce in robotic all the usual bullet handling (what happens when it hits various creatures etc.), except for a special case when hitting the player. However other code potentially on the board, such as code checking for the presence of a bullet in a given location, or if any bullet etc. will not work.

That sounds absolutely headache-inducing. As someone who recently put code into a Robot which, when activated, turned it into a "fake bullet" (related to my "short-ranged bullets" thing above), I can imagine what a pain creating an "overlay bullet" script would be. I don't even know how hit detection would work with that. I could probably figure it out and code something, but man, it just sounds daunting right now.
(Then again, I'm staying in the "bronze age" of v2.5x, so…)
I'm not that hard to find… if you know where to look.
-=( https://jolikmc.tumblr.com )=-
0

#4 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,933
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 06 March 2024 - 08:10 PM

Here's a quick proof-of-concept I threw together of this using duplicate self projectiles that simulate built-in bullets. It's hardly problem-free (the way the SHOT label is handled needs to change to make it a real enemy; the char commands might break when copied into MZX) but this can be done.

set "local" to "robot_id"
set "bullettype" to 2
color c0d

: "l"
goto "#shootn"
wait for 10
goto "#shoote"
wait for 10
goto "#shoots"
wait for 10
goto "#shootw"
wait for 10
goto "l"

: "#shootn"
if touching NORTH then "hit"
if blocked NORTH then "blkn"
char '‘'
color c0f
duplicate self to NORTH
send at NORTH to "bulletn"
char ''
color c0d
goto "#return"
: "blkn"
shoot to NORTH
goto "#return"

: "#shoots"
if touching SOUTH then "hit"
if blocked SOUTH then "blks"
char '’'
color c0f
duplicate self to SOUTH
send at SOUTH to "bullets"
char ''
color c0d
goto "#return"
: "blks"
shoot to SOUTH
goto "#return"

: "#shoote"
if touching EAST then "hit"
if blocked EAST then "blke"
char '“'
color c0f
duplicate self to EAST
send at EAST to "bullete"
char ''
color c0d
goto "#return"
: "blke"
shoot to EAST
goto "#return"

: "#shootw"
if touching WEST then "hit"
if blocked WEST then "blkw"
char '”'
color c0f
duplicate self to WEST
send at WEST to "bulletw"
char ''
color c0d
goto "#return"
: "blkw"
shoot to WEST
goto "#return"

: "hit"
shoot to SEEK
* "The player has been hit by my bullet point-blank."
goto "#return"

: "#hit"
* "The player has been hit by my bullet at a distance."
goto "#return"


. "-----"


: "#sendshot"
send at "r&local&.thisx" "r&local&.thisy" to "#hit"
goto "#return"

| "shot"
sfx 29
: "die"
die

: "bulletn"
restore "shot" 1
set "lava_walk" to 1
set "goop_walk" to 1
: "bn"
if touching NORTH then "hitn"
if blocked NORTH then "brkn"
if "thisy" = 0 then "die"
go NORTH for 1
goto "bn"
: "hitn"
goto "#sendshot"
: "brkn"
shoot to NORTH
die

: "bullets"
restore "shot" 1
set "lava_walk" to 1
set "goop_walk" to 1
: "bs"
if touching SOUTH then "hits"
if blocked SOUTH then "brks"
if "thisy" = "('boardh'-1)" then "die"
go SOUTH for 1
goto "bs"
: "hits"
goto "#sendshot"
: "brks"
shoot to SOUTH
die

: "bullete"
restore "shot" 1
set "lava_walk" to 1
set "goop_walk" to 1
: "be"
if touching EAST then "hite"
if blocked EAST then "brke"
if "thisx" = "('boardw'-1)" then "die"
go EAST for 1
goto "be"
: "hite"
goto "#sendshot"
: "brke"
shoot to EAST
die

: "bulletw"
restore "shot" 1
set "lava_walk" to 1
set "goop_walk" to 1
: "bw"
if touching WEST then "hitw"
if blocked WEST then "brkw"
if "thisx" = 0 then "die"
go WEST for 1
goto "bw"
: "hitw"
goto "#sendshot"
: "brkw"
shoot to WEST
die

"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users