import pgzrun
import random
# constants
WIDTH = 800
HEIGHT = 600
# initialise score
score = 0
# store image inside image folder in the same directory
#ship = Actor(‘playership1_red’)
ship = Actor(‘playerflacon3_white’)
ship.x = 400
ship.y = 500
gem = Actor(‘gemyellow’)
gem.x = 400
gem.y = 100
def update():
global score
if keyboard.left:
if ship.x <= 15: #detects if ship has reached left side of screen
ship.x = 15
ship.x = ship.x – 5
if keyboard.right:
if ship.x >= 785: #detects if ship has reached right side of screen
ship.x = 785
ship.x = ship.x + 5
if keyboard.up:
if ship.y <= 0: #detects if ship has reached the top of screen
ship.y = 15
ship.y = ship.y – 5
if keyboard.down:
if ship.y >= 600: #detects if ship has reached the bottom of screen
ship.y = 600
ship.y = ship.y + 5
gem.y = gem.y + 4
if gem.y > 600:
gem.y = 0
if gem.colliderect(ship):
gem.x = random.randint(20, 780)
gem.y = 0
score = score + 10
def draw ():
screen.clear()
ship.draw()
enemy.draw()
gem.draw()
screen.draw.text(‘Score: ‘ + str(score), (15,10), color=(255,255,255), fontsize=30)
pgzrun.go() # Must be last line