Log In  

I just recently began using PICO-8 (I do have experience with other programming languages) and I have started a new project. It is supposed to be a VVVVVV clone/variation. I'm setting up the controls and the physics. I've gotten the basis for the y-axis down, so I'm working on movement along the x-axis. The left and right keys both subtract and add speed to the x-axis and when neither key is being pressed, it decays exponentially. However, when the left (and ONLY the left) key is no longer being pressed, the speed decays until a certain point and stops. This isn't a problem on the right side, only on the left. I've been messing around with the code for a while and I still can't figure it out. I disabled gravity on the demo linked below to make it easier to test the movement on just the x-axis. Any help is appreciated.
https://i.imgur.com/8fMCvze.png

P#55876 2018-08-30 01:03 ( Edited 2018-09-06 00:56)

xs = flr(xs*0.5)

The floor of -1 * 0.5 is -1. So if xs is -1 or less, that will never put it above -1.
One simple way to fix it would be

xs = flr(xs*0.4+0.5)

With the values xs is limited to, that wouldn't make have any other effect on behavior.

By the way, you could use far fewer parentheses. This line:

 if (not((btn(⬅️)or(btn(➡️))))) then

could be

 if not (btn(⬅️) or btn(➡️)) then

That's not just a matter of style; it'll make a significant difference in your token count.

P#55878 2018-08-30 01:53 ( Edited 2018-08-30 05:53)

@SerialBull

If you want a version of flr() that always floors towards 0, rather than -∞, you could do this:

function flr0(v)
  return flr(abs(v))*sgn(v)
end

Same pattern for ceil(), of course.

P#55881 2018-08-30 02:41 ( Edited 2018-08-30 06:42)

Forgot to thank you, commenters above. That solved my problem. However, I have been working on the game quite a bit since last time and I had hit another roadblock. As you may have guessed, my game is a VVVVVV clone. Earlier today, I decided to move the chunk of code responsible for 'flipping' (the character flips gravity instead of jumping) into a function to allow me to control it easier without eating up a lot of more tokens in the process. This backfired. The character flips gravity every frame. I removed all of the code in _UPDATE() that called the FLIP(k) function I made, but it still keeps flipping every tick. I have no idea why it won't stop since I'm not calling it anywhere in the code. It would be appreciated if anybody could figure this out or at least point me in the right direction.

Link to the cart
https://i.imgur.com/5pFotzg.png

P#56147 2018-09-03 22:30 ( Edited 2018-09-04 02:30)

I believe the problem is the name. P8 calls a function called flip() in drawing. By using that name, you've replaced the regular function, so yours gets called instead.

If the editor highlights a name in green, you shouldn't define it at global scope, or something like that might happen.

P#56207 2018-09-04 23:14 ( Edited 2018-09-05 03:14)

Yep, that's definitely the issue. I've done the exact same thing before :D

This is the method you're overriding, and it gets called automatically by _draw() every frame: https://pico-8.wikia.com/wiki/Flip

P#56216 2018-09-05 03:48 ( Edited 2018-09-05 07:48)

@Saffith @tobaisvl
Thanks! I was about to lose my mind because I couldn't figure it out.

P#56245 2018-09-05 20:56 ( Edited 2018-09-06 00:56)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:51:58 | 0.050s | Q:22