-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpellets.py
More file actions
77 lines (63 loc) · 2.39 KB
/
Copy pathpellets.py
File metadata and controls
77 lines (63 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pygame
from vector import Vector2
from constants import *
class Pellet(object):
def __init__(self, x, y):
self.name = "pellet"
self.position = Vector2(x, y)
self.color = WHITE
self.radius = max(int(TILEWIDTH / 8), 1)
self.points = 10
self.visible = True
def render(self, screen):
if self.visible:
p = self.position.asInt()
p = (int(p[0]+TILEWIDTH/2), int(p[1]+TILEWIDTH/2))
pygame.draw.circle(screen, self.color, p, self.radius)
class PowerPellet(Pellet):
def __init__(self, x, y):
Pellet.__init__(self, x, y)
self.name = "powerpellet"
self.radius = 8
self.points = 50
self.flashTime = 0.2
self.timer= 0
def update(self, dt):
self.timer += dt
if self.timer >= self.flashTime:
self.visible = not self.visible
self.timer = 0
class PelletGroup(object):
def __init__(self, mazefile):
self.pelletList = []
self.powerpellets = []
self.pelletSymbols = ["p", "n", "Y"]
self.powerpelletSymbols = ["P", "N"]
self.createPelletList(mazefile)
self.dummy_list = [1 for pellet in self.pelletList]
def update(self, dt):
for powerpellet in self.powerpellets:
powerpellet.update(dt)
def createPelletList(self, mazefile):
grid = self.readMazeFile(mazefile)
rows = len(grid)
cols = len(grid[0])
for row in range(rows):
for col in range(cols):
if (grid[row][col] in self.pelletSymbols):
self.pelletList.append(Pellet(col*TILEWIDTH, row*TILEHEIGHT))
if (grid[row][col] in self.powerpelletSymbols):
pp = PowerPellet(col*TILEWIDTH, row*TILEHEIGHT)
self.pelletList.append(pp)
self.powerpellets.append(pp)
def readMazeFile(self, textfile):
f = open(textfile, "r")
lines = [line.rstrip('\n') for line in f]
return [line.split(' ') for line in lines]
def isEmpty(self):
if len(self.pelletList) == 0:
return True
return False
def render(self, screen):
for pellet in self.pelletList:
pellet.render(screen)