-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollisions.py
More file actions
174 lines (142 loc) · 4.07 KB
/
Copy pathcollisions.py
File metadata and controls
174 lines (142 loc) · 4.07 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
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
import pygame
import math
import time
wait = 0
c = 1
pygame.font.init()
font = pygame.font.SysFont('Impact', 30)
pygame.init()
def euclidean_distance(point1, point2):
distance = 0
for i in range(len(point1)):
distance += (point1[i] - point2[i]) ** 2
return math.sqrt(distance)
screen = pygame.display.set_mode((500,500))
running = True
velx = 0
vely = 0
tempx = velx
tempy = vely
x = 40
y = 250
velx1 = 0
vely1 = 0
tempx1 = velx1
tempy1 = vely1
x1 = 480
y1 = 250
reload = 3
string = "READY " + str(round(reload, 2))
time = 0
mx, my = pygame.mouse.get_pos()
angle_rad = math.atan2(vely, velx)
larium = 0
circle_x = x + 40 * math.cos(angle_rad)
circle_y = y + 40 * math.sin(angle_rad)
# dont touch
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
time = time + 0.001
screen.fill((0,0,0))
pygame.draw.circle(screen,(255,255,0),(x,y),40)
pygame.draw.circle(screen,(255,0,255),(x1,y1),20)
angle_rad = math.atan2(vely, velx)
circle_x = x + 40 * -math.cos(larium)
circle_y = y + 40 * -math.sin(larium)
pygame.draw.circle(screen,(255,0,0),(circle_x,circle_y),10)
pygame.draw.circle(screen,(255,32,64),(250,250),wait*100)
text = font.render(string, 0, ((math.sin(time)*255)%255, (math.sin(time*2)*255)%255, (math.sin(time*3)*255)%255))
csad = pygame.transform.scale(text,(abs(math.sqrt(abs(velx+velx1)/20)*10+256),abs(math.sqrt(abs(vely+vely1)/2)*10+32)))
rectfont = text.get_rect()
rectfont.topleft = (0, 0)
screen.blit(csad, rectfont)
if larium < angle_rad:
larium = larium + 0.0025
if larium > angle_rad:
larium = larium - 0.0025
pygame.display.update()
x += velx/100
y += vely/100
x1 += velx1/100
y1 += vely1/100
tempx1 = velx1
tempx = velx
tempy1 = vely1
tempy = vely
# collision
if euclidean_distance((x,y), (x1,y1))<=60:
x = x + tempx1/100
velx = tempx1 /reload
x1 = x1 + tempx/100
velx1 = tempx /1
y = y + tempy1/100
vely = tempy1 /reload
y1 = y1 + tempy/100
vely1 = tempy /1
if euclidean_distance((circle_x,circle_y), (x1,y1))<=30:
string = "game over"
c = 0
if c == 0:
if wait < 5:
wait = wait + 0.01
string = "game over"
print(wait)
string = "game over"
if wait > 4:
running = False
string = "game over"
running = False
print(3)
print(13)
mx, my = pygame.mouse.get_pos()
# bound
if x1 > 480:
velx1 = -velx1
if x1 < 20:
velx1 = -velx1
if y1 > 480:
vely1 = -vely1
if y1 < 20:
vely1 = -vely1
if x > 460:
velx = -velx
if x < 40:
velx = -velx
if y > 460:
vely = -vely
if y < 40:
vely = -vely
# tiny
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
velx1 = velx1 - 0.025
elif keys[pygame.K_RIGHT]:
velx1 = velx1 + 0.025
if keys[pygame.K_UP]:
vely1 = vely1 - 0.025
elif keys[pygame.K_DOWN]:
vely1 = vely1 + 0.025
# BIF
if keys[pygame.K_a]:
velx = velx - 0.025
elif keys[pygame.K_d]:
velx = velx + 0.025
if keys[pygame.K_w]:
vely = vely - 0.025
elif keys[pygame.K_s]:
vely = vely + 0.025
if keys[pygame.K_SPACE] and math.floor(reload) == 3:
reload = 0.5
# damp
velx = velx / 1.001
velx1 = velx1 / 1.001
vely = vely / 1.001
vely1 = vely1 / 1.001
if reload < 3:
reload = reload * 1.000125
if math.floor(reload) == 3 and wait == 0:
string = "READY " + str(round(reload, 2))
elif not math.floor(reload) == 3 and wait == 0:
string = "CHARGING " + str(round(reload, 2))