Log In  

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[1]),abs(v[2]))
  local n = min(abs(v[1]),abs(v[2])) / d
  return sqrt(n*n + 1) * d
P#38407 2017-03-19 11:39 ( Edited 2017-05-16 19:01)


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.

P#22116 2016-06-02 16:50 ( Edited 2016-06-02 20:50)


Cart #33610 | 2016-12-17 | Code ▽ | Embed ▽ | No License

Climb to survive.



Movement: Left, Right, Up, Down
A-Button: Jump
B-Button: Use item in item box

Player1 (yellow): Cursors + ZX / NM
Player2 (white): SDFE + tab,Q / shift A

* New high score: 228 (by flightrush)

My personal high score video:

P#19561 2016-04-03 08:49 ( Edited 2016-12-17 23:01)


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.

P#19387 2016-03-24 14:06 ( Edited 2016-04-03 12:57)


Cart #17567 | 2015-12-06 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
I made this "fan" game as an exercise to learn what I could do with pico-8. Pico-8 is such a great platform, and definitely challenging. My next effort will be something original. Enjoy!

P#17568 2015-12-06 18:13 ( Edited 2017-08-04 06:28)

Follow Lexaloffle:          
Generated 2024-02-27 05:48:06 | 0.070s | Q:14