bon collision mur ok - faudra gérer la case temp de dplct de pacman pour le prochain croisement - graphique faut afficher la carte lel et voilà pour aujourd'hui
This commit is contained in:
parent
ea1e4e6724
commit
b6622fc8d5
@ -18,6 +18,7 @@ class Screen:
|
||||
self.pacman_sprite = pacman_sprite.PacmanSprite(size[0]/28)
|
||||
self.clock = pg.time.Clock()
|
||||
self.max_fps = 30
|
||||
self.entity_group = pg.sprite.Group(self.pacman_sprite)
|
||||
|
||||
self.loop()
|
||||
|
||||
@ -32,28 +33,39 @@ class Screen:
|
||||
pacman.change_dir(m_pacman.direction.left)
|
||||
if key[pg.K_RIGHT]:
|
||||
pacman.change_dir(m_pacman.direction.right)
|
||||
# print(pacman.direction)
|
||||
|
||||
def refresh(self):
|
||||
"""refresh/redraw all"""
|
||||
pass
|
||||
pac_x, pac_y = self.pacman.position
|
||||
pac_res = self.pacman.resolution
|
||||
self.pacman_sprite.rect.x = int(pac_x / 28 / pac_res * self.screen.get_width())
|
||||
self.pacman_sprite.rect.y = int(pac_y / 31 / pac_res * self.screen.get_height())
|
||||
# print(self.pacman_sprite.rect.x, self.pacman_sprite.rect.y, self.pacman_sprite.rect.size)
|
||||
|
||||
self.entity_group.draw(self.screen)
|
||||
# print(self.entity_group)
|
||||
|
||||
|
||||
def create_maze_surface(self):
|
||||
pass
|
||||
|
||||
def loop(self):
|
||||
while 1:
|
||||
self.screen.fill((0, 0, 0))
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
sys.exit()
|
||||
|
||||
self.user_events()
|
||||
self.physic_motor.move_all()
|
||||
self.refresh()
|
||||
self.user_events()
|
||||
self.physic_motor.move_all()
|
||||
self.refresh()
|
||||
|
||||
self.clock.tick(max_fps)
|
||||
self.clock.tick(self.max_fps)
|
||||
pg.display.flip()
|
||||
|
||||
if __name__ == '__main__':
|
||||
pacman = m_pacman.Pacman((1,1))
|
||||
pacmap = m_pacmap.Map(maze_img_file="../pacmap_maze_1.png")
|
||||
pacmap = m_pacmap.Map(maze_img_file="../pacmap_maze1.png")
|
||||
phys_motor = PhysicMotor(pacmap, pacman)
|
||||
screen = Screen((280, 310), pacmap, phys_motor, pacman)
|
||||
screen = Screen((560, 620), pacmap, phys_motor, pacman)
|
@ -34,17 +34,19 @@ class Fruit:
|
||||
|
||||
|
||||
class Pacman:
|
||||
def __init__(self, position=[0, 0]):
|
||||
self.position = list(position)
|
||||
def __init__(self, position=[0, 0], resolution=10):
|
||||
self.position = [position[0]+resolution, position[1]+resolution]
|
||||
self.direction = direction.right
|
||||
self.next_direction = direction.right
|
||||
self.super_power = 0 # Counter of super pacdots in effect (> 0 means super power is active)
|
||||
self.ghost_combo = 0
|
||||
self.size = (1.8, 1.8) # size related to tile size
|
||||
self.speed = 0.1
|
||||
self.resolution = resolution # when pacman in 0:10 he's in the 1st cell if resolution=10
|
||||
|
||||
def matrix_position(self):
|
||||
return (int(self.position[0]), int(self.position[1]))
|
||||
# return (int(self.position[0]), int(self.position[1]))
|
||||
return int(self.position[0] / self.resolution), int(self.position[1] / self.resolution)
|
||||
|
||||
def has_super_power(self):
|
||||
return self.super_power > 0
|
||||
@ -98,9 +100,10 @@ class Pacman:
|
||||
self.direction = new_dir
|
||||
|
||||
def move(self):
|
||||
self.position[0] = self.position[0] + self.direction[0] * self.speed
|
||||
self.position[1] = self.position[1] + self.direction[1] * self.speed
|
||||
|
||||
# self.position[0] += self.direction[0] * self.speed
|
||||
# self.position[1] += self.direction[1] * self.speed
|
||||
self.position[0] += self.direction[0]
|
||||
self.position[1] += self.direction[1]
|
||||
|
||||
def game_over(status = "lose"):
|
||||
#TODO
|
||||
|
@ -5,7 +5,8 @@ class PacmanSprite(pg.sprite.Sprite):
|
||||
def __init__(self, size):
|
||||
super().__init__()
|
||||
self.image = pg.Surface([size, size])
|
||||
pg.draw.circle(self.image, (255, 255, 0), (size/2, size/2), size/2, width=0)
|
||||
half_size = int(size / 2)
|
||||
pg.draw.circle(self.image, (255, 255, 0), (half_size, half_size), half_size)
|
||||
|
||||
# Fetch the rectangle object that has the dimensions of the image
|
||||
# Update the position of this object by setting the values of rect.x and rect.y
|
||||
|
@ -46,12 +46,14 @@ class Map:
|
||||
2: big pac-dot
|
||||
"""
|
||||
if maze_img_file and os.path.isfile(maze_img_file):
|
||||
print('coucou')
|
||||
try:
|
||||
self.phys_map = decode_map(maze_img_file)
|
||||
except Exception as e:
|
||||
raise e
|
||||
self.phys_map = phys_map # in the first part we assume phys_map is correct and no need to verify
|
||||
self.dots_map = dots_map
|
||||
else:
|
||||
self.phys_map = phys_map # in the first part we assume phys_map is correct and no need to verify
|
||||
self.dots_map = dots_map
|
||||
self.intersect_map = [] # TODO - the layer which contains intersections pre-calculated
|
||||
|
||||
|
||||
|
@ -9,8 +9,20 @@ class PhysicMotor:
|
||||
|
||||
def move_all(self):
|
||||
# pacman movement
|
||||
pac_x, pac_y = self.pacman.position
|
||||
print(self.pacman.position)
|
||||
pac_x, pac_y = self.pacman.matrix_position()
|
||||
pac_res = self.pacman.resolution
|
||||
print(pac_x, pac_y, self.pacmap.get_tile(pac_x, pac_y))
|
||||
print("next:", self.pacmap.get_tile(pac_x + self.pacman.direction[0], pac_y + self.pacman.direction[1]))
|
||||
if self.pacman.direction in (direction.up, direction.down):
|
||||
if pac_y % 1 == 0.5: # change this in the future
|
||||
if self.pacman.position[1] % pac_res == pac_res / 2: # change this in the future
|
||||
if self.pacmap.get_tile(pac_x, pac_y + self.pacman.direction[1]) in (PhysTile.GRD, PhysTile.TPT):
|
||||
self.pacman.move()
|
||||
else:
|
||||
self.pacman.move()
|
||||
else:
|
||||
if self.pacman.position[0] % pac_res == pac_res / 2: # change this in the future
|
||||
if self.pacmap.get_tile(pac_x + self.pacman.direction[0], pac_y) in (PhysTile.GRD, PhysTile.TPT):
|
||||
self.pacman.move()
|
||||
else:
|
||||
self.pacman.move()
|
Reference in New Issue
Block a user