-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.lua
168 lines (153 loc) · 3.95 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
local start_load = love.timer.getTime()
debug = false
require "utils"
require "values/attacks"
require "values/pokemon"
require "values/types"
battle = require 'battle/scene'
overworld = require 'overworld/scene'
require "battle/game"
require "overworld/game"
require "overworld/object"
require "overworld/shop"
require "overworld/undo"
tween = require "lib/tween"
function love.load()
print([[
BBBBBBBB
BBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBB BBBBBBBBBBB
BBBB
BBBBBBBBBB BBBB BBBBBBBBBBB
BBBBBBBBBB BBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBB
BBBBBBBB
]])
if love.math.random() > 0.5 then
love.window.setTitle("babbemon reed")
else
love.window.setTitle("babbemon bleu")
end
default_font = love.graphics.newFont()
game_start_time = love.timer.getTime()
love.graphics.setFont(default_font)
love.graphics.setDefaultFilter("nearest","nearest")
love.graphics.setLineStyle("rough")
keydown = {}
tweens = {}
--sprite loader stolen from bab be u, as i'm sure many other things will be
sprites = {}
local function addsprites(d)
local dir = "assets/sprites"
if d then
dir = dir .. "/" .. d
end
local files = love.filesystem.getDirectoryItems(dir)
for _,file in ipairs(files) do
if string.sub(file, -4) == ".png" then
local spritename = string.sub(file, 1, -5)
local sprite = love.graphics.newImage(dir .. "/" .. file)
if d then
spritename = d .. "/" .. spritename
end
sprites[spritename] = sprite
elseif love.filesystem.getInfo(dir .. "/" .. file).type == "directory" then
local newdir = file
if d then
newdir = d .. "/" .. newdir
end
addsprites(newdir)
end
end
end
addsprites()
local end_load = love.timer.getTime()
loadScene(overworld)
print("load took "..tostring(round(end_load-start_load,4)).." seconds, "..(end_load-start_load < 1 and "fast" or "slow"))
end
function loadScene(new)
loaded_scene = false
scene = new
if scene.load then
scene:load()
end
end
function addTween(tween, id, after)
tweens[id] = {tween = tween, after = after}
end
function love.update()
loaded_scene = true
local dt = love.timer.getDelta()
for k,v in pairs(tweens) do
if v.tween:update(dt) then
tweens[k] = nil
if v.after then v:after() end
end
end
if loaded_scene and scene.update then
scene:update(dt)
end
end
function love.draw()
local dt = love.timer.getDelta()
anim_timer = anim_timer+dt
if anim_timer > 0.2 then
anim_stage = (anim_stage+1)%3
anim_timer = anim_timer-0.2
end
if loaded_scene and scene.draw then
scene:draw(dt)
end
end
function love.keypressed(key)
keydown[key] = true
if key == "lshift" or key == "rshift" then
keydown["shift"] = true
end
if key == "lctrl" or key == "rctrl" then
keydown["ctrl"] = true
end
if key == "lalt" or key == "ralt" then
keydown["alt"] = true
end
if key == "return" or key == "kpenter" then
keydown["enter"] = true
end
if key == "f1" then
loadScene(overworld)
elseif key == "f2" then
loadScene(battle)
end
if scene and scene.keyPressed then
scene:keyPressed(key)
end
end
function love.keyreleased(key)
keydown[key] = false
if key == "lshift" or key == "rshift" then
keydown["shift"] = false
end
if key == "lctrl" or key == "rctrl" then
keydown["ctrl"] = false
end
if key == "lalt" or key == "ralt" then
keydown["alt"] = false
end
if key == "return" or key == "kpenter" then
keydown["enter"] = false
end
if loaded_scene and scene.keyReleased then
scene:keyReleased(key)
end
end
function love.mousepressed(x, y, button)
if loaded_scene and scene.mousePressed then
scene:mousePressed(x, y, button)
end
end