Log In  

I'm new to PICO-8, and am trying to get a basic top-down movement system. So far I have this:

left = btn(⬅️)
right = btn(➡️)
up = btn(⬆️)
down = btn(⬇️)

xspd = (num(right) - num(left)) * player.speed
yspd = (num(down) - num(up)) * player.speed

if fget(player.x + xspd, player.y) == 0 then
    xspd = 0
end

if fget(player.x, player.y + yspd) == 0 then
    yspd = 0
end

player.x = player.x + xspd
player.y = player.y + yspd

num() takes in a boolean, and outputs a number (true being 1, false being 0)
The problem I have, is that I'm trying to stop the player if they hit a wall (The wall's sprite having flag 0), and I'm not sure what to do. Does anyone know what's going on?

P#116747 2022-09-01 19:13

You are almost there. Read up on how fget works: https://pico-8.fandom.com/wiki/Fget

In short, you have to pass it a tile from the map. To do so, you can get the tile with mget: https://pico-8.fandom.com/wiki/Mget

The thing is, mget works in map cell coordinates, not on screen x and y coordinates, so you have to account for that.

Map collision is relatively simple when you are doing a point collision. If you are having a hard time grasping how to do this, I recommend you check this tutorial series: https://www.lexaloffle.com/bbs/?tid=35135 it's short and straight to the point and it explains a lot of the basics on pico-8.

Where things get a bit more complicated is when you are trying to achieve free movement, because then you can't just rely on a 1 point collision checking system. I wrote a couple of examples for this in the past, you might find them helpful:
https://www.lexaloffle.com/bbs/?pid=112642#p
https://www.lexaloffle.com/bbs/?pid=115726#p

P#116748 2022-09-01 19:25

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 00:57:35 | 0.005s | Q:11