This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-05 12:53:44

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

"Machine gun" firing

So, I have a game where you are a plane.  It's based off of RC Plane Sim - 2, so you are flying and turning by pointing in different directions.  How do I get many bullets (say 5 or 10) to fire, but not fire all at once?
I know it has to do with a firing variable or something, but I'm not sure.

Last edited by firedrake969_test (2012-12-05 12:54:12)


Alt of Firedrake969.

Offline

 

#2 2012-12-05 14:29:15

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: "Machine gun" firing

Using a sprite for each bullet, something like this:

Anywhere:

when gf clicked
forever if <key [space v] pressed?>
broadcast [fire v] and wait
wait (2) secs // interval between bursts after all bullets are done moving
For the bullets:
when I receive [fire v]
go to [cannon v]
point towards [main-character v] // or wherever they should aim
wait (0.2) secs // increase the time for each cannon ball so they fire in sequence
show
repeat until<touching [edge v]?>
move (4) steps // not to big or the bullets may phase through objects
end
hide


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-12-06 12:12:14

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: "Machine gun" firing

MoreGamesNow wrote:

Using a sprite for each bullet, something like this:

Anywhere:

when gf clicked
forever if <key [space v] pressed?>
broadcast [fire v] and wait
wait (2) secs // interval between bursts after all bullets are done moving
For the bullets:
when I receive [fire v]
go to [cannon v]
point towards [main-character v] // or wherever they should aim
wait (0.2) secs // increase the time for each cannon ball so they fire in sequence
show
repeat until<touching [edge v]?>
move (4) steps // not to big or the bullets may phase through objects
end
hide

Do I need 2 sprites/bullet? or can I just do both scripts in one bullet?


Alt of Firedrake969.

Offline

 

#4 2012-12-06 17:27:18

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: "Machine gun" firing

firedrake969_test wrote:

MoreGamesNow wrote:

Using a sprite for each bullet, something like this:

Anywhere:

when gf clicked
forever if <key [space v] pressed?>
broadcast [fire v] and wait
wait (2) secs // interval between bursts after all bullets are done moving
For the bullets:
when I receive [fire v]
go to [cannon v]
point towards [main-character v] // or wherever they should aim
wait (0.2) secs // increase the time for each cannon ball so they fire in sequence
show
repeat until<touching [edge v]?>
move (4) steps // not to big or the bullets may phase through objects
end
hide

Do I need 2 sprites/bullet? or can I just do both scripts in one bullet?

You can put both scripts in one bullet, but you only need it in the first bullet.  You will, however, need multiple bullets to really simulate a machine gun firing.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-12-06 18:16:33

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

MoreGamesNow wrote:

firedrake969_test wrote:

MoreGamesNow wrote:

Using a sprite for each bullet, something like this:

Anywhere:

when gf clicked
forever if <key [space v] pressed?>
broadcast [fire v] and wait
wait (2) secs // interval between bursts after all bullets are done moving
For the bullets:
when I receive [fire v]
go to [cannon v]
point towards [main-character v] // or wherever they should aim
wait (0.2) secs // increase the time for each cannon ball so they fire in sequence
show
repeat until<touching [edge v]?>
move (4) steps // not to big or the bullets may phase through objects
end
hide

Do I need 2 sprites/bullet? or can I just do both scripts in one bullet?

You can put both scripts in one bullet, but you only need it in the first bullet.  You will, however, need multiple bullets to really simulate a machine gun firing.

Say I press space once.  Will it only fire 1 bullet?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#6 2012-12-06 21:51:01

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Firedrake969 wrote:

MoreGamesNow wrote:

firedrake969_test wrote:

Do I need 2 sprites/bullet? or can I just do both scripts in one bullet?

You can put both scripts in one bullet, but you only need it in the first bullet.  You will, however, need multiple bullets to really simulate a machine gun firing.

Say I press space once.  Will it only fire 1 bullet?

It depends; if you have one bullet, yes, but if you have more, no.


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2012-12-07 08:48:04

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: "Machine gun" firing

