Single shot ?
Blitz3D Forums/Blitz3D Beginners Area/Single shot ?
| ||
How can i get just one grenade to fire at a time I need it to wait for the first grenade to delete before i can fire a second grenade Thanks destroyer :) |
| ||
Change your creation code for grenade to this:If MouseHit(1) g.grenade = First grenade If g = Null Then g.grenade = New grenade g\x = gunendx : g\y = gunendy g\ang= ATan2(MouseX()-g\x,MouseY()-g\y) g\speed=4+me\speed g\life=100 g\ammo=1 EndIf End If (and delete the global g.grenade = new grenade line, it is not needed...) Basically it just sets g.grenade to the last grenade of the type, and if there is no grenade in that spot, then there are no grenades on screen. Alternatively, you could just use a global number of grenades, and then incriment it when you create a gernade and decrement it when you delete a grenade, and then check to see how many grenades are present before creating. |
| ||
Thanks mindstorms works spot on :) I did'nt know about the First type_variable. Pays to read the manual lol Thanks Destroyer :) |
| ||
Ok a new problem :) How can i get the enemy to respawn every new level? I start off with 2 enemy's and start on level 1. I would like to increase the amount of enemy by 2 every new level. Thanks Destroyer :) |
| ||
Just put a function like this:Function create_enemies(numb) For i=1 To numb en.enemy=New enemy en\enx=Rand(0,800) en\eny=Rand(0,600) en\img=CreateImage(9,9) en\hp=100 SetBuffer ImageBuffer(en\img) Color 255,100,100 Oval 0,0,8,8 MidHandle en\img SetBuffer BackBuffer() Next End Function then call it when the number of enemies is 0, with the level times two as the number of enemies to create |
| ||
Thanks again Mindstorms. Will add that function. Thanks Destroyer :) |
| ||
On second thought, It would probably be better to create a base image at the beginning of the program, then copy it in the create enemy function |
| ||
This is what i have so far. Things seem to be working well apart from the enemy fire, but its late so ill try again tomorrow Thanks Destroyer |
| ||
If I were you I would go through your code and make it more efficient and easy to read (like using just the function to create enemies instead of three different times, or not drawing the enemy image to the new enemy everytime, but copy the image from a base image created at the beginning.) In other words, delete duplicated code and try to make it run more efficiently... |
| ||
[codebox] |
| ||
Thanks Octothorpe and Mindstorms for the tips Thanks Destroyer :) |