added gameover
This commit is contained in:
parent
4281545f3c
commit
2bd9fec9f9
BIN
assets/Horse.png
Normal file
BIN
assets/Horse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 869 B |
BIN
assets/Horse.xcf
Normal file
BIN
assets/Horse.xcf
Normal file
Binary file not shown.
BIN
assets/Horse2.png
Normal file
BIN
assets/Horse2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 996 B |
BIN
assets/blood.png
Normal file
BIN
assets/blood.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 906 B |
BIN
assets/blood.xcf
Normal file
BIN
assets/blood.xcf
Normal file
Binary file not shown.
BIN
assets/gameover.png
Normal file
BIN
assets/gameover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 934 KiB |
BIN
assets/gameover.xcf
Normal file
BIN
assets/gameover.xcf
Normal file
Binary file not shown.
BIN
assets/pnj/knight.png
Normal file
BIN
assets/pnj/knight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
47
game.py
47
game.py
@ -77,11 +77,14 @@ class Pnj:
|
||||
self.direction = direction
|
||||
self.objectif = objectif
|
||||
self.speed = speed
|
||||
self.alive = True
|
||||
|
||||
def avance(self):
|
||||
'''
|
||||
Vérifie que l'objectif n'est pas atteint et avance le pnj dans la direction
|
||||
'''
|
||||
if not self.alive:
|
||||
return
|
||||
if self.check_objectif():
|
||||
return
|
||||
else:
|
||||
@ -128,6 +131,15 @@ class Pnj:
|
||||
return True
|
||||
return False
|
||||
|
||||
def kill(self):
|
||||
self.sprite = pygame.transform.scale_by(pygame.image.load("assets/blood.png"), 3.0)
|
||||
self.alive = False
|
||||
player.killcounter += 1
|
||||
if player.killcounter == game.pnj_number:
|
||||
village.final_boss()
|
||||
elif player.killcounter >= game.pnj_number+8:
|
||||
game.game_over()
|
||||
|
||||
class Village:
|
||||
def __init__(self, nb_pnj: int) -> None:
|
||||
self.liste_pnj = []
|
||||
@ -149,6 +161,19 @@ class Village:
|
||||
village_sprites.append((p.x, p.y, p.sprite))
|
||||
return village_sprites
|
||||
|
||||
def check_kill(self)->None:
|
||||
player_rect = pygame.Rect(player.x-50, player.y-50, 100, 100)
|
||||
for p in self.liste_pnj:
|
||||
if p.alive and player_rect.collidepoint(p.x, p.y):
|
||||
p.kill()
|
||||
|
||||
def final_boss(self)->None:
|
||||
for i in ("A", "B", "C", "D", "E", "F", "G", "H"):
|
||||
start_waypoint = Waypoint(i)
|
||||
objective_waypoint = start_waypoint.get_new_connected()
|
||||
self.liste_pnj.append(Pnj(start_waypoint.x, start_waypoint.y, "assets/pnj/knight.png", start_waypoint.get_direction(start_waypoint, objective_waypoint), objective_waypoint, 10))
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self)-> None:
|
||||
self.x = 800
|
||||
@ -156,6 +181,7 @@ class Player:
|
||||
self.mov_speed = 8
|
||||
self.rotate_speed = 5
|
||||
self.angle = 90
|
||||
self.killcounter = 0
|
||||
|
||||
def rotate(self, angle: math.degrees)-> None:
|
||||
self.angle += angle*self.rotate_speed
|
||||
@ -170,17 +196,19 @@ class Player:
|
||||
self.y = new_y
|
||||
elif(game.test_collision(pygame.Rect(new_x-50, self.y-50, 100, 100), game.collisions) == False):
|
||||
self.x = new_x
|
||||
village.check_kill()
|
||||
|
||||
class Game:
|
||||
def __init__(self):
|
||||
self.is_paused = False
|
||||
self.pnj_number = 5
|
||||
pygame.font.init()
|
||||
self.font = pygame.font.SysFont('Comic Sans MS', 30)
|
||||
self.load_sprites()
|
||||
self.load_collisions()
|
||||
|
||||
def load_sprites(self):
|
||||
self.perso_sprite = pygame.image.load("assets/perso_sprite.png")
|
||||
self.perso_sprite = pygame.image.load("assets/Horse2.png")
|
||||
self.map_sprite = pygame.image.load("assets/map3.png")
|
||||
|
||||
def load_collisions(self):
|
||||
@ -200,9 +228,11 @@ class Game:
|
||||
angle_surface = self.font.render("angle: "+str(player.angle), False, (0, 0, 0))
|
||||
x_surface = self.font.render("x: "+str(player.x), False, (0, 0, 0))
|
||||
y_surface = self.font.render("y: "+str(player.y), False, (0, 0, 0))
|
||||
kill_surface = self.font.render("kills: "+str(player.killcounter), False, (0, 0, 0))
|
||||
screen.blit(angle_surface, (0,0))
|
||||
screen.blit(x_surface, (0,30))
|
||||
screen.blit(y_surface, (0,60))
|
||||
screen.blit(kill_surface, (0,90))
|
||||
#pygame.draw.rect(screen, "blue",pygame.Rect(player.x-50, player.y-50, 100, 100))
|
||||
|
||||
def check_input(self):
|
||||
@ -218,7 +248,7 @@ class Game:
|
||||
|
||||
def draw_player(self):
|
||||
#pygame.draw.rect(screen, "red", pygame.Rect(player.x, player.y, 50, 50))
|
||||
img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 0.2)
|
||||
img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 1)
|
||||
screen.blit(img, (540-img.get_rect().centerx, 360-img.get_rect().centery))
|
||||
|
||||
def draw_village(self):
|
||||
@ -227,7 +257,7 @@ class Game:
|
||||
|
||||
def display_all(self):
|
||||
# fill the screen with a color to wipe away anything from last frame
|
||||
screen.fill("purple")
|
||||
screen.fill("gray")
|
||||
screen.blit(self.map_sprite, (540-player.x, 360-player.y))
|
||||
|
||||
self.draw_village()
|
||||
@ -239,10 +269,19 @@ class Game:
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
||||
def game_over(self)->None:
|
||||
screen.blit(pygame.image.load("assets/gameover.png"), (0,0))
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
exit()
|
||||
|
||||
player = Player()
|
||||
game = Game()
|
||||
#pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"), 3)
|
||||
village = Village(20)
|
||||
village = Village(game.pnj_number)
|
||||
|
||||
while running:
|
||||
# poll for events
|
||||
|
Loading…
Reference in New Issue
Block a user