gestion sale des téléporteurs

This commit is contained in:
papush! 2019-12-09 18:24:35 +01:00
parent 51347041d3
commit 0857619cf4
3 changed files with 15 additions and 22 deletions

View File

@ -55,20 +55,17 @@ class Ghost(Entity):
return return
def script(self): def script(self):
graph = SceneManager().scene.entities['level'].graph level = SceneManager().scene.entities['level']
if self.x >= level.w:
self.x = 0
if self.x < 0:
self.x = level.w-1
if self.x % S != 0 or self.y % S != 0: if self.x % S != 0 or self.y % S != 0:
return return
graph = SceneManager().scene.entities['level'].graph
# cur_node = graph[self.y//S][self.x//S]
# print(self.y//S, self.x//S)
pacman = SceneManager().scene.entities['pacman'] pacman = SceneManager().scene.entities['pacman']
# x_dist = pacman.x - self.x
# y_dist = pacman.y - self.y
# s = 1
# print(pacman.y//S, pacman.x//S)
p = self.find_shortest_path(graph[pacman.y//S][pacman.x//S]) p = self.find_shortest_path(graph[pacman.y//S][pacman.x//S])
# print([x[1] for x in p])
cur_dir = p[0][1] cur_dir = p[0][1]
if cur_dir == Direction.UP: if cur_dir == Direction.UP:
self.phys.vx = 0 self.phys.vx = 0
@ -83,19 +80,6 @@ class Ghost(Entity):
self.phys.vx = 1 self.phys.vx = 1
self.phys.vy = 0 self.phys.vy = 0
# if self.direction == Direction.UP:
# self.phys.vy = -Ghost.SPEED
# self.phys.vx = 0
# elif self.direction == Direction.DOWN:
# self.phys.vy = Ghost.SPEED
# self.phys.vx = 0
# elif self.direction == Direction.LEFT:
# self.phys.vx = -Ghost.SPEED
# self.phys.vy = 0
# elif self.direction == Direction.RIGHT:
# self.phys.vx = Ghost.SPEED
# self.phys.vy = 0
def find_shortest_path(self, final_node): def find_shortest_path(self, final_node):
if final_node is None: if final_node is None:
print('oups') print('oups')

View File

@ -53,6 +53,8 @@ class Level(Entity):
def load(self): def load(self):
desc = image.load(res(self.path)) desc = image.load(res(self.path))
w, h = desc.get_size() w, h = desc.get_size()
self.w = w * S
self.h = h * S
GraphicsServer().resize((w * S, h * S)) GraphicsServer().resize((w * S, h * S))
self.surf = Surface((w * S, h * S)).convert() self.surf = Surface((w * S, h * S)).convert()
self.surf.fill((0, 0, 0)) self.surf.fill((0, 0, 0))

View File

@ -3,6 +3,7 @@ from pygame.locals import K_UP, K_DOWN, K_LEFT, K_RIGHT
from engine.entity import Entity from engine.entity import Entity
from engine.game import Game from engine.game import Game
from engine.scene_manager import SceneManager
from engine.resources import res from engine.resources import res
from engine.components.collide_rect import CollideRect from engine.components.collide_rect import CollideRect
from engine.components.sprite import Sprite from engine.components.sprite import Sprite
@ -82,6 +83,12 @@ class PacMan(Entity):
p = self.phys p = self.phys
s = self.sprite s = self.sprite
level = SceneManager().scene.entities['level']
if self.x >= level.w:
self.x = 0
if self.x < 0:
self.x = level.w-1
# Expiration du rapetissement. # Expiration du rapetissement.
if self.smol and Game.cur_tick - self.smol_since > 60*2: if self.smol and Game.cur_tick - self.smol_since > 60*2:
# On se réaligne dans le couloir. # On se réaligne dans le couloir.