0,]']>S}Wup8d%qy)6o;]AsVl333vfffffffffffffffffffffffՍՍ>ggffffffffffffffffffffff݆݆3vfvfffffffffffffffffffffvmxvmxgfffffffffffffffffffffff~g~gvfgfffffffffffffffffffffUw޻޻ggffffffffffffffffffffffmvfffffffffffffffffffffffmgfgfffffffffffffffffffffuvfffffffffffffffffffffffՍggffffffffffffffffffffff݆vfvfffffffffffffffffffffvmxgfffffffffffffffffffffff~gvfgfffffffffffffffffffffUwUwUwUwUw޻Uw޻UwUwUwUwUwUwUw޻޻޻޻޻޻ffffffffffffffffffffffffmmmmmmmmmmmmmffffffffffffffffffffffffmmmmmmmmmmmmmffffffffffffffffffffffffuuuuuuuuuuuuuffffffffffffffffffffffffՍՍՍՍՍՍՍՍՍՍՍՍՍffffffffffffffffffffffff݆݆݆݆݆݆݆݆݆݆݆݆݆ffffffffffffffffffffffffvmxvmxvmxvmxvmxvmxvmxvmxvmxvmxvmxvmxvmxffffffffffffffffffffffff~g~g~g~g~g~g~g~g~g~g~g~g~gffffffffffffffffffffffffffffvvvvffffvvvvvvvvvvvvffffffffffffvvvvvvvvffffffffffffffffvvvvvvvvvvvvffffDDDDDDDDDDDDffffvvvvffffffffffffffffffffffffffffggggffffggggggggggggffffffffffffggggggggffffffffffffffffggggggggggggffff4DDD4DDD4DDDffffggggfffffffffffffffffffffffffffffvfvfffffvfvfvfvfvfvfffffffffffffvfvfvfvfffffffffffffffffvfvfvfvfvfvffffDD4DDD4DDD4DfffffvfvffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDCDDDCDDDCDDffffffffffffffffffffffffffffffffffffgfvfffffgfvfgfvfgfvfffffffffffffgfvfgfvfffffffffffffffffgfvfgfvfgfvfffffDDDDDDDDDDDDffffgfvfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDCDDDCDDDCffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4DDD4DDD4DDDffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDDDDDDDDDDffffffffffffffffffffffnfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDDDDDDfffffvfgffffffffffffffffffnfnnnnffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4DDD4DDDfffffffvffffffffffffffffffnfnnnnnnffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDD4DDD4DfffffffgffffffffffffffffffnffnnfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDCDDDCDDfffffgvvffffffffffffffffffnnfnnfnfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDDDDDDfffffffgffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDCDDDCfffffvvvffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4DDD4DDDfffffffgffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffDDDDDDDDffffffvvffffffffffffffffq-- title: Dungeon23 -- author: Garvalf -- desc: A dungeon for the #dungeon23 challenge -- site: -- license: MIT License -- version: 0.11 -- script: lua t=0 SCREENSIZE={x= 240, y = 136} WALL=80 cannotmove = 0 --Direction constants U={x= 0,y=-1} --up D={x= 0,y= 1} --down L={x=-1,y= 0} --left R={x= 1,y= 0} --right --game constants SCREEN_X=29 SCREEN_Y=16 --player object p={x=23, y=15} -- sprites LICORNE={a=333,b=334} PLAYER=257 exit={ x=1, y=1} MAPX=29 MAPY=16 mapindex={x=2,y=2} LEVEL=1 -- see https://github.com/nesbox/TIC-80/wiki/Simple-Collision-Detection function check_exit() local z = mget((MAPX+1)*(mapindex.x-1)+p.x, (MAPY+1)*(mapindex.y-1)+p.y) if z == 33 or z == 49 then trace("exit!") change_level() end cannotmove = 0 end --check ahead of player for obstacles function is_clear_ahead(dir) --log the directions x,y for convenience local x=dir.x local y=dir.y --the mget() function is the heart of the function. it takes an (x,y) coordinate, and checks the --map cell at that point. then it returns the sprite id. when I build a game i keep all the collidable --sprites past slot 17 on the sprite sheet, so if mget() returns anything less than 17 it won't --register as an obstacle. --if mget(p.x+x,p.y+y)<80 then if mget((MAPX+1)*(mapindex.x-1)+p.x+x, (MAPY+1)*(mapindex.y-1)+p.y+y)<80 then -- trace("--") --trace(p.x) --trace(p.y) -- trace(mget(p.x+x,p.y+x)) --we'll return true...as in it is clear ahead. return true else cannotmove = 1 cantmove() return false end end btnwait=25 btnrep=5 function move() -- "up" if btnp(0,btnwait,btnrep) and is_clear_ahead(U) then p.y=p.y-1 check_exit() end -- "down" if btnp(1,btnwait,btnrep) and is_clear_ahead(D) then p.y=p.y+1 check_exit() end -- "left" if btnp(2,btnwait,btnrep) and is_clear_ahead(L) then p.x=p.x-1 check_exit() end --player presses "right" if btnp(3,btnwait,btnrep) and is_clear_ahead(R) then p.x=p.x+1 check_exit() end -- trace(p.x .. ' '.. p.y) -- trace(mapindex.x .. ' '.. mapindex.y) if p.x < 0 then change_map_left() end if p.x > 240 / 8 then change_map_right() end if p.y < 0 then change_map_top() end if p.y > 136 / 8 then change_map_bottom() end -- if mapindex.x == 2 and mapindex.y == 2 then LEVEL = 1 end if LEVEL==1 then mapindex={x=2,y=2} end if LEVEL==1.1 then --mapindex={x=3,y=2} end if LEVEL==2 then mapindex={x=4,y=1} end if LEVEL==3 then mapindex={x=5,y=1} end end function draw() cls() -- map(0,0,SCREEN_X+1,SCREEN_Y+1) --multiplying the player coors by 8 (the size of the map cells) --gives us grid movement -- spr(DUDE,p.x*8,p.y*8,0) current_level=1 map((MAPX+1)*(mapindex.x-1), (MAPY+1)*(mapindex.y-1),MAPX+1,MAPY+1) spr(PLAYER,p.x*8,p.y*8,0) print("Level " .. LEVEL,4,128,14,false,1,true) --print("Level " .. LEVEL,4,128,14,{smallfont=true}) if cannotmove == 1 then cantmove() end end function change_level() if LEVEL==1 or LEVEL == 1.1 and current_level==1 then LEVEL=2 current_level=0 end if LEVEL==2 and current_level==1 and p.x > 8 then LEVEL=1 current_level=0 end if LEVEL==2 and current_level==1 and p.x < 8 then LEVEL=3 current_level=0 end if LEVEL==3 and current_level==1 and p.x < 8 then LEVEL=2 current_level=0 end end function change_map_left() mapindex.x = mapindex.x - 1 LEVEL = 1.1 p.x = 240 / 8 is_it_level_1() end function change_map_right() mapindex.x = mapindex.x + 1 LEVEL = 1.1 p.x = 1 is_it_level_1() end function change_map_top() mapindex.y = mapindex.y - 1 LEVEL = 1.1 p.y = 136 / 8 is_it_level_1() end function change_map_bottom() mapindex.y = mapindex.y + 1 LEVEL = 1.1 p.y = 1 is_it_level_1() end -- level 1 is a special level because the map is wider function is_it_level_1() if mapindex.x == 2 and mapindex.y == 2 then LEVEL = 1 end if mapindex.x < 1 then mapindex.x = 1 p.x = 0 cannotmove = 1 end if mapindex.x > 3 then mapindex.x = 3 p.x = 240/8 -1 cannotmove = 1 end if mapindex.y < 1 then mapindex.y = 1 p.y = 0 cannotmove = 1 end if mapindex.y > 3 then mapindex.y = 3 p.y = 136/8 -1 cannotmove = 1 end end function cantmove() rect(SCREENSIZE.x / 2 - 25, SCREENSIZE.y / 2 - 15, 70, 18, 15) rectb(SCREENSIZE.x / 2 - 25, SCREENSIZE.y / 2 - 15, 70, 18, 0) print("Can't move there", SCREENSIZE.x / 2 - 20, SCREENSIZE.y / 2 - 10, 13, false, 1 , true) -- trace('cant move') end --check for collision between two objects function collision(obj1,obj2) --check both objects (x,y) coords and return true if they are in the same cell. if obj1.x==obj2.x and obj1.y==obj2.y then return true end end function HideNumbers() if btnp(4) then for i = 6,15 do SwitchTile(17,i) end HideTileGrass(65,36) HideTileGrass(23,36) HideTileGrass(53,36) HideTileGrass(53,41) HideTileGrass(53,48) end end function HideTileGrass(x,y) for j = 0,2 do mset(x+j, y, math.random(2,4)) end end function TypeGrassNumber(x,y,number) --for k = 1,3 do a=string.sub(number,1,1) a=tonumber(a) or 0 --trace(ax) trace(a) mset(x, y, 6+a) b=string.sub(number,2,2) b=tonumber(b) or 0 --trace(bx) trace(b) mset(x+1, y, 6+b) c=string.sub(number,3,3) c=tonumber(c) or 0 --trace(cx) trace(c) mset(x+2, y, 6+c) --end for j = 0,2 do --mset(x+j, y, ) --trace(a .. ' x ' .. b .. c ) --trace(x) trace(y) --if c == 1 then mset(x+j, y, 6) end --mset(x+j, y, 6+a) --mset(x+j, y, 6+b) --mset(x+j, y, 6+c) end end function ShowNumbers() if btnp(5) then for i = 0,9 do SwitchTile(22+i, 6+i) end TypeGrassNumber(65,36,"003") TypeGrassNumber(23,36,"006") TypeGrassNumber(53,36,"004") TypeGrassNumber(53,41,"002") TypeGrassNumber(53,48,"001") end end -- not used function toggle_nb(nb) --if btnp(4) then fset(nb,4,not fget(nb,4)) end if btnp(4) then fset(nb,4,not fget(nb,4)) end if btnp(4) then Replace() end if btnp(5) then fset(nb,6,not fget(nb,6)) end -- show sprite if flag 4 is true if fget(nb,4) then -- scale up if flag 6 is true if fget(nb,6) then spr(nb,0,0,-1,2) else spr(nb,0,0,-1,1) end end end function TIC() --hide mouse poke(0x3FFB,0) move() draw() -- draw move error --toggle_nb(6) --toggle_nb(7) HideNumbers() ShowNumbers() t=t+1 end function SwitchTile(SourceTile, DestTile) for i=0,31 do --read the bytes and put them back to the destination tile val=peek(0x4000+SourceTile*32+i) poke(0x4000+DestTile*32+i,val) end -- write it back to the game sync(0,0,true) end -- not used function Replace(tile) -- see https://github.com/nesbox/TIC-80/wiki/peek img="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" -- foreach of the 32 bytes in the sprite for i=0,31 do --extract the data from the string 2 chars at time s = string.sub(img,i*2+1,i*2+2) --convert the hex string to a decimal number val = tonumber(s,16) --put the value in the RAM area dedicated to sprites, sprite number 6 poke(0x4000+tile*32+i,val) end -- read back the sprite data and print it to console msg='' -- foreach of the 32 bytes in the sprite for i=0,31 do --read the byte value in decimal format val=peek(0x4000+tile*32+i) -- convert the value in hexadecimal format s=string.format("%02x",val) -- concatenate the string to a final message msg=msg..s end -- print it to the console trace(msg) -- add sprite to TIC cartridge sync(0,0,true) end