Hello! I have a bit of a query. I'm making a space invaders type game and iv'e got one bullet firing from my ship but when i press the fire button (Z) repeatedly the bullet shoots comes back and then shoots again. What I need to know is how to make it so I can fire one bullet then fire another straight away without the first one coming back. Here is my code:
stage:addEventListener(Event.KEY_DOWN,function(e)
if e.keyCode==KeyCode.LEFT then
left=true
playerDir=-1
elseif e.keyCode==KeyCode.RIGHT then
right=true
playerDir=1
elseif e.keyCode==KeyCode.Z then
print("fire")
bx,by=playership1:getPosition()
bullet:setPosition(bx,by)
bDir=-1
end
end)
I've been told I need to use an array but I am pretty in experienced with gideros. If you could help and tell me what to do I would really appreciate it.
Thanks for your support!
Comments
I think that you have only one instance of bullet at a time, so everytime you press Z you reset its position.
You can use an array to keep track of your bullets: every lua table is an array. You just need to name each bullet with a unique name (you could use a counter, or os.timer() ) and then you can "access" the bullet (as long as you can access the table that contains it).
assuming that somewhere before you placed a "bullets" array and a counter,
However, have you noticed this raw space invader clone by SinisterSoft? it may give you some hints or ideas http://giderosmobile.com/forum/discussion/5615/space-invader-clone/p1
Likes: SinisterSoft
Edit: @pie must have hit enter before me. He provided much more detail than me too.
Likes: SinisterSoft
Thanks!
BTW I checked out the sinister soft thing and it turns out the person who runs sinister soft is the person who often helps me with coding. his son goes to the same school as me and we are quite close friends.
Likes: SinisterSoft
(Everyone else: Thanks for helping 'Minstrel', he is new to Gideros and I know that any help you have given will be greatly appreciated. )
https://deluxepixel.com
Firstly you can create a separate class only for that, that you may reuse it for other purposes. This sprite (class) must have initial x and y (kick off positions). And you manage its movement inside an enter_frame event, like:
in the objects that will 'fire' you can create specific 'shoot' behaviours.
Nevermind it may help others
Likes: antix, SinisterSoft