TEXT   14
123
Guest on 17th September 2023 03:09:22 AM


  1. import pgzrun
  2. from random import randint
  3.  
  4. WIDTH = 1000
  5. HEIGHT = 1000
  6.  
  7. score = 0
  8.  
  9. game_over = False
  10.  
  11. pikachu = Actor("pikachu")
  12.  
  13. pikachu.pos = 100,100
  14.  
  15.  
  16. ball = Actor("Ball")
  17. ball.pos = 200,200
  18.  
  19. screen.draw.text("Score: " + Str(Score), color = "black", topleft = (10,10))
  20.  
  21. if game_over:
  22.     screen.fill("hotpink")
  23.     screen.draw.text("30 seconds is up! GAME OVER", topleft = (10,10), fontsize = 40)
  24.     screen.draw.text("Your score is "+str(Score), color = "black", topleft = 10,70, fontsize = 40)
  25.  
  26. def place_ball():
  27.     ball.x = randint(10, (WIDTH-150))
  28.     ball.y = randint(10, (HEIGHT-150))
  29.  
  30. def TimeUp():
  31.     global game_over
  32.     game_over = True
  33.  
  34. place_ball()
  35.  
  36. def update():
  37.     global score
  38.     ball_collected = pikachu.colliderect(ball)
  39.     steps = 5
  40.  
  41.     if keyboard.up:
  42.         pikachu.y -= steps
  43.  
  44.     if keyboard.down:
  45.         pikachu.y += steps
  46.  
  47.     if keyboard.left:
  48.         pikachu.x -= steps
  49.        
  50.     if keyboard.right:
  51.         pikachu.x += steps
  52.  
  53.     if ball_collected:
  54.         score += 1
  55.         place_ball()
  56.    
  57. clock.schedule(TimeUp,30.0)
  58. place_ball()
  59. pgzrun.go

Raw Paste

Login or Register to edit or fork this paste. It's free.