Is there a way to do it where it behaves like a real machine gun? i.e., you can fire 1 bullet, or 10 bullets.


Alt of Firedrake969.

Offline

 

#8 2012-12-07 15:33:11

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

firedrake969_test wrote:

Is there a way to do it where it behaves like a real machine gun? i.e., you can fire 1 bullet, or 10 bullets.

Yes, though I wouldn't like typing up the script. I'll see if I can create the script in a project for you tomorrow morning.


http://i46.tinypic.com/35ismmc.png

Offline

 

#9 2012-12-07 17:07:25

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

ErnieParke wrote:

firedrake969_test wrote:

Is there a way to do it where it behaves like a real machine gun? i.e., you can fire 1 bullet, or 10 bullets.

Yes, though I wouldn't like typing up the script. I'll see if I can create the script in a project for you tomorrow morning.

Ok.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#10 2012-12-08 12:06:02

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

Ready?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#11 2012-12-08 14:19:10

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Firedrake969 wrote:

Ready?

No, because my parents and I went shopping for folders and lights for the past 1~2 hours, and my mom just called for me to help decorate the Christmas tree in my house, but once I'm done with that, I should start working on it. It shouldn't be too hard to make.  smile


http://i46.tinypic.com/35ismmc.png

Offline

 

#12 2012-12-08 14:46:40

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

ErnieParke wrote:

Firedrake969 wrote:

Ready?

No, because my parents and I went shopping for folders and lights for the past 1~2 hours, and my mom just called for me to help decorate the Christmas tree in my house, but once I'm done with that, I should start working on it. It shouldn't be too hard to make.  smile

Oh, xD


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#13 2012-12-08 15:06:54

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Firedrake969 wrote:

ErnieParke wrote:

Firedrake969 wrote:

Ready?

No, because my parents and I went shopping for folders and lights for the past 1~2 hours, and my mom just called for me to help decorate the Christmas tree in my house, but once I'm done with that, I should start working on it. It shouldn't be too hard to make.  smile

Oh, xD

It's finished!

(link to project)

Last edited by ErnieParke (2012-12-08 15:07:02)


http://i46.tinypic.com/35ismmc.png

Offline

 

#14 2012-12-09 19:04:13

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

Can you give me a screenshot of the script?  I am using chrome, if that explains anything.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#15 2012-12-09 21:04:01

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Firedrake969 wrote:

Can you give me a screenshot of the script?  I am using chrome, if that explains anything.

No. From what I know about chrome, it doesn't, though before I do post the scripts, I have a question; couldn't you just download the engine I made you and, if you wanted, export the sprites so that it doesn't look like you remixed a project of mine?


http://i46.tinypic.com/35ismmc.png

Offline

 

#16 2012-12-10 12:12:26

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: "Machine gun" firing

ErnieParke wrote:

Firedrake969 wrote:

Can you give me a screenshot of the script?  I am using chrome, if that explains anything.

No. From what I know about chrome, it doesn't, though before I do post the scripts, I have a question; couldn't you just download the engine I made you and, if you wanted, export the sprites so that it doesn't look like you remixed a project of mine?

No, because I'm remixing a project and adding the machine gun scripts.


Alt of Firedrake969.

Offline

 

#17 2012-12-10 16:12:23

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Okay. Now for the machine gun:

when gf clicked
set [Ammo v] to (500)
set [bullet v] to (0)
delete [all v] of [bullets v]
add [1] to [bullets v]
add [2] to [bullets v]
add [3] to [bullets v]
add [4] to [bullets v]
Filler.//Repeat for the # of bullets you'll have.
forever
 if <<(mouse down?) and <(ammo) > (0)>> and <(length of [bullets v]) > [0]>>
  change [Ammo v] by (-1)
  set [bullet v] to (item [1 v] of [bullets v])
  delete [1 v] of [bullets v]
  wait (0.1) secs//Delay.
 end
 go to front
when gf clicked
forever
 point towards [mouse pointer v]

For the first bullet:

