gestion sale des téléporteurs
This commit is contained in:
parent
51347041d3
commit
0857619cf4
@ -55,20 +55,17 @@ class Ghost(Entity):
|
||||
return
|
||||
|
||||
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:
|
||||
return
|
||||
|
||||
# cur_node = graph[self.y//S][self.x//S]
|
||||
# print(self.y//S, self.x//S)
|
||||
graph = SceneManager().scene.entities['level'].graph
|
||||
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])
|
||||
# print([x[1] for x in p])
|
||||
cur_dir = p[0][1]
|
||||
if cur_dir == Direction.UP:
|
||||
self.phys.vx = 0
|
||||
@ -83,19 +80,6 @@ class Ghost(Entity):
|
||||
self.phys.vx = 1
|
||||
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):
|
||||
if final_node is None:
|
||||
print('oups')
|
||||
|
@ -53,6 +53,8 @@ class Level(Entity):
|
||||
def load(self):
|
||||
desc = image.load(res(self.path))
|
||||
w, h = desc.get_size()
|
||||
self.w = w * S
|
||||
self.h = h * S
|
||||
GraphicsServer().resize((w * S, h * S))
|
||||
self.surf = Surface((w * S, h * S)).convert()
|
||||
self.surf.fill((0, 0, 0))
|
||||
|
@ -3,6 +3,7 @@ from pygame.locals import K_UP, K_DOWN, K_LEFT, K_RIGHT
|
||||
|
||||
from engine.entity import Entity
|
||||
from engine.game import Game
|
||||
from engine.scene_manager import SceneManager
|
||||
from engine.resources import res
|
||||
from engine.components.collide_rect import CollideRect
|
||||
from engine.components.sprite import Sprite
|
||||
@ -82,6 +83,12 @@ class PacMan(Entity):
|
||||
p = self.phys
|
||||
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.
|
||||
if self.smol and Game.cur_tick - self.smol_since > 60*2:
|
||||
# On se réaligne dans le couloir.
|
||||
|
Reference in New Issue
Block a user