2024-04-14 21:13:54 +02:00
|
|
|
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 19:13:33",revision=31]]
|
2024-04-14 17:22:50 +02:00
|
|
|
mouse_debug = true
|
2024-04-14 16:19:38 +02:00
|
|
|
|
2024-04-14 15:51:45 +02:00
|
|
|
function _init()
|
2024-04-14 21:13:54 +02:00
|
|
|
player={}
|
|
|
|
|
add(player, {
|
|
|
|
|
x=128,
|
|
|
|
|
y=128,
|
|
|
|
|
speed=2,
|
|
|
|
|
hflip=false,
|
|
|
|
|
spriteIndex=64,
|
|
|
|
|
draw=function(self)
|
|
|
|
|
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
|
|
|
|
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.x = col_x
|
|
|
|
|
self.y = col_y
|
|
|
|
|
|
|
|
|
|
--if (checkCollision(col_x,col_y) == false) then
|
|
|
|
|
-- x = col_x
|
|
|
|
|
-- y = col_y
|
|
|
|
|
--end
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
tile_width = 16
|
|
|
|
|
tile_height = 16
|
2024-04-14 15:51:45 +02:00
|
|
|
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 21:13:54 +02:00
|
|
|
|
|
|
|
|
for p in all(player) do
|
|
|
|
|
p:draw()
|
|
|
|
|
end
|
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 21:13:54 +02:00
|
|
|
for p in all(player) do
|
|
|
|
|
p:update()
|
2024-04-14 17:22:50 +02:00
|
|
|
end
|
2024-04-14 16:19:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function checkCollision(x,y)
|
2024-04-14 21:13:54 +02:00
|
|
|
return true
|
|
|
|
|
--return fget(mget(x/tile_width,y/tile_height),0)
|
2024-04-14 17:22:50 +02:00
|
|
|
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
|