add images
This commit is contained in:
BIN
images/dino.png
BIN
images/dino.png
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 2.5 KiB |
BIN
images/dino2.png
Normal file
BIN
images/dino2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
images/sword.png
BIN
images/sword.png
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 970 B |
11
main.py
11
main.py
@@ -19,7 +19,10 @@ min_spawn_interval = 0.2
|
|||||||
spawn_timer = 0
|
spawn_timer = 0
|
||||||
game_time = 0
|
game_time = 0
|
||||||
|
|
||||||
|
def on_mouse_mmove(pso , rel , buttons):
|
||||||
|
sword.x = pos[0]
|
||||||
|
sword.y = pos[1]
|
||||||
|
|
||||||
def spawn_dinosaurs():
|
def spawn_dinosaurs():
|
||||||
dino = Actor("dino")
|
dino = Actor("dino")
|
||||||
|
|
||||||
@@ -48,9 +51,7 @@ def update(dt):
|
|||||||
if spawn_timer >= spawn_interval:
|
if spawn_timer >= spawn_interval:
|
||||||
spawn_dinosaurs()
|
spawn_dinosaurs()
|
||||||
spawn_timer = 0
|
spawn_timer = 0
|
||||||
|
|
||||||
sword.pos = mouse.pos
|
|
||||||
|
|
||||||
for dino in dinosuars[:]:
|
for dino in dinosuars[:]:
|
||||||
dx = apple_x - dino.x
|
dx = apple_x - dino.x
|
||||||
dy = apple_y - dino.y
|
dy = apple_y - dino.y
|
||||||
@@ -61,7 +62,7 @@ def update(dt):
|
|||||||
if dino.colliderect(sword):
|
if dino.colliderect(sword):
|
||||||
dino.image = "dead"
|
dino.image = "dead"
|
||||||
corpses.append({"Actor":dino,"die_time": game_time})
|
corpses.append({"Actor":dino,"die_time": game_time})
|
||||||
sounds.hit.play()
|
sounds.hit.play(hit.mp3)
|
||||||
dinosuars.remove(dino)
|
dinosuars.remove(dino)
|
||||||
|
|
||||||
for corpse in corpses[:]:
|
for corpse in corpses[:]:
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import pgzrun
|
|
||||||
|
|
||||||
WIDTH = 800
|
|
||||||
HEIGHT = 600
|
|
||||||
|
|
||||||
ship = Actor('dead8')
|
|
||||||
ship.x = 370
|
|
||||||
ship.y = 550
|
|
||||||
|
|
||||||
def update():
|
|
||||||
if keyboard.left:
|
|
||||||
ship.x = ship.x - 5
|
|
||||||
if keyboard.right:
|
|
||||||
ship.x = ship.x + 5
|
|
||||||
|
|
||||||
def draw():
|
|
||||||
screen.fill((80,0,70))
|
|
||||||
ship.draw()
|
|
||||||
|
|
||||||
pgzrun.go() # Must be last line
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import pgzrun
|
|
||||||
|
|
||||||
WIDTH = 800
|
|
||||||
HEIGHT = 600
|
|
||||||
|
|
||||||
ship = Actor('dead8')
|
|
||||||
ship.x = 370
|
|
||||||
ship.y = 550
|
|
||||||
|
|
||||||
def update():
|
|
||||||
if keyboard.left:
|
|
||||||
ship.x = ship.x - 5
|
|
||||||
if keyboard.right:
|
|
||||||
ship.x = ship.x + 5
|
|
||||||
|
|
||||||
def draw():
|
|
||||||
screen.fill((80,0,70))
|
|
||||||
ship.draw()
|
|
||||||
|
|
||||||
pgzrun.go() # Must be last line
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import pgzrun
|
|
||||||
import random
|
|
||||||
|
|
||||||
#background
|
|
||||||
WIDTH = 600
|
|
||||||
HEIGHT = 200
|
|
||||||
def draw():
|
|
||||||
screen.fill((80,0,70))
|
|
||||||
|
|
||||||
#colour
|
|
||||||
WHITE = (255,255,255)
|
|
||||||
BLACK = (0,0,0)
|
|
||||||
|
|
||||||
clock = pgzrun.time.Clock()
|
|
||||||
FPS = 60
|
|
||||||
gravity = 0.8
|
|
||||||
jump_vel = -16
|
|
||||||
is_jump = False
|
|
||||||
|
|
||||||
#dinosaur
|
|
||||||
dino_x = 50
|
|
||||||
dino_y = 140
|
|
||||||
dino_y_vel = 0
|
|
||||||
is_jump = False
|
|
||||||
|
|
||||||
#bairies
|
|
||||||
cactus_list = []
|
|
||||||
cactus_speed = 6
|
|
||||||
spawn_timer = 0
|
|
||||||
|
|
||||||
#game condition
|
|
||||||
game_over = False
|
|
||||||
score = 0
|
|
||||||
font = pgzrun.font.SysFont(None,30)
|
|
||||||
|
|
||||||
#main loop
|
|
||||||
running = True
|
|
||||||
while running:
|
|
||||||
clock.tick(FPS)
|
|
||||||
screen.fill(WHITE)
|
|
||||||
|
|
||||||
for event in pgzrun.event.get():
|
|
||||||
if event.type == pgzrun.QUIT:
|
|
||||||
running = False
|
|
||||||
if event.type == pgzrun.KEYKNOWN:
|
|
||||||
if event.key == pgzrun.K_SPACE and not is_jump and not game_over:
|
|
||||||
dino_y_vel = jump_vel
|
|
||||||
is_jump = True
|
|
||||||
#restart the game
|
|
||||||
if event.key == pgzrun.K_SPACE and game_over:
|
|
||||||
game_over = False
|
|
||||||
score = 0
|
|
||||||
cactus_list.clear()
|
|
||||||
dino_y = 140
|
|
||||||
dino_y_vel = 0
|
|
||||||
|
|
||||||
if not game_over:
|
|
||||||
dino_y_vel += gravity
|
|
||||||
dino_y += dino_y_vel
|
|
||||||
|
|
||||||
if dino_y >= 140:
|
|
||||||
dino_y = 140
|
|
||||||
dino_y_vel = 0
|
|
||||||
is_jump = False
|
|
||||||
|
|
||||||
#produce bairy
|
|
||||||
spawn_timer += 1
|
|
||||||
if spawn_timer > 80:
|
|
||||||
cactus_x = WIDTH
|
|
||||||
cactus_y = 150
|
|
||||||
cactus_list.append([cactus_x , cactus_y])
|
|
||||||
spawn_timer = random.randint(40,80)
|
|
||||||
|
|
||||||
#movement of cactus+ score
|
|
||||||
for cactus in cactus_list:
|
|
||||||
cactus[0] -= cactus_speed
|
|
||||||
score += 0.1
|
|
||||||
|
|
||||||
cactus_list = [c for c in cactus_list if c[0] > -20]
|
|
||||||
|
|
||||||
#checking touches
|
|
||||||
dino_rect = pgzrun.Rect(dino_x , dino_y , 30,40)
|
|
||||||
for cactus in cactus_list:
|
|
||||||
cactus_rect = pgzrun.Rect(cactus[0],cactus[1],20,30)
|
|
||||||
if dino_rect.colliderect(cactus_list):
|
|
||||||
game_over = True
|
|
||||||
|
|
||||||
#draw dinosaur
|
|
||||||
pgzrun.draw.rect(screen,BLACK,(dino_x,dino_y,30,40))
|
|
||||||
|
|
||||||
#draw cactus
|
|
||||||
for c in cactus_list:
|
|
||||||
pgzrun.draw.rect(screen,BLACK,(c[0],c[1],20,30))
|
|
||||||
|
|
||||||
#draw horizon
|
|
||||||
pgzrun.draw.line(screen,BLACK,(0,180),(WIDTH,180),2)
|
|
||||||
|
|
||||||
#draw score
|
|
||||||
score_text = font.render(f"Score: {int(score)}" ,True,BLACK)
|
|
||||||
screen.blit(score_text,(450,20))
|
|
||||||
|
|
||||||
#notice of game over
|
|
||||||
if game_over:
|
|
||||||
over_text = font.render("Game Over! Press SPACE to restart", True,BLACK)
|
|
||||||
screen.blit(over_text,(120,80))
|
|
||||||
|
|
||||||
pgzrun.display.update()
|
|
||||||
|
|
||||||
pgzrun.go()
|
|
||||||
BIN
sounds/hit.mp3
Normal file
BIN
sounds/hit.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user