when gf clicked
forever
 if <(Bullet) = (1)>
  show
  go to [machine gun v]
  point in direction ([direction v] of [Machine Gun v])
  move (30) steps
  repeat until (touching [edge v]?)
   move (5) steps
  end
  if <(Bullet) = (1)>
   set [Bullet v] to (0)
  end
  add [1] to [bullets v]
 end
 hide

For the second bullet:

when gf clicked
forever
 if <(Bullet) = (2)>
  show
  go to [machine gun v]
  point in direction ([direction v] of [Machine Gun v])
  move (30) steps
  repeat until (touching [edge v]?)
   move (5) steps
  end
  if <(Bullet) = (2)>
   set [Bullet v] to (0)
  end
  add [2] to [bullets v]
 end
 hide

And so on for all of the bullets.


http://i46.tinypic.com/35ismmc.png

Offline

 

#18 2012-12-10 19:07:40

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

ErnieParke wrote:

Okay. Now for the machine gun:

when gf clicked
set [Ammo v] to (500)
set [bullet v] to (0)
delete [all v] of [bullets v]
add [1] to [bullets v]
add [2] to [bullets v]
add [3] to [bullets v]
add [4] to [bullets v]
Filler.//Repeat for the # of bullets you'll have.
forever
 if <<(mouse down?) and <(ammo) > (0)>> and <(length of [bullets v]) > [0]>>
  change [Ammo v] by (-1)
  set [bullet v] to (item [1 v] of [bullets v])
  delete [1 v] of [bullets v]
  wait (0.1) secs//Delay.
 end
 go to front
when gf clicked
forever
 point towards [mouse pointer v]

For the first bullet:

when gf clicked
forever
 if <(Bullet) = (1)>
  show
  go to [machine gun v]
  point in direction ([direction v] of [Machine Gun v])
  move (30) steps
  repeat until (touching [edge v]?)
   move (5) steps
  end
  if <(Bullet) = (1)>
   set [Bullet v] to (0)
  end
  add [1] to [bullets v]
 end
 hide

For the second bullet:

when gf clicked
forever
 if <(Bullet) = (2)>
  show
  go to [machine gun v]
  point in direction ([direction v] of [Machine Gun v])
  move (30) steps
  repeat until (touching [edge v]?)
   move (5) steps
  end
  if <(Bullet) = (2)>
   set [Bullet v] to (0)
  end
  add [2] to [bullets v]
 end
 hide

And so on for all of the bullets.

Tried & script breaks.  I'll upload tomorrow.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#19 2012-12-10 20:08:11

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Hmmm… That's interesting because it works for me. So how is it breaking?


http://i46.tinypic.com/35ismmc.png

Offline

 

#20 2012-12-10 21:41:28

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Machine gun" firing

ErnieParke wrote:

Hmmm… That's interesting because it works for me. So how is it breaking?

Here it is, you have to fire a few volleys w/ space key.  Then, it won't fire anymore.  And I removed the when key space pressed stop all.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#21 2012-12-10 21:50:07

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: "Machine gun" firing

Firedrake969 wrote:

ErnieParke wrote:

Hmmm… That's interesting because it works for me. So how is it breaking?

Here it is, you have to fire a few volleys w/ space key.  Then, it won't fire anymore.  And I removed the when key space pressed stop all.

Ah, okay. I see the problem. You had made "Bullets" a local list of your plane, so the bullets can't add theirselves back to the list. Fix that and it should work.  wink


http://i46.tinypic.com/35ismmc.png

Offline

 

#22 2012-12-11 12:11:32

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: "Machine gun" firing

ErnieParke wrote:

Firedrake969 wrote:

ErnieParke wrote:

Hmmm… That's interesting because it works for me. So how is it breaking?

Here it is, you have to fire a few volleys w/ space key.  Then, it won't fire anymore.  And I removed the when key space pressed stop all.

Ah, okay. I see the problem. You had made "Bullets" a local list of your plane, so the bullets can't add theirselves back to the list. Fix that and it should work.  wink

Ok.


Alt of Firedrake969.

Offline

 

Board footer