-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighscores.lua
124 lines (102 loc) · 3.41 KB
/
highscores.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
local gamestate = require("gamestate")
local fonts = require("fonts")
local settings = require("settings")
local highscorescreen = {}
highscorescreen.new = function(self,name)
local _playstate = gamestate:new(name or "mainmenu")
setmetatable(_playstate,{__index = self})
return _playstate
end
highscorescreen.initialize = function(self)
self.width, self.height = settings.width,settings.height
self.R,self.G,self.B,self.A = love.graphics.getColor()
--self.background = love.graphics.newImage("background.png")
self.pointTimer = 0
local rb = 32
local gb = 32
local bb = 32
love.graphics.setBackgroundColor(rb,gb,bb)
self.scorefilename = "highscores.txt"
self.scores = {}
if love.filesystem.exists(self.scorefilename) then
self.scorefile = love.filesystem.newFile(self.scorefilename)
self.scorefile:open("r")
for line in self.scorefile:lines() do
table.insert(self.scores,line)
end
self.scorefile:close()
else
self.errorstring = "High score file not found :("
end
end
highscorescreen.terminate = function(self)
end
highscorescreen.update = function(self,dt)
self.pointTimer = self.pointTimer + dt
end
highscorescreen.draw = function(self)
--love.graphics.draw(self.background,0,0)
local npoints = math.min(math.floor(self.pointTimer*30),38)+2
local spread = self.width/2
--bottom left
xpoints = {}
ypoints = {}
originx = 0
originy = self.height
for i=1,npoints do
table.insert(xpoints,originx+i*spread/npoints+10*math.sin(2*math.pi*self.pointTimer/20))
table.insert(ypoints,originy-i*spread/npoints+10*math.sin(2*math.pi*self.pointTimer/20))
end
love.graphics.setColor(0,255,255,31)
for i=1,#xpoints do
love.graphics.line(xpoints[i],originy,originx,ypoints[#ypoints-i+1])
end
--top right
local xpoints = {}
local ypoints = {}
local originx = self.width
local originy = 0
for i=1,npoints do
table.insert(xpoints,originx-i*spread/npoints+10*math.sin(2*math.pi*self.pointTimer/20))
table.insert(ypoints,originy+i*spread/npoints+10*math.sin(2*math.pi*self.pointTimer/20))
end
love.graphics.setColor(255,255,0,31)
for i=1,#xpoints do
love.graphics.line(xpoints[i],originy,originx,ypoints[#ypoints-i+1])
end
self:drawHighscores()
love.graphics.setColor(self.R,self.G,self.B,self.A)
end
highscorescreen.keypressed = function(self, key, isrepeat )
if key == "return" or key == "escape"then
self.manager:switchToState(self.manager.states["mainmenu"])
end
end
highscorescreen.gamepadpressed = function(self,joystick,button)
if button == "a" or button == "b" then
self.manager:switchToState(self.manager.states["mainmenu"])
end
end
highscorescreen.drawHighscores = function(self)
love.graphics.setFont(fonts.mainmenu)
love.graphics.setColor(255,255,0)
love.graphics.printf("High Scores",self.width/4,100,self.width/2,"center")
if self.errorstring then
love.graphics.printf(self.errorstring,self.width/4,200,self.width/2,"center")
else
love.graphics.setFont(fonts.tutorial)
local scoreString = ""
for i=1,settings.maxHighScores do
if self.scores[i+1] ~= nil then
scoreString = scoreString..tonumber(i)..". --- "..self.scores[i+1].."\n"
else
scoreString = scoreString..tonumber(i)..". --- ".."______\n"
end
end
love.graphics.printf(scoreString,self.width/4,200,self.width/2,"center")
end
love.graphics.setColor(0,255,255)
love.graphics.setFont(fonts.mainmenu)
love.graphics.printf("Back",self.width/4,self.height-100,self.width/2,"center")
end
return highscorescreen