mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-13 23:35:55 +00:00
New bullet instantiation method
This commit is contained in:
parent
c33488fabd
commit
cc921f9ade
4 changed files with 121 additions and 84 deletions
|
|
@ -2,6 +2,7 @@
|
|||
--include("/cirnofarm/src/actor.lua")
|
||||
|
||||
local weapons_manager = require(make_path("weapons"))
|
||||
local map_manager = require(make_path("map"))
|
||||
|
||||
last_coll=0
|
||||
mouse_debug = true
|
||||
|
|
@ -198,13 +199,13 @@ function check_collision(x,y,w,h)
|
|||
|
||||
for i=x,x+w,w do
|
||||
|
||||
if (is_tile_solid(i,y) or is_tile_solid(i,y+h)) then
|
||||
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 (is_tile_solid(x,i) or is_tile_solid(x+w,i)) then
|
||||
if (map_manager.is_tile_solid(x,i) or map_manager.is_tile_solid(x+w,i)) then
|
||||
collide = collide or true
|
||||
end
|
||||
end
|
||||
|
|
@ -212,27 +213,6 @@ function check_collision(x,y,w,h)
|
|||
return collide
|
||||
end
|
||||
|
||||
function get_layer_tile(x,y,layer)
|
||||
return get(fetch"map/0.map"[layer].bmp,x,y)
|
||||
end
|
||||
|
||||
function is_tile(tile_type,x,y)
|
||||
--local tile = mget(x/tile_width,y/tile_height)
|
||||
local tile = get_layer_tile(x/tile_width,y/tile_height,3)
|
||||
local has_flag = fget(tile,tile_type)
|
||||
--last_coll = fget(tile)
|
||||
return has_flag
|
||||
end
|
||||
|
||||
function is_tile_solid(x,y)
|
||||
return is_tile(1,x,y) == 1
|
||||
end
|
||||
|
||||
function can_move(x,y)
|
||||
return is_tile(0,x,y)
|
||||
end
|
||||
|
||||
|
||||
function cmap(o)
|
||||
local ct=false
|
||||
local cb=false
|
||||
|
|
|
|||
28
src/map.lua
Normal file
28
src/map.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
M = {}
|
||||
|
||||
local tile_width = 16
|
||||
local tile_height = 16
|
||||
|
||||
local current_map = "0"
|
||||
|
||||
function get_layer_tile(x,y,layer)
|
||||
return get(fetch("map/".. current_map .. ".map")[layer].bmp,x,y)
|
||||
end
|
||||
|
||||
function is_tile(tile_type,x,y)
|
||||
--local tile = mget(x/tile_width,y/tile_height)
|
||||
local tile = get_layer_tile(x/tile_width,y/tile_height,3)
|
||||
local has_flag = fget(tile,tile_type)
|
||||
--last_coll = fget(tile)
|
||||
return has_flag
|
||||
end
|
||||
|
||||
function M.is_tile_solid(x,y)
|
||||
return is_tile(1,x,y) == 1
|
||||
end
|
||||
|
||||
function M.can_move(x,y)
|
||||
return is_tile(0,x,y)
|
||||
end
|
||||
|
||||
return M
|
||||
131
src/weapons.lua
131
src/weapons.lua
|
|
@ -22,27 +22,61 @@ bullet = {
|
|||
destroy_sprite_index=66,
|
||||
life=100,
|
||||
damage=1,
|
||||
draw=function(self)
|
||||
--pset(self.x,self.y,8)
|
||||
spr(self.spriteIndex,self.x,self.y)
|
||||
end,
|
||||
update=function(self)
|
||||
self.x+=self.dx
|
||||
self.y+=self.dy
|
||||
-- draw=function(self)
|
||||
-- --pset(self.x,self.y,8)
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
-- end,
|
||||
-- update=function(self)
|
||||
-- self.x+=self.dx
|
||||
-- self.y+=self.dy
|
||||
|
||||
self.life-=1
|
||||
if self.life<0 then
|
||||
del(bullets,self)
|
||||
-- TODO: Create particle
|
||||
end
|
||||
-- self.life-=1
|
||||
-- if self.life<0 then
|
||||
-- del(bullets,self)
|
||||
-- -- TODO: Create particle
|
||||
-- end
|
||||
|
||||
self.check_collision(self)
|
||||
end,
|
||||
check_collision=function(self)
|
||||
-- If Collide with wall destroy self and create particle
|
||||
-- self.check_collision(self)
|
||||
-- end,
|
||||
-- check_collision=function(self)
|
||||
-- -- If Collide with wall destroy self and create particle
|
||||
|
||||
end
|
||||
-- end
|
||||
}
|
||||
bullet.__index = bullet
|
||||
function bullet:new(x, y, dx, dy)
|
||||
local o = setmetatable({}, bullet)
|
||||
o.x = x
|
||||
o.y = y
|
||||
o.dx = dx
|
||||
o.dy = dy
|
||||
--o.life = 100
|
||||
--o.spriteIndex = 80
|
||||
--o.destroy_sprite_index = 66
|
||||
--o.damage = 1
|
||||
return o
|
||||
end
|
||||
|
||||
function bullet:check_collision()
|
||||
--
|
||||
end
|
||||
|
||||
function bullet:update()
|
||||
self.x+=self.dx
|
||||
self.y+=self.dy
|
||||
|
||||
self.life-=1
|
||||
if self.life<0 then
|
||||
del(bullets,self)
|
||||
-- TODO: Create particle
|
||||
end
|
||||
|
||||
self.check_collision()
|
||||
end
|
||||
|
||||
function bullet:draw()
|
||||
spr(self.spriteIndex,self.x,self.y)
|
||||
end
|
||||
|
||||
function M.create_bullet(new_x, new_y, dir_x, dir_y)
|
||||
-- Calculate the length of the direction vector
|
||||
|
|
@ -52,45 +86,40 @@ function M.create_bullet(new_x, new_y, dir_x, dir_y)
|
|||
local normalized_dir_x = dir_x / length
|
||||
local normalized_dir_y = dir_y / length
|
||||
|
||||
b = bullet
|
||||
b.life = 100
|
||||
b.x = new_x
|
||||
b.y = new_y
|
||||
b.dx = normalized_dir_x * 2
|
||||
b.dy = normalized_dir_y * 2
|
||||
local b = bullet:new(new_x, new_y, normalized_dir_x * 2, normalized_dir_y * 2)
|
||||
|
||||
--add(bullets, b)
|
||||
add(bullets, b)
|
||||
|
||||
add(bullets, {
|
||||
x=new_x,
|
||||
y=new_y,
|
||||
dx=normalized_dir_x * 2,
|
||||
dy=normalized_dir_y * 2,
|
||||
spriteIndex=80,
|
||||
destroy_sprite_index=66,
|
||||
life=100,
|
||||
damage=1,
|
||||
draw=function(self)
|
||||
--pset(self.x,self.y,8)
|
||||
spr(self.spriteIndex,self.x,self.y)
|
||||
end,
|
||||
update=function(self)
|
||||
self.x+=self.dx
|
||||
self.y+=self.dy
|
||||
-- add(bullets, {
|
||||
-- x=new_x,
|
||||
-- y=new_y,
|
||||
-- dx=normalized_dir_x * 2,
|
||||
-- dy=normalized_dir_y * 2,
|
||||
-- spriteIndex=80,
|
||||
-- destroy_sprite_index=66,
|
||||
-- life=100,
|
||||
-- damage=1,
|
||||
-- draw=function(self)
|
||||
-- --pset(self.x,self.y,8)
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
-- end,
|
||||
-- update=function(self)
|
||||
-- self.x+=self.dx
|
||||
-- self.y+=self.dy
|
||||
|
||||
self.life-=1
|
||||
if self.life<0 then
|
||||
del(bullets,self)
|
||||
-- TODO: Create particle
|
||||
end
|
||||
-- self.life-=1
|
||||
-- if self.life<0 then
|
||||
-- del(bullets,self)
|
||||
-- -- TODO: Create particle
|
||||
-- end
|
||||
|
||||
self.check_collision(self)
|
||||
end,
|
||||
check_collision=function(self)
|
||||
-- If Collide with wall destroy self and create particle
|
||||
-- self.check_collision(self)
|
||||
-- end,
|
||||
-- check_collision=function(self)
|
||||
-- -- If Collide with wall destroy self and create particle
|
||||
|
||||
end
|
||||
})
|
||||
-- end
|
||||
-- })
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue