-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.py
More file actions
38 lines (32 loc) · 1.17 KB
/
Copy pathParticle.py
File metadata and controls
38 lines (32 loc) · 1.17 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
import Ray
import pygame as py
import math as m
class Particle:
def __init__(self, startx, starty):
self.position = (startx, starty)
self.rays = []
for i in range(360):
self.rays.append(Ray.Ray(self.position, i))
def show(self, window):
py.draw.circle(window, (255, 255, 255), self.position, 4, 1)
for r in self.rays:
r.show(window)
def look(self, walls, window):
result = ()
for r in self.rays:
closest = m.inf
best_point = ()
for w in walls:
result = r.cast(w)
if result and result[0]:
d = m.hypot(result[1][1] - self.position[1], result[1][0] - self.position[0])
if d < closest:
closest = d
best_point = result[1]
if closest != m.inf:
py.draw.line(window, (255, 255, 255, 100), self.position, best_point, 1)
def update(self, pos):
self.position = pos
self.rays.clear()
for i in range(360):
self.rays.append(Ray.Ray(self.position, i))