Noah Petherbridge
8965a7d86a
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.
94 lines
1.8 KiB
Go
94 lines
1.8 KiB
Go
// +build js,wasm
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"syscall/js"
|
|
|
|
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() {
|
|
fmt.Printf("Hello world\n")
|
|
// testRawCanvas()
|
|
|
|
// Enable workarounds.
|
|
balance.DisableChunkTextureCache = true
|
|
js.Global().Get("sessionStorage").Call("clear")
|
|
|
|
// HTML5 Canvas engine.
|
|
engine, _ := canvas.New("canvas")
|
|
engine.AddEventListeners()
|
|
|
|
game := doodle.New(true, engine)
|
|
game.SetupEngine()
|
|
|
|
doodle.DebugOverlay = true
|
|
|
|
// Manually inform Doodle of the canvas size since it can't control
|
|
// the size on its own.
|
|
w, h := engine.WindowSize()
|
|
game.SetWindowSize(w, h)
|
|
|
|
// game.Goto(&doodle.GUITestScene{})
|
|
game.Goto(&doodle.EditorScene{})
|
|
|
|
game.Run()
|
|
}
|
|
|
|
func testRawCanvas() {
|
|
engine, _ := canvas.New("canvas")
|
|
engine.SetTitle(
|
|
fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
|
|
)
|
|
fmt.Printf("Got engine: %+v\n", engine)
|
|
engine.Clear(render.Green)
|
|
|
|
for pt := range render.IterLine(render.NewPoint(20, 20), render.NewPoint(300, 300)) {
|
|
engine.DrawPoint(render.Red, pt)
|
|
}
|
|
|
|
engine.DrawLine(render.Blue, render.NewPoint(20, 300), render.NewPoint(300, 20))
|
|
|
|
engine.DrawRect(render.Black, render.Rect{
|
|
X: 5,
|
|
Y: 5,
|
|
W: 10,
|
|
H: 10,
|
|
})
|
|
engine.DrawBox(render.White, render.Rect{
|
|
X: 5,
|
|
Y: 5,
|
|
W: 10,
|
|
H: 10,
|
|
})
|
|
|
|
engine.DrawBox(render.Purple, render.Rect{
|
|
X: 25,
|
|
Y: 5,
|
|
W: 10,
|
|
H: 10,
|
|
})
|
|
|
|
engine.DrawText(render.Text{
|
|
Text: "Hello world!",
|
|
FontFilename: "DejaVuSans",
|
|
Size: 14,
|
|
}, render.NewPoint(400, 400))
|
|
|
|
size, _ := engine.ComputeTextRect(render.Text{
|
|
Text: "Hello world! blah blah",
|
|
FontFilename: "DejaVuSans",
|
|
Size: 14,
|
|
})
|
|
log.Info("text rect: %+v", size)
|
|
_ = engine
|
|
}
|