mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-21 02:13:49 +00:00
Camera refactor
This commit is contained in:
parent
2507ba301c
commit
56fa9bce02
3 changed files with 102 additions and 88 deletions
130
src/cirno.lua
130
src/cirno.lua
|
|
@ -29,73 +29,77 @@ function cirno_init()
|
|||
--bullets={}
|
||||
|
||||
player={}
|
||||
add(player, {
|
||||
x=128,
|
||||
y=128,
|
||||
w=16,
|
||||
h=16,
|
||||
speed=0.05,
|
||||
hflip=false,
|
||||
spriteIndex=65,
|
||||
crosshair_index=82,
|
||||
move_x=0,
|
||||
move_y=0,
|
||||
noclip=false,
|
||||
cm=true, -- Collide with map tiles
|
||||
cb=true, -- Collide with world bounds
|
||||
draw=function(self)
|
||||
camera(self.x - 240, self.y - 135)
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f",self.x,self.y,
|
||||
self.move_x,self.move_y),0,0,1)
|
||||
local cirnoInstance = {
|
||||
x=128,
|
||||
y=128,
|
||||
w=16,
|
||||
h=16,
|
||||
speed=0.05,
|
||||
hflip=false,
|
||||
spriteIndex=65,
|
||||
crosshair_index=82,
|
||||
move_x=0,
|
||||
move_y=0,
|
||||
noclip=false,
|
||||
cm=true, -- Collide with map tiles
|
||||
cb=true, -- Collide with world bounds
|
||||
draw=function(self)
|
||||
|
||||
draw_crosshair(self)
|
||||
--print(string.format("dir_x:%.4f dir_y:%.4f",self.
|
||||
end,
|
||||
update=function(self)
|
||||
self.move_character(self)
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f",self.x,self.y,
|
||||
self.move_x,self.move_y),0,0,1)
|
||||
|
||||
draw_crosshair(self)
|
||||
--print(string.format("dir_x:%.4f dir_y:%.4f",self.
|
||||
end,
|
||||
update=function(self)
|
||||
self.move_character(self)
|
||||
|
||||
-- Shoot bullet with Z
|
||||
if (btn(4)) then
|
||||
--create_bullet(self.x,self.y,self.move_x,self.move_Y)
|
||||
weapons_manager.create_bullet(self.x+8,self.y+8,self.move_x,self.move_y)
|
||||
end
|
||||
end,
|
||||
move_character=function(self)
|
||||
|
||||
-- Shoot bullet with Z
|
||||
if (btn(4)) then
|
||||
--create_bullet(self.x,self.y,self.move_x,self.move_Y)
|
||||
weapons_manager.create_bullet(self.x+8,self.y+8,self.move_x,self.move_y)
|
||||
end
|
||||
end,
|
||||
move_character=function(self)
|
||||
local hitbox_x = 4
|
||||
local hitbox_y = 8
|
||||
local hitbox_w = 6
|
||||
local hitbox_h = 8
|
||||
|
||||
local hitbox_x = 4
|
||||
local hitbox_y = 8
|
||||
local hitbox_w = 6
|
||||
local hitbox_h = 8
|
||||
|
||||
--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
|
||||
|
||||
if (check_collision(self.x+self.move_x+hitbox_x,
|
||||
self.y+hitbox_y,
|
||||
hitbox_w,
|
||||
hitbox_h)) then
|
||||
if (not self.noclip) then self.move_x = 0 end
|
||||
end
|
||||
|
||||
if (check_collision(self.x+hitbox_x,
|
||||
self.y+self.move_y+hitbox_y,
|
||||
hitbox_w,
|
||||
hitbox_h)) then
|
||||
if (not self.noclip) then self.move_y = 0 end
|
||||
--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
|
||||
|
||||
if (check_collision(self.x+self.move_x+hitbox_x,
|
||||
self.y+hitbox_y,
|
||||
hitbox_w,
|
||||
hitbox_h)) then
|
||||
if (not self.noclip) then self.move_x = 0 end
|
||||
end
|
||||
|
||||
if (check_collision(self.x+hitbox_x,
|
||||
self.y+self.move_y+hitbox_y,
|
||||
hitbox_w,
|
||||
hitbox_h)) then
|
||||
if (not self.noclip) then self.move_y = 0 end
|
||||
end
|
||||
|
||||
self.move_x *= 0.95
|
||||
self.move_y *= 0.95
|
||||
|
||||
self.x += self.move_x
|
||||
self.y += self.move_y
|
||||
end
|
||||
}
|
||||
|
||||
self.move_x *= 0.95
|
||||
self.move_y *= 0.95
|
||||
add(player, cirnoInstance)
|
||||
|
||||
self.x += self.move_x
|
||||
self.y += self.move_y
|
||||
end
|
||||
})
|
||||
return cirnoInstance
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -182,4 +186,8 @@ function M.draw()
|
|||
return cirno_draw()
|
||||
end
|
||||
|
||||
function M.get()
|
||||
return player[1]
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -62,7 +62,7 @@ tile_height = 16
|
|||
|
||||
function _init()
|
||||
spawn_objects()
|
||||
cirno.init()
|
||||
cirnoInstance = cirno.init()
|
||||
end
|
||||
|
||||
function _update()
|
||||
|
|
@ -97,10 +97,15 @@ particles = {}
|
|||
function _draw()
|
||||
cls(0)
|
||||
|
||||
camera(cirnoInstance.x - 240, cirnoInstance.y - 135)
|
||||
|
||||
foreach(LAYERS, render_layer)
|
||||
|
||||
mouse_debug.draw(4, tile_width, tile_height)
|
||||
weapons_manager.debug_draw()
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function spawn_objects()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue