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
Offline
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
Offline
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
Offline
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.
Offline
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
Offline
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
Offline
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
Offline
I could solve your problems MUCH easier if you could post your project online
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)
Offline
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.
Offline
No problem, helping newbies out is what I like to do when I get bored of working on my own projects
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)
Offline
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
Offline
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)
Offline
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.
Offline
@ 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
Last edited by archmage (2007-08-16 12:45:04)
Offline
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
Offline
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
Offline
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
Offline
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
Last edited by archmage (2007-08-16 23:50:55)
Offline
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
Offline
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.
Offline
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.
Offline
Broadcasts are not very expensive. They are often a cleaner, faster way to communicate than setting and testing variables.
Offline
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)
Offline