From 302e7f4289d0af371403efba2d378b532a2a25c7 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 14 Apr 2024 23:11:08 +0200 Subject: [PATCH] Made the debug better --- src/cirno.lua | 72 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/src/cirno.lua b/src/cirno.lua index 408d7a3..91b3ab3 100644 --- a/src/cirno.lua +++ b/src/cirno.lua @@ -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 - +w=480 +h=300 function _init() player={} add(player, { @@ -9,20 +10,32 @@ function _init() speed=2, hflip=false, spriteIndex=64, + move_x=0, + move_y=0, + cm=true, -- Collide with map tiles + cb=true, -- Collide with world bounds draw=function(self) 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, update=function(self) - local col_x = self.x - local col_y = self.y - if (btn(0)) col_x -= self.speed self.hflip = true - if (btn(1)) col_x += self.speed self.hflip = false - if (btn(2)) col_y -= self.speed - if (btn(3)) col_y += self.speed + self.move_x = self.x + self.move_y = self.y + if (btn(0)) self.move_x -= self.speed self.hflip = true + if (btn(1)) self.move_x += self.speed self.hflip = false + if (btn(2)) self.move_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 -- x = col_x -- y = col_y @@ -60,8 +73,7 @@ function _update() end 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 function debug_mouse() @@ -82,13 +94,39 @@ function debug_mouse() if my>h-29 then y_offset=-24 end -- draw debug text box - local tile_x = mx/tw - local tile_y = my/th + local tile_x = mx\tw + local tile_y = my\th local sprite = mget(tile_x,tile_y) 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) - print(mx/tw,mx+x_offset,my+y_offset,8) - print(my/th,mx+x_offset,my+y_offset+8,9) + print(string.format("%d (%d)",tile_x,mx),mx+x_offset,my+y_offset,8) + 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(flag,mx+x_offset,my+y_offset+8+8*2,10) +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 \ No newline at end of file