NewBubble -> bubble.go

This commit is contained in:
Josh Deprez 2021-09-16 15:07:14 +10:00
parent dd0cb76162
commit 43d95c0f65
2 changed files with 35 additions and 29 deletions

View file

@ -3,7 +3,6 @@ package game
import ( import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"image"
"math" "math"
"drjosh.dev/gurgle/engine" "drjosh.dev/gurgle/engine"
@ -114,34 +113,7 @@ func (aw *Awakeman) realUpdate() error {
aw.bubbleTimer-- aw.bubbleTimer--
if aw.bubbleTimer <= 0 { if aw.bubbleTimer <= 0 {
aw.bubbleTimer = bubblePeriod aw.bubbleTimer = bubblePeriod
bubble := &Bubble{ bubble := NewBubble(aw.Sprite.Actor.Pos.Add(geom.Pt3(1, -15, -1)))
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},
},
OneShot: true,
},
},
CellSize: image.Pt(8, 8),
Src: engine.ImageRef{Path: "assets/bubble.png"},
},
},
}
if err := engine.PreorderWalk(bubble, func(c, _ interface{}) error { if err := engine.PreorderWalk(bubble, func(c, _ interface{}) error {
if p, ok := c.(engine.Loader); ok { if p, ok := c.(engine.Loader); ok {
return p.Load(Assets) return p.Load(Assets)

View file

@ -1,6 +1,7 @@
package game package game
import ( import (
"image"
"math/rand" "math/rand"
"drjosh.dev/gurgle/engine" "drjosh.dev/gurgle/engine"
@ -14,6 +15,39 @@ type Bubble struct {
game *engine.Game game *engine.Game
} }
func NewBubble(pos geom.Int3) *Bubble {
return &Bubble{
Life: 60,
Sprite: engine.Sprite{
Actor: engine.Actor{
Pos: pos,
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},
},
OneShot: true,
},
},
CellSize: image.Pt(8, 8),
Src: engine.ImageRef{Path: "assets/bubble.png"},
},
},
}
}
func (b *Bubble) Scan() []interface{} { func (b *Bubble) Scan() []interface{} {
return []interface{}{&b.Sprite} return []interface{}{&b.Sprite}
} }