From 7005786a314a051f049151ea46dfdfece98c458e Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 5 May 2022 21:35:32 -0700 Subject: [PATCH] Swimming Physics and Bubble Pattern Water pixels finally do something other than turn your character blue! * When the player character is "wet" (touching water pixels, and so appearing in a blue mask), water physics apply: gravity is slower, your jump height is halved, but you get infinite jumps to swim higher in the water. * Holding the jump key under water will incur a short delay between jumps, so that you don't just fly straight up to the surface. Tap the jump button to move up quicker, you can spam it all you want. Azulians are also able to handle being under water: * They'll sink to the bottom and keep walking back and forth normally. * If you are above them and noticed, they'll jump (swim) up towards you, aware of the water and it jumps like you do. * The Blue Azulian has the poorest vertical aggro range so it isn't a very good swimmer. The White Azulian is very good at navigating water as it can pursue the player from the furthest distance of them all. Changes to the editor: * New brush pattern added: bubbles.png * It's the default pattern now for the "water" color of all of the built-in palettes instead of ink.png * A repeating pattern of bubbles carved out showing the level wallpaper. * The old "Bubbles (circles.png)" is renamed "Circles" * The last scroll position is saved with the Level file, so when you reload the level later it's scrolled at where you left it. --- dev-assets/doodads/azulian/azulian.js | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dev-assets/doodads/azulian/azulian.js b/dev-assets/doodads/azulian/azulian.js index 2c77b6d..73e0943 100644 --- a/dev-assets/doodads/azulian/azulian.js +++ b/dev-assets/doodads/azulian/azulian.js @@ -2,9 +2,11 @@ const color = Self.GetTag("color"); var playerSpeed = color === 'blue' ? 2 : 4, + swimSpeed = playerSpeed * 0.4, aggroX = 250, // X/Y distance sensitivity from player aggroY = color === 'blue' ? 100 : 200, jumpSpeed = color === 'blue' ? 14 : 18, + swimJumpSpeed = jumpSpeed * 0.4, animating = false, direction = "right", lastDirection = "right"; @@ -14,7 +16,9 @@ if (color === 'white') { aggroX = 1000; aggroY = 400; playerSpeed = 8; + swimSpeed = playerSpeed * 0.4; jumpSpeed = 20; + swimJumpSpeed = jumpSpeed * 0.4; } function setupAnimations(color) { @@ -30,6 +34,9 @@ function setupAnimations(color) { function main() { playerSpeed = color === 'blue' ? 2 : 4; + let swimJumpCooldownTick = 0, // minimum Game Tick before we can jump while swimming + swimJumpCooldown = 10; // CONFIG: delta of ticks between jumps while swimming + Self.SetMobile(true); Self.SetGravity(true); Self.SetInventory(true); @@ -95,8 +102,25 @@ function main() { sampleTick++; } - let Vx = parseFloat(playerSpeed * (direction === "left" ? -1 : 1)), - Vy = jump && Self.Grounded() ? parseFloat(-jumpSpeed) : Self.GetVelocity().Y; + // Handle being underwater. + let canJump = Self.Grounded(); + if (Self.IsWet()) { + let tick = GetTick(); + if (tick > swimJumpCooldownTick) { + canJump = true; + swimJumpCooldownTick = tick + swimJumpCooldown; + } + } + + // How speedy would our movement and jump be? + let xspeed = playerSpeed, yspeed = jumpSpeed; + if (Self.IsWet()) { + xspeed = swimSpeed; + yspeed = swimJumpSpeed; + } + + let Vx = parseFloat(xspeed * (direction === "left" ? -1 : 1)), + Vy = jump && canJump ? parseFloat(-yspeed) : Self.GetVelocity().Y; Self.SetVelocity(Vector(Vx, Vy)); // If we changed directions, stop animating now so we can