Log In  

Hi all!

I am trying to implement a very small and simple clone of space invaders.

I am thinking how to implement a nice shoot bullet function but I am struggling with picturing a way to shoot bullets in a nice stream that is always steady so that its pace can be increased picking up right power-ups.

I tried, for example, to count maximum number of bullets on screen and shoot only if < than 5 but when the player shoots, clearly, all the bullets are shot almost at the same time.
Then I thought about storing the bullet starting point and comparing it to the next bullet but since my ship goes also forward and back this way is also wrong...

Can you please suggest me some idea to remove this nasty wall? :)

Thanks for your kind help!

Ps
In case it can be helpful here's the code so far:
https://raw.githubusercontent.com/ltpitt/lua-pico-8-invaders/master/pico-8-invaders.p8

P#83089 2020-10-18 22:06

you could use some kind of cooldown timer, for instance along those lines:

gun_timer = 0
gun_cooldown = 10 -- 1 bullet every 10 frames

function update() 
  ...
  if (gun_timer>0) gun_timer-=1
  ...
end

function shoot()
  ...
  if (gun_timer==0) then
    spawn_a_bullet()
    gun_timer = gun_cooldown
  end
  ...
end
P#83093 2020-10-18 23:05

Worked like a charm! :D

Super-duper-thanks :)

P#83189 2020-10-21 15:34

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 13:21:02 | 0.015s | Q:9