diff --git a/src/cirno.lua b/src/cirno.lua index ee73e9b..8d01f78 100644 --- a/src/cirno.lua +++ b/src/cirno.lua @@ -1,4 +1,4 @@ ---[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-16 22:07:51",revision=191]] +--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-17 09:28:52",revision=219]] --include("/cirnofarm/src/actor.lua") last_coll=0 mouse_debug = true @@ -25,8 +25,6 @@ function _init() cb=true, -- Collide with world bounds draw=function(self) spr(self.spriteIndex,self.x,self.y, self.hflip) - drawCollision(self.x+self.move_x,self.y,self.w-1,self.h-1) - drawCollision(self.x,self.y+self.move_y,self.w-1,self.h-1) print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f coll:%d",self.x,self.y, self.move_x,self.move_y,last_coll),0,0,1) end, @@ -38,16 +36,11 @@ function _init() if (btn(2)) self.move_y -= self.speed if (btn(3)) self.move_y += self.speed - if (checkCollision(self.x+self.move_x,self.y,self.w-1,self.h-1)) then - --if (can_move(self.move_x,self.move_y)) then - --if (cmap(self) == false) then - - if (not self.noclip) then self.move_x = 0 end - --else - -- sfx(0) + if (check_collision(self.x+self.move_x,self.y,self.w-1,self.h-1)) then + if (not self.noclip) then self.move_x = 0 end end - if (not self.noclip and checkCollision(self.x,self.y+self.move_y,self.w-1,self.h-1)) then + if (check_collision(self.x,self.y+self.move_y,self.w-1,self.h-1)) then if (not self.noclip) then self.move_y = 0 end end @@ -55,11 +48,7 @@ function _init() self.move_y *= 0.95 self.x += self.move_x - self.y += self.move_y - --if (checkCollision(col_x,col_y) == false) then - -- x = col_x - -- y = col_y - --end + self.y += self.move_y end }) @@ -91,46 +80,22 @@ function _update() end end -function drawCollision(x,y,w,h) - for i=x,x+w,w do - - pset(i,y,8) - --pset(i,y+h,18) - - end - - --[[for i=y,y+h,w do - pset(x,i,8) - pset(x+w,i,8) - end]] - - --rect(left,top,right,bottom,2) -end - -function checkCollision(x,y,w,h) +function check_collision(x,y,w,h) local collide = false - last_coll = 0 - for i=x,x+w,w do - - local sprite = mget(i,y) - local flag = fget(sprite) - if (flag == 1) then - collide = true - last_coll = 1 - end - --if (is_tile_solid(i,y) --[[or is_tile_solid(i,y+h)]]) then - -- collide = true - -- last_coll = 1 - --end + for i=x,x+w,w do + + if (is_tile_solid(i,y) or is_tile_solid(i,y+h)) then + collide = collide or true + end end - --for i=y,y+h do - -- if (is_tile_solid(x,i) or is_tile_solid(x+w,i)) then - -- collide = true - -- end - --end - + for i=y,y+h do + if (is_tile_solid(x,i) or is_tile_solid(x+w,i)) then + collide = collide or true + end + end + return collide end @@ -142,7 +107,7 @@ function is_tile(tile_type,x,y) end function is_tile_solid(x,y) - return is_tile(1,x,y) + return is_tile(1,x,y) == 1 end function can_move(x,y)