python - Pygame - Run event for 3 seconds only once -
i new pygame , creating space shooter game. part of game powerups , when specific powerup picked player, want player not able shoot 3 seconds. shooting done mouse click.
i can pick powerup, know powerup player last picked up, struggling event. how thinking of implementing is:
- can't shoot power picked -> that's done
- block mouse buttons
- wait 3 seconds, while rest of game still running
- unblock mouse buttons.
i aware python functions, such wait, won't help.
any ideas/suggestions? thanks
when call clock.tick()
returns time since last call. save time: dt = clock.tick()
, use variable count down seconds.
example:
dt = clock.tick() # call once per iteration if attack_blocked: attack_block_count += dt if attack_block_count >= 3000: # dt in ms attack_blocked = false
example 2:
while true: dt = clock.tick(60) event.... if block_attack_power_up: attack_blocked = true attack_block_count = 0 if not attack_blocked: # attack if attack_blocked: attack_block_count += dt if attack_block_count >= 3000: attack_blocked = false
Comments
Post a Comment