-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItems.py
92 lines (69 loc) · 2.72 KB
/
Items.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pygame
from Constants import *
import random
class Pellet:
def __init__(self, x, y,sparseFlipped = False):
self.array_coord = [x, y]
self.x = x * block_size + half_block_size
self.y = y * block_size + half_block_size
self.colour = (255, 255, 255)
self.here = True
if(sparseFlipped and neatMode): self.here = random.choice([False,False,False,False,True])
def draw(self, display):
if self.here:
half = pellet_size/2
pygame.draw.ellipse(display, self.colour, (self.x - half, self.y - half + offset,
pellet_size, pellet_size))
def collide(self, player):
dist_x = abs(self.x - player.x)
dist_y = abs(self.y - player.y)
if dist_x < pellet_size and dist_y < pellet_size and self.here:
self.here = False
return True
return False
class PowerPellet:
def __init__(self, x, y,generation):
self.array_coord = [x, y]
self.x = x * block_size + half_block_size
self.y = y * block_size + half_block_size
if ((not ((generation%disablePowerPelletsEvery==0) and (disablePowerPellets))) or not neatMode):
self.here = True
else:
self.here = False
def draw(self, display):
if self.here:
half = power_pellet_size/2
pygame.draw.ellipse(display, (255, 255, 255), (self.x - half, self.y - half + offset,
power_pellet_size, power_pellet_size))
def collide(self, player):
dist_x = abs(self.x - player.x)
dist_y = abs(self.y - player.y)
if dist_x < power_pellet_size and dist_y < power_pellet_size and self.here:
self.here = False
return True
return False
class Fruit:
def __init__(self, x, y, score, image, here):
self.array_coord = [x, y]
self.x = x * block_size + half_block_size
self.y = y * block_size + half_block_size
self.score = score
self.image = image
self.time = 0
self.here = here
def update(self):
if self.here:
self.time -= 1
if self.time == 0:
self.here = False
def draw(self, display):
if self.here:
display.blit(self.image, (self.x - half_block_size, self.y - half_block_size + offset))
def collide(self, player):
if self.here:
dist_x = abs(self.x - player.x)
dist_y = abs(self.y - player.y)
if dist_x < half_block_size and dist_y < half_block_size:
self.here = False
return self.score
return 0