-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgametry1.py
198 lines (164 loc) · 7.28 KB
/
gametry1.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import pygame
from pygameGame import *
import math, string, copy, time, random
class gameObject(pygame.sprite.Sprite):
def __init__(self,x,y,r,angle,screen):
super(gameObject, self).__init__()
self.x = x
self.y = y
self.r = r
self.rect = ()
self.angle = angle
self.screen = screen
self.color = (0,0,0)
self.mask = pygame.mask.from_surface(screen)
def draw(self):
x = self.x
y = self.y
r = self.r
self.rect = (x-r, y-r, 2*r, 2*r)
class CirclePurple(gameObject):
def draw(self):
super().draw()
self.color = (153,153,255)
pygame.draw.arc(self.screen, self.color , self.rect,
self.angle + 3*math.pi/4,
self.angle + 5*math.pi/4,10)
class CirclePink(gameObject):
def draw(self):
super().draw()
self.color = (255,153,204)
pygame.draw.arc(self.screen, self.color, self.rect,
self.angle + math.pi/4,
self.angle + 3*math.pi/4,10)
class CircleYellow(gameObject):
def draw(self):
super().draw()
self.color = (255,255,153)
pygame.draw.arc(self.screen, self.color, self.rect,
self.angle + -math.pi/4,
self.angle + math.pi/4, 10)
class CircleGreen(gameObject):
def draw(self):
super().draw()
self.color = (153,255,204)
pygame.draw.arc(self.screen, self.color, self.rect,
self.angle + -3*math.pi/4,
self.angle + -math.pi/4,10)
class Cursor(pygame.sprite.Sprite):
def __init__(self, screenWidth, screenHeight, screen):
super(Cursor, self).__init__()
self.x = screenWidth//2
self.y = screenHeight - 20
self.r = 10
self.cursorSpeed = 5
self.color = (255,255,153) #yellow
self.rect = (self.x-self.r, self.y-self.r, 2*self.r, 2*self.r)
self.mask = pygame.mask.from_surface(screen)
def draw(self, screen):
pygame.draw.circle(screen, self.color, (self.x,self.y), self.r)
def update(self, keysDown):
if keysDown(pygame.K_LEFT):
self.x -= self.cursorSpeed
if keysDown(pygame.K_RIGHT):
self.x += self.cursorSpeed
if keysDown(pygame.K_UP):
self.y -= self.cursorSpeed
if keysDown(pygame.K_DOWN):
self.y += self.cursorSpeed
class myProject(PygameGame):
def init(self):
self.purple = (153,153,255)
self.pink = (255,153,204)
self.yellow = (255,255,153)
self.green = (153,255,204)
#circle
self.circleList = []
self.angleList = []
#layers
self.screenPurple = pygame.Surface((self.width, self.height))
self.screenPink = pygame.Surface((self.width, self.height))
self.screenYellow = pygame.Surface((self.width, self.height))
self.screenGreen = pygame.Surface((self.width, self.height))
self.screenCursor = pygame.Surface((self.width, self.height))
#groups
self.purpleGrp = pygame.sprite.Group()
self.pinkGrp = pygame.sprite.Group()
self.yellowGrp = pygame.sprite.Group()
self.greenGrp = pygame.sprite.Group()
self.cursorGrp = pygame.sprite.Group()
self.cursor = Cursor(self.width, self.height,self.screenCursor)
self.cursorGrp.add(self.cursor)
def mousePressed(self, x, y):
r = random.randint(40,50)
self.circleList.append((x,y,r))
self.angleList.append(0)
def timerFired(self, dt):
for i in range (len(self.angleList)):
self.angleList[i] += 0.05
self.cursor.update(self.isKeyPressed)
if self.cursor.color == self.purple:
for pinkArc in self.pinkGrp:
if pygame.sprite.collide_mask(self.cursor, pinkArc) != None:
print ("COLLIDED WITH PINK")
for yellowArc in self.yellowGrp:
if pygame.sprite.collide_mask(self.cursor, yellowArc) != None:
print ("COLLIDED WITH YELLOW")
for greenArc in self.greenGrp:
if pygame.sprite.collide_mask(self.cursor, greenArc) != None:
print ("COLLIDED WITH GREEN")
elif self.cursor.color == self.pink:
for purpleArc in self.purpleGrp:
if pygame.sprite.collide_mask(self.cursor, purpleArc) != None:
print ("COLLIDED WITH PURPLE")
for yellowArc in self.yellowGrp:
if pygame.sprite.collide_mask(self.cursor, yellowArc) != None:
print ("COLLIDED WITH YELLOW")
for greenArc in self.greenGrp:
if pygame.sprite.collide_mask(self.cursor, greenArc) != None:
print ("COLLIDED WITH GREEN")
elif self.cursor.color == self.yellow:
for purpleArc in self.purpleGrp:
if pygame.sprite.collide_mask(self.cursor, purpleArc) != None:
print ("COLLIDED WITH PURPLE")
for pinkArc in self.pinkGrp:
if pygame.sprite.collide_mask(self.cursor, pinkArc) != None:
print ("COLLIDED WITH PINK")
for greenArc in self.greenGrp:
if pygame.sprite.collide_mask(self.cursor, greenArc) != None:
print ("COLLIDED WITH GREEN")
elif self.cursor.color == self.green:
for purpleArc in self.purpleGrp:
if pygame.sprite.collide_mask(self.cursor, purpleArc) != None:
print ("COLLIDED WITH PURPLE")
for yellowArc in self.yellowGrp:
if pygame.sprite.collide_mask(self.cursor, yellowArc) != None:
print ("COLLIDED WITH YELLOW")
for pinkArc in self.pinkGrp:
if pygame.sprite.collide_mask(self.cursor, pinkArc) != None:
print ("COLLIDED WITH PINK")
def redrawAll(self, screen):
for i in range (len(self.circleList)):
x, y, r = self.circleList[i]
angle = self.angleList[i]
circlePurple = CirclePurple(x,y,r, angle, self.screenPurple)
circlePink = CirclePink(x,y,r, angle, self.screenPink)
circleYellow = CircleYellow(x,y,r, angle, self.screenYellow)
circleGreen = CircleGreen(x,y,r, angle, self.screenGreen)
self.purpleGrp.add(circlePurple)
self.pinkGrp.add(circlePink)
self.yellowGrp.add(circleYellow)
self.greenGrp.add(circleGreen)
circlePurple.draw()
circlePink.draw()
circleYellow.draw()
circleGreen.draw()
screen.blit(self.screenPurple, (0,0))
screen.blit(self.screenPink, (0,0))
screen.blit(self.screenYellow,(0,0))
screen.blit(self.screenGreen, (0,0))
self.cursor.draw(screen)
screen.blit(self.screenCursor, (0,0))
#creating and running the game
game = myProject()
game.run()