PICO-8 Top-Down Adventure Game Tutorial - Step 8/10

PICO-8 Top-Down Adventure Game Tutorial - Step 8/10

Dylan Bennett (MBoffin)

5 лет назад

12,338 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@jamesyork
@jamesyork - 04.04.2020 12:54

Really intuitive. Thank you for making these!

Ответить
@steve_cdh7324
@steve_cdh7324 - 14.07.2020 04:06

mine is not working

Runtime error line 4 tab 4
for x=mapx,mapx+15 do

Ответить
@steve_cdh7324
@steve_cdh7324 - 14.07.2020 04:11

I wasted my money buying this

Ответить
@thecaptem
@thecaptem - 15.10.2020 03:45

I really love this tutorial but I gotta say, the code typed is REALLY fast and, since I'm new to programming, I can barely keep up even when watching in 0.75x speed and I end up having to pause pretty regularly.

Ответить
@ThisPossumKnits
@ThisPossumKnits - 08.06.2021 13:01

Almost there! :D

Ответить
@JoseSantos-bl9fk
@JoseSantos-bl9fk - 02.07.2021 00:25

My tiles are changing much too fast lol someone HEEEEELp

Ответить
@andrewzhang5670
@andrewzhang5670 - 24.11.2021 04:45

Hey! Looking for help once again xD

I've properly tagged my spikes, but all of my tiles are changing to a tile beside them.
Help!

Script:
--game loop

function _init()
map_setup()
make_player()
end

function _update()
update_map()
move_player()
end

function _draw()
cls()
draw_map()
draw_player()
if (btn(5)) show_inventory()
end

--map code

function map_setup()
--map tile settings
wall=0
key=1
door=2
anim1=3
anim2=4
lose=6
win=7
end

function draw_map()
map(0,0,0,0,128,64)
end

function open_door(x,y)
p.keys-=1
swap_tile(x,y)
sfx(2)
end

function map_setup()
--timers
timer=0
anim_time=30 -- 30 = 1 second

function unswap_tile(x,y)
tile=mget(x,y)
mset(x,y,tile-1)
end

function update_map()
if (timer<0) then
toggle_tiles()
timer=anim_time
end
timer-=1
end

-- player code

function make_player()
p={}
p.x=9
p.y=41
p.sprite=1
p.keys=0
end

function draw_player()
spr(p.sprite,p.x*8,p.y*8)
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

function move_player()
newx=p.x
newy=p.y

if (btnp(0)) newx-=1
if (btnp(1)) newx+=1
if (btnp(2)) newy-=1
if (btnp(3)) newy+=1

interact(newx,newy)

if can_move(newx,newy) then
p.x=mid(0,newx,127)
p.y=mid(0,newy,63)
else
sfx(0)
end
end

function draw_map()
mapx=flr(p.x/16)*16
mapy=flr(p.y/16)*16
camera(mapx*8,mapy*8)

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

function swap_tile(x,y)
tile=mget(x,y)
mset(x,y,tile+1)
end

function get_key(x,y)
p.keys+=1
swap_tile(x,y)
sfx(1)
end

function interact(x,y)
if (is_tile(key,x,y)) then
get_key(x,y)
elseif (is_tile(door,x,y) and p.keys>0) then
open_door(x,y)
end
end

function show_inventory()
invx=mapx*8+40
invy=mapy*8+8

rectfill(invx,invy,invx+48,invy+24,0)
print("inventory",invx+7,invy+4,7)
print("keys "..p.keys,invx+12,invy+14,9)
end

--animation code
function toggle_tiles()
for x=mapx,mapx+15 do
for y=mapy,mapy+15 do
if (is_tile(anim1,x,y)) then
swap_tile(x,y)
sfx(3)
elseif (is_tile(anim2,x,y))then
unswap_tile(x,y)
sfx(3)
end
end
end
end
end

Ответить
@rbernhardsson9857
@rbernhardsson9857 - 08.01.2022 13:59

I slowly getting forward, but now this hit me:
Runtime error line 10 tae 0
update_map()
atttempt to call global 'update_map' (a nil value)
in _update

my code:

--gameloop
--runs one time
function _init()
map_setup()
make_player()
end


--runs again and again every 30 sec
function _update()
update_map()
move_player()
end


--runs as _updates, but only after it.
function _draw()
cls()
draw_map()
draw_player()
if (btn(❎)) show_inventory()
end



--map code

function map_setup()

--timers
timer=0
anim_time=30 -- 30 = 1 second


--map tile settings
wall=0
key=1
door=2
anim1=3
anim2=4
lose=6
win=7
end


function draw_map()
mapx=flr(p.x/16)*16
mapy=flr(p.y/16)*16
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


function swap_tile(x,y)
tile=mget(x,y)
mset(x,y,tile+1)
end



function unswap_tile(x,y)
tile=mget(x,y)
mset(x,y,tile-1)
end


function get_key(x,y)
p.keys+=1
swap_tile(x,y)
sfx(2)
end


function open_door(x,y)
p.keys-=1
swap_tile(x,y)
sfx(2)
end

--player code

function make_player()
p={}
p.x=3
p.y=2
p.sprite=3
p.keys=0
p.gold=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

interact(newx,newy)

if (can_move(newx,newy)) then
p.x=mid(0,newx,127)
p.y=mid(0,newy,63)
else
sfx(01)
end
end


function interact(x,y)
if (is_tile(key,x,y)) then
get_key(x,y)
elseif (is_tile(door,x,y) and p.keys>0) then
open_door(x,y)
end
end

--inventory code

function show_inventory()
invx=mapx*8+40
invy=mapy*8+8

rectfill(invx,invy,invx+48,invy+24,0)
print("inventory",invx+7,invy+4,7)
print("carrots "..p.keys,invx+12,invy+14,9)
end

--animation code

function toggle_til()
for x=mapx,mapx+15 do
for y=mapy,mapy+15 do
if (is_tile(anim1,x,y)) then
swap_tile(x,y)
sfx(3)
elseif (is_tile(anim2,x,y)) then
unswap_tile(x,y)
sfx(3)
end
end
end
end

Ответить
@urpalwithgudmoral
@urpalwithgudmoral - 19.04.2022 21:37

my tiles are turning to other tiles that i dont want and arent changeing a 2nd time
plz help

Ответить
@jesperanderberg486
@jesperanderberg486 - 30.06.2022 16:11

pls help

runtime error line 10 tab 4
unswap_tile(x,y)
attempt to index local ´x´ (a number value)


My code:

--animation code

function toggle_tiles()

for x=mapx,mapx+15 do

for y=mapy,mapy+15 do

if (is_tile(anim1,x,y)) then

swap_tile(x,y)

sfx(3)

elseif (is_tile(anim2,x,y)) then

unswap_tile(x.y)

sfx(3)

end

end

end

end



Unswap code:


function unswap_tile(x,y)

tile=mget(x,y)

mset(x,y,tile-1)

end

Ответить