Minor Tweaks

physics
Noah 2019-06-08 17:02:28 -07:00
parent de79bde776
commit 567b3158f1
12 changed files with 115 additions and 29 deletions

View File

@ -1,6 +1,9 @@
function main() { function main() {
log.Info("Azulian '%s' initialized!", Self.Doodad.Title); log.Info("Azulian '%s' initialized!", Self.Doodad.Title);
Self.Canvas.SetBackground(RGBA(0, 153, 255, 100));
var playerSpeed = 12; var playerSpeed = 12;
var gravity = 4; var gravity = 4;
var Vx = Vy = 0; var Vx = Vy = 0;

View File

@ -2,6 +2,8 @@ function main() {
Self.AddAnimation("open", 0, [1]); Self.AddAnimation("open", 0, [1]);
var unlocked = false; var unlocked = false;
Self.Canvas.SetBackground(RGBA(0, 255, 255, 100));
// Map our door names to key names. // Map our door names to key names.
var KeyMap = { var KeyMap = {
"Blue Door": "Blue Key", "Blue Door": "Blue Key",
@ -32,6 +34,5 @@ function main() {
}); });
Events.OnLeave(function(e) { Events.OnLeave(function(e) {
console.log("%s has stopped touching %s", e, Self.Doodad.Title) console.log("%s has stopped touching %s", e, Self.Doodad.Title)
Self.Canvas.SetBackground(RGBA(0, 0, 1, 0));
}) })
} }

View File

@ -3,7 +3,7 @@ function main() {
var timer = 0; var timer = 0;
Self.SetHitbox(0, 0, 72, 9); Self.SetHitbox(0, 0, 72, 6);
var animationSpeed = 100; var animationSpeed = 100;
var opened = false; var opened = false;

View File

@ -8,8 +8,9 @@ import (
// State keeps track of event states. // State keeps track of event states.
type State struct { type State struct {
// Mouse buttons. // Mouse buttons.
Button1 *BoolTick Button1 *BoolTick // left
Button2 *BoolTick Button2 *BoolTick // right
Button3 *BoolTick // middle
EscapeKey *BoolTick EscapeKey *BoolTick
EnterKey *BoolTick EnterKey *BoolTick
@ -33,6 +34,7 @@ func New() *State {
return &State{ return &State{
Button1: &BoolTick{}, Button1: &BoolTick{},
Button2: &BoolTick{}, Button2: &BoolTick{},
Button3: &BoolTick{},
EscapeKey: &BoolTick{}, EscapeKey: &BoolTick{},
EnterKey: &BoolTick{}, EnterKey: &BoolTick{},
ShiftActive: &BoolTick{}, ShiftActive: &BoolTick{},

View File

@ -83,7 +83,7 @@ func (r *Renderer) Poll() (*events.State, error) {
return false return false
} }
if checkDown(1, s.Button1) || checkDown(3, s.Button2) { if checkDown(1, s.Button1) || checkDown(3, s.Button2) || checkDown(2, s.Button3) {
// Return the event immediately. // Return the event immediately.
return s, nil return s, nil
} }

View File

@ -17,8 +17,8 @@ type Actor interface {
SetGrounded(bool) SetGrounded(bool)
// Actor's elected hitbox set by their script. // Actor's elected hitbox set by their script.
SetHitbox(x, y, w, h int) // SetHitbox(x, y, w, h int)
Hitbox() render.Rect // Hitbox() render.Rect
// Movement commands. // Movement commands.
MoveBy(render.Point) // Add {X,Y} to current Position. MoveBy(render.Point) // Add {X,Y} to current Position.
@ -39,3 +39,12 @@ func GetBoundingRect(d Actor) render.Rect {
H: S.H, H: S.H,
} }
} }
// GetBoundingRectWithHitbox is like GetBoundingRect but adjusts it for the
// relative hitbox of the actor.
// func GetBoundingRectWithHitbox(d Actor, hitbox render.Rect) render.Rect {
// rect := GetBoundingRect(d)
// rect.W = hitbox.W
// rect.H = hitbox.H
// return rect
// }

View File

@ -76,20 +76,20 @@ func (d *Drawing) SetGrounded(v bool) {
d.grounded = v d.grounded = v
} }
// SetHitbox sets the actor's elected hitbox. // // SetHitbox sets the actor's elected hitbox.
func (d *Drawing) SetHitbox(x, y, w, h int) { // func (d *Drawing) SetHitbox(x, y, w, h int) {
d.hitbox = render.Rect{ // d.hitbox = render.Rect{
X: int32(x), // X: int32(x),
Y: int32(y), // Y: int32(y),
W: int32(w), // W: int32(w),
H: int32(h), // H: int32(h),
} // }
} // }
//
// Hitbox returns the actor's elected hitbox. // // Hitbox returns the actor's elected hitbox.
func (d *Drawing) Hitbox() render.Rect { // func (d *Drawing) Hitbox() render.Rect {
return d.hitbox // return d.hitbox
} // }
// MoveBy a relative value. // MoveBy a relative value.
func (d *Drawing) MoveBy(by render.Point) { func (d *Drawing) MoveBy(by render.Point) {

View File

@ -548,9 +548,12 @@ func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame {
} }
} }
// TODO: right-aligned labels clip out of bounds var shareware string
if balance.FreeVersion {
shareware = " (shareware)"
}
extraLabel := ui.NewLabel(ui.Label{ extraLabel := ui.NewLabel(ui.Label{
Text: "blah", Text: "Doodle v" + Version + shareware,
Font: balance.StatusFont, Font: balance.StatusFont,
}) })
extraLabel.Configure(ui.Config{ extraLabel.Configure(ui.Config{

View File

@ -49,6 +49,68 @@ func (u *EditorUI) setupDoodadFrame(e render.Engine, window *ui.Window) (*ui.Fra
perRow = balance.UIDoodadsPerRow perRow = balance.UIDoodadsPerRow
) )
frame.SetBackground(render.RGBA(0, 153, 255, 153))
// Toolbar on top of the Doodad panel.
toolbar := ui.NewFrame("Doodad Palette Toolbar")
toolbar.Configure(ui.Config{
Background: render.Grey,
BorderSize: 2,
BorderStyle: ui.BorderRaised,
Height: 20,
})
{
// Link button.
linkButton := ui.NewButton("Link", ui.NewLabel(ui.Label{
Text: "Link Doodads",
}))
linkButton.Handle(ui.Click, func(p render.Point) {
u.d.Flash("Hello world")
})
u.Supervisor.Add(linkButton)
toolbar.Pack(linkButton, ui.Pack{
Anchor: ui.N,
FillX: true,
})
}
frame.Pack(toolbar, ui.Pack{
Anchor: ui.N,
Fill: true,
})
// Pager buttons on top of the doodad list.
pager := ui.NewFrame("Doodad Pager")
{
leftBtn := ui.NewButton("Prev Page", ui.NewLabel(ui.Label{
Text: "<",
}))
u.Supervisor.Add(leftBtn)
pager.Pack(leftBtn, ui.Pack{
Anchor: ui.W,
})
pageLabel := ui.NewLabel(ui.Label{
Text: " Page 1 of 20",
})
pager.Pack(pageLabel, ui.Pack{
Anchor: ui.W,
Expand: true,
})
rightBtn := ui.NewButton("Next Page", ui.NewLabel(ui.Label{
Text: ">",
}))
u.Supervisor.Add(rightBtn)
pager.Pack(rightBtn, ui.Pack{
Anchor: ui.W,
})
}
frame.Pack(pager, ui.Pack{
Anchor: ui.N,
Fill: true,
})
doodadsAvailable, err := doodads.ListDoodads() doodadsAvailable, err := doodads.ListDoodads()
if err != nil { if err != nil {
return frame, fmt.Errorf( return frame, fmt.Errorf(

View File

@ -65,6 +65,10 @@ type Canvas struct {
OnDeleteActors func([]*level.Actor) OnDeleteActors func([]*level.Actor)
OnDragStart func(filename string) OnDragStart func(filename string)
// When the Canvas wants to link two actors together. Arguments are the IDs
// of the two actors.
OnLinkActors func(a, b string)
// Tracking pixels while editing. TODO: get rid of pixelHistory? // Tracking pixels while editing. TODO: get rid of pixelHistory?
pixelHistory []*level.Pixel pixelHistory []*level.Pixel
lastPixel *level.Pixel lastPixel *level.Pixel

View File

@ -88,19 +88,19 @@ func (w *Canvas) PresentWallpaper(e render.Engine, p render.Point) error {
// from the Origin (0,0) we find out by how far (subtract full tile sizes) // from the Origin (0,0) we find out by how far (subtract full tile sizes)
// and use the remainder as an offset for drawing the tiles. // and use the remainder as an offset for drawing the tiles.
var dx, dy int32 var dx, dy int32
if origin.X > 0 { if origin.X > p.X {
for origin.X > 0 && origin.X > size.W { for origin.X > p.X && origin.X > size.W {
origin.X -= size.W origin.X -= size.W
} }
dx = origin.X dx = origin.X
origin.X = 0 origin.X = p.X
} }
if origin.Y > 0 { if origin.Y > p.Y {
for origin.Y > 0 && origin.Y > size.H { for origin.Y > p.Y && origin.Y > size.H {
origin.Y -= size.H origin.Y -= size.H
} }
dy = origin.Y dy = origin.Y
origin.Y = 0 origin.Y = p.Y
} }
// And capping the scroll delta in the other direction. // And capping the scroll delta in the other direction.

View File

@ -7,11 +7,13 @@ type Tool int
const ( const (
PencilTool Tool = iota // draw pixels where the mouse clicks PencilTool Tool = iota // draw pixels where the mouse clicks
ActorTool // drag and move actors ActorTool // drag and move actors
LinkTool
) )
var toolNames = []string{ var toolNames = []string{
"Pencil", "Pencil",
"Doodad", // readable name for ActorTool "Doodad", // readable name for ActorTool
"Link",
} }
func (t Tool) String() string { func (t Tool) String() string {