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

#1 2007-08-14 00:23:00

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Multiple Bullets...

Hey, I'm trying to make a space invaders game where I have 3 bullets that can rotate seamlessly so that every time you hit the spacebar, there's a new bullet leaving from the ship and an old bullet still traveling on the screen...any help would be awesome, and if you need to look at my code, let me know.

Thanks everyone,
C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#2 2007-08-14 01:35:09

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

I did exactly what you are describing in my defend your turf game
located @ http://scratch.mit.edu/projects/archmage/14986

What I did was I created a variable called bulletorder to control the order of shooting.
I think you should make yours like this:

///On spaceship sprite
when space pressed
change bulletorder by 1
if bulletorder > 3
set bullet order to 1
broadcast firelazer

/// On the bullet sprites
///(replace "bulletnumber" with the bullets number ie,1,2,3)
When I recieve firelazer
if bulletorder = "bullenumber"
(insert shooting code blocks here)

end script.


I didn't give you shooting codes because it seems you already know them  smile


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2007-08-14 01:54:17

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Thanks, I will take a look at that tomorrow, I think I'm "close" to what you're saying, but I've messed with it so much at this point that it's kind of jumbled up so I'll have to clean up and see what happens.

Thanks though,
C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#4 2007-08-14 03:15:20

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Multiple Bullets...

I have a multiple bullet demo here:

http://scratch.mit.edu/projects/Mayhem/19961

Fires 5 shots horizontally.  Should be easy enough to change to vertical.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#5 2007-08-15 22:32:10

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Hey, messing with my code, and thank you archmage for the help, i've been tweaking with yours but I can't seem to get it quite right.  all three bullets will distinctly shoot at the right time, but the previous bullet will stop right where it is...I know I'm just missing something small, but please help.

Thanks,
C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#6 2007-08-15 23:30:11

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

So I think what you are saying is you don't want the idle bullets to show up. If this is the case then do this:

/// On the bullet sprites
///(replace "bulletnumber" with the bullets number ie,1,2,3)
When I recieve firelazer
if bulletorder = "bullenumber"
go to spaceship
show
repeat until touching (edge) or (baddies) or (whatever else){
change y by 3}
/// Then after the repeat block
hide

end script.

It's really ok if a bullet just lies there until it is fired again you just have to hide it  tongue


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#7 2007-08-15 23:46:15

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

ha ha ha, that's exactly what i have in there right now, but what happens is that I will shoot my first bullet, then, say, it gets halfway up the screen and space gets pushed again.  The first bullet will stop halfway up the screen, right where it was on the second space bar push, and the second bullet will go upward like normal, unless i push the space again, then the same process occurs, and then once it comes back around, the first bullet will disappear and come out at the right spot, but will still stop on the next spacebar, if that makes any sense at all...

thanks,
C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#8 2007-08-16 00:22:48

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

I could solve your problems MUCH easier if you could post your project online  smile
Because in theory everything should work correctly, it's probably something you just over looked that is causing the problems.

Last edited by archmage (2007-08-16 00:25:46)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#9 2007-08-16 00:31:15

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Yeah, I understand, I think I might have gotten it figured out now changing to Mayhem's method...dunno what the problem was, but as long as it's fixed, I'm a happy camper...Thanks for all of your help, it really helped me understand what was going on and I enjoyed looking through your code.


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#10 2007-08-16 00:35:48

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

No problem, helping newbies out is what I like to do when I get bored of working on my own projects  tongue

PS: I think I understand what your problem was. Was it that the bullets try to execute their firing code while flying after being shot. If this was the case then the code should have been like this to prevent it from being fired while in motion.

First make a variable on each of the bullets and select for this sprite only. I will name my new variable fired.

/// On the bullet sprites
///(replace "bulletnumber" with the bullets number ie,1,2,3)
When I recieve firelazer
if bulletorder = "bullenumber" and "fired"=0
set "fired to 1"
go to spaceship
show
repeat until touching (edge) or (baddies) or (whatever else){
change y by 3}
/// Then after the repeat block
hide
set "fired to 0"

I took a look at mayhems and it has many unnecessary broadcast and global variables.

Last edited by archmage (2007-08-16 00:49:11)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#11 2007-08-16 00:46:28

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

ha ha, no worries, i'm just a newb to this language, i've already written this same program in VB6 along with several games in others, just this language has some funky things that don't work the way you'd think they would, but all in all i like it and it's new and less cumbersome than other languages.

C

by the way... http://scratch.mit.edu/projects/soccrplyer4life13/29492 should be the link to my project, i just have to keep working on the bullets from the aliens, but i'm almost done, just can't get the bullets to go away for good after the alien is dead


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#12 2007-08-16 00:58:24

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Maybe I will take a look back at it again this weekend and see if yours works, but at the moment, i'm just happy that something worked, lol, but again, i greatly appreciate all the help you've given me and hopefully i will have more projects to contribute shortly.

For now, I want to get the alien bullets working right, which i think i can use your local variable scheme for possibly, and i'll have the bullets speed up each level to increase the difficulty...i wish it would run smoother online, if you download, it's (IMO) the perfect speed and difficulty.

C

Last edited by soccrplyer4life13 (2007-08-16 00:59:54)


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#13 2007-08-16 07:42:41

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Multiple Bullets...

I don't think the broadcasts and global values in my method are unnecessary - it does something yours does not.

It always fires the first available bullet.  Looking at yours, it is possible for the bullet order and the available bullet to get out of synch (if bullet 2 hits an enemy whilst bullet 1 is still flying for example) then you might get missfires where "bulletorder" is changed to 1 but the bullet isn't available.

I deliberately set out to avoid that problem.

I used the code in the game "Starfighter X" and was also able to vary the amount of bullets available by changing the firing code rather than the bullet code.  In Starfighter X, you begin the game only able o fire one bullet at a time, but your firepower gradually increases until you can fire all 5.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#14 2007-08-16 11:48:53

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

@ soccrplyer4life13: Oh I think I know what was causing you problems.  I was programming in my firing method and for some inexplicable reason the shot froze. I think this was because when it received the shooting broadcast while being shot it would stop its firing script. I have never encounter this problem because I never used broadcasts to fire. Well since I guessed that broadcast could stop scripts I used when key space pressed. I think your many broadcasts may be the cause of your lag.

and @ mayhem: I improved your shooter demo. It functions pretty much the same way yours does except it has less global variables. As for the bullet order syncing in my defend your turf game it never went out of sync because of the timing on the bullets. However I know about your concern for the bullet order syncing and so I have altered your shooter demo to include bullet order syncing as well as I few other things. My altered project doesn't use broadcast at all to fire and has less global variables.

find it @ http://scratch.mit.edu/projects/archmage/29593
smile

Last edited by archmage (2007-08-16 12:45:04)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#15 2007-08-16 12:00:56

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

thanks again, i'm at work, but when i get home i'll try some different things and see if i can negate a few broadcasts and speed things up.

C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#16 2007-08-16 22:39:53

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

More questions for you guys...I have 12 bullets, one for each alien...they shoot fine and whatnot, but I can't, for the life of me, get them to stop shooting once the alien has been shot...they shoot in the code i have uploaded, and i've been trying to tweak it all evening, no luck...any help would be awesome...

http://scratch.mit.edu/projects/soccrplyer4life13/29492

C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#17 2007-08-16 22:58:37

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Never mind...I hope...when I get it posted, I'd really like it if anyone who reads this would test it for me to make sure I don't have any glaring bugs.

C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#18 2007-08-16 23:50:43

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Multiple Bullets...

I was looking through your project and its pretty huge and I have a hard time understanding it all. But anyways, what you need is a way for the alien's bullets to know if their ships have died. I think I have the solution. After the alien has died and is on  "hide"   set it's y coronate to 180 before you stop its script. And so, then when a alien bullet sprite goes to its homeship ONLY execute your shooting code if it's y coordinate is less than 170 after if goes to the ship. Therefore, if the alien ship is dead it's y coordinate should be 180 and when the ship's bullet goes to the ship and sees that it's y coordinate is greater than 170 it will not execute its firing code  smile

Last edited by archmage (2007-08-16 23:50:55)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#19 2007-08-17 00:02:01

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

I think I came up with a solution on my own, I'll need some other people to play it to know for sure, but we'll see how it goes, I should have it uploaded again shortly.  It's pretty big, and I need to clean it up a bit, but I like being thorough and making sure that everything works well...the main issue is that there's 5 levels, that's why it takes up so much space.

C


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#20 2007-08-17 15:56:40

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Multiple Bullets...

One way to do it is to have the bullets launched by a broadcast that comes from the alien, and that can only be broadcast if the alien is alive.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#21 2007-08-17 16:07:04

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

I understand your method, but wouldn't that slow the game down even further because of more broadcasts? at this point all i need to do is try and optimize the code to make things run faster.


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

#22 2007-08-17 17:18:52

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Multiple Bullets...

Broadcasts are not very expensive.  They are often a cleaner, faster way to communicate than setting and testing variables.

Offline

 

#23 2007-08-17 17:20:34

soccrplyer4life13
Scratcher
Registered: 2007-07-28
Posts: 77

Re: Multiple Bullets...

Feel free to try and tweak my game, I don't doubt that there are better ways to do what I did, I just wanted to get a finished product out there for everyone to see...(not that very many people are viewing it though)


My Projects:
http://scratch.mit.edu/users/soccrplyer4life13

Offline

 

Board footer