Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

PICO-8: Top-Down Adventure Game Tutorial

A beginner-level tutorial for making a top-down adventure game in PICO-8. · By MBoffin (Dylan Bennett)

Stuck on video 3, can't move in the X axis

A topic by Left-Lane created Aug 21, 2022 Views: 185 Replies: 2
Viewing posts 1 to 3
(1 edit)

So I was on step 3 making my character move but there seems to be a invisible wall blocking me off that is separate from the collision I made. Any idea why? 

code:

--map code

function map_setup()

 --map tile settings

wall=0

key=1

door=2

ania1=3

ania2=4

lose=6

win=7

end

function draw_map()

 mapx=mid(0,p.x-8,111)

 mapy=mid(0,p.y-8,47)

 camera(mapx*8,mapy*8)

 map(0,0,0,0,128,64)

end

function is_tile(tile_type,x,y)

 tile=mget(x,y)

 has_flag=fget(tile,tile_type)

 return has_flag

end

function can_move(x,y)

 return not is_tile(wall,x,y)

end



--player code

function make_player()

 p={}

 p.y=5

 p.x=3

 p.sprite=1

 p.keys=0

end

function draw_player()

 spr(p.sprite,p.x*8,p.y*8)

end

function move_player()

 newx=p.x

 newy=p.y

if (btnp(⬅️)) newx-=1

if (btnp(➡️)) newx+=1

if (btnp(⬆️)) newy-=1

if (btnp(⬇️)) newy+=1

if (can_move(newx,newy)) then

 p.x=mid(0,mewx,128)

 p.y=mid(0,newy,64)

 else 

 sfx(0)

 end

end

Developer (1 edit)

I noticed two tiny errors (that are VERY easy to miss, so don't beat yourself up over it). First, in the map_setup() function, you have ania1 and ania2, but they should be anim1 and anim2 (you have a instead of m). That little error will trip you up later. But the one I think that's causing the problem is toward the end of your move_player() function. You have p.x=mid(0,mewx,128) instead of p.x=mid(0,newx,127). (You have mewx instead of newx and 128 instead of 127.) And then on the next line you have p.y=mid(0,newy,64) instead of p.y=mid(0,newy,63). (You have 64 instead of 63.)

Hope that helps! Let me know if you're still stuck after fixing that. (Also, make sure your sprites/tiles don't have any flags checked that shouldn't be checked.)

Thank you so much!  This really helps!