-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctrl.go
90 lines (84 loc) · 1.99 KB
/
ctrl.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
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type Button struct {
AABB
Pressed bool
}
// CtrlScene has the Boss in the control room with the level design buttons.
type CtrlScene struct {
SceneData
Buttons []Button
}
// NewCtrlScene creates a new control room scheme with boss at the door.
func NewCtrlScene(g *Game) *CtrlScene {
room := &Room{
Width: ScreenWidth,
Height: ScreenHeight,
Obstacles: []AABB{
{0, 0, ScreenWidth, 40},
{0, ScreenHeight - 40, ScreenWidth/2 - 100, 40},
{ScreenWidth/2 + 100, ScreenHeight - 40, ScreenWidth/2 - 100, 40},
{0, 40, 40, ScreenHeight - 80},
{ScreenWidth - 40, 40, 40, ScreenHeight - 80},
},
Floor: Color7,
Wall: Color6,
Button: Color3,
}
idle, left, right := BossAnimations()
bossX, bossY := ScreenWidth/2-64., ScreenHeight-129.
boss := &Boss{
Mob: Mob{
AABB: AABB{bossX, bossY, 128, 128},
IdleAnimation: idle,
LeftAnimation: left,
RightAnimation: right,
Color: Color0,
},
}
room.Triggers = append(room.Triggers, Trigger{
AABB: AABB{ScreenWidth/2 - 150, ScreenHeight - 1, 300, 1},
Fn: func() {
g.Scene = NewWaitScene(g, ScreenWidth/2-64, 1)
},
})
var buttons []Button
for i := 0; i < 8; i++ {
i := i
button := Button{
AABB: AABB{100 + 150*float64(i), 100, 32, 32},
}
buttons = append(buttons, button)
room.Triggers = append(room.Triggers, Trigger{
AABB: button.AABB,
Fn: func() {
buttons[i].Pressed = true
},
})
}
return &CtrlScene{
SceneData{
Room: room,
Boss: boss,
},
buttons,
}
}
// Update updates the boss and triggers in the scene.
func (c *CtrlScene) Update(g *Game) {
c.Boss.Update(c.SceneData)
c.Room.Update(c.SceneData)
}
// Draw draws the boss in the control room.
func (c *CtrlScene) Draw(screen *ebiten.Image) {
c.Room.Draw(screen)
for _, btn := range c.Buttons {
if btn.Pressed {
ebitenutil.DrawRect(screen, btn.X, btn.Y, btn.W, btn.H, Color6)
}
}
c.Boss.Draw(screen)
}