Not really sure if this was mentioned anywhere, but I thought it might be useful for anyone who wants to make use of vector math, specifically calculating the length of a 2D vector, while minimizing the risk of overflow.
Because the sqrt(32767) ~= 181, it is easy to overflow when using the textbook equation for calculating vector length:
|len = sqrt(x*x + y*y)|
To derisk overflowing when squaring the terms, you can first scale down the vector's x and y components:
|m = max(x,y)|
x = x / m
y = y / m
then scale the square root of their sums:
|len = sqrt(x*x + y*y) * m|
Lua code (simplified since one term will always == 1):
function length(v) local d = max(abs(v),abs(v)) local n = min(abs(v),abs(v)) / d return sqrt(n*n + 1) * d end
Here's a capture of some of the movement animations.
Still lots to do. For this game I am using the awesome Pyxel Edit software to create the animations. It is so nice to be able to import and export spritesheets with pico-8.
I'll hopefully have something more to post soon.
Climb to survive.
Movement: Left, Right, Up, Down
|* New high score: 228 (by flightrush)|
My personal high score video:
Started work on a game based loosely on "jumpman" called "HighSteal".
I should be done in a few days... ok, maybe a week or so.
So far it is coming along really well. My original though was to create a 2-player game, and if there was time and space, add a single player mode.
I was so glad today when I upgraded to the latest pico-8 and found the code char limit had been doubled!!! Thank you!!!
So I am now working on the single player mode, and I think it will work out well.