/
LOVE.LUA
270 lines (185 loc) · 5.02 KB
/
LOVE.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
--love2d port for psp
--GNU GPL 2 AnRu all rights reserved
--main module
love = {}
--other modules
love.graphics = {}
love.image = {}
love.filesystem = {}
love.timer = {}
love.joystick = {}
love.keyboard = {}
love.timer = {}
--font
--Load a font, 12 pixels high, in VRAM
verdana12 = pge.font.load("verdana.ttf", 12, PGE_VRAM)
--callbacks
love.load = function ()
end
love.update = function ()
end
love.draw = function ()
end
love.joystick.isDown = function (b)
end
love.keyboard.isDown = function (b)
return love._controls[b]
end
--const
love._version = "0.8.0"
love._os = "PSP"
love._color = {255,255,255}
love._backColor = {0,0,0}
love._controls = {}
love._currentTime = 0
love._lastTime = 0
love._loop=0
--GRAPHICS
love.graphics.newImage = function (filepath)
return pge.gfx.load(filepath, PGE_RAM)
end
love.graphics.draw = function (image, x, y, a, width, height)
if not a then
image:activate()
image:draweasy(x,y)
else
image:activate()
image:draw(x,y,width,height,0,0,width,height,a)
end
end
love.graphics.drawq = function (image, x, y, a, width, height)
if not a then
image:activate()
image:draweasy(x,y)
else
image:draw(x,y,width,height,0,0,width,height,a)
end
end
love.graphics.rectangle = function(mode, x, y, w, h)
screen:fillRect(x, y, w, h, Color.new(love._color[1],love._color[2],love._color[3]) )
end
love.graphics.print = function (text, x, y, a)
screen:print(x,y,text,Color.new(love._color[1],love._color[2],love._color[3]))
end
love.graphics.setMode = function ()
end
love.graphics.setColor = function (r, g, b, a)
if r==nil or g==nil or b==nil then
error("[LOVE]: ...setColor: one of the colors expected")
end
love._color = {r, g, b, a}
end
love.graphics.setBackgroundColor = function (r, g, b, a)
if r==nil or g==nil or b==nil then
error("[LOVE]: ...setBackgroundColor: one of the colors expected")
end
love._backColor = {r, g, b, a}
end
--CONTROLS
love.keyboard.updateButtons = function ()
love._controls["cross"] = pge.controls.held(PGE_CTRL_CROSS)
love._controls["circle"] = pge.controls.held(PGE_CTRL_CIRCLE)
love._controls["triangle"] = pge.controls.held(PGE_CTRL_TRIANGLE)
love._controls["square"] = pge.controls.held(PGE_CTRL_SQUARE)
love._controls["up"] = pge.controls.held(PGE_CTRL_UP)
love._controls["down"] = pge.controls.held(PGE_CTRL_DOWN)
love._controls["left"] = pge.controls.held(PGE_CTRL_LEFT)
love._controls["right"] = pge.controls.held(PGE_CTRL_RIGHT)
love._controls["l"] = pge.controls.held(PGE_CTRL_LTRIGGER)
love._controls["r"] = pge.controls.held(PGE_CTRL_RTRIGGER)
end
--TIMER
love.timer.getDelta = function ()
return love._dt
end
love.timer.getFPS = function ()
return love._fps
end
--FILESYSTEM
love.filesystem.write = function (filepath, text)
file = pge.file.open(filepath, PGE_FILE_CREATE + PGE_FILE_WRONLY)
file:write(text)
end
--game
love.run = function ()
love.load()
love._frameTimer:start()
while pge.running() do
-- Update controls
pge.controls.update()
love.update(love._dt)
if love.keypressed then
if pge.controls.pressed(PGE_CTRL_CROSS) then
love.keypressed("cross")
end
if pge.controls.pressed(PGE_CTRL_CIRCLE) then
love.keypressed("circle")
end
if pge.controls.pressed(PGE_CTRL_TRIANGLE) then
love.keypressed("triangle")
end
if pge.controls.pressed(PGE_CTRL_SQUARE) then
love.keypressed("square")
end
if pge.controls.pressed(PGE_CTRL_UP) then
love.keypressed("up")
end
if pge.controls.pressed(PGE_CTRL_DOWN) then
love.keypressed("down")
end
if pge.controls.pressed(PGE_CTRL_LEFT) then
love.keypressed("left")
end
if pge.controls.pressed(PGE_CTRL_RIGHT) then
love.keypressed("right")
end
if pge.controls.pressed(PGE_CTRL_LTRIGGER) then
love.keypressed("r")
end
if pge.controls.pressed(PGE_CTRL_RTRIGGER) then
love.keypressed("l")
end
end
if love.released then
if pge.controls.released(PGE_CTRL_CROSS) then
love.keyreleased("cross")
end
if pge.controls.released(PGE_CTRL_CIRCLE) then
love.keyreleased("circle")
end
if pge.controls.released(PGE_CTRL_TRIANGLE) then
love.keyreleased("triangle")
end
if pge.controls.released(PGE_CTRL_SQUARE) then
love.keyreleased("square")
end
if pge.controls.released(PGE_CTRL_UP) then
love.keyreleased("up")
end
if pge.controls.released(PGE_CTRL_DOWN) then
love.keyreleased("down")
end
if pge.controls.released(PGE_CTRL_LEFT) then
love.keyreleased("left")
end
if pge.controls.released(PGE_CTRL_RIGHT) then
love.keyreleased("right")
end
if pge.controls.released(PGE_CTRL_LTRIGGER) then
love.keyreleased("r")
end
if pge.controls.released(PGE_CTRL_RTRIGGER) then
love.keyreleased("l")
end
end
-- Start drawing
pge.gfx.startdrawing()
-- Clear screen (to black)
pge.gfx.clearscreen(pge.gfx.createcolor(love._backColor[1],love._backColor[2],love._backColor[3]))
love.draw()
-- End drawing
pge.gfx.enddrawing()
-- Swap buffers
pge.gfx.swapbuffers()
end
end