This repository was archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalls.py
More file actions
43 lines (37 loc) · 1.59 KB
/
walls.py
File metadata and controls
43 lines (37 loc) · 1.59 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
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
from vector import Vector
import globals
class Wall:
# side: number representing which side to put wall on (0=top, 1=right, 2=bottom, 3=left)
def __init__(self, side):
if side == 0: # top of the map
self.pA = Vector(0, 0)
self.pB = Vector(globals.CANVAS_DIMS[0], 0)
self.direction_of_player = Vector(0, 1)
elif side == 1: # right side
self.pA = Vector(globals.CANVAS_DIMS[0], 0)
self.pB = Vector(globals.CANVAS_DIMS[0], globals.CANVAS_DIMS[1])
self.direction_of_player = Vector(-1, 0)
elif side == 2: # bottom side
self.pA = Vector(0, globals.CANVAS_DIMS[1])
self.pB = Vector(globals.CANVAS_DIMS[0], globals.CANVAS_DIMS[1])
self.direction_of_player = Vector(0, -1)
elif side == 3: # right side
self.pA = Vector(0, 0)
self.pB = Vector(0, globals.CANVAS_DIMS[1])
self.direction_of_player = Vector(1, 0)
self.thickness = 20
self.unit = (self.pB - self.pA).normalize()
self.normal = Vector(-self.unit.y, self.unit.x)
def draw(self, canvas):
canvas.draw_line(self.pA.get_p(), self.pB.get_p(), self.thickness, "Brown")
def distanceTo(self, pos):
posToA = pos - self.pA
proj = posToA.dot(self.normal) * self.normal
return proj.length()
def covers(self, pos):
return ((pos - self.pA).dot(self.unit) >= 0 and
(pos - self.pB).dot(-self.unit) >= 0)