mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-22 15:53:47 +00:00
Converted cirno to movable object
This commit is contained in:
parent
5e667fd6d2
commit
81a8c11823
5 changed files with 76 additions and 186 deletions
194
src/cirno.lua
194
src/cirno.lua
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
local weapons_manager = require(make_path("weapons"))
|
||||
local map_manager = require(make_path("map"))
|
||||
local MovableActor = require(make_path("movable_actor"))
|
||||
|
||||
last_coll=0
|
||||
mouse_debug = true
|
||||
|
|
@ -11,6 +12,29 @@ h=300
|
|||
asdf = {top=0, side=1}
|
||||
LAYERS_COUNT=4
|
||||
|
||||
local Cirno = MovableActor:new()
|
||||
Cirno.spriteIndex = 65
|
||||
Cirno.crosshair_index=82
|
||||
|
||||
function Cirno:update()
|
||||
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:move()
|
||||
|
||||
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
|
||||
|
||||
function Cirno:draw()
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
|
||||
draw_crosshair(self)
|
||||
end
|
||||
|
||||
function draw_crosshair(self)
|
||||
local radius = 20 -- Adjust the radius of the crosshair as needed
|
||||
|
|
@ -24,170 +48,24 @@ function draw_crosshair(self)
|
|||
--circfill(crosshair_x, crosshair_y, 2, 7) -- Adjust the size and color as needed
|
||||
end
|
||||
|
||||
|
||||
function cirno_init()
|
||||
--bullets={}
|
||||
|
||||
player={}
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
self.move_x *= 0.95
|
||||
self.move_y *= 0.95
|
||||
|
||||
self.x += self.move_x
|
||||
self.y += self.move_y
|
||||
end
|
||||
}
|
||||
|
||||
add(player, cirnoInstance)
|
||||
|
||||
return cirnoInstance
|
||||
|
||||
|
||||
end
|
||||
|
||||
function cirno_draw()
|
||||
--cls(0)
|
||||
|
||||
|
||||
--drawMap()
|
||||
|
||||
--debug_mouse()
|
||||
for p in all(player) do
|
||||
p:draw()
|
||||
end
|
||||
|
||||
print(string.format("%.4f %dfps",stat(1),stat(7)),2,16,5)
|
||||
|
||||
end
|
||||
|
||||
|
||||
function cirno_update()
|
||||
for p in all(player) do
|
||||
p:update()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function check_collision(x,y,w,h)
|
||||
local collide = false
|
||||
|
||||
for i=x,x+w,w do
|
||||
|
||||
if (map_manager.is_tile_solid(i,y) or map_manager.is_tile_solid(i,y+h)) then
|
||||
collide = collide or true
|
||||
end
|
||||
end
|
||||
|
||||
for i=y,y+h do
|
||||
if (map_manager.is_tile_solid(x,i) or map_manager.is_tile_solid(x+w,i)) then
|
||||
collide = collide or true
|
||||
end
|
||||
end
|
||||
|
||||
return collide
|
||||
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
|
||||
|
||||
|
||||
M = {}
|
||||
|
||||
function M.init()
|
||||
return cirno_init()
|
||||
--return cirno_init()
|
||||
local c = Cirno:new(128,128)
|
||||
return c
|
||||
end
|
||||
|
||||
function M.update()
|
||||
return cirno_update()
|
||||
end
|
||||
-- function M.update()
|
||||
-- return cirno_update()
|
||||
-- end
|
||||
|
||||
function M.draw()
|
||||
return cirno_draw()
|
||||
end
|
||||
-- function M.draw()
|
||||
-- return cirno_draw()
|
||||
-- end
|
||||
|
||||
function M.get()
|
||||
return player[1]
|
||||
end
|
||||
-- function M.get()
|
||||
-- return player[1]
|
||||
-- end
|
||||
|
||||
return M
|
||||
11
src/game.lua
11
src/game.lua
|
|
@ -51,7 +51,7 @@ end
|
|||
--local strawberry = require(make_path("strawberry"))
|
||||
--strawberry.func()
|
||||
|
||||
local cirno = require(make_path("cirno"))
|
||||
local Cirno = require(make_path("cirno"))
|
||||
local mouse_debug = require(make_path("mouse_debug"))
|
||||
local map_manager = require(make_path("map"))
|
||||
local weapons_manager = require(make_path("weapons"))
|
||||
|
|
@ -63,11 +63,12 @@ tile_height = 16
|
|||
|
||||
function _init()
|
||||
spawn_objects()
|
||||
cirnoInstance = cirno.init()
|
||||
cirnoInstance = Cirno.init()
|
||||
add(actors,cirnoInstance)
|
||||
end
|
||||
|
||||
function _update()
|
||||
cirno.update()
|
||||
--cirno.update()
|
||||
|
||||
weapons_manager.update()
|
||||
|
||||
|
|
@ -106,7 +107,7 @@ function _draw()
|
|||
weapons_manager.debug_draw()
|
||||
|
||||
print(string.format("Actors: %d", count(actors)),0,32+8)
|
||||
|
||||
print(string.format("%.4f %dfps",stat(1),stat(7)),2,16,5)
|
||||
end
|
||||
|
||||
function spawn_objects()
|
||||
|
|
@ -142,7 +143,7 @@ function render_layer(layer)
|
|||
|
||||
if (layer.render_objects) then
|
||||
-- Render all objects here
|
||||
cirno.draw()
|
||||
--cirno.draw()
|
||||
|
||||
weapons_manager.draw()
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ MovableActor.noclip=false
|
|||
MovableActor.collide_map=true
|
||||
MovableActor.collide_actors=true
|
||||
MovableActor.collide_bounds=true
|
||||
MovableActor.friction_x=0.95
|
||||
MovableActor.friction_y=0.95
|
||||
|
||||
function MovableActor:draw()
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
|
|
@ -42,8 +44,8 @@ function MovableActor:move()
|
|||
end
|
||||
end
|
||||
|
||||
self.move_x *= 0.95
|
||||
self.move_y *= 0.95
|
||||
self.move_x *= self.friction_x
|
||||
self.move_y *= self.friction_y
|
||||
|
||||
self.x += self.move_x
|
||||
self.y += self.move_y
|
||||
|
|
|
|||
|
|
@ -6,4 +6,12 @@ Strawberry.collide_map=false
|
|||
Strawberry.collide_actors=false
|
||||
Strawberry.collide_bounds=false
|
||||
|
||||
function Strawberry:update()
|
||||
if (btn(5)) then
|
||||
self.move_x = 1
|
||||
end
|
||||
|
||||
self:move()
|
||||
end
|
||||
|
||||
return Strawberry
|
||||
Loading…
Add table
Add a link
Reference in a new issue