bubble
This commit is contained in:
parent
4a7deaca47
commit
ecff7f9850
4 changed files with 81 additions and 0 deletions
BIN
asset_src/bubble.aseprite
Normal file
BIN
asset_src/bubble.aseprite
Normal file
Binary file not shown.
BIN
game/assets/bubble.png
Normal file
BIN
game/assets/bubble.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
52
game/aw.go
52
game/aw.go
|
@ -3,6 +3,7 @@ package game
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"drjosh.dev/gurgle/engine"
|
"drjosh.dev/gurgle/engine"
|
||||||
|
@ -30,6 +31,7 @@ type Awakeman struct {
|
||||||
CameraID string
|
CameraID string
|
||||||
ToastID string
|
ToastID string
|
||||||
|
|
||||||
|
game *engine.Game
|
||||||
camera *engine.Camera
|
camera *engine.Camera
|
||||||
toast *engine.DebugToast
|
toast *engine.DebugToast
|
||||||
vel geom.Float3
|
vel geom.Float3
|
||||||
|
@ -38,6 +40,7 @@ type Awakeman struct {
|
||||||
jumpBuffer int
|
jumpBuffer int
|
||||||
noclip bool
|
noclip bool
|
||||||
spawnPoint geom.Int3
|
spawnPoint geom.Int3
|
||||||
|
bubbleTimer int
|
||||||
|
|
||||||
anims map[string]*engine.Anim
|
anims map[string]*engine.Anim
|
||||||
}
|
}
|
||||||
|
@ -104,8 +107,56 @@ func (aw *Awakeman) realUpdate() error {
|
||||||
coyoteTime = 5
|
coyoteTime = 5
|
||||||
jumpBufferTime = 5
|
jumpBufferTime = 5
|
||||||
respawnY = 1000
|
respawnY = 1000
|
||||||
|
bubblePeriod = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Add a bubble?
|
||||||
|
aw.bubbleTimer--
|
||||||
|
if aw.bubbleTimer <= 0 {
|
||||||
|
aw.bubbleTimer = bubblePeriod
|
||||||
|
bubble := &Bubble{
|
||||||
|
Life: 60,
|
||||||
|
Sprite: engine.Sprite{
|
||||||
|
Actor: engine.Actor{
|
||||||
|
CollisionDomain: aw.Sprite.Actor.CollisionDomain,
|
||||||
|
Pos: aw.Sprite.Actor.Pos.Add(geom.Pt3(1, -15, -1)),
|
||||||
|
Bounds: geom.Box{Min: geom.Pt3(-4, -4, -4), Max: geom.Pt3(4, 4, 4)},
|
||||||
|
},
|
||||||
|
DrawOffset: image.Pt(-4, -4),
|
||||||
|
Sheet: engine.Sheet{
|
||||||
|
AnimDefs: map[string]*engine.AnimDef{
|
||||||
|
"bubble": {
|
||||||
|
Steps: []engine.AnimStep{
|
||||||
|
{Cell: 0, Duration: 5},
|
||||||
|
{Cell: 1, Duration: 15},
|
||||||
|
{Cell: 2, Duration: 20},
|
||||||
|
{Cell: 3, Duration: 15},
|
||||||
|
{Cell: 4, Duration: 3},
|
||||||
|
{Cell: 5, Duration: 2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CellSize: image.Pt(8, 8),
|
||||||
|
Src: engine.ImageRef{Path: "assets/bubble.png"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
engine.PreorderWalk(bubble, func(c, _ interface{}) error {
|
||||||
|
if p, ok := c.(engine.Loader); ok {
|
||||||
|
return p.Load(Assets)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
aw.game.Register(bubble, aw.game.Parent(aw))
|
||||||
|
engine.PreorderWalk(bubble, func(c, _ interface{}) error {
|
||||||
|
if p, ok := c.(engine.Prepper); ok {
|
||||||
|
return p.Prepare(aw.game)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
bubble.Sprite.SetAnim(bubble.Sprite.Sheet.NewAnim("bubble"))
|
||||||
|
}
|
||||||
|
|
||||||
// Fell below some threshold?
|
// Fell below some threshold?
|
||||||
if aw.Sprite.Actor.Pos.Y > respawnY {
|
if aw.Sprite.Actor.Pos.Y > respawnY {
|
||||||
aw.Sprite.Actor.Pos = aw.spawnPoint
|
aw.Sprite.Actor.Pos = aw.spawnPoint
|
||||||
|
@ -219,6 +270,7 @@ func (aw *Awakeman) realUpdate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aw *Awakeman) Prepare(game *engine.Game) error {
|
func (aw *Awakeman) Prepare(game *engine.Game) error {
|
||||||
|
aw.game = game
|
||||||
cam, ok := game.Component(aw.CameraID).(*engine.Camera)
|
cam, ok := game.Component(aw.CameraID).(*engine.Camera)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("component %q not *engine.Camera", aw.CameraID)
|
return fmt.Errorf("component %q not *engine.Camera", aw.CameraID)
|
||||||
|
|
29
game/bubble.go
Normal file
29
game/bubble.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"drjosh.dev/gurgle/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Bubble struct {
|
||||||
|
Life int
|
||||||
|
Sprite engine.Sprite
|
||||||
|
|
||||||
|
game *engine.Game
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bubble) Scan() []interface{} {
|
||||||
|
return []interface{}{&b.Sprite}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bubble) Prepare(g *engine.Game) error {
|
||||||
|
b.game = g
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bubble) Update() error {
|
||||||
|
b.Life--
|
||||||
|
if b.Life <= 0 {
|
||||||
|
b.game.Unregister(b)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue