-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.lua
236 lines (194 loc) · 6.84 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
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
function love.load()
require "normal"
require "menu"
require "highscoreentry"
require "options"
require "intro"
------------
--SETTINGS--
------------
soundenabled = true
fullscreen = false
joystickdeadzone = 0.5
numhighscores = 9
gravitymul = 260
scale = 2
zoom = 1
controlmethods = {"mouse", "keyboard", "mouse direction", "joystick", "wheel steering", "wheel direct"}
controldescriptions = { mouse="move the mouse\n\nleft and right",
keyboard="use arrow keys to\n\nrotate, shift to\n\nspeed up",
['mouse direction']="point with your\n\nmouse towards a\n\ndirection",
joystick="point with your\n\njoystick",
['wheel steering']="drive like a car",
['wheel direct']="1:1 wheel to\n\ngame translation"}
controlmethod = "mouse"
pacfocus = false
superpower = "normal" --clone, walls, normal
powerupduration = 6
superpelletblinkrate = 0.5
wakkatimer = 0
highscore = 0
deathtime = 1.5
deathdelay = 1
mouse2rate = 0.05
mouse2speed = 20 --50 for my macbook because who knows why, 20 else
volume = 10
pacmouthlimit = 0.25
mouthduration = 0.22
whitelist = "abcdefghijklmnopqrstuvwxyz 0123456789"
scale = 2
----END----
loadhighscores()
icon = love.graphics.newImage("graphics/icon.png");icon:setFilter("nearest", "nearest")
changescale(scale)
boardwidth = 220
boardheight = 216
--GRAPHICS--
mainfield = love.graphics.newImage("graphics/field.png");mainfield:setFilter("nearest", "nearest")
mainfieldoverlay = love.graphics.newImage("graphics/fieldoverlay.png");mainfieldoverlay:setFilter("nearest", "nearest")
superpellet = love.graphics.newImage("graphics/superpellet.png");superpellet:setFilter("nearest", "nearest")
pacman = love.graphics.newImage("graphics/pacmanman.png")
ghost1 = love.graphics.newImage("graphics/ghost1.png")
ghost2 = love.graphics.newImage("graphics/ghost2.png")
ghost3 = love.graphics.newImage("graphics/ghost3.png")
ghostscared1 = love.graphics.newImage("graphics/ghostscared1.png")
ghostscared2 = love.graphics.newImage("graphics/ghostscared2.png")
ghosteyes = love.graphics.newImage("graphics/eyes.png")
spinnyeyes = love.graphics.newImage("graphics/spinnyeyes.png")
title = love.graphics.newImage("graphics/title.png");title:setFilter("nearest", "nearest")
gamescoreimg = love.graphics.newImage("graphics/gamescore.png");gamescoreimg:setFilter("nearest", "nearest")
highscoreimg = love.graphics.newImage("graphics/highscore.png");highscoreimg:setFilter("nearest", "nearest")
gameoverimg = love.graphics.newImage("graphics/gameover.png");gameoverimg:setFilter("nearest", "nearest")
clockimg = love.graphics.newImage("graphics/clock.png");clockimg:setFilter("nearest", "nearest")
optionsimg = love.graphics.newImage("graphics/options.png");optionsimg:setFilter("nearest", "nearest")
logo = love.graphics.newImage("graphics/logo.png")
logoblood = love.graphics.newImage("graphics/logoblood.png")
fontimage = love.graphics.newImage("graphics/font.png");fontimage:setFilter("nearest","nearest")
pacmanfont = love.graphics.newImageFont(fontimage, "0123456789abcdefghijklmnopqrstuvwxyz.:/,'C-_> <")
love.graphics.setFont(pacmanfont)
--SOUNDS--
wakka1 = love.audio.newSource("sounds/pacman_waka_wa.ogg", "static")
wakka2 = love.audio.newSource("sounds/pacman_waka_ka.ogg", "static")
eatghost = love.audio.newSource("sounds/eat_ghost.ogg", "static"); eatghost:setVolume(0.5)
ghostsiren = love.audio.newSource("sounds/ghosts_siren.ogg", "static"); ghostsiren:setVolume(0); ghostsiren:setLooping(true)
ghostrunaway = love.audio.newSource("sounds/ghosts_runaway.ogg", "static"); ghostrunaway:setVolume(0); ghostrunaway:setLooping(true)
beginning = love.audio.newSource("sounds/pacman_beginning.ogg", "static")
gamewin = love.audio.newSource("sounds/win.ogg", "static")
death = love.audio.newSource("sounds/pacman_death.ogg", "static")
stabsound = love.audio.newSource("sounds/stab.ogg", "static")
intro_load()
end
function love.update(dt)
if skipupdate then
skipupdate = false
return
end
dt = math.min(dt, 1/30)
if _G[gamestate .. "_update"] then
_G[gamestate .. "_update"](dt)
end
end
function love.draw()
if _G[gamestate .. "_draw"] then
_G[gamestate .. "_draw"]()
end
end
function love.keypressed(key, unicode)
if _G[gamestate .. "_keypressed"] then
_G[gamestate .. "_keypressed"](key, unicode)
end
end
function love.mousepressed(x, y, button)
if _G[gamestate .. "_mousepressed"] then
_G[gamestate .. "_mousepressed"](x, y, button)
end
end
function love.joystickpressed(joystick, button)
if _G[gamestate .. "_joystickpressed"] then
_G[gamestate .. "_joystickpressed"](joystick, button)
end
end
function string:split(delimiter) --Not by me
local result = {}
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
function changescale(s)
local grabbed = love.mouse.isGrabbed()
scale = s
windowwidth = 320*scale
windowheight = 250*scale
screenwidth = windowwidth
screenheight = windowheight
fsaa = 16
vsync = true
love.graphics.setLineWidth(5/3*scale)
if gamestate == "options" then
options_createdemoworld()
end
if love.graphics.getWidth() ~= windowwidth or love.graphics.getHeight() ~= windowheight then
love.graphics.setMode(windowwidth, windowheight, fullscreen, vsync, fsaa)
end
love.graphics.setIcon(icon)
love.mouse.setGrab(grabbed)
end
function print_r (t, indent) --Not by me
local indent=indent or ''
for key,value in pairs(t) do
io.write(indent,'[',tostring(key),']')
if type(value)=="table" then io.write(':\n') print_r(value,indent..'\t')
else io.write(' = ',tostring(value),'\n') end
end
end
function loadhighscores()
if love.filesystem.exists("highscoreA") then
local s = love.filesystem.read("highscoreA"):split("#")
if #s < 2 then
s[3] = s[1]
else
controlmethod = s[1]
scale = tonumber(s[2])
end
local t = s[3]
highscoreA = t:split(";")
for i = 1, #highscoreA do
highscoreA[i] = highscoreA[i]:split(":")
highscoreA[i][1] = tonumber(highscoreA[i][1])
highscoreA[i][2] = tonumber(highscoreA[i][2])
end
else
highscoreA = {}
for i = 1, numhighscores do
highscoreA[i] = {0, 0, "------"}
end
end
savehighscoresA()
end
function savehighscoresA()
local s = controlmethod .. "#"
local s = s .. scale .. "#"
for i = 1, numhighscores do
if (highscoreA[i][1] and highscoreA[i][2] and highscoreA[i][3]) then
s = s .. highscoreA[i][1] .. ":" .. highscoreA[i][2] .. ":" .. highscoreA[i][3]
else
s = s .. "------" .. ":0:0"
end
if i ~= numhighscores then
s = s .. ";"
end
end
love.filesystem.write("highscoreA", s)
end
function addzeros(s, i)
for j = string.len(s)+1, i do
s = "0" .. s
end
return s
end