Doodads: Crumbly Floor, Start Flag & State Blocks
Add new doodads: * Start Flag: place this in a level to set the spawn point of the player character. If no flag is found, the player spawns at 0,0 in the top corner of the map. Only use one Start Flag per level, otherwise the player will randomly spawn at one of them. * Crumbly Floor: a solid floor that begins to shake and then fall apart after a moment when a mobile character steps on it. The floor respawns after 5 seconds. * State Blocks: blue and orange blocks that toggle between solid and pass-thru whenever a State Button is activated. * State Button: a solid "ON/OFF" block that toggles State Blocks back and forth when touched. Only activates if touched on the side or bottom; acts as a solid floor when walked on from the top. New features for doodad scripts: * Actor scripts: call SetMobile(true) to mark an actor as a mobile mob (i.e. player character or enemy). Other doodads can check if the actor colliding with them IsMobile so they don't activate if placed too close to other (non-mobile) doodads in a level. The Blue and Red Azulians are the only mobile characters so far. * Message.Broadcast allows sending a pub/sub message out to ALL doodads in the level, instead of only to linked doodads as Message.Publish does. This is used for the State Blocks to globally communicate on/off status without needing to link them all together manually.
|
@ -11,11 +11,11 @@ import (
|
|||
|
||||
"image/png"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/image/bmp"
|
||||
)
|
||||
|
@ -322,7 +322,7 @@ func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette
|
|||
newColors[color.String()] = swatch
|
||||
}
|
||||
|
||||
chunker.Set(render.NewPoint(int32(x), int32(y)), swatch)
|
||||
chunker.Set(render.NewPoint(x, y), swatch)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ package commands
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"git.kirsle.net/go/render/sdl"
|
||||
doodle "git.kirsle.net/apps/doodle/pkg"
|
||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||
"git.kirsle.net/apps/doodle/pkg/bindata"
|
||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||
"git.kirsle.net/go/render/sdl"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
_ "image/png"
|
||||
|
|
|
@ -7,6 +7,7 @@ function main() {
|
|||
|
||||
var direction = "right";
|
||||
|
||||
Self.SetMobile(true);
|
||||
Self.SetGravity(true);
|
||||
Self.AddAnimation("walk-left", 100, ["red-wl1", "red-wl2", "red-wl3", "red-wl4"]);
|
||||
Self.AddAnimation("walk-right", 100, ["red-wr1", "red-wr2", "red-wr3", "red-wr4"]);
|
||||
|
|
|
@ -7,6 +7,7 @@ function main() {
|
|||
var animStart = animEnd = 0;
|
||||
var animFrame = animStart;
|
||||
|
||||
Self.SetMobile(true);
|
||||
Self.SetGravity(true);
|
||||
Self.SetHitbox(7, 4, 17, 28);
|
||||
Self.AddAnimation("walk-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]);
|
||||
|
|
|
@ -115,6 +115,33 @@ objects() {
|
|||
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad
|
||||
doodad install-script exit-flag.js exit-flag.doodad
|
||||
|
||||
doodad convert -t "Start Flag" start-flag.png start-flag.doodad
|
||||
|
||||
cp *.doodad ../../../assets/doodads/
|
||||
|
||||
cd ../crumbly-floor
|
||||
|
||||
doodad convert -t "Crumbly Floor" floor.png shake1.png shake2.png \
|
||||
fall1.png fall2.png fall3.png fall4.png fallen.png \
|
||||
crumbly-floor.doodad
|
||||
doodad install-script crumbly-floor.js crumbly-floor.doodad
|
||||
cp *.doodad ../../../assets/doodads/
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
onoff() {
|
||||
cd on-off/
|
||||
|
||||
doodad convert -t "State Button" blue-button.png orange-button.png state-button.doodad
|
||||
doodad install-script state-button.js state-button.doodad
|
||||
|
||||
doodad convert -t "State Block (Blue)" blue-on.png blue-off.png state-block-blue.doodad
|
||||
doodad install-script state-block-blue.js state-block-blue.doodad
|
||||
|
||||
doodad convert -t "State Block (Orange)" orange-off.png orange-on.png state-block-orange.doodad
|
||||
doodad install-script state-block-orange.js state-block-orange.doodad
|
||||
|
||||
cp *.doodad ../../../assets/doodads/
|
||||
|
||||
cd ..
|
||||
|
@ -126,5 +153,6 @@ doors
|
|||
trapdoors
|
||||
azulians
|
||||
objects
|
||||
onoff
|
||||
doodad edit-doodad -quiet -lock -author "Noah" ../../assets/doodads/*.doodad
|
||||
doodad edit-doodad -hide ../../assets/doodads/azu-blu.doodad
|
||||
|
|
60
dev-assets/doodads/crumbly-floor/crumbly-floor.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Crumbly Floor.
|
||||
function main() {
|
||||
Self.SetHitbox(0, 0, 65, 7);
|
||||
|
||||
Self.AddAnimation("shake", 100, ["shake1", "shake2", "floor", "shake1", "shake2", "floor"]);
|
||||
Self.AddAnimation("fall", 100, ["fall1", "fall2", "fall3", "fall4"]);
|
||||
|
||||
// Recover time for the floor to respawn.
|
||||
var recover = 5000;
|
||||
|
||||
// States of the floor.
|
||||
var stateSolid = 0;
|
||||
var stateShaking = 1;
|
||||
var stateFalling = 2;
|
||||
var stateFallen = 3;
|
||||
var state = stateSolid;
|
||||
|
||||
// Started the animation?
|
||||
var startedAnimation = false;
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
// Only trigger for mobile characters.
|
||||
if (!e.Actor.IsMobile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the floor is falling, the player passes right thru.
|
||||
if (state === stateFalling || state === stateFallen) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Floor is solid until it begins to fall.
|
||||
if (e.InHitbox && (state === stateSolid || state === stateShaking)) {
|
||||
// Only activate when touched from the top.
|
||||
if (e.Overlap.Y > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Begin the animation sequence if we're in the solid state.
|
||||
if (state === stateSolid) {
|
||||
state = stateShaking;
|
||||
Self.PlayAnimation("shake", function() {
|
||||
state = stateFalling;
|
||||
Self.PlayAnimation("fall", function() {
|
||||
state = stateFallen;
|
||||
Self.ShowLayerNamed("fallen");
|
||||
|
||||
// Recover after a while.
|
||||
setTimeout(function() {
|
||||
Self.ShowLayer(0);
|
||||
state = stateSolid;
|
||||
}, recover);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
BIN
dev-assets/doodads/crumbly-floor/fall1.png
Normal file
After Width: | Height: | Size: 1021 B |
BIN
dev-assets/doodads/crumbly-floor/fall2.png
Normal file
After Width: | Height: | Size: 986 B |
BIN
dev-assets/doodads/crumbly-floor/fall3.png
Normal file
After Width: | Height: | Size: 957 B |
BIN
dev-assets/doodads/crumbly-floor/fall4.png
Normal file
After Width: | Height: | Size: 855 B |
BIN
dev-assets/doodads/crumbly-floor/fallen.png
Normal file
After Width: | Height: | Size: 652 B |
BIN
dev-assets/doodads/crumbly-floor/floor.png
Normal file
After Width: | Height: | Size: 868 B |
BIN
dev-assets/doodads/crumbly-floor/shake1.png
Normal file
After Width: | Height: | Size: 897 B |
BIN
dev-assets/doodads/crumbly-floor/shake2.png
Normal file
After Width: | Height: | Size: 891 B |
|
@ -23,8 +23,8 @@ function main() {
|
|||
});
|
||||
} else {
|
||||
animating = true;
|
||||
opened = false;
|
||||
Self.PlayAnimation("close", function() {
|
||||
opened = false;
|
||||
animating = false;
|
||||
})
|
||||
}
|
||||
|
|
BIN
dev-assets/doodads/objects/start-flag.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
dev-assets/doodads/on-off/blue-button.png
Normal file
After Width: | Height: | Size: 741 B |
BIN
dev-assets/doodads/on-off/blue-off.png
Normal file
After Width: | Height: | Size: 648 B |
BIN
dev-assets/doodads/on-off/blue-on.png
Normal file
After Width: | Height: | Size: 683 B |
BIN
dev-assets/doodads/on-off/orange-button.png
Normal file
After Width: | Height: | Size: 751 B |
BIN
dev-assets/doodads/on-off/orange-off.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
dev-assets/doodads/on-off/orange-on.png
Normal file
After Width: | Height: | Size: 687 B |
28
dev-assets/doodads/on-off/state-block-blue.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Blue State Block
|
||||
function main() {
|
||||
Self.SetHitbox(0, 0, 33, 33);
|
||||
|
||||
// Blue block is ON by default.
|
||||
var state = true;
|
||||
|
||||
Message.Subscribe("broadcast:state-change", function(newState) {
|
||||
state = !newState;
|
||||
console.warn("BLUE BLOCK Received state=%+v, set mine to %+v", newState, state);
|
||||
|
||||
// Layer 0: ON
|
||||
// Layer 1: OFF
|
||||
if (state) {
|
||||
Self.ShowLayer(0);
|
||||
} else {
|
||||
Self.ShowLayer(1);
|
||||
}
|
||||
});
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
if (e.Actor.IsMobile() && e.InHitbox) {
|
||||
if (state) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
28
dev-assets/doodads/on-off/state-block-orange.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Orange State Block
|
||||
function main() {
|
||||
Self.SetHitbox(0, 0, 33, 33);
|
||||
|
||||
// Orange block is OFF by default.
|
||||
var state = false;
|
||||
|
||||
Message.Subscribe("broadcast:state-change", function(newState) {
|
||||
state = newState;
|
||||
console.warn("ORANGE BLOCK Received state=%+v, set mine to %+v", newState, state);
|
||||
|
||||
// Layer 0: OFF
|
||||
// Layer 1: ON
|
||||
if (state) {
|
||||
Self.ShowLayer(1);
|
||||
} else {
|
||||
Self.ShowLayer(0);
|
||||
}
|
||||
});
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
if (e.Actor.IsMobile() && e.InHitbox) {
|
||||
if (state) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
47
dev-assets/doodads/on-off/state-button.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
// State Block Control Button
|
||||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
Self.SetHitbox(0, 0, 33, 33);
|
||||
|
||||
// When the button is activated, don't keep toggling state until we're not
|
||||
// being touched again.
|
||||
var colliding = false;
|
||||
|
||||
// Button is "OFF" by default.
|
||||
var state = false;
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
if (colliding) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only trigger for mobile characters.
|
||||
if (e.Actor.IsMobile()) {
|
||||
console.log("Mobile actor %s touched the on/off button!", e.Actor.Actor.Filename);
|
||||
|
||||
// Only activate if touched from the bottom or sides.
|
||||
if (e.Overlap.Y === 0) {
|
||||
console.log("... but touched the top!");
|
||||
return false;
|
||||
}
|
||||
|
||||
colliding = true;
|
||||
console.log(" -> emit state change");
|
||||
state = !state;
|
||||
Message.Broadcast("broadcast:state-change", state);
|
||||
|
||||
if (state) {
|
||||
Self.ShowLayer(1);
|
||||
} else {
|
||||
Self.ShowLayer(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Always a solid button.
|
||||
return false;
|
||||
});
|
||||
|
||||
Events.OnLeave(function(e) {
|
||||
colliding = false;
|
||||
})
|
||||
}
|
|
@ -6,6 +6,9 @@
|
|||
* `don't edit and drive` - enable editing while playing a level.
|
||||
* `scroll scroll scroll your boat` - enable scrolling the level with arrow keys
|
||||
while playing a level.
|
||||
* `import antigravity` - during Play Mode, disables gravity for the player
|
||||
character and allows free movement in all directions with the arrow keys.
|
||||
Enter the cheat again to restore gravity to normal.
|
||||
|
||||
## Bool Props
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ package collision_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||
"git.kirsle.net/go/render"
|
||||
)
|
||||
|
||||
func TestActorCollision(t *testing.T) {
|
||||
|
|
|
@ -49,6 +49,20 @@ func (c Command) Run(d *Doodle) error {
|
|||
d.Flash("Use this cheat in Play Mode to make the level scrollable.")
|
||||
}
|
||||
return nil
|
||||
} else if c.Raw == "import antigravity" {
|
||||
if playScene, ok := d.Scene.(*PlayScene); ok {
|
||||
playScene.antigravity = !playScene.antigravity
|
||||
playScene.Player.SetGravity(!playScene.antigravity)
|
||||
|
||||
if playScene.antigravity {
|
||||
d.Flash("Gravity disabled for player character.")
|
||||
} else {
|
||||
d.Flash("Gravity restored for player character.")
|
||||
}
|
||||
} else {
|
||||
d.Flash("Use this cheat in Play Mode to disable gravity for the player character.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch c.Command {
|
||||
|
|
|
@ -25,8 +25,11 @@ type Actor interface {
|
|||
MoveTo(render.Point) // Set current Position to {X,Y}.
|
||||
}
|
||||
|
||||
// GetBoundingRect computes the full pairs of points for the collision box
|
||||
// around a doodad actor.
|
||||
// GetBoundingRect computes the full pairs of points for the bounding box of
|
||||
// the actor.
|
||||
//
|
||||
// The X,Y coordinates are the position in the level of the actor,
|
||||
// The W,H are the size of the actor's drawn box.
|
||||
func GetBoundingRect(d Actor) render.Rect {
|
||||
var (
|
||||
P = d.Position()
|
||||
|
@ -40,6 +43,27 @@ func GetBoundingRect(d Actor) render.Rect {
|
|||
}
|
||||
}
|
||||
|
||||
// GetBoundingRectHitbox returns the bounding rect of the Actor taking into
|
||||
// account their self-declared collision hitbox.
|
||||
//
|
||||
// The rect returned has the X,Y coordinate set to the actor's position, plus
|
||||
// the X,Y of their hitbox, if any.
|
||||
//
|
||||
// The W,H of the rect is the W,H of their declared hitbox.
|
||||
//
|
||||
// If the actor has NOT declared its hitbox, this function returns exactly the
|
||||
// same way as GetBoundingRect() does.
|
||||
func GetBoundingRectHitbox(d Actor, hitbox render.Rect) render.Rect {
|
||||
rect := GetBoundingRect(d)
|
||||
if !hitbox.IsZero() {
|
||||
rect.X += hitbox.X
|
||||
rect.Y += hitbox.Y
|
||||
rect.W = hitbox.W
|
||||
rect.H = hitbox.H
|
||||
}
|
||||
return rect
|
||||
}
|
||||
|
||||
// GetBoundingRectWithHitbox is like GetBoundingRect but adjusts it for the
|
||||
// relative hitbox of the actor.
|
||||
// func GetBoundingRectWithHitbox(d Actor, hitbox render.Rect) render.Rect {
|
||||
|
|
|
@ -76,21 +76,6 @@ func (d *Drawing) SetGrounded(v bool) {
|
|||
d.grounded = v
|
||||
}
|
||||
|
||||
// // SetHitbox sets the actor's elected hitbox.
|
||||
// func (d *Drawing) SetHitbox(x, y, w, h int) {
|
||||
// d.hitbox = render.Rect{
|
||||
// X: int32(x),
|
||||
// Y: int32(y),
|
||||
// W: int32(w),
|
||||
// H: int32(h),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Hitbox returns the actor's elected hitbox.
|
||||
// func (d *Drawing) Hitbox() render.Rect {
|
||||
// return d.hitbox
|
||||
// }
|
||||
|
||||
// MoveBy a relative value.
|
||||
func (d *Drawing) MoveBy(by render.Point) {
|
||||
d.point.Add(by)
|
||||
|
|
|
@ -3,10 +3,10 @@ package doodle
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
)
|
||||
|
||||
// SetupPalette sets up the palette panel.
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/go/render"
|
||||
)
|
||||
|
||||
// Test the high level Chunker.
|
||||
|
|
|
@ -50,6 +50,7 @@ type PlayScene struct {
|
|||
|
||||
// Player character
|
||||
Player *uix.Actor
|
||||
antigravity bool // Cheat: disable player gravity
|
||||
playerJumpCounter int // limit jump length
|
||||
}
|
||||
|
||||
|
@ -154,21 +155,7 @@ func (s *PlayScene) Setup(d *Doodle) error {
|
|||
}
|
||||
|
||||
// Load in the player character.
|
||||
player, err := doodads.LoadFile("azu-blu.doodad")
|
||||
if err != nil {
|
||||
log.Error("PlayScene.Setup: failed to load player doodad: %s", err)
|
||||
player = doodads.NewDummy(32)
|
||||
}
|
||||
|
||||
s.Player = uix.NewActor("PLAYER", &level.Actor{}, player)
|
||||
s.Player.MoveTo(render.NewPoint(128, 128))
|
||||
s.drawing.AddActor(s.Player)
|
||||
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)
|
||||
}
|
||||
s.setupPlayer()
|
||||
|
||||
// Run all the actor scripts' main() functions.
|
||||
if err := s.drawing.InstallScripts(); err != nil {
|
||||
|
@ -186,6 +173,60 @@ func (s *PlayScene) Setup(d *Doodle) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// setupPlayer creates and configures the Player Character in the level.
|
||||
func (s *PlayScene) setupPlayer() {
|
||||
// Load in the player character.
|
||||
player, err := doodads.LoadFile("azu-blu.doodad")
|
||||
if err != nil {
|
||||
log.Error("PlayScene.Setup: failed to load player doodad: %s", err)
|
||||
player = doodads.NewDummy(32)
|
||||
}
|
||||
|
||||
// Find the spawn point of the player. Search the level for the
|
||||
// "start-flag.doodad"
|
||||
var (
|
||||
spawn render.Point
|
||||
flagCount int
|
||||
)
|
||||
for actorID, actor := range s.Level.Actors {
|
||||
if actor.Filename == "start-flag.doodad" {
|
||||
if flagCount > 1 {
|
||||
break
|
||||
}
|
||||
|
||||
// TODO: start-flag.doodad is 86x86 pixels but we can't tell that
|
||||
// from right here.
|
||||
size := render.NewRect(86, 86)
|
||||
log.Info("Found start-flag.doodad at %s (ID %s)", actor.Point, actorID)
|
||||
spawn = render.NewPoint(
|
||||
// X: centered inside the flag.
|
||||
actor.Point.X+(size.W/2)-(player.Layers[0].Chunker.Size/2),
|
||||
|
||||
// Y: the bottom of the flag, 4 pixels from the floor.
|
||||
actor.Point.Y+size.H-4-(player.Layers[0].Chunker.Size),
|
||||
)
|
||||
flagCount++
|
||||
}
|
||||
}
|
||||
|
||||
// Surface warnings around the spawn flag.
|
||||
if flagCount == 0 {
|
||||
s.d.Flash("Warning: this level contained no Start Flag.")
|
||||
} else if flagCount > 1 {
|
||||
s.d.Flash("Warning: this level contains multiple Start Flags. Player spawn point is ambiguous.")
|
||||
}
|
||||
|
||||
s.Player = uix.NewActor("PLAYER", &level.Actor{}, player)
|
||||
s.Player.MoveTo(spawn)
|
||||
s.drawing.AddActor(s.Player)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// SetupAlertbox configures the alert box UI.
|
||||
func (s *PlayScene) SetupAlertbox() {
|
||||
window := ui.NewWindow("Level Completed")
|
||||
|
@ -393,31 +434,24 @@ func (s *PlayScene) movePlayer(ev *event.State) {
|
|||
if ev.Right {
|
||||
velocity.X = playerSpeed
|
||||
}
|
||||
if ev.Up && (s.Player.Grounded() || s.playerJumpCounter >= 0) {
|
||||
if ev.Up && (s.Player.Grounded() || s.playerJumpCounter >= 0 || s.antigravity) {
|
||||
velocity.Y = -playerSpeed
|
||||
|
||||
if s.Player.Grounded() {
|
||||
s.playerJumpCounter = 20
|
||||
}
|
||||
}
|
||||
if ev.Down && s.antigravity {
|
||||
velocity.Y = playerSpeed
|
||||
}
|
||||
|
||||
if !s.Player.Grounded() {
|
||||
s.playerJumpCounter--
|
||||
}
|
||||
|
||||
// // Apply gravity if not grounded.
|
||||
// if !s.Player.Grounded() {
|
||||
// // Gravity has to pipe through the collision checker, too, so it
|
||||
// // can't give us a cheated downward boost.
|
||||
// velocity.Y += gravity
|
||||
// }
|
||||
|
||||
s.Player.SetVelocity(velocity)
|
||||
|
||||
// TODO: invoke the player OnKeypress for animation testing
|
||||
// if velocity != render.Origin {
|
||||
s.scripting.To(s.Player.ID()).Events.RunKeypress(ev)
|
||||
// }
|
||||
}
|
||||
|
||||
// Drawing returns the private world drawing, for debugging with the console.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package doodle
|
||||
|
||||
import (
|
||||
"git.kirsle.net/go/render/event"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render/event"
|
||||
)
|
||||
|
||||
// Scene is an abstraction for a game mode in Doodle. The app points to one
|
||||
|
|
|
@ -18,7 +18,7 @@ RegisterPublishHooks adds the pub/sub hooks to a JavaScript VM.
|
|||
This adds the global methods `Message.Subscribe(name, func)` and
|
||||
`Message.Publish(name, args)` to the JavaScript VM's scope.
|
||||
*/
|
||||
func RegisterPublishHooks(vm *VM) {
|
||||
func RegisterPublishHooks(s *Supervisor, vm *VM) {
|
||||
// Goroutine to watch the VM's inbound channel and invoke Subscribe handlers
|
||||
// for any matching messages received.
|
||||
go func() {
|
||||
|
@ -47,7 +47,6 @@ func RegisterPublishHooks(vm *VM) {
|
|||
},
|
||||
|
||||
"Publish": func(name string, v ...interface{}) {
|
||||
log.Error("PUBLISH: %s %+v", name, v)
|
||||
for _, channel := range vm.Outbound {
|
||||
channel <- Message{
|
||||
Name: name,
|
||||
|
@ -55,5 +54,15 @@ func RegisterPublishHooks(vm *VM) {
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
"Broadcast": func(name string, v ...interface{}) {
|
||||
// Send the message to all actor VMs.
|
||||
for _, vm := range s.scripts {
|
||||
vm.Inbound <- Message{
|
||||
Name: name,
|
||||
Args: v,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ func (s *Supervisor) AddLevelScript(id string) error {
|
|||
}
|
||||
|
||||
s.scripts[id] = NewVM(id)
|
||||
RegisterPublishHooks(s.scripts[id])
|
||||
RegisterPublishHooks(s, s.scripts[id])
|
||||
RegisterEventHooks(s, s.scripts[id])
|
||||
if err := s.scripts[id].RegisterLevelHooks(); err != nil {
|
||||
return err
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"reflect"
|
||||
"time"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||
"git.kirsle.net/go/render"
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"os"
|
||||
"runtime"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
"git.kirsle.net/apps/doodle/pkg/bindata"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/apps/doodle/pkg/wasm"
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
)
|
||||
|
||||
// LoadImage loads a sprite as a ui.Image object. It checks Doodle's embedded
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render"
|
||||
"github.com/google/uuid"
|
||||
"github.com/robertkrimen/otto"
|
||||
|
@ -29,6 +30,7 @@ type Actor struct {
|
|||
|
||||
// Actor runtime variables.
|
||||
hasGravity bool
|
||||
isMobile bool // Mobile character, such as the player or an enemy
|
||||
hitbox render.Rect
|
||||
data map[string]string
|
||||
|
||||
|
@ -75,6 +77,18 @@ func (a *Actor) SetGravity(v bool) {
|
|||
a.hasGravity = v
|
||||
}
|
||||
|
||||
// SetMobile configures whether the actor is a mobile character (i.e. is the
|
||||
// player or a mobile enemy). Mobile characters can set off certain traps when
|
||||
// touched but non-mobile actors don't set each other off if touching.
|
||||
func (a *Actor) SetMobile(v bool) {
|
||||
a.isMobile = v
|
||||
}
|
||||
|
||||
// IsMobile returns whether the actor is a mobile character.
|
||||
func (a *Actor) IsMobile() bool {
|
||||
return a.isMobile
|
||||
}
|
||||
|
||||
// GetBoundingRect gets the bounding box of the actor's doodad.
|
||||
func (a *Actor) GetBoundingRect() render.Rect {
|
||||
return doodads.GetBoundingRect(a)
|
||||
|
@ -133,6 +147,21 @@ func (a *Actor) ShowLayer(index int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ShowLayerNamed sets the actor's ActiveLayer to the one named.
|
||||
func (a *Actor) ShowLayerNamed(name string) error {
|
||||
// Find the layer.
|
||||
for i, layer := range a.Doodad.Layers {
|
||||
if layer.Name == name {
|
||||
return a.ShowLayer(i)
|
||||
}
|
||||
}
|
||||
log.Warn("Actor(%s) ShowLayerNamed(%s): layer not found",
|
||||
a.Actor.Filename,
|
||||
name,
|
||||
)
|
||||
return fmt.Errorf("the layer named %s was not found", name)
|
||||
}
|
||||
|
||||
// Destroy deletes the actor from the running level.
|
||||
func (a *Actor) Destroy() {
|
||||
a.flagDestroy = true
|
||||
|
|
|
@ -46,13 +46,18 @@ func (w *Canvas) loopActorCollision() error {
|
|||
// Advance any animations for this actor.
|
||||
if a.activeAnimation != nil && a.activeAnimation.nextFrameAt.Before(now) {
|
||||
if done := a.TickAnimation(a.activeAnimation); done {
|
||||
// Animation has finished, run the callback script.
|
||||
if a.animationCallback.IsFunction() {
|
||||
a.animationCallback.Call(otto.NullValue())
|
||||
// Animation has finished, get the callback function.
|
||||
callback := a.animationCallback
|
||||
|
||||
// Clean up the animation state, in case the callback wants
|
||||
// to immediately play another animation.
|
||||
a.StopAnimation()
|
||||
|
||||
// Call the callback function.
|
||||
if callback.IsFunction() {
|
||||
callback.Call(otto.NullValue())
|
||||
}
|
||||
|
||||
// Clean up the animation state.
|
||||
a.StopAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +109,13 @@ func (w *Canvas) loopActorCollision() error {
|
|||
if w.scripting != nil {
|
||||
var (
|
||||
rect = doodads.GetBoundingRect(b)
|
||||
lastGoodBox = boxes[tuple.B] // worst case scenario we get blocked right away
|
||||
lastGoodBox = render.Rect{
|
||||
X: originalPositions[b.ID()].X,
|
||||
Y: originalPositions[b.ID()].Y,
|
||||
W: boxes[tuple.B].W,
|
||||
H: boxes[tuple.B].H,
|
||||
}
|
||||
// lastGoodBox = originalPositions[b.ID()] // boxes[tuple.B] // worst case scenario we get blocked right away
|
||||
)
|
||||
|
||||
// Firstly we want to make sure B isn't able to clip through A's
|
||||
|
@ -121,7 +132,12 @@ func (w *Canvas) loopActorCollision() error {
|
|||
// B's movement. The next time A does NOT protest, that is to be
|
||||
// B's new position.
|
||||
|
||||
var firstPoint = true
|
||||
// Special case for when a mobile actor lands ON TOP OF a solid
|
||||
// actor. We want to stop their Y movement downwards, but allow
|
||||
// horizontal movement on the X axis.
|
||||
// Touching the solid actor from the side is already fine.
|
||||
var onTop = false
|
||||
|
||||
for point := range render.IterLine(
|
||||
origPoint,
|
||||
b.Position(),
|
||||
|
@ -133,6 +149,11 @@ func (w *Canvas) loopActorCollision() error {
|
|||
H: rect.H,
|
||||
}
|
||||
|
||||
var (
|
||||
lockX bool
|
||||
lockY bool
|
||||
)
|
||||
|
||||
if info, err := collision.CompareBoxes(boxes[tuple.A], test); err == nil {
|
||||
// B is overlapping A's box, call its OnCollide handler
|
||||
// with Settled=false and see if it protests the overlap.
|
||||
|
@ -145,27 +166,41 @@ func (w *Canvas) loopActorCollision() error {
|
|||
|
||||
// Did A protest?
|
||||
if err == scripting.ErrReturnFalse {
|
||||
// Are they on top?
|
||||
if render.AbsInt(lastGoodBox.Y+lastGoodBox.H-boxes[tuple.A].Y) <= 2 {
|
||||
onTop = true
|
||||
}
|
||||
|
||||
// What direction were we moving?
|
||||
if test.Y != lastGoodBox.Y {
|
||||
lockY = true
|
||||
b.SetGrounded(true)
|
||||
}
|
||||
if test.X != lastGoodBox.X {
|
||||
if !onTop {
|
||||
lockX = true
|
||||
}
|
||||
}
|
||||
|
||||
// Move them back to the last good box, locking the
|
||||
// axis they were moving from being able to enter
|
||||
// this box.
|
||||
tmp := lastGoodBox
|
||||
lastGoodBox = test
|
||||
if lockY {
|
||||
lastGoodBox.Y = tmp.Y
|
||||
}
|
||||
if lockX {
|
||||
lastGoodBox.X = tmp.X
|
||||
break
|
||||
}
|
||||
} else {
|
||||
lastGoodBox = test
|
||||
}
|
||||
}
|
||||
|
||||
firstPoint = false
|
||||
}
|
||||
|
||||
// Were we stopped before we even began?
|
||||
if firstPoint {
|
||||
// TODO: undo the effect of gravity this tick. Use case:
|
||||
// the player lands on top of a solid door, and their
|
||||
// movement is blocked the first step by the door. Originally
|
||||
// he'd continue falling, so I had to move him up to stop it,
|
||||
// turns out moving up by the -gravity is exactly the distance
|
||||
// to go. Don't know why.
|
||||
b.MoveBy(render.NewPoint(0, -balance.Gravity))
|
||||
} else {
|
||||
b.MoveTo(lastGoodBox.Point())
|
||||
}
|
||||
} else {
|
||||
log.Error(
|
||||
"ERROR: Actors %s and %s overlap and the script returned false,"+
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/apps/doodle/pkg/scripting"
|
||||
"git.kirsle.net/go/render"
|
||||
)
|
||||
|
||||
// InstallActors adds external Actors to the canvas to be superimposed on top
|
||||
|
|
|
@ -303,7 +303,7 @@ func (w *Canvas) loopEditable(ev *event.State) error {
|
|||
w.OnDragStart(actor.Actor)
|
||||
}
|
||||
break
|
||||
} else if ev.Button2 {
|
||||
} else if ev.Button3 {
|
||||
// Right click to delete an actor.
|
||||
deleteActors = append(deleteActors, actor.Actor)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package uix
|
||||
|
||||
import (
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/ui"
|
||||
)
|
||||
|
||||
// canvas_strokes.go: functions related to drawtool.Stroke and the Canvas.
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"errors"
|
||||
"image"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||
"git.kirsle.net/apps/doodle/pkg/userdir"
|
||||
"git.kirsle.net/go/render"
|
||||
)
|
||||
|
||||
// CornerTexture returns the Texture.
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/apps/doodle/pkg/bindata"
|
||||
"git.kirsle.net/go/render"
|
||||
)
|
||||
|
||||
// Wallpaper is a repeatable background image to go behind levels.
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
"syscall/js"
|
||||
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/render/canvas"
|
||||
doodle "git.kirsle.net/apps/doodle/pkg"
|
||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||
"git.kirsle.net/apps/doodle/pkg/log"
|
||||
"git.kirsle.net/go/render"
|
||||
"git.kirsle.net/go/render/canvas"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|