0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3 max then return max else return x end end function TIC() poke(0x3FFB, 0) cls() if keyp(48) -- space key and tilefun.exists(1) -- player spawn then editing = not editing sfx(04) launched = true end if keyp(19) then saveMap() end map(cam.x//8,cam.y//8, 40,30, -(cam.x%8),-(cam.y%8), -1, 1, tilefun.add) -- main gameplay loop if editing then -- EDIT MODE --[[ mx: mouse x pos. my: mouse y pos. ml: left mouse button pressed (boolean) mm: middle mouse button pressed (boolean) mr: right mouse button pressed (boolean) scroll: mouse scroll wheel direction ]] mx, my, ml, mm, mr, _, scroll = mouse() cam.x = cam.x//1 cam.y = cam.y//1 cursorx, cursory = 120, 64 spr(272, cursorx-cam.x%8,cursory-cam.y%8, 0) -- delete tile if (mr or btn(6)) and (mget(cursorx+cam.x//8, cursory+cam.y//8) ~= 0) then mset(cursorx+cam.x//8, cursory+cam.y//8, 0) sfx(03) end -- place tile if (ml or btn(4)) and (mget(cursorx//8+cam.x//8, cursory//8+cam.y//8) ~= curtile) then sfx(03) mset(cursorx//8+cam.x//8, cursory//8+cam.y//8, curtile) end --camera controls if key(64) then cam.speed = 8 else cam.speed = 2 end if btn(0) then cam.y = cam.y - cam.speed elseif btn(1) then cam.y = cam.y + cam.speed end if btn(3) then cam.x = cam.x + cam.speed elseif btn(2) then cam.x = cam.x - cam.speed end -- scroll to change cur tile if scroll > 0 or btnp(7) then if curtile < 255 then curtile = curtile + 01 else curtile = 0 end end if scroll < 0 or btnp(5) then if curtile > 0 then curtile = curtile - 01 else curtile = 255 end end --cur tile display spr(257, 4,4) spr(258, 12,4) spr(273, 4,12) spr(274, 12,12) spr(curtile, 8,10) print(string.format("%03d",curtile), 7,5, 12, false, 1, true) -- logic for the clear map timer if key(18) and destroyTimer >= 60 then if destroyTimer % 60 == 0 then sfx(01, "E-4", -1, 1) end destroyTimer = destroyTimer - 1 print("Clearing map in "..(destroyTimer//60).."...", 32, 8, 2) else destroyTimer = 60 * 4 end -- clears the map after R is pressed for 3+ secs if destroyTimer < 60 then clearMap() sfx(02, -1, -1, 2) end print("Position ".. cam.x ..", ".. cam.y) else -- PLAY MODE if launched then -- set init player pos p = {x=0, y=0, vx=0, vy=0, speed=1} p.x = tilefun.tiles["1x"] p.y = tilefun.tiles["1y"] end cam.x = (p.x//240)*30 cam.y = (p.y//136)*17 -- physics code by trelemar @ https://tic80.com/dev?id=5 -- thank you so fucking much man... if btn(2) then p.vx=-1 p.flipped = 1 elseif btn(3) then p.vx=1 p.flipped = 0 else p.vx=0 end if flag(p.x+5+p.vx,p.y+p.vy) or flag(p.x+2+p.vx,p.y+p.vy) or flag(p.x+p.vx,p.y+7+p.vy) or flag(p.x+7+p.vx,p.y+7+p.vy) then p.vx=0 end if flag(p.x+2,p.y+8+p.vy) or flag(p.x+5,p.y+8+p.vy) then p.vy=0 else p.vy=p.vy+0.14 end if btnp(4) and p.vy == 0 then p.vy=-2.5 end if p.vy<0 and (flag(p.x+p.vx,p.y+p.vy) or flag(p.x+7+p.vx,p.y+p.vy)) then p.vy=0 end -- physics code ends here if flag(p.x+7, p.y, 1) or flag(p.x-7, p.y, 1) or flag(p.x, p.y+7, 1) or flag(p.x, p.y-7, 1) then editing = true end -- if touching spike p.x=p.x+p.vx p.y=p.y+p.vy cam.x = p.x - 120 cam.y = p.y - 136/2 spr(256, 240/2, 136/2, 0, 1, p.flipped) p.x = clamp(p.x, 0, 240*8) p.y = clamp(p.y, 0, 136*8) launched = false end cam.x = clamp(cam.x, -120, 240*8) cam.y = clamp(cam.y, -64, 136*8) if key(49) then rect(20,20, helpwidth, helpwidth/1.9, 0) helpwidth = print(help, 20,20, 12, true,1) end end