-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
138 lines (90 loc) · 2.87 KB
/
Copy pathinit.lua
File metadata and controls
138 lines (90 loc) · 2.87 KB
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
package.path =
"./src/?.lua;" ..
"./src/assets_scripts/?.lua;" ..
package.path
local pb = require "PudimBasicsGl"
local colors = require "src.constants.colors"
local cPlayerGroup = require "player"
local vectors = require "vectors"
local rtb = require "RenderTiledBackground"
local gameC = require "gamecore"
local Render,
Window,
Texture,
Camera,
Sond,
Input,
Time,
Text,
Pmath,
shader,
studio,
ui
=
pb.renderer,
pb.window,
pb.texture,
pb.camera,
pb.audio,
pb.input,
pb.time,
pb.text,
pb.math,
pb.shader,
pb.studio,
pb.ui
--- game
gameC:setInit(function (self)
gameC:setName "mathmancer"
gameC:setVersion "dev-1"
local defalt_size = self.configs.screen_size
self.win = Window.create(defalt_size[1], defalt_size[2], "mathmancer")
self.win:set_resizable(false)
Render.init()
Render.enable_blend(true)
Render.enable_depth_test(false)
end)
gameC:add_screen{
name = "game",
init = function (self, global)
if not self.entitys then self.entitys = {} end
self.entitys.players = cPlayerGroup()
self.entitys.players:add{
name = "player",
position = vectors.CreateVector(0, 0),
speed = 150,
cameraId = 0,
}
if not global.font then global.font = Text.load("./src/fonts/Comic Sans MS.ttf") end
if not global.floor then global.floor = Texture.load("./src/sprites/floor.png") end
if not self._virtual_diag then self._virtual_diag = math.floor(math.sqrt(240*240 + 136*136)) end
end,
draw = function (self, global)
local scrW, scrH = Window.get_size(global.win)
local s = math.floor(math.sqrt(scrW*scrW + scrH*scrH)) * 0.5
Camera.set_zoom(math.max(0.01, s / self._virtual_diag))
Render.clear(0,0,0,1)
Render.begin(scrW, scrH)
rtb(Camera, global.win, global.floor)
for idx, ent in pairs(self.entitys) do
ent:draw(Time.get())
end
Render.begin_ui(scrW, scrH)
global.font:draw(math.floor(Time.fps()), 0, 0, colors["white"])
Render.end_ui()
Render.finish()
Window.swap_buffers(global.win)
Window.poll_events()
end,
update = function (self, global)
if global.win:should_close() then gameC:close() end
Time.update()
local dt = Time.delta()
for idx, ent in pairs(self.entitys) do
ent:update(dt, global.win)
end
if not global.win then error("not load window") end
if self.RESTART then self:init() self.RESTART = false end
end
}
gameC:update()