Friday
This commit is contained in:
BIN
images/dead.png
Normal file
BIN
images/dead.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 145 KiB |
BIN
images/dino.png
Normal file
BIN
images/dino.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
68
main.py
68
main.py
@@ -19,24 +19,62 @@ min_spawn_interval = 0.2
|
|||||||
spawn_timer = 0
|
spawn_timer = 0
|
||||||
game_time = 0
|
game_time = 0
|
||||||
|
|
||||||
def draw():
|
|
||||||
screen.fill((100,220,100))
|
|
||||||
apple.draw()
|
|
||||||
|
|
||||||
def spawn_dinosaur():
|
|
||||||
dino = Actor("dino")
|
|
||||||
|
|
||||||
|
def spawn_dinosaurs():
|
||||||
|
dino = Actor("dino")
|
||||||
|
|
||||||
side = random.randint(0,3)
|
side = random.randint(0,3)
|
||||||
if side == 0:
|
if side == 0: #up
|
||||||
dino_x = random.randint(0.WIDTH)
|
dino.x = random.randint(2,WIDTH)
|
||||||
dino_y = -50
|
dino.y = -50
|
||||||
elif side == 1:
|
elif side == 1: #down
|
||||||
dino_x = random.randint(0,WIDTH)
|
dino.x = random.randint(0,WIDTH)
|
||||||
dino_y = HEIGHT + 50
|
dino.y = HEIGHT + 50
|
||||||
elif side == 2:
|
elif side == 2: #left
|
||||||
dino_x = WIDTH + 50
|
dino.x = -50
|
||||||
dino_y = random.randint(0,HEIGHT)
|
dino.y = random.randint(0,HEIGHT)
|
||||||
|
else:
|
||||||
|
dino.x = WIDTH + 50
|
||||||
|
dino.y = random.randint(0,HEIGHT)
|
||||||
dinosuars.append(dino)
|
dinosuars.append(dino)
|
||||||
|
|
||||||
|
def update(dt):
|
||||||
|
global spawn_timer , spawn_interval , game_time
|
||||||
|
game_time += dt
|
||||||
|
spawn_timer += dt
|
||||||
|
|
||||||
|
spawn_interval = max(min_spawn_interval , spawn_interval - 0.005 * dt)
|
||||||
|
|
||||||
|
if spawn_timer >= spawn_interval:
|
||||||
|
spawn_dinosaurs()
|
||||||
|
spawn_timer = 0
|
||||||
|
|
||||||
|
sword.pos = mouse.pos
|
||||||
|
|
||||||
|
for dino in dinosuars[:]:
|
||||||
|
dx = apple_x - dino.x
|
||||||
|
dy = apple_y - dino.y
|
||||||
|
speed = 80
|
||||||
|
dino.x += dx * speed * dt
|
||||||
|
dino.y += dy * speed * dt
|
||||||
|
|
||||||
|
if dino.colliderect(sword):
|
||||||
|
dino.image = "dead"
|
||||||
|
corpses.append({"Actor":dino,"die_time": game_time})
|
||||||
|
sounds.hit.play()
|
||||||
|
dinosuars.remove(dino)
|
||||||
|
|
||||||
|
for corpse in corpses[:]:
|
||||||
|
if game_time - corpse["die_time"] >= 2:
|
||||||
|
corpses.remove(corpse)
|
||||||
|
|
||||||
|
def draw():
|
||||||
|
screen.fill((100,200,100))
|
||||||
|
apple.draw()
|
||||||
|
sword.draw()
|
||||||
|
for dino in dinosuars:
|
||||||
|
dino.draw()
|
||||||
|
for corpse in corpses:
|
||||||
|
corpse["Actor"].draw()
|
||||||
|
|
||||||
pgzrun.go()
|
pgzrun.go()
|
||||||
Reference in New Issue
Block a user