dMZX Forums: Help? Trying to make a gun of sorts - dMZX Forums

Jump to content

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

Help? Trying to make a gun of sorts

#1 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 04 June 2007 - 05:52 AM

Hey all,

Im totally new to the world of game programming, so bare with me, Ive only had megazeux for a whole day :(

Im trying to make a thingy in the top left hand corner thatll show me how much ammo Ive got, and how many reload/canister thingys.

Also trying to get it to shoot invisible bullets so you only see the impact.

Also trying to make it shoot whichever way im facing by pressing q (i prefer the WASD movement keys).

Sorry to dump my problems on your guys, but hey, you all know more than I do.
0

#2 User is offline   RoSS 

  • RIP Fred Friedberg 2004
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,283
  • Joined: 22-October 00
  • Gender:Male
  • Location:Right in front of behind you.

Post icon  Posted 04 June 2007 - 07:15 AM

The simplest implementation of what you're looking for is a robot that just does this
: "loop"
write overlay c0f "&ammo&" 0 0
wait 1
goto "loop"

To make it work, you need to go into the board options (press I) and turn it to static overlay (normal overlay would put it at the top-left of the board instead of the top-left of the window). Putting &counter& anywhere where you could put text will show the value of the counter (in this case, how much ammo you have) instead. I'd play with it and get it more your liking (by putting "Ammo: &ammo&" or something better-looking)

The invisible bullets are a little more difficult and if you're going to do that, you might as well make the bullets instantaneous (instead of going the same speed as the player running). As for how to do that, there's several good examples already made, although I can't remember the specific titles that used them; I'll let somebody else help.
-RoSS
<img src="http://ross.box43.net/sig.php/sig.png" border="0" class="linked-sig-image" />
0

#3 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 04 June 2007 - 09:31 AM

Quote

The simplest implementation of what you're looking for is a robot that just does this

CODE 
: "loop"
write overlay c0f "&ammo&" 0 0
wait 1
goto "loop"


To make it work, you need to go into the board options (press I) and turn it to static overlay (normal overlay would put it at the top-left of the board instead of the top-left of the window). Putting &counter& anywhere where you could put text will show the value of the counter (in this case, how much ammo you have) instead. I'd play with it and get it more your liking (by putting "Ammo: &ammo&" or something better-looking)

The invisible bullets are a little more difficult and if you're going to do that, you might as well make the bullets instantaneous (instead of going the same speed as the player running). As for how to do that, there's several good examples already made, although I can't remember the specific titles that used them; I'll let somebody else help.


Thanks for the ammo tip, i'll muck around with that now, see what I can do.

Instantaneous bullets sound okay, hope it isn't too hard though.

This post has been edited by Kakita: 04 June 2007 - 09:32 AM

0

#4 User is offline   CJA 

  • «≡larch bucket≡»
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,262
  • Joined: 23-June 05
  • Gender:Male
  • Location:......@.c....

Posted 04 June 2007 - 12:36 PM

Okay, invisible bullets. Lancer-X loves these and I may be depriving him but anyway,

: "check"
wait 1

. "This erases the gun burst, created later in the code."
change overlay c0e '*' c07 ' '

. "if the A key (Code 30) is OFF, go back and wait"
if "key30" = 0 "check"

. "Reset things."
set "increaseX" to 0
set "increaseY" to 0

set "bulletX" to "playerX"
set "bulletY" to "playerY"

. "Because of the &playerfacedir& here, we'll go to different labels depending on what way the player is facing."
goto "shoot&playerfacedir&"


: "shoot0"
. "Facing North"
. "We want the bullet to go up.  When you travel up, the Y-coordinate decreases."
set "increaseY" to -1
goto "shoot"

: "shoot1"
. "Facing South"
. "We want the bullet to go down.  When you travel down, the Y-coordinate increases."
set "increaseY" to 1
goto "shoot"

: "shoot2"
. "Facing East"
. "We want the bullet to go east.  When you travel east, the X-coordinate increases."
set "increaseX" to 1
goto "shoot"

: "shoot3"
. "Facing West"
. "We want the bullet to go west.  When you travel west, the X-coordinate decreases."
set "increaseX" to -1
goho "shoot"

. "What this loop does is it silently increases the bullet's position one step at a time. When it hits something, we'll get out of the loop."
loop start

. "Update the position.  For example, if we are going right, this would make bulletX go up by one since increaseX is 1, so the bullet is actually going right."
inc "bulletX" by "increaseX"
inc "bulletY" by "increaseY"

. "Is there something at this position?"
if c?? Robot p?? at "bulletX" "bulletY" then "hit"
if c?? PushableRobot p?? at "bulletX" "bulletY" then "hit"
if c?? CustomBlock p?? at "bulletX" "bulletY" then "hit"
if c?? Solid p?? at "bulletX" "bulletY" then "hit"
if c?? Normal p?? at "bulletX" "bulletY" then "hit"

. "There must be nothing good there, so let's return to the top of the loop and travel more."
loop for 80

. "If you get here, that loop happened 80 times, meaning the bullet has traveled 80 spaces and is no longer ''visible'' since 80 is the maximum viewport size possible.  Let's act like it never hit and go back to the main loop."
goto "check"

: "hit"
. "There's something hittable at (bulletX,bulletY).  Let's put a little burst there.  There's code in the main loop to erase the burst after one cycle."
put c0e '*' overlay at "bulletX" "bulletY"

. "If a Robot is there, make it go to the SHOT label."
send at "bulletX" "bulletY" to "shot"

. "And that's all there is to do."
goto "check"


Also note that if the overlay is static the gun burst will show up in the wrong place on scrolling boards. Here's an idea for a status engine not needing the static overlay:

: "loop"
. "scrolledX and scrolledY always refer to the top corner of the visible screen no matter how far you've scrolled."
write overlay c0f "Ammo &ammo&" "scrolledX" "scrolledY"

. "Let the player see it"
wait 1

. "This loop turns every last white character on the overlay into space."
loop start
change overlay c0f "loopcount" c07 ' '
loop 255
goto "loop"


Lastly, make sure to set the "commands" counter to something like 32767 (in your global robot) so that these loops can do a lot of stuff without having to wait 1 every 40 commands.

There's a way to get this counter extremely high but I don't use it because if there's a loop somewhere without wait 1, it'll freeze MZX.
Need a dispenser here.
0

#5 User is offline   Dr Lancer-X 

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

Posted 04 June 2007 - 07:29 PM

I like to have "commands" insanely high and just code carefully. Then I'll know immediately if I did something wrong :>

And yeah, invisible bullets are fine but for some things I actually prefer fast bullets (like in Termination), to give more visual feedback while being realistically faster than anything else.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#6 User is offline   Terryn 

  • ******
  • Group: DigiStaff
  • Posts: 2,960
  • Joined: 12-October 00
  • Gender:Male

Posted 04 June 2007 - 07:35 PM

The term's "hitscan", not invisible bullets =DDD Unless you really mean that the bullets actually are invisible objects which go at normal MZX bullet speeds.
angelic stream - shed sanguine - ill-adapt - avis - para/lyser - renaissance - dead tangent - phosphene blur - birth breeds death - ________ - painted glass - lagniappe

<Exophase> HES STEALING MAH AIRSHIP!!!!!!11111111
0

#7 User is offline   Koji 

  • End
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 6,644
  • Joined: 15-November 01
  • Gender:Not Telling
  • Location:US, NC

Posted 04 June 2007 - 09:33 PM

You know, a sound effect is usually the BEST feedback for a gun in mzx. graphic feed back is secondary, to tell you where it went. and you can easily have a baddie blink red or something when he gets hit.

So there ya go do hitscans that make a sound effect and turn hit enemies red.
0

#8 User is offline   Dr Lancer-X 

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

Posted 04 June 2007 - 10:07 PM

Unless all your bullets are straight and completely accurate, you need more than that. Because the bullets in Meritous can sometimes have strange paths, it was necessary to draw the bullet in-flight so you could see exactly what area it was covering.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#9 User is offline   T-Bone 

  • Wastelander
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,487
  • Joined: 16-August 02
  • Gender:Male
  • Location:Canada

Posted 04 June 2007 - 11:46 PM

Actually for the HUD you should do something like

: "loop"
write overlay c0f "&ammo&   " 0 0
wait 1
goto "loop"


With like a couple spaces after &ammo& to prevent some extended numbers being displayed. Say you have 4123 ammo left and you shoot 4000 of them. You may get a little "3" at the end of your true ammo amount. So its just good practice to put a couple spaces after your &counter& HUDs.

EDIT:

Its possible that CJA example code may also get rid of any extra numbers.

This post has been edited by T-bone6: 04 June 2007 - 11:49 PM

0

#10 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 04 June 2007 - 11:49 PM

CJA, on Jun 4 2007, 12:36 PM, said:

Okay, invisible bullets. Lancer-X loves these and I may be depriving him but anyway,

: "check"
wait 1

. "This erases the gun burst, created later in the code."
change overlay c0e '*' c07 ' '

. "if the A key (Code 30) is OFF, go back and wait"
if "key30" = 0 "check"

. "Reset things."
set "increaseX" to 0
set "increaseY" to 0

set "bulletX" to "playerX"
set "bulletY" to "playerY"

. "Because of the &playerfacedir& here, we'll go to different labels depending on what way the player is facing."
goto "shoot&playerfacedir&"


: "shoot0"
. "Facing North"
. "We want the bullet to go up. ?When you travel up, the Y-coordinate decreases."
set "increaseY" to -1
goto "shoot"

: "shoot1"
. "Facing South"
. "We want the bullet to go down. ?When you travel down, the Y-coordinate increases."
set "increaseY" to 1
goto "shoot"

: "shoot2"
. "Facing East"
. "We want the bullet to go east. ?When you travel east, the X-coordinate increases."
set "increaseX" to 1
goto "shoot"

: "shoot3"
. "Facing West"
. "We want the bullet to go west. ?When you travel west, the X-coordinate decreases."
set "increaseX" to -1
goho "shoot"

. "What this loop does is it silently increases the bullet's position one step at a time. When it hits something, we'll get out of the loop."
loop start

. "Update the position. ?For example, if we are going right, this would make bulletX go up by one since increaseX is 1, so the bullet is actually going right."
inc "bulletX" by "increaseX"
inc "bulletY" by "increaseY"

. "Is there something at this position?"
if c?? Robot p?? at "bulletX" "bulletY" then "hit"
if c?? PushableRobot p?? at "bulletX" "bulletY" then "hit"
if c?? CustomBlock p?? at "bulletX" "bulletY" then "hit"
if c?? Solid p?? at "bulletX" "bulletY" then "hit"
if c?? Normal p?? at "bulletX" "bulletY" then "hit"

. "There must be nothing good there, so let's return to the top of the loop and travel more."
loop for 80

. "If you get here, that loop happened 80 times, meaning the bullet has traveled 80 spaces and is no longer ''visible'' since 80 is the maximum viewport size possible. ?Let's act like it never hit and go back to the main loop."
goto "check"

: "hit"
. "There's something hittable at (bulletX,bulletY). ?Let's put a little burst there. ?There's code in the main loop to erase the burst after one cycle."
put c0e '*' overlay at "bulletX" "bulletY"

. "If a Robot is there, make it go to the SHOT label."
send at "bulletX" "bulletY" to "shot"

. "And that's all there is to do."
goto "check"


Also note that if the overlay is static the gun burst will show up in the wrong place on scrolling boards. Here's an idea for a status engine not needing the static overlay:

: "loop"
. "scrolledX and scrolledY always refer to the top corner of the visible screen no matter how far you've scrolled."
write overlay c0f "Ammo &ammo&" "scrolledX" "scrolledY"

. "Let the player see it"
wait 1

. "This loop turns every last white character on the overlay into space."
loop start
change overlay c0f "loopcount" c07 ' '
loop 255
goto "loop"


Lastly, make sure to set the "commands" counter to something like 32767 (in your global robot) so that these loops can do a lot of stuff without having to wait 1 every 40 commands.

There's a way to get this counter extremely high but I don't use it because if there's a loop somewhere without wait 1, it'll freeze MZX.

Man thats alot of code. Ill try it out, see what I can get it to do.

Hitscan huh? Fair enough, but kick-ass-come-out-of-nowhere-to-smack-you-in-the-face-bullets is a better name, IMO.

Sound effects are cool, know where I can download some?
0

#11 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 04 June 2007 - 11:52 PM

T-bone6, on Jun 4 2007, 11:46 PM, said:

Actually for the HUD you should do something like

: "loop"
write overlay c0f "&ammo& ? " 0 0
wait 1
goto "loop"


With like a couple spaces after &ammo& to prevent some extended numbers being displayed. Say you have 4123 ammo left and you shoot 4000 of them. You may get a little "3" at the end of your true ammo amount. So its just good practice to put a couple spaces after your &counter& HUDs.

EDIT:

Its possible that CJA example code may also get rid of any extra numbers.

Lol, I worked out how to stop that crappy problem. Thanks though :(

EDIT:

Is there a code that lets you figure out if the player is:

* facing a certain direction

* to the north, of a robot

This post has been edited by Kakita: 04 June 2007 - 11:55 PM

0

#12 User is offline   Genrok 

  • My name's not really Genrok
  • PipPipPip
  • Group: Members
  • Posts: 269
  • Joined: 25-April 07
  • Gender:Male
  • Location:Here

Posted 05 June 2007 - 01:39 AM

Kakita, on Jun 4 2007, 07:52 PM, said:

Is there a code that lets you figure out if the player is:

* facing a certain direction

* to the north, of a robot

You can use the the counter playerfacedir to check the player's direction. If the counter= 0 then the player's facing north, 1 is south, 2 is east, and 3 is west. One way to check if the player's north of the robot is to use:


: "loop"
if player at "thisx" "('thisy'-1)" "label"
goto "loop"


I'm not sure if there's an easier way to do it, I haven't really used mzx for a while.

This post has been edited by Genrok: 05 June 2007 - 01:50 AM

"I'm not superstitious, I'm just a little stitious." - Michael Scott
"I'm a victim of circumstance!" - Curly
"I reject your reality and substitute my own." - Adam Savage
"Why don't you cry me a river, build a bridge, and get over it."
"I see you're drinking 1%, is that because you think you're fat?" - Napoleon Dynamite
"War is Groovy" - some violent hippie

I have about 30 unfinished mzx games, and I plan to keep it that way.
0

#13 User is offline   Dr Lancer-X 

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

Posted 05 June 2007 - 02:32 AM

Genrok, on Jun 5 2007, 11:39 AM, said:

: "loop"
if player at "thisx" "('thisy'-1)" "label"
goto "loop"

eliminate busyloop thx
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#14 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 05 June 2007 - 04:46 AM

Genrok, on Jun 5 2007, 01:39 AM, said:

label

Kakita, on Jun 4 2007, 07:52 PM, said:

Is there a code that lets you figure out if the player is:

* facing a certain direction

* to the north, of a robot

You can use the the counter playerfacedir to check the player's direction. If the counter= 0 then the player's facing north, 1 is south, 2 is east, and 3 is west. One way to check if the player's north of the robot is to use:


: "loop"
if player at "thisx" "('thisy'-1)" "label"
goto "loop"


I'm not sure if there's an easier way to do it, I haven't really used mzx for a while.

Ahh ok, but that will only check north 1 of the robot wont it, i need to check the entire north?

What if I did something like

if playery = thisy "label"

would that work?
0

#15 User is offline   CJA 

  • «≡larch bucket≡»
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,262
  • Joined: 23-June 05
  • Gender:Male
  • Location:......@.c....

Posted 05 June 2007 - 12:33 PM

The "entire north?"

To see if it's to the north of the player and aligned with him,

if "(('playerx'='thisx') a ('playery' < 'thisy'))" = 1 then "label"

...#...
...#...
...#...
...R...
.......


That'll check to see if the robot is in a line with the player and to the north. In that situation, the player has the same X and a Y that's less.

If you mean ANYWHERE, as long as it's above the robot,

if "playery" < "thisy" then "label"

#######
#######
#######
...R...
.......

Need a dispenser here.
0

#16 User is offline   Kakita 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-June 07

Posted 06 June 2007 - 07:12 AM

CJA, on Jun 5 2007, 12:33 PM, said:

The "entire north?"

To see if it's to the north of the player and aligned with him,

if "(('playerx'='thisx') a ('playery' < 'thisy'))" = 1 then "label"

...#...
...#...
...#...
...R...
.......


That'll check to see if the robot is in a line with the player and to the north. In that situation, the player has the same X and a Y that's less.

If you mean ANYWHERE, as long as it's above the robot,

if "playery" < "thisy" then "label"

#######
#######
#######
...R...
.......

It works!

Thanks!
0

Share this topic:


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

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