Added spaceship
This commit is contained in:
BIN
images/gemgreen.png
Normal file
BIN
images/gemgreen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
images/playership1_blue.png
Normal file
BIN
images/playership1_blue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
29
main.py
29
main.py
@@ -1,6 +1,35 @@
|
|||||||
import pgzrun
|
import pgzrun
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
HEIGHT = 600
|
HEIGHT = 600
|
||||||
|
|
||||||
|
ship = Actor('playership1_blue')
|
||||||
|
ship.x = 370
|
||||||
|
ship.y = 550
|
||||||
|
|
||||||
|
gem = Actor('gemgreen')
|
||||||
|
gem.x = random.randint(20, 780)
|
||||||
|
gem.y = 0
|
||||||
|
|
||||||
|
def update():
|
||||||
|
if keyboard.left:
|
||||||
|
ship.x = ship.x - 5
|
||||||
|
if keyboard.right:
|
||||||
|
ship.x = ship.x + 5
|
||||||
|
|
||||||
|
gem.y = gem.y + 4
|
||||||
|
if gem.y > 600:
|
||||||
|
gem.x = random.randint(20, 780)
|
||||||
|
gem.y = 0
|
||||||
|
if gem.colliderect(ship):
|
||||||
|
gem.x = random.randint(20, 780)
|
||||||
|
gem.y = 0
|
||||||
|
|
||||||
|
def draw():
|
||||||
|
screen.fill((80,0,70))
|
||||||
|
gem.draw()
|
||||||
|
ship.draw()
|
||||||
|
|
||||||
pgzrun.go() # Must be last line
|
pgzrun.go() # Must be last line
|
||||||
Reference in New Issue
Block a user