Update main.py
This commit is contained in:
34
main.py
34
main.py
@@ -1,4 +1,5 @@
|
|||||||
import pgzrun
|
import pgzrun
|
||||||
|
import random
|
||||||
|
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
HEIGHT = 600
|
HEIGHT = 600
|
||||||
@@ -7,13 +8,40 @@ ship = Actor('playership1_blue')
|
|||||||
ship.x = 370
|
ship.x = 370
|
||||||
ship.y = 550
|
ship.y = 550
|
||||||
|
|
||||||
|
gem = Actor('dead__009')
|
||||||
|
gem.x = random.randint(20, 780)
|
||||||
|
gem.y = 0
|
||||||
|
|
||||||
|
score = 0
|
||||||
|
game_over = False
|
||||||
|
|
||||||
|
def on_mouse_move(pos, rel, buttons):
|
||||||
|
ship.x = pos[0]
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
global score, game_over
|
||||||
|
|
||||||
if keyboard.left:
|
if keyboard.left:
|
||||||
ship.x = ship.x - 5
|
ship.x = ship.x - 10
|
||||||
if keyboard.right:
|
if keyboard.right:
|
||||||
ship.x = ship.x + 5
|
ship.x = ship.x + 10
|
||||||
|
|
||||||
|
gem.y = gem.y + 4 + score / 5
|
||||||
|
if gem.y > 600:
|
||||||
|
game_over = True
|
||||||
|
if gem.colliderect(ship):
|
||||||
|
gem.x = random.randint(20, 780)
|
||||||
|
gem.y = 0
|
||||||
|
score = score + 1
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
ship.draw()
|
screen.fill((80,0,70))
|
||||||
|
if game_over:
|
||||||
|
screen.draw.text('Game Over', (360, 300), color=(255,255,255), fontsize=60)
|
||||||
|
screen.draw.text('Score: ' + str(score), (360, 350), color=(255,255,255), fontsize=60)
|
||||||
|
else:
|
||||||
|
gem.draw()
|
||||||
|
ship.draw()
|
||||||
|
screen.draw.text('Score: ' + str(score), (15,10), color=(255,255,255), fontsize=30)
|
||||||
|
|
||||||
pgzrun.go() # Must be last line
|
pgzrun.go() # Must be last line
|
||||||
Reference in New Issue
Block a user