mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-18 17:33:48 +00:00
Made the debug better
This commit is contained in:
parent
d9daf68d2b
commit
302e7f4289
1 changed files with 55 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 19:13:33",revision=31]]
|
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 21:05:28",revision=66]]
|
||||||
mouse_debug = true
|
mouse_debug = true
|
||||||
|
w=480
|
||||||
|
h=300
|
||||||
function _init()
|
function _init()
|
||||||
player={}
|
player={}
|
||||||
add(player, {
|
add(player, {
|
||||||
|
|
@ -9,20 +10,32 @@ function _init()
|
||||||
speed=2,
|
speed=2,
|
||||||
hflip=false,
|
hflip=false,
|
||||||
spriteIndex=64,
|
spriteIndex=64,
|
||||||
|
move_x=0,
|
||||||
|
move_y=0,
|
||||||
|
cm=true, -- Collide with map tiles
|
||||||
|
cb=true, -- Collide with world bounds
|
||||||
draw=function(self)
|
draw=function(self)
|
||||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||||
|
|
||||||
|
if (mouse_debug == true) then
|
||||||
|
local col = 8;
|
||||||
|
if (checkCollision(self.move_x,self.move_y) == true) then col = 7 end
|
||||||
|
pset(self.move_x,self.move_y,col)
|
||||||
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
update=function(self)
|
update=function(self)
|
||||||
local col_x = self.x
|
self.move_x = self.x
|
||||||
local col_y = self.y
|
self.move_y = self.y
|
||||||
if (btn(0)) col_x -= self.speed self.hflip = true
|
if (btn(0)) self.move_x -= self.speed self.hflip = true
|
||||||
if (btn(1)) col_x += self.speed self.hflip = false
|
if (btn(1)) self.move_x += self.speed self.hflip = false
|
||||||
if (btn(2)) col_y -= self.speed
|
if (btn(2)) self.move_y -= self.speed
|
||||||
if (btn(3)) col_y += self.speed
|
if (btn(3)) self.move_y += self.speed
|
||||||
|
|
||||||
self.x = col_x
|
|
||||||
self.y = col_y
|
|
||||||
|
|
||||||
|
--if (cmap(self) == false) then
|
||||||
|
self.x = self.move_x
|
||||||
|
self.y = self.move_y
|
||||||
|
--end
|
||||||
--if (checkCollision(col_x,col_y) == false) then
|
--if (checkCollision(col_x,col_y) == false) then
|
||||||
-- x = col_x
|
-- x = col_x
|
||||||
-- y = col_y
|
-- y = col_y
|
||||||
|
|
@ -60,8 +73,7 @@ function _update()
|
||||||
end
|
end
|
||||||
|
|
||||||
function checkCollision(x,y)
|
function checkCollision(x,y)
|
||||||
return true
|
return fget(mget(x/tile_width,y/tile_height),0)
|
||||||
--return fget(mget(x/tile_width,y/tile_height),0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function debug_mouse()
|
function debug_mouse()
|
||||||
|
|
@ -82,13 +94,39 @@ function debug_mouse()
|
||||||
if my>h-29 then y_offset=-24 end
|
if my>h-29 then y_offset=-24 end
|
||||||
|
|
||||||
-- draw debug text box
|
-- draw debug text box
|
||||||
local tile_x = mx/tw
|
local tile_x = mx\tw
|
||||||
local tile_y = my/th
|
local tile_y = my\th
|
||||||
local sprite = mget(tile_x,tile_y)
|
local sprite = mget(tile_x,tile_y)
|
||||||
local flag = fget(sprite)
|
local flag = fget(sprite)
|
||||||
|
rect((tile_x*tw)+tw,(tile_y*th)+th,tile_x*tw,(tile_y*th),8)
|
||||||
rectfill(mx+x_offset-1,my+y_offset-1,mx+x_offset+14,my+y_offset+23+8,1)
|
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(string.format("%d (%d)",tile_x,mx),mx+x_offset,my+y_offset,8)
|
||||||
print(my/th,mx+x_offset,my+y_offset+8,9)
|
print(string.format("%d (%d)",tile_y,my),mx+x_offset,my+y_offset+8,9)
|
||||||
print(sprite,mx+x_offset,my+y_offset+8*2,10)
|
print(sprite,mx+x_offset,my+y_offset+8*2,10)
|
||||||
print(flag,mx+x_offset,my+y_offset+8+8*2,10)
|
print(flag,mx+x_offset,my+y_offset+8+8*2,10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function cmap(o)
|
||||||
|
local ct=false
|
||||||
|
local cb=false
|
||||||
|
|
||||||
|
-- if colliding with map tiles
|
||||||
|
if(o.cm) then
|
||||||
|
local x1=o.x/tile_width
|
||||||
|
local y1=o.y/tile_height
|
||||||
|
local x2=(o.x+tile_width-1)/tile_width
|
||||||
|
local y2=(o.y+tile_height-1)/tile_height
|
||||||
|
local a=fget(mget(x1,y1),1)
|
||||||
|
local b=fget(mget(x1,y2),1)
|
||||||
|
local c=fget(mget(x2,y2),1)
|
||||||
|
local d=fget(mget(x2,y1),1)
|
||||||
|
ct=a or b or c or d
|
||||||
|
end
|
||||||
|
-- if colliding world bounds
|
||||||
|
if(o.cw) then
|
||||||
|
cb=(o.x<0 or o.x+tile_width>w or
|
||||||
|
o.y<0 or o.y+tile_height>h)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ct or cb
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue