-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
145 lines (116 loc) · 3.31 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Meevere.
--- DateTime: 16.10.2022 12:20
---
Vector2, Vector3 = unpack(require("utility/vector"))
TINY = require("libs/TINY")
CLASS = require("libs/30log")
Stack = require("utility/stack")
dump = require("utility/dump")
fill_table = require("utility/settingslike")
function pdump(o, n, i)
print(dump(o, n or 3, i or 2))
end
require("libs/strong")
local IS_DEBUG = os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" and arg[2] == "debug"
if IS_DEBUG then
require("lldebugger").start()
function love.errorhandler(msg)
error(msg, 2)
end
end
local Camera = require("libs/MyCamera")
local window_w, window_h, flags = love.window.getMode()
GraphicsLoader = require("loaders/GraphicsLoader")()
PrefabsLoader = require("loaders/PrefabsLoader")(GraphicsLoader)
LEVELS = {
forest = require("levels/forest/forest"),
mainMenu = require("levels/main_menu/main_menu")
}
--GAME_CANVAS = love.graphics.newCanvas(400, 300)
--
--function DRAW_GAME_CANVAS()
-- love.graphics.setCanvas()
-- love.graphics.draw(GAME_CANVAS, 0, 0, 0, 1.5)
-- love.graphics.setCanvas(GAME_CANVAS)
--end
function CHANGE_LEVEL(level)
CURRENT_LEVEL = level
if level == "exit" then
love.event.quit()
return
end
CURRENT_LEVEL.load()
end
function love.load()
print("Love Lua version: ", _VERSION)
local info = "LuaJIT version: "
if (jit) then
info = info .. jit.version
else
info = info .. "this is not LuaJIT"
end
print(info)
love.graphics.setDefaultFilter('nearest', 'nearest')
love.window.setTitle("HeavySteelRoads")
love.window.setMode( 800, 600, {
resizable = true,
minwidth = 600,
minheight = 400
} )
window_w, window_h, flags = love.window.getMode()
camera = Camera();
camera:setFromSizes({0,0}, {window_w, window_h}, {0,0}, {600, 400} )
camera:setDeadzone({camera.from.size[1]/2, camera.from.size[2]/2}, {0, 0})
camera.from.scale = 1
love.physics.setMeter(64)
CURRENT_LEVEL = LEVELS.mainMenu;
CURRENT_LEVEL.load()
end
function love.update(dt)
if dt > 1 then
dt = 1
end
CURRENT_LEVEL.update(dt)
end
function love.draw()
local dt = love.timer.getDelta()
if dt > 1 then
dt = 1
end
CURRENT_LEVEL.draw(dt)
end
function love.keypressed(key, scancode, is_repeat)
if CURRENT_LEVEL.keypressed then
CURRENT_LEVEL.keypressed(key, scancode, is_repeat)
end
end
function love.keyreleased(key, scancode)
if CURRENT_LEVEL.keyreleased then
CURRENT_LEVEL.keyreleased(key, scancode)
end
end
function love.mousemoved(x, y, dx, dy, istouch)
if CURRENT_LEVEL.mousemoved then
CURRENT_LEVEL.mousemoved(x, y, dx, dy, istouch)
end
end
function love.mousepressed(x, y, button, istouch, presses)
if CURRENT_LEVEL.mousepressed then
CURRENT_LEVEL.mousepressed(x, y, button, istouch, presses)
end
end
function love.mousereleased(x, y, button, istouch, presses)
if CURRENT_LEVEL.mousereleased then
CURRENT_LEVEL.mousereleased(x, y, button, istouch, presses)
end
end
function love.resize(w, h)
--camera.w = w
--camera.h = h
camera:setFromSizes({0, 0}, {w, h}, nil, {600, 400})
if CURRENT_LEVEL.resize then
CURRENT_LEVEL.resize(w, h)
end
end