- import pgzrun
- from random import randint
- WIDTH = 1000
- HEIGHT = 1000
- score = 0
- game_over = False
- pikachu = Actor("pikachu")
- pikachu.pos = 100,100
- ball = Actor("Ball")
- ball.pos = 200,200
- screen.draw.text("Score: " + Str(Score), color = "black", topleft = (10,10))
- if game_over:
- screen.fill("hotpink")
- screen.draw.text("30 seconds is up! GAME OVER", topleft = (10,10), fontsize = 40)
- screen.draw.text("Your score is "+str(Score), color = "black", topleft = 10,70, fontsize = 40)
- def place_ball():
- ball.x = randint(10, (WIDTH-150))
- ball.y = randint(10, (HEIGHT-150))
- def TimeUp():
- global game_over
- game_over = True
- place_ball()
- def update():
- global score
- ball_collected = pikachu.colliderect(ball)
- steps = 5
- if keyboard.up:
- pikachu.y -= steps
- if keyboard.down:
- pikachu.y += steps
- if keyboard.left:
- pikachu.x -= steps
- if keyboard.right:
- pikachu.x += steps
- if ball_collected:
- score += 1
- place_ball()
- clock.schedule(TimeUp,30.0)
- place_ball()
- pgzrun.go
Raw Paste