Objectified player

This commit is contained in:
MaddoScientisto 2024-04-14 21:13:54 +02:00
commit d9daf68d2b
2 changed files with 50 additions and 31 deletions

View file

@ -1,12 +1,37 @@
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 15:22:15",revision=25]]
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-14 19:13:33",revision=31]]
mouse_debug = true
function _init()
x = 128
y = 128
speed = 2
hflip = false
playerSpr = 64
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
end
function _draw()
@ -14,8 +39,10 @@ function _draw()
--camera(x - 240, y - 135)
drawMap()
spr(playerSpr,x,y, hflip)
for p in all(player) do
p:draw()
end
debug_mouse()
end
@ -27,22 +54,14 @@ function drawMap()
end
function _update()
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
for p in all(player) do
p:update()
end
end
function checkCollision(x,y)
return fget(mget(x,y),0)
return true
--return fget(mget(x/tile_width,y/tile_height),0)
end
function debug_mouse()