-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmain.lua
140 lines (118 loc) · 3.65 KB
/
smain.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
-------------------------------------------------------------------------
-- [smain.lua]
-- Main menu
-------------------------------------------------------------------------
local Gamestate = require "lib.gamestate"
local soundmanager = require "lib.soundmanager"
local Monster = require "mon"
local Ability = require "abilities"
local sprites = require "gfx"
local _M = Gamestate.new()
-------------------------------------------------------------------------
Gamestate.main = _M
_M.name = "Main"
_M.options = {
{'Battle Test', function(s)
local alist = Ability.list;
local monsters = {
Monster:new {name = "Circuloid"; scale = 2;
image = sprites.monsters[1];
scale = 2;
abilities = {
alist.bite,
alist.leech,
alist.crush,
alist.heal,
}
},
Monster:new {name = "Tyran"; scale = 2;
image = sprites.monsters[2];
abilities = {
alist.bite,
alist.heal,
alist.thick_hide,
alist.buffed,
}
},
}
return Gamestate.switch(Gamestate.battle, monsters)
end };
{'Map Test', function() Gamestate.switch(Gamestate.world) end};
{'Credits', function() Gamestate.switch(Gamestate.credits) end};
{'Exit', function(s) love.event.quit() end};
}
local width, height = love.graphics.getMode( )
width, height = width / 2, height / 2 -- we scale up by x2
local COLOR_NORMAL = {200, 200, 200}
local COLOR_SELECTED = {255, 255, 255}
_M.selected = 0
function _M:enter()
self.time = 0
local fontimg = love.graphics.newImage("gfx/font.png")
fontimg:setFilter('nearest', 'nearest')
local font = love.graphics.newImageFont(fontimg, [[ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+abcdefghijklmnopqrstuvwxyz`1234567890[]/\:|?, .'";{}<>-=]])
love.graphics.setFont(font)
self.font = font
self.logo = love.graphics.newImage('gfx/monsters/circuloid.png')
self.logo:setFilter('nearest', 'nearest')
end
function _M:update(dt)
soundmanager:update(dt)
end
function _M:draw()
local lg = love.graphics
local lt = love.timer
lg.scale(2)
lg.setFont(self.font)
local scale, rot = (math.sin(self.time)*.05)+.95, (self.time / (math.pi*2))
lg.draw(self.logo, width/2, height/2, rot, scale, scale, self.logo:getWidth()/2, self.logo:getHeight()/2)
if self.selected == 0 then
if math.floor(self.time) % 2 == 0 then
-- lg.setFont(self.font_sm)
local msg = "Press any button to continue."
local center = (width - lg.getFont():getWidth(msg)) / 2
lg.print(msg, center, height*.75)
end
else
local offset = height * .1
local indent = offset
local font, fh = lg.getFont()
fh = font:getHeight()
for i =#self.options, 1, -1 do
lg.setColor(self.selected == i and COLOR_SELECTED or COLOR_NORMAL)
-- we have to subtract an extra line height, because fonts are=
-- rendered from the topline, not the baseline.
lg.print(self.options[i][1], indent, (height-fh)-offset)
offset = offset + fh
end
end
end
function _M:update(dt)
self.time = self.time+dt
end
function _M:keypressed(key, unicode)
print(string.format("Keypressed: '%s'", key))
local selected = self.selected
if selected == 0 then
selected = 1
else
if key == 'down' then
selected = selected + 1
if selected > #self.options then selected = 1 end
elseif key == 'up' then
selected = selected - 1
if selected < 1 then selected = #self.options end
elseif key == 'enter' or key == 'return' or key == ' ' then
local option = self.options[self.selected]
print(string.format("doing option '%s' [%d] ", tostring(option[1]),selected))
option[2](self)
end
end
self.selected = selected
end
function _M:mousepressed(x, y, button)
end
function _M:leave()
end
-------------------------------------------------------------------------
return _M