/
gate.go
95 lines (80 loc) · 2.4 KB
/
gate.go
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
package main
import (
"github.com/nsf/termbox-go"
)
type Gate struct {
pos Position
game *Game
form Form
exploded bool
switchForm bool
switchDelay int
}
func (o *Gate) Init(x, y int, game *Game) {
o.pos.X = x
o.pos.Y = y
o.game = game
o.switchDelay = 0
o.game.AddCollideAt(x, y+2)
o.game.AddCollideAt(x, y+1)
o.game.AddCollideAt(x, y)
}
func (o *Gate) SetForm(form Form) {
o.form = form
}
func (o *Gate) Type() GameObjectType {
if o.exploded {
return GOGateOpen
}
return GOGateClosed
}
func (o *Gate) Explode() {
if o.form == FormDemon {
o.exploded = true
o.game.RemoveCollideAt(o.pos.X, o.pos.Y+2)
o.game.RemoveCollideAt(o.pos.X, o.pos.Y+1)
o.game.RemoveCollideAt(o.pos.X, o.pos.Y)
}
}
func (o *Gate) Contains(x, y int) bool {
if o.pos.X <= x && o.pos.X+3 > x {
if o.pos.Y <= y && o.pos.Y+3 > y {
return true
}
}
return false
}
func (o *Gate) Draw() {
if o.exploded {
return
}
if o.form == FormDemon {
o.game.SetCell(o.pos.X, o.pos.Y, termbox.ColorMagenta)
// o.game.SetCell(o.pos.X+1, o.pos.Y, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+2, o.pos.Y, termbox.ColorWhite)
o.game.SetCell(o.pos.X+3, o.pos.Y, termbox.ColorMagenta)
// o.game.SetCell(o.pos.X, o.pos.Y+1, termbox.ColorRed)
o.game.SetCell(o.pos.X+1, o.pos.Y+1, termbox.ColorRed)
o.game.SetCell(o.pos.X+2, o.pos.Y+1, termbox.ColorRed)
// o.game.SetCell(o.pos.X+3, o.pos.Y+1, termbox.ColorRed)
o.game.SetCell(o.pos.X, o.pos.Y+2, termbox.ColorMagenta)
// o.game.SetCell(o.pos.X+1, o.pos.Y+2, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+2, o.pos.Y+2, termbox.ColorWhite)
o.game.SetCell(o.pos.X+3, o.pos.Y+2, termbox.ColorMagenta)
} else {
o.game.SetCell(o.pos.X, o.pos.Y, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+1, o.pos.Y, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+2, o.pos.Y, termbox.ColorWhite)
o.game.SetCell(o.pos.X+3, o.pos.Y, termbox.ColorWhite)
o.game.SetCell(o.pos.X, o.pos.Y+1, termbox.ColorWhite)
o.game.SetCell(o.pos.X+1, o.pos.Y+1, termbox.ColorYellow)
o.game.SetCell(o.pos.X+2, o.pos.Y+1, termbox.ColorYellow)
o.game.SetCell(o.pos.X+3, o.pos.Y+1, termbox.ColorWhite)
o.game.SetCell(o.pos.X, o.pos.Y+2, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+1, o.pos.Y+2, termbox.ColorWhite)
// o.game.SetCell(o.pos.X+2, o.pos.Y+2, termbox.ColorWhite)
o.game.SetCell(o.pos.X+3, o.pos.Y+2, termbox.ColorWhite)
}
}
func (o *Gate) Update() {
}