2024-04-24 11:11:16 +02:00
|
|
|
--cd("/cirnofarm/src")
|
|
|
|
|
--include("/cirnofarm/src/cirno.lua")
|
|
|
|
|
|
|
|
|
|
function make_path(name)
|
|
|
|
|
local base_path = "/cirnofarm/src/" -- Change this when releasing
|
|
|
|
|
return base_path .. name
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local _modules = {}
|
|
|
|
|
|
|
|
|
|
function loadfile (filename)
|
|
|
|
|
local src = fetch(filename)
|
|
|
|
|
|
|
|
|
|
if (type(src) ~= "string") then
|
|
|
|
|
notify("could not include "..filename)
|
|
|
|
|
stop()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- https://www.lua.org/manual/5.4/manual.html#pdf-load
|
|
|
|
|
-- chunk name (for error reporting), mode ("t" for text only -- no binary chunk loading), _ENV upvalue
|
|
|
|
|
-- @ is a special character that tells debugger the string is a filename
|
|
|
|
|
local func,err = load(src, "@"..filename, "t", _ENV)
|
|
|
|
|
-- syntax error while loading
|
|
|
|
|
if (not func) then
|
|
|
|
|
send_message(3, {event="report_error", content = "*syntax error"})
|
|
|
|
|
send_message(3, {event="report_error", content = tostr(err)})
|
|
|
|
|
|
|
|
|
|
stop()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
return func
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function require(name)
|
|
|
|
|
local already_imported = _modules[name]
|
|
|
|
|
if already_imported ~= nil then
|
|
|
|
|
return already_imported
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local filename = fullpath(name:gsub ('%.', '/') ..'.lua')
|
|
|
|
|
|
|
|
|
|
local func = loadfile (filename)
|
|
|
|
|
|
|
|
|
|
local module = func(name)
|
|
|
|
|
_modules[name]=module
|
|
|
|
|
|
|
|
|
|
return module
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--local strawberry = require(make_path("strawberry"))
|
|
|
|
|
--strawberry.func()
|
|
|
|
|
|
|
|
|
|
local cirno = require(make_path("cirno"))
|
|
|
|
|
local mouse_debug = require(make_path("mouse_debug"))
|
2024-04-25 23:07:49 +02:00
|
|
|
local map_manager = require(make_path("map"))
|
|
|
|
|
local weapons_manager = require(make_path("weapons"))
|
2024-04-26 11:22:51 +02:00
|
|
|
local Barrel = require(make_path("barrel"))
|
2024-04-24 11:11:16 +02:00
|
|
|
|
|
|
|
|
tile_width = 16
|
|
|
|
|
tile_height = 16
|
2024-04-14 15:51:45 +02:00
|
|
|
|
|
|
|
|
function _init()
|
2024-04-26 11:22:51 +02:00
|
|
|
spawn_objects()
|
2024-04-24 11:11:16 +02:00
|
|
|
cirno.init()
|
2024-04-14 15:51:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function _update()
|
2024-04-24 11:11:16 +02:00
|
|
|
cirno.update()
|
2024-04-25 23:07:49 +02:00
|
|
|
|
|
|
|
|
weapons_manager.update()
|
2024-04-26 11:30:53 +02:00
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
for a in all(actors) do
|
|
|
|
|
a:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for b in all(bullets) do
|
2024-04-26 11:30:53 +02:00
|
|
|
b:update()
|
|
|
|
|
end
|
2024-04-26 13:31:42 +02:00
|
|
|
|
|
|
|
|
for p in all(particles) do
|
|
|
|
|
p:update()
|
|
|
|
|
end
|
2024-04-14 15:51:45 +02:00
|
|
|
end
|
|
|
|
|
|
2024-04-25 23:07:49 +02:00
|
|
|
LAYERS = {
|
|
|
|
|
{index=4, name="background", render=true, render_objects=false, spawn_objects=false},
|
|
|
|
|
{index=3, name="solid", render=true, render_objects=true, spawn_objects=false},
|
|
|
|
|
{index=2, name="foreground", render=true, render_objects=false, spawn_objects=false},
|
|
|
|
|
{index=1, name="objects", render=false, render_objects=false, spawn_objects=true}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 11:22:51 +02:00
|
|
|
actors = {}
|
2024-04-26 13:31:42 +02:00
|
|
|
bullets = {}
|
|
|
|
|
particles = {}
|
2024-04-26 11:22:51 +02:00
|
|
|
|
2024-04-14 15:51:45 +02:00
|
|
|
function _draw()
|
2024-04-25 23:07:49 +02:00
|
|
|
cls(0)
|
|
|
|
|
|
|
|
|
|
foreach(LAYERS, render_layer)
|
|
|
|
|
|
2024-04-24 22:53:04 +02:00
|
|
|
mouse_debug.draw(4, tile_width, tile_height)
|
2024-04-25 23:07:49 +02:00
|
|
|
weapons_manager.debug_draw()
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-26 11:22:51 +02:00
|
|
|
function spawn_objects()
|
2024-04-26 13:31:42 +02:00
|
|
|
|
|
|
|
|
local width = 32
|
|
|
|
|
local height = 32
|
|
|
|
|
|
|
|
|
|
for x=0,width,1 do
|
|
|
|
|
|
|
|
|
|
for y=0,height,1 do
|
|
|
|
|
local tile = map_manager.get_layer_tile(x,y,1)
|
|
|
|
|
|
|
|
|
|
if (tile == 3) then
|
|
|
|
|
local b = Barrel:new(x*tile_width,y*tile_height)
|
|
|
|
|
add(actors,b)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2024-04-26 11:22:51 +02:00
|
|
|
end
|
|
|
|
|
|
2024-04-25 23:07:49 +02:00
|
|
|
function render_layer(layer)
|
|
|
|
|
if (layer.render) then
|
|
|
|
|
-- todo move function in map manager
|
|
|
|
|
map(fetch("map/".. map_manager.get_current_map() .. ".map")[layer.index].bmp)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (layer.render_objects) then
|
|
|
|
|
-- Render all objects here
|
|
|
|
|
cirno.draw()
|
|
|
|
|
|
|
|
|
|
weapons_manager.draw()
|
2024-04-26 11:22:51 +02:00
|
|
|
|
|
|
|
|
for b in all(actors) do
|
|
|
|
|
b:draw()
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
for b in all(bullets) do
|
|
|
|
|
b:draw()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for p in all(particles) do
|
|
|
|
|
p:draw()
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-04-25 23:07:49 +02:00
|
|
|
|
2024-04-14 15:51:45 +02:00
|
|
|
end
|