Комментарии:
Really intuitive. Thank you for making these!
Ответитьmine is not working
Runtime error line 4 tab 4
for x=mapx,mapx+15 do
I wasted my money buying this
Ответить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.
ОтветитьAlmost there! :D
ОтветитьMy tiles are changing much too fast lol someone HEEEEELp
Ответить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
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
my tiles are turning to other tiles that i dont want and arent changeing a 2nd time
plz help
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