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:

  1. can't shoot power picked -> that's done
  2. block mouse buttons
  3. wait 3 seconds, while rest of game still running
  4. 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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -