Log In  

Hello! I am trying to make my sprite stop moving when they hit a wall sprite. I have gotten to the point where I can observe when the sprite is or isn't in the flagged wall sprite, but I can't actually stop the sprite from moving. Still very new to pico-8 and coding in general so any help is much appreciated!

x=16
y=16
dx=0
dy=0

function _init()

end

function _draw()
    cls()
    map(0,0,0,0,16,16)
    spr(3,x,y)
    if collide() then 
        spr(5,0,0)
    end
end

function _update()
    x+=dx
    y+=dy
    if btn(0) then 
        if collide() then 
        dx=-dx 
        else 
        x-=1 
        end 
        end
    if btn(1) then
        if collide() then 
        dx=-dx
        else 
        x+=1 
        end 
        end
    if btn(2) then 
        if collide() then
        dy=-dy
        else
        y-=1
        end
        end
    if btn(3) then
    if collide() then 
        dy=-dy
        else 
        y+=1
        end
        end
end

function collide()
    v = mget(flr(x/8)+1,flr(y/8)+1)
    return fget(v,0)
end
P#33466 2016-12-13 20:08 ( Edited 2016-12-14 01:08)


[Please log in to post a comment]