Use Azulian doodad as player character instead of empty dummy

This commit is contained in:
Noah 2019-05-01 18:30:30 -07:00
parent af35703df0
commit d042457365
4 changed files with 67 additions and 19 deletions

32
pkg/doodads/dummy.go Normal file
View File

@ -0,0 +1,32 @@
package doodads
import (
"git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/pkg/level"
)
// NewDummy creates a placeholder dummy doodad with a giant "X" across it.
func NewDummy(size int) *Doodad {
dummy := New(size)
red := &level.Swatch{
Color: render.Red,
Name: "missing color",
}
dummy.Palette.Swatches = []*level.Swatch{red}
for i := 0; i < size; i++ {
left := render.NewPoint(int32(i), int32(i))
right := render.NewPoint(int32(size-i), int32(i))
// Draw the stroke 2 pixels thick
dummy.Layers[0].Chunker.Set(left, red)
dummy.Layers[0].Chunker.Set(right, red)
left.Y++
right.Y++
dummy.Layers[0].Chunker.Set(left, red)
dummy.Layers[0].Chunker.Set(right, red)
}
return dummy
}

View File

@ -6,7 +6,7 @@ import (
"git.kirsle.net/apps/doodle/lib/events" "git.kirsle.net/apps/doodle/lib/events"
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/doodads/dummy" "git.kirsle.net/apps/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
"git.kirsle.net/apps/doodle/pkg/scripting" "git.kirsle.net/apps/doodle/pkg/scripting"
@ -86,16 +86,29 @@ func (s *PlayScene) Setup(d *Doodle) error {
if err := s.scripting.InstallScripts(s.Level); err != nil { if err := s.scripting.InstallScripts(s.Level); err != nil {
log.Error("PlayScene.Setup: failed to InstallScripts: %s", err) log.Error("PlayScene.Setup: failed to InstallScripts: %s", err)
} }
if err := s.drawing.InstallScripts(); err != nil {
log.Error("PlayScene.Setup: failed to drawing.InstallScripts: %s", err) // Load in the player character.
player, err := doodads.LoadJSON("./assets/doodads/azu-blu.doodad")
if err != nil {
log.Error("PlayScene.Setup: failed to load player doodad: %s", err)
player = doodads.NewDummy(32)
} }
player := dummy.NewPlayer() s.Player = uix.NewActor("PLAYER", &level.Actor{}, player)
s.Player = uix.NewActor(player.ID(), &level.Actor{}, player.Doodad)
s.Player.MoveTo(render.NewPoint(128, 128)) s.Player.MoveTo(render.NewPoint(128, 128))
s.drawing.AddActor(s.Player) s.drawing.AddActor(s.Player)
s.drawing.FollowActor = s.Player.ID() s.drawing.FollowActor = s.Player.ID()
// Set up the player character's script in the VM.
if err := s.scripting.AddLevelScript(s.Player.ID()); err != nil {
log.Error("PlayScene.Setup: scripting.InstallActor(player) failed: %s", err)
}
// Run all the actor scripts' main() functions.
if err := s.drawing.InstallScripts(); err != nil {
log.Error("PlayScene.Setup: failed to drawing.InstallScripts: %s", err)
}
d.Flash("Entered Play Mode. Press 'E' to edit this map.") d.Flash("Entered Play Mode. Press 'E' to edit this map.")
return nil return nil

View File

@ -36,7 +36,15 @@ func (s *Supervisor) Loop() error {
// InstallScripts loads scripts for all actors in the level. // InstallScripts loads scripts for all actors in the level.
func (s *Supervisor) InstallScripts(level *level.Level) error { func (s *Supervisor) InstallScripts(level *level.Level) error {
for _, actor := range level.Actors { for _, actor := range level.Actors {
id := actor.ID() if err := s.AddLevelScript(actor.ID()); err != nil {
return err
}
}
return nil
}
// AddLevelScript adds a script to the supervisor with level hooks.
func (s *Supervisor) AddLevelScript(id string) error {
log.Debug("InstallScripts: load script from Actor %s", id) log.Debug("InstallScripts: load script from Actor %s", id)
if _, ok := s.scripts[id]; ok { if _, ok := s.scripts[id]; ok {
@ -47,7 +55,7 @@ func (s *Supervisor) InstallScripts(level *level.Level) error {
if err := s.scripts[id].RegisterLevelHooks(); err != nil { if err := s.scripts[id].RegisterLevelHooks(); err != nil {
return err return err
} }
}
return nil return nil
} }

View File

@ -6,7 +6,6 @@ import (
"git.kirsle.net/apps/doodle/lib/events" "git.kirsle.net/apps/doodle/lib/events"
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/lib/ui"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level"
) )
@ -119,10 +118,6 @@ func (w *Canvas) loopFollowActor(ev *events.State) error {
continue continue
} }
actor.Canvas.SetBorderSize(2)
actor.Canvas.SetBorderColor(render.Red)
actor.Canvas.SetBorderStyle(ui.BorderSolid)
var ( var (
APosition = actor.Position() // absolute world position APosition = actor.Position() // absolute world position
ASize = actor.Drawing.Size() ASize = actor.Drawing.Size()