-
Notifications
You must be signed in to change notification settings - Fork 0
/
ray_cast.py
61 lines (45 loc) · 1.48 KB
/
ray_cast.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
import pygame as pg
from random import randint
from boundary import Boundary
from particle import Particle
from ray import Ray
def main():
### CONFIG
screen_w = 500
screen_h = 500
border_on = True
num_walls = 6
num_rays = 180
### END CONFIG
pg.init()
screen = pg.display.set_mode((screen_w, screen_h))
running = True
pg.event.set_allowed([pg.QUIT, pg.KEYDOWN, pg.KEYUP])
p = Particle()
boundaries = []
rays = []
if border_on:
boundaries.append(Boundary(screen, (0, 0), (screen_w, 0)))
boundaries.append(Boundary(screen, (screen_w, 0), (screen_w, screen_h)))
boundaries.append(Boundary(screen, (screen_w, screen_h), (0, screen_h)))
boundaries.append(Boundary(screen, (0, screen_h), (0, 0)))
for i in range(num_walls):
boundaries.append(Boundary(screen,
(randint(0, screen_w), randint(0, screen_h)),
(randint(0, screen_w), randint(0, screen_h))))
for i in range(num_rays):
rays.append(Ray(p, i * 360 / num_rays))
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
screen.fill((0, 0, 0))
for b in boundaries:
b.update(screen)
p.update(screen)
for r in rays:
r.update(screen, p, boundaries)
pg.display.update()
pg.time.wait(75)
if __name__ == "__main__":
main()