cirnofarm/src/cirno.lua

75 lines
1.4 KiB
Lua
Raw Normal View History

2024-04-14 17:22:50 +02:00
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 15:22:15",revision=25]]
mouse_debug = true
2024-04-14 16:19:38 +02:00
2024-04-14 15:51:45 +02:00
function _init()
x = 128
y = 128
2024-04-14 17:22:50 +02:00
speed = 2
2024-04-14 15:51:45 +02:00
hflip = false
playerSpr = 64
end
function _draw()
cls(0)
2024-04-14 17:22:50 +02:00
--camera(x - 240, y - 135)
2024-04-14 15:51:45 +02:00
2024-04-14 16:19:38 +02:00
drawMap()
2024-04-14 15:51:45 +02:00
spr(playerSpr,x,y, hflip)
2024-04-14 16:19:38 +02:00
2024-04-14 17:22:50 +02:00
debug_mouse()
2024-04-14 16:19:38 +02:00
end
2024-04-14 15:51:45 +02:00
2024-04-14 16:19:38 +02:00
function drawMap()
for i=2,1,-1 do
map(fetch"map/0.map"[i].bmp)
end
2024-04-14 15:51:45 +02:00
end
function _update()
2024-04-14 17:22:50 +02:00
local col_x = x
local col_y = y
if (btn(0)) col_x -= speed hflip = true
if (btn(1)) col_x += speed hflip = false
if (btn(2)) col_y -= speed
if (btn(3)) col_y += speed
if (checkCollision(col_x,col_y) == true) then
x = col_x
y = col_y
end
2024-04-14 16:19:38 +02:00
end
function checkCollision(x,y)
2024-04-14 17:22:50 +02:00
return fget(mget(x,y),0)
end
function debug_mouse()
local mx,my = mouse()
local x_offset = 5
local y_offset = 5
-- tile size
local tw=16
local th=16
-- window width and height
local w=480
local h=270
-- offset if box leaves screen
if mx>w-20 then x_offset=-15 end
if my>h-29 then y_offset=-24 end
2024-04-14 16:19:38 +02:00
2024-04-14 17:22:50 +02:00
-- draw debug text box
local tile_x = mx/tw
local tile_y = my/th
local sprite = mget(tile_x,tile_y)
local flag = fget(sprite)
rectfill(mx+x_offset-1,my+y_offset-1,mx+x_offset+14,my+y_offset+23+8,1)
print(mx/tw,mx+x_offset,my+y_offset,8)
print(my/th,mx+x_offset,my+y_offset+8,9)
print(sprite,mx+x_offset,my+y_offset+8*2,10)
print(flag,mx+x_offset,my+y_offset+8+8*2,10)
2024-04-14 15:51:45 +02:00
end