ajout de l'objet pacman et quelques fonctions
This commit is contained in:
parent
deb474e0b8
commit
a8c79b1c47
92
src/pacman.py
Normal file
92
src/pacman.py
Normal file
@ -0,0 +1,92 @@
|
||||
#!/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
|
||||
|
||||
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, map):
|
||||
global score
|
||||
global pacdot_counter
|
||||
map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT
|
||||
pacdot_counter -= 1
|
||||
score += 10
|
||||
|
||||
def eat_super_pacdot(self, map):
|
||||
global score
|
||||
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, map):
|
||||
global score
|
||||
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, map):
|
||||
global lives
|
||||
#TODO score loss ?
|
||||
self.position = map.spawn_point #TODO
|
||||
lives -= 1
|
||||
if lives <= 0:
|
||||
game_over()
|
||||
|
||||
def game_over():
|
||||
#TODO
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user