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:
Noah 2020-04-04 21:00:32 -07:00
parent 4ba3e18e18
commit 81e986fadf
13 changed files with 20 additions and 18 deletions

View File

@ -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);

View File

@ -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));
// })
}

View File

@ -1,5 +1,5 @@
function main() {
console.log("%s initialized!", Self.Doodad.Title);
console.log("%s initialized!", Self.Doodad().Title);
var pressed = false;

View File

@ -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.

View File

@ -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) {

View File

@ -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();
}
})

View File

@ -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);

View File

@ -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));

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
function main() {
console.log("%s initialized!", Self.Doodad.Title);
console.log("%s initialized!", Self.Doodad().Title);
var timer = 0;

View File

@ -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;