96 lines
2.3 KiB
Python
Executable File
96 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import pacmap
|
|
import os
|
|
|
|
from enum import IntEnum
|
|
|
|
pacdot_counter = 88
|
|
score = 0
|
|
lives = 3
|
|
|
|
class Direction(IntEnum):
|
|
U = 0
|
|
D = 1
|
|
R = 2
|
|
L = 3
|
|
|
|
class FruitType(IntEnum):
|
|
A = 0
|
|
|
|
class Fruit:
|
|
def __init__(self, fruit_type, score, position = (0, 0)):
|
|
self.fruit_type = fruit_type
|
|
self.score = score
|
|
self.position = position
|
|
|
|
|
|
class Pacman:
|
|
def __init__(self):
|
|
self.position = (0.0, 0.0)
|
|
self.direction = Direction.R
|
|
self.next_direction = Direction.R
|
|
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
|
|
|
|
def matrix_position(self):
|
|
return (int(self.position[0]), int(self.position[1]))
|
|
|
|
def has_super_power(self):
|
|
return self.super_power > 0
|
|
|
|
def eat_pacdot(self, dot_map):
|
|
global score
|
|
global pacdot_counter
|
|
dot_map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT
|
|
pacdot_counter -= 1
|
|
score += 10
|
|
if pacdot_counter == 0:
|
|
game_over("win")
|
|
|
|
def eat_super_pacdot(self, dot_map):
|
|
global score
|
|
dot_map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT
|
|
score += 50
|
|
self.super_power += 1
|
|
|
|
# TODO
|
|
# Requires UNIX
|
|
#pid = os.fork()
|
|
#if pid == 0:
|
|
# return
|
|
|
|
#os.sleep(10)
|
|
self.super_power -= 1
|
|
self.ghost_combo = 0
|
|
#os._exit(0)
|
|
|
|
def eat_fruit(self, fruit, dot_map):
|
|
global score
|
|
dot_map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT
|
|
score += fruit.score
|
|
|
|
def eat_ghost(self, ghost):
|
|
global score
|
|
ghost.despawn_and_respawn()
|
|
self.ghost_combo += 1
|
|
score += (2 ** self.ghost_combo) * 100
|
|
|
|
def get_eaten(self, dot_map):
|
|
global lives
|
|
#TODO score loss ?
|
|
self.position = dot_map.spawn_point #TODO
|
|
lives -= 1
|
|
if lives < 0: # à vérifier
|
|
game_over()
|
|
|
|
def game_over(status = "lose"):
|
|
#TODO
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|