mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-11 20:25:55 +00:00
mouse checker
This commit is contained in:
parent
c3fa3ab07c
commit
dd064deda5
2 changed files with 66 additions and 26 deletions
|
|
@ -1,24 +1,23 @@
|
|||
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 14:17:48",revision=5]]
|
||||
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 15:22:15",revision=25]]
|
||||
mouse_debug = true
|
||||
|
||||
function _init()
|
||||
x = 128
|
||||
y = 128
|
||||
speed = 2
|
||||
hflip = false
|
||||
playerSpr = 64
|
||||
end
|
||||
|
||||
function _draw()
|
||||
cls(0)
|
||||
camera(x - 240, y - 135)
|
||||
--camera(x - 240, y - 135)
|
||||
|
||||
drawMap()
|
||||
|
||||
spr(playerSpr,x,y, hflip)
|
||||
|
||||
spr(playerSpr,x+32,y, hflip)
|
||||
|
||||
|
||||
|
||||
debug_mouse()
|
||||
end
|
||||
|
||||
function drawMap()
|
||||
|
|
@ -28,12 +27,49 @@ function drawMap()
|
|||
end
|
||||
|
||||
function _update()
|
||||
if (btn(0)) x -= 2 hflip = true
|
||||
if (btn(1)) x += 2 hflip = false
|
||||
if (btn(2)) y -= 2
|
||||
if (btn(3)) y += 2
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
function checkCollision(x,y)
|
||||
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
|
||||
|
||||
-- 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)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue