added some pnj walking around
This commit is contained in:
parent
5e34471405
commit
093e054aaf
41
game.py
41
game.py
@ -69,15 +69,14 @@ class Waypoint:
|
||||
else:
|
||||
raise Exception("crash: POINT A and B impossible")
|
||||
|
||||
|
||||
class Pnj:
|
||||
def __init__(self, x: int, y: int, sprite_path: str, direction: str, objectif: Waypoint) -> None:
|
||||
def __init__(self, x: int, y: int, sprite_path: str, direction: str, objectif: Waypoint, speed: int) -> None:
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.sprite = pygame.transform.scale_by(pygame.image.load(sprite_path), 3.0)
|
||||
self.direction = direction
|
||||
self.objectif = objectif
|
||||
self.speed = 6
|
||||
self.speed = speed
|
||||
|
||||
def avance(self):
|
||||
'''
|
||||
@ -129,6 +128,27 @@ class Pnj:
|
||||
return True
|
||||
return False
|
||||
|
||||
class Village:
|
||||
def __init__(self, nb_pnj: int) -> None:
|
||||
self.liste_pnj = []
|
||||
for i in range(nb_pnj):
|
||||
start_waypoint = Waypoint(random.choice(("A", "B", "C", "D", "E", "F", "G", "H")))
|
||||
objective_waypoint = start_waypoint.get_new_connected()
|
||||
self.liste_pnj.append(Pnj(start_waypoint.x, start_waypoint.y, "assets/MiniPeasant.png", start_waypoint.get_direction(start_waypoint, objective_waypoint), objective_waypoint, random.randint(1, 4)))
|
||||
|
||||
def ajouter_pnj_random(self)-> None:
|
||||
pass
|
||||
|
||||
def update_pnj(self)-> None:
|
||||
for p in self.liste_pnj:
|
||||
p.avance()
|
||||
|
||||
def get_village_sprites(self)->list:
|
||||
village_sprites = []
|
||||
for p in self.liste_pnj:
|
||||
village_sprites.append((p.x, p.y, p.sprite))
|
||||
return village_sprites
|
||||
|
||||
class Player:
|
||||
def __init__(self)-> None:
|
||||
self.x = 800
|
||||
@ -197,15 +217,16 @@ class Game:
|
||||
img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 0.2)
|
||||
screen.blit(img, (540-img.get_rect().centerx, 360-img.get_rect().centery))
|
||||
|
||||
def draw_villager(self):
|
||||
screen.blit(pnj.sprite, (540-player.x + pnj.x - pnj.sprite.get_rect().centerx, 360-player.y + pnj.y - pnj.sprite.get_rect().centery))
|
||||
def draw_village(self):
|
||||
for s in village.get_village_sprites():
|
||||
screen.blit(s[2], (540-player.x + s[0] - s[2].get_rect().centerx, 360-player.y + s[1] - s[2].get_rect().centery))
|
||||
|
||||
def display_all(self):
|
||||
# fill the screen with a color to wipe away anything from last frame
|
||||
screen.fill("purple")
|
||||
screen.blit(self.map_sprite, (540-player.x, 360-player.y))
|
||||
|
||||
self.draw_villager()
|
||||
self.draw_village()
|
||||
self.draw_player()
|
||||
|
||||
# We display it at the end so it's on top of all
|
||||
@ -214,11 +235,10 @@ class Game:
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
|
||||
player = Player()
|
||||
game = Game()
|
||||
pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"))
|
||||
#pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"), 3)
|
||||
village = Village(20)
|
||||
|
||||
while running:
|
||||
# poll for events
|
||||
@ -226,7 +246,8 @@ while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
pnj.avance()
|
||||
# make all the pnj move and do their pnj stuff
|
||||
village.update_pnj()
|
||||
|
||||
game.check_input()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user