-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
100 lines (82 loc) · 2.11 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
--[[
Dinojump
Based on Chrome's offline jumping dinosaur game.
MIT License
(c) DJ Hartman 2017
]]
local Game = require 'src/screens/game'
local Title = require 'src/screens/title'
local game, title, currentScreen, highScore
local started = false
local dimensions = {
w = 320,
h = 480,
}
local colors = {
yellow = {255, 182, 25},
violet = {184, 0, 255},
purple = {86, 6, 114},
lightGreen = {20, 204, 123},
darkGreen = {9, 178, 104},
black = {25, 25, 25},
white = {255, 255, 255},
lightBlue = {27, 174, 204},
}
function love.load()
love.window.setMode(dimensions.w, dimensions.h)
local saveFile = love.filesystem.newFile('save.txt')
saveFile:open('r')
local data = saveFile:read()
if highScore == nil then
highScore = 0
else
highScore = tonumber(data)
end
-- Seed rng
math.randomseed(os.time())
title = Title.create{
dimensions = dimensions,
colors = colors,
}
-- Load game
game = Game.create{
highScore = highScore,
dimensions = dimensions,
colors = colors,
}
-- Set the first screen
currentScreen = title
currentScreen:load()
end
function love.update(dt)
love.window.setTitle("Dinojump")
currentScreen:update(dt)
-- Start the game
if not started and love.keyboard.isDown("space") then
started = true
currentScreen = nil
currentScreen = game
currentScreen:load()
end
if currentScreen == game and currentScreen:isOver() and love.keyboard.isDown("r") then
if game.score.value > highScore then
-- NEW HIGH SCORE AWWWW YEAHHHH
highScore = math.floor(game.score.value)
end
currentScreen = nil
game = nil
game = Game.create{
dimensions = dimensions,
colors = colors,
highScore = highScore
}
currentScreen = game
currentScreen:load()
end
end
function love.draw()
currentScreen:draw()
end
function love.quit()
love.filesystem.write('save.txt', math.floor(game.highScore.value))
end