Overhaul the Platformer Physics System
* Player character now experiences acceleration and friction when walking around the map! * Actor position and movement had to be converted from int's (render.Point) to float64's to support fine-grained acceleration steps. * Added "physics" package and physics.Vector to be a float64 counterpart for render.Point. Vector is used for uix.Actor.Position() for the sake of movement math. Vector is flattened back to a render.Point for collision purposes, since the levels and hitboxes are pixel-bound. * Refactor the uix.Actor to no longer extend the doodads.Drawing (so it can have a Position that's a Vector instead of a Point). This broke some code that expected `.Doodad` to directly reference the Drawing.Doodad: now you had to refer to it as `a.Drawing.Doodad` which was ugly. Added convenience method .Doodad() for a shortcut. * Moved functions like GetBoundingRect() from doodads package to collision, where it uses its own slimmer Actor interface for just the relevant methods it needs.
This commit is contained in:
parent
4ba3e18e18
commit
81e986fadf
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
log.Info("Azulian '%s' initialized!", Self.Doodad.Title);
|
||||
log.Info("Azulian '%s' initialized!", Self.Doodad().Title);
|
||||
|
||||
var playerSpeed = 4;
|
||||
var gravity = 4;
|
||||
|
@ -28,8 +28,10 @@ function main() {
|
|||
}
|
||||
sampleTick++;
|
||||
|
||||
var Vx = playerSpeed * (direction === "left" ? -1 : 1);
|
||||
Self.SetVelocity(Point(Vx, 0));
|
||||
// TODO: Vector() requires floats, pain in the butt for JS,
|
||||
// the JS API should be friendlier and custom...
|
||||
var Vx = parseFloat(playerSpeed * (direction === "left" ? -1 : 1));
|
||||
Self.SetVelocity(Vector(Vx, 0.0));
|
||||
|
||||
if (!Self.IsAnimating()) {
|
||||
Self.PlayAnimation("walk-"+direction, null);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
var timer = 0;
|
||||
|
||||
|
@ -28,7 +28,7 @@ function main() {
|
|||
});
|
||||
|
||||
// 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));
|
||||
// })
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
var pressed = false;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
function main() {
|
||||
var color = Self.Doodad.Tag("color");
|
||||
var color = Self.Doodad().Tag("color");
|
||||
var keyname = "key-" + color + ".doodad";
|
||||
|
||||
// Layers in the doodad image.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
|
||||
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
|
||||
|
@ -9,7 +9,7 @@ function main() {
|
|||
Self.SetHitbox(16, 0, 32, 64);
|
||||
|
||||
Message.Subscribe("power", function(powered) {
|
||||
console.log("%s got power=%+v", Self.Doodad.Title, powered);
|
||||
console.log("%s got power=%+v", Self.Doodad().Title, powered);
|
||||
|
||||
if (powered) {
|
||||
if (animating || opened) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
function main() {
|
||||
var color = Self.Doodad.Tag("color");
|
||||
var color = Self.Doodad().Tag("color");
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
if (e.Settled) {
|
||||
e.Actor.AddItem(Self.Doodad.Filename, 0);
|
||||
e.Actor.AddItem(Self.Doodad().Filename, 0);
|
||||
Self.Destroy();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
function main() {
|
||||
Self.AddAnimation("open", 0, [1]);
|
||||
var unlocked = false;
|
||||
var color = Self.Doodad.Tag("color");
|
||||
var color = Self.Doodad().Tag("color");
|
||||
|
||||
Self.SetHitbox(16, 0, 32, 64);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
console.log(Object.keys(console));
|
||||
console.log(Object.keys(log));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Exit Flag.
|
||||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
Self.SetHitbox(22+16, 16, 75-16, 86);
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
var state = false;
|
||||
|
||||
function main() {
|
||||
console.log("%s ID '%s' initialized!", Self.Doodad.Title, Self.ID());
|
||||
console.log("%s ID '%s' initialized!", Self.Doodad().Title, Self.ID());
|
||||
Self.SetHitbox(0, 0, 33, 33);
|
||||
|
||||
// When the button is activated, don't keep toggling state until we're not
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
// Switch has two frames:
|
||||
// 0: Off
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function main() {
|
||||
console.log("%s initialized!", Self.Doodad.Title);
|
||||
console.log("%s initialized!", Self.Doodad().Title);
|
||||
|
||||
var timer = 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function main() {
|
||||
// What direction is the trapdoor facing?
|
||||
var direction = Self.Doodad.Tag("direction");
|
||||
var direction = Self.Doodad().Tag("direction");
|
||||
console.log("Trapdoor(%s) initialized", direction);
|
||||
|
||||
var timer = 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user