2

I'm trying to make a game similar to Galaga using pygame. As a new feature I wanted to add a "booster feature" where you can go faster (move the spaceship faster) every few seconds (maybe every 5-10 seconds for 3 seconds). The problem is I'm not sure how to do this. I fear I am trying to do something too complex for a beginner. Right now I have the boosting feature implemented, but I don't know how to create a time. I thought maybe I could use a while loop and say something like while x < time "boost." Here is my code for the boosting itself. Also I tried looking this up and didn't quite understand some of the code or didn't find anything that related to what I'm trying to do. Thanks in advance guys! Let me know if something I said is confusing.

Boosting Code:

    if pygame.key.get_mods() and pygame.KMOD_SHIFT: # need to add timer (can't boost forever)
        if pygame.K_LEFT in keys:
            ship.x -= 15
        if pygame.K_RIGHT in keys:
            ship.x += 15
        if pygame.K_UP in keys:
            ship.y -= 15
        if pygame.K_DOWN in keys:
            ship.y += 15
Gitau Harrison
  • 3,179
  • 1
  • 19
  • 23
bob jones
  • 21
  • 2
  • Why not use [`pygame.time`](https://www.pygame.org/docs/ref/time.html)? – Random Davis Nov 09 '20 at 23:39
  • Okay I'll look into that more. Thanks! – bob jones Nov 10 '20 at 01:23
  • I'm still confused on how to exactly implement that. Any pointers? – bob jones Nov 10 '20 at 03:46
  • If that's proving to be beyond your comprehension, even given the massive amount of examples of the various uses of that part of the library online, it seems like you should start with something more basic in order to build up your Python knowledge to the point where this isn't so challenging. – Random Davis Nov 10 '20 at 16:32

0 Answers0