So I have an issue where the player object can clip through about half a collision tile, but only when moving to the left. As I type that I realize how weird and niche this problem is. Anyways, here's my move function:
function control_player() newx=p.x newy=p.y if (btn(⬅️)) then newx-=.1 p.sprite=d.left elseif (btn(➡️)) then newx+=.1 p.sprite=d.right elseif (btn(⬆️)) then newy-=.1 p.sprite=d.up elseif (btn(⬇️)) then newy+=.1 p.sprite=d.down end if (can_move(newx,newy)) then p.x=mid(0,newx,127) p.y=mid(0,newy,63) end if (door_tile(newx,newy)) then scene="room1" p.x=6 p.y=10 end end |
and here's my collision function:
function is_tile(tile_type,x,y) local tile_x=newx+pixeloffset_x local tile_y=newy+pixeloffset_y tile=mget(tile_x,tile_y) has_flag=fget(tile,tile_type) return has_flag end function can_move(x,y) return not is_tile(wall,x,y) end function door_tile(x,y) return is_tile(door,x,y) end |
pixel_offset is initially 0, and changes based on scene to account for the map change.
Any idea what is causing this?
side note: Everyone on this forum has been so helpful and I just want to say thanks for all the help! This is my first coding project outside of html and I really appreciate it :]
I am trying to use values in a table to dictate which scene is being shown in the game. I defined the table 'S' at the top of the code but a piece at the bottom referring to it comes back nil. What's the problem?
function _init() cls() music(0) s={} s.menu=1 s.start=0 s.t1=0 s.one=0 map_setup() make_player() end |
if s.menu>0 then screen_menu() end if s.start>0 then screen_start() end if s.t1>0 then screen_t1() end if s.one>0 then screen_scene1() end |
So I want to make a sound effect that only plays when a direction is pushed, and the trouble that I'm running into is that:
- using (btn(input)) loops the sound so fast it almost crashes PICO-8
- using (btnp(input)) only plays it when the button is first pressed
How do I make it so it plays consistently while pressing a direction, and loops at a normal speed? I tried making a timer that gets added to while a direction is pushed, but the only way I could find to do it was i+=1 which only added 1 a single time. Is a timer the right way to go or is there a more efficient way?
function move_player() newx=p.x newy=p.y if (btn(⬅️)) then newx-=.1 p.sprite=d.left sfx(0) elseif (btn(➡️)) then newx+=.1 p.sprite=d.right sfx(0) elseif (btn(⬆️)) then newy-=.1 p.sprite=d.up sfx(0) elseif (btn(⬇️)) then newy+=.1 p.sprite=d.down sfx(0) end |
Here's a snippet of my code if it helps. Thanks!
So I currently have a movement system down for my player, and the sprite changes based on direction. Here's an excerpt:
function make_player() p={} p.x=3 p.y=10 p.sprite=4 end function draw_player() spr(p.sprite,p.x*8,p.y*8) end function move_player() newx=p.x newy=p.y if (btn(⬅️)) newx-=.1 if (btn(➡️)) newx+=.1 if (btn(⬆️)) newy-=.1 if (btn(⬇️)) newy+=.1 if (can_move(newx,newy)) then p.x=mid(0,newx,127) p.y=mid(0,newy,63) else p.x+=0 p.y+=0 end end function player_anim() if (btnp(⬅️)) p.sprite=3 if (btnp(➡️)) p.sprite=2 if (btnp(⬆️)) p.sprite=4 if (btnp(⬇️)) p.sprite=1 end function player_walk() end |
Now how would I go about adding footstep animations every second or so as a direction is pressed?