-
Notifications
You must be signed in to change notification settings - Fork 0
/
floor.go
170 lines (135 loc) · 3.9 KB
/
floor.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package objects
import (
_ "image/png"
"math/rand"
"github.com/darellanodev/jetpack-game/lib"
"github.com/darellanodev/jetpack-game/particles"
"github.com/hajimehoshi/ebiten/v2"
)
type FloorType int
const (
FloorNormal FloorType = iota
FloorLava
FloorLavaWithDrops
)
const (
lavaFloorFrameWidth = 180
lavaFloorFrameHeight = 53
lavaFloorFrameSpeed = 5
lavadropFloorLightMax = 0.2
lavadropLightIncrement = 0.03
lavadropMaxWarningTimes = 5
maxRandomDropWarningTime = 200
minRandomDropWarningTime = 200
)
type Floor struct {
x int
y int
FloorType FloorType
fire *particles.ParticlesSystem
collisionHitBox *ebiten.Image
imgFloor1 *ebiten.Image
imgLavaFloor *ebiten.Image
imgAnimFire *ebiten.Image
Lavadrop *Lavadrop
lavadropFloorLight float64
lavadropFloorWarning bool
lavadropFloorWarningTimes int
lavadropTimeToActivateWarning int
lavadropMaxTimeToActivateWarning int
jumpLavadrop bool
}
func NewFloor(floorSprites []*ebiten.Image) *Floor {
return &Floor{
x: 0,
y: 0,
collisionHitBox: floorSprites[0],
imgFloor1: floorSprites[0],
imgLavaFloor: floorSprites[1],
imgAnimFire: floorSprites[2],
Lavadrop: NewLavadrop(floorSprites[3]),
lavadropFloorLight: 0,
lavadropFloorWarning: false,
lavadropTimeToActivateWarning: 0,
lavadropMaxTimeToActivateWarning: rand.Intn(maxRandomDropWarningTime) + minRandomDropWarningTime,
jumpLavadrop: false,
}
}
func (f *Floor) CollisionHitBox() *ebiten.Image {
return f.collisionHitBox
}
func (f *Floor) Position() (int, int) {
return f.x, f.y
}
func (f *Floor) InitFloor() {
f.fire = &particles.ParticlesSystem{
CurrentSprite: f.imgAnimFire,
Creating: true,
PosX: f.x,
PosY: f.y,
}
}
func (f *Floor) MoveTo(x int, y int) {
f.x = x
f.y = y
lavadropX := x + lavaFloorFrameWidth / 2 - lavadropWith / 2
f.Lavadrop.SetInitialPosition(lavadropX, y)
}
func (f *Floor) IsLavaFloor() bool {
return f.FloorType == FloorLava || f.FloorType == FloorLavaWithDrops
}
func (f *Floor) Update() {
if f.lavadropFloorWarning {
if (f.lavadropFloorWarningTimes < lavadropMaxWarningTimes) && f.lavadropFloorLight >= lavadropFloorLightMax {
f.lavadropFloorWarningTimes++
f.lavadropFloorLight = 0
}
if (f.lavadropFloorLight < lavadropFloorLightMax) {
f.lavadropFloorLight += lavadropLightIncrement
}
if (f.lavadropFloorWarningTimes >= lavadropMaxWarningTimes) {
f.lavadropFloorWarningTimes = 0
f.lavadropFloorLight = 0
f.lavadropFloorWarning = false
f.jumpLavadrop = true
}
} else {
if f.lavadropTimeToActivateWarning >= f.lavadropMaxTimeToActivateWarning {
f.lavadropFloorWarning = true
f.lavadropTimeToActivateWarning = 0
f.lavadropMaxTimeToActivateWarning = rand.Intn(maxRandomDropWarningTime) + minRandomDropWarningTime
} else {
f.lavadropTimeToActivateWarning++
}
}
if f.IsLavaFloor() && f.fire.Creating {
f.fire.UpdateUp(lavaFloorFrameWidth)
}
if f.FloorType == FloorLavaWithDrops && f.jumpLavadrop {
f.jumpLavadrop = f.Lavadrop.Update()
}
}
func (f *Floor) drawLavaFloor(screen *ebiten.Image, subImage *ebiten.Image) {
lib.DrawNormalImage(screen, subImage, f.x, f.y)
}
func (f *Floor) drawLavaFloorDrop(screen *ebiten.Image, subImage *ebiten.Image) {
lib.DrawLightenImage(screen, subImage, f.x, f.y, f.lavadropFloorLight)
}
func (f *Floor) Draw(screen *ebiten.Image, spriteCount int) {
var subImage *ebiten.Image
if f.IsLavaFloor() {
subImage = lib.GetSubImage(f.imgLavaFloor, lavaFloorFrameWidth, lavaFloorFrameHeight, spriteCount, frameCount, lavaFloorFrameSpeed)
}
switch f.FloorType {
case FloorNormal:
lib.DrawNormalImage(screen, f.imgFloor1, f.x, f.y)
case FloorLava:
f.drawLavaFloor(screen, subImage)
case FloorLavaWithDrops:
f.Lavadrop.Draw(screen)
f.drawLavaFloorDrop(screen, subImage)
}
if f.IsLavaFloor() && f.fire.Creating {
f.fire.Draw(screen)
}
}