-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.go
More file actions
107 lines (96 loc) · 2.15 KB
/
room.go
File metadata and controls
107 lines (96 loc) · 2.15 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
package main
type Room struct {
id int
pos Vector2d // This is the position on the world grid
size Vector2d
visible bool
a, b, c, d bool // These are the available doors, clockwise from the top (a)
}
func NewRoom(pos, size Vector2d, visible, a, b, c, d bool) *Room {
return &Room{
pos: pos,
size: size,
visible: visible,
a: a,
b: b,
c: c,
d: d,
}
}
func (r *Room) IsValidPosition(pos Vector2d) bool {
if pos.x < 1 || pos.x > 28 || pos.y < 1 || pos.y > 8 {
return false
}
return true
}
func (r *Room) GetSpawnLocation() Vector2d {
return Vector2d{r.size.x / 2, r.size.y / 2}
}
func (r *Room) IsDoor(pos Vector2d) bool {
if (V.Equal(pos, Vector2d{15, 0}) && r.a) {
return true
}
if (V.Equal(pos, Vector2d{29, 5}) && r.b) {
return true
}
if (V.Equal(pos, Vector2d{15, 9}) && r.c) {
return true
}
if (V.Equal(pos, Vector2d{0, 5}) && r.d) {
return true
}
return false
}
func (r *Room) GetDoorDirection(pos Vector2d) Vector2d {
if (V.Equal(pos, Vector2d{15, 0})) {
return V.Up
}
if (V.Equal(pos, Vector2d{29, 5})) {
return V.Right
}
if (V.Equal(pos, Vector2d{15, 9})) {
return V.Down
}
if (V.Equal(pos, Vector2d{0, 5})) {
return V.Left
}
return V.Zero
}
func (r *Room) GetNextRoomEnterPosition(pos Vector2d) Vector2d {
if (V.Equal(pos, Vector2d{15, 0})) {
return Vector2d{15, 8}
}
if (V.Equal(pos, Vector2d{29, 5})) {
return Vector2d{1, 5}
}
if (V.Equal(pos, Vector2d{15, 9})) {
return Vector2d{15, 1}
}
if (V.Equal(pos, Vector2d{0, 5})) {
return Vector2d{28, 5}
}
return V.Identity
}
// Draw a room at a given position in a Canvas
func (r *Room) Draw(c *Canvas, p Vector2d) {
c.SetBrush(BLOCK_2593)
c.DrawBox(p, r.size)
if r.visible {
c.SetBrush(' ')
} else {
c.SetBrush(BLOCK_2571)
}
c.DrawBox(Vector2d{p.x + 1, p.y + 1}, Vector2d{r.size.x - 2, r.size.y - 2})
if r.a {
c.AddString(terminal.pos(p.x+r.size.x/2, p.y) + " ")
}
if r.b {
c.AddString(terminal.pos(p.x+r.size.x-1, p.y+r.size.y/2) + " ")
}
if r.c {
c.AddString(terminal.pos(p.x+r.size.x/2, p.y+r.size.y-1) + " ")
}
if r.d {
c.AddString(terminal.pos(p.x, p.y+r.size.y/2) + " ")
}
}