-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld.go
More file actions
96 lines (86 loc) · 2.07 KB
/
world.go
File metadata and controls
96 lines (86 loc) · 2.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
package main
type World struct {
rooms []*Room
position Vector2d
currentRoom int
}
func NewWorld() *World {
return &World{
rooms: []*Room{},
position: Vector2d{45, 15},
currentRoom: 0,
}
}
func (w *World) Generate() {
w.rooms = append(w.rooms, NewRoom(
Vector2d{0, 0}, Vector2d{30, 10}, true, true, true, true, true,
))
w.rooms = append(w.rooms, NewRoom(
Vector2d{1, 0}, Vector2d{30, 10}, false, false, false, false, true,
))
w.rooms = append(w.rooms, NewRoom(
Vector2d{0, 1}, Vector2d{30, 10}, false, true, false, false, false,
))
w.rooms = append(w.rooms, NewRoom(
Vector2d{-1, 0}, Vector2d{30, 10}, false, false, true, false, false,
))
w.rooms = append(w.rooms, NewRoom(
Vector2d{0, -1}, Vector2d{30, 10}, false, false, false, true, false,
))
}
func (w *World) GetRoom(pos Vector2d) (*Room, bool) {
for _, room := range w.rooms {
if V.Equal(room.pos, pos) {
return room, true
}
}
return &Room{}, false
}
func (w *World) GetStartingRoomIndex() int {
return 0
}
func (w *World) GetStartingPosition() Vector2d {
if len(w.rooms) > 0 {
roomIndex := 1
r := w.rooms[roomIndex]
pad := V.Sum(r.size, V.Identity)
topLeft := V.Sum(w.position, Vector2d{pad.x * r.pos.x, pad.y * r.pos.y})
return V.Sum(
topLeft,
Vector2d{
r.size.x/2 - 0,
r.size.y/2 - 0,
},
)
}
return V.Sum(w.position, V.Identity)
}
func (w *World) GetRoomWoldPosition(pos Vector2d) Vector2d {
r, _ := w.GetRoom(pos)
pad := V.Sum(r.size, V.Identity)
return Vector2d{
x: pad.x * r.pos.x,
y: pad.y * r.pos.y,
}
}
func (w *World) GetRoomInnerBounds(index int) (Vector2d, Vector2d) {
if len(w.rooms) < (index + 1) {
return w.position, w.position
}
r := w.rooms[index]
pad := V.Sum(r.size, V.Identity)
topLeft := V.Sum(w.position, Vector2d{pad.x * r.pos.x, pad.y * r.pos.y})
return topLeft, V.Sum(
topLeft,
Vector2d{
r.size.x - 1,
r.size.y - 1,
},
)
}
func (w *World) Draw(c *Canvas) {
for _, r := range w.rooms {
drawPos := V.Sum(w.position, Vector2d{r.pos.x * (r.size.x + 1), r.pos.y * (r.size.y + 1)})
r.Draw(c, drawPos)
}
}