TPT ok - map à afficher lel
This commit is contained in:
parent
b6622fc8d5
commit
86e56be3e5
@ -34,8 +34,8 @@ class Fruit:
|
|||||||
|
|
||||||
|
|
||||||
class Pacman:
|
class Pacman:
|
||||||
def __init__(self, position=[0, 0], resolution=10):
|
def __init__(self, position=[0, 0], map_size=(28, 31), resolution=10):
|
||||||
self.position = [position[0]+resolution, position[1]+resolution]
|
self.position = [position[0]+int(resolution/2), position[1]+int(resolution/2)]
|
||||||
self.direction = direction.right
|
self.direction = direction.right
|
||||||
self.next_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.super_power = 0 # Counter of super pacdots in effect (> 0 means super power is active)
|
||||||
@ -43,11 +43,18 @@ class Pacman:
|
|||||||
self.size = (1.8, 1.8) # size related to tile size
|
self.size = (1.8, 1.8) # size related to tile size
|
||||||
self.speed = 0.1
|
self.speed = 0.1
|
||||||
self.resolution = resolution # when pacman in 0:10 he's in the 1st cell if resolution=10
|
self.resolution = resolution # when pacman in 0:10 he's in the 1st cell if resolution=10
|
||||||
|
self.map_size = map_size
|
||||||
|
|
||||||
def matrix_position(self):
|
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)
|
return int(self.position[0] / self.resolution), int(self.position[1] / self.resolution)
|
||||||
|
|
||||||
|
def next_matrix_position(self):
|
||||||
|
next_x = int(self.position[0] / self.resolution + self.direction[0]) % self.map_size[0]
|
||||||
|
next_y = int(self.position[1] / self.resolution + self.direction[1]) % self.map_size[1]
|
||||||
|
print(self.position, next_x, next_y)
|
||||||
|
return next_x, next_y
|
||||||
|
|
||||||
def has_super_power(self):
|
def has_super_power(self):
|
||||||
return self.super_power > 0
|
return self.super_power > 0
|
||||||
|
|
||||||
@ -102,8 +109,8 @@ class Pacman:
|
|||||||
def move(self):
|
def move(self):
|
||||||
# self.position[0] += self.direction[0] * self.speed
|
# self.position[0] += self.direction[0] * self.speed
|
||||||
# self.position[1] += self.direction[1] * self.speed
|
# self.position[1] += self.direction[1] * self.speed
|
||||||
self.position[0] += self.direction[0]
|
self.position[0] = (self.position[0] + self.direction[0]) % (self.resolution * self.map_size[0])
|
||||||
self.position[1] += self.direction[1]
|
self.position[1] = (self.position[1] + self.direction[1]) % (self.resolution * self.map_size[1])
|
||||||
|
|
||||||
def game_over(status = "lose"):
|
def game_over(status = "lose"):
|
||||||
#TODO
|
#TODO
|
||||||
|
@ -25,8 +25,8 @@ class Map:
|
|||||||
Pacman maps size is 28×31
|
Pacman maps size is 28×31
|
||||||
"""
|
"""
|
||||||
|
|
||||||
width = 28 * 2 + 1
|
width = 28
|
||||||
height = 31 * 2 + 1
|
height = 31
|
||||||
# tile_size = 16 # tile subdivision for dynamic movement
|
# tile_size = 16 # tile subdivision for dynamic movement
|
||||||
|
|
||||||
def __init__(self, phys_map = [], dots_map = [], maze_img_file=""):
|
def __init__(self, phys_map = [], dots_map = [], maze_img_file=""):
|
||||||
|
@ -10,19 +10,21 @@ class PhysicMotor:
|
|||||||
def move_all(self):
|
def move_all(self):
|
||||||
# pacman movement
|
# pacman movement
|
||||||
print(self.pacman.position)
|
print(self.pacman.position)
|
||||||
pac_x, pac_y = self.pacman.matrix_position()
|
# pac_x, pac_y = self.pacman.matrix_position()
|
||||||
|
next_pac_tile = self.pacman.next_matrix_position()
|
||||||
pac_res = self.pacman.resolution
|
pac_res = self.pacman.resolution
|
||||||
print(pac_x, pac_y, self.pacmap.get_tile(pac_x, pac_y))
|
# 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]))
|
# 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 self.pacman.direction in (direction.up, direction.down):
|
||||||
if self.pacman.position[1] % pac_res == pac_res / 2: # 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):
|
if self.pacmap.get_tile(*next_pac_tile) in (PhysTile.GRD, PhysTile.TPT):
|
||||||
self.pacman.move()
|
self.pacman.move()
|
||||||
else:
|
else:
|
||||||
self.pacman.move()
|
self.pacman.move()
|
||||||
else:
|
else:
|
||||||
if self.pacman.position[0] % pac_res == pac_res / 2: # change this in the future
|
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):
|
if self.pacmap.get_tile(*next_pac_tile) in (PhysTile.GRD, PhysTile.TPT):
|
||||||
self.pacman.move()
|
self.pacman.move()
|
||||||
else:
|
else:
|
||||||
self.pacman.move()
|
self.pacman.move()
|
Reference in New Issue
Block a user