-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
107 lines (81 loc) · 2.67 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
WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720
VIRTUAL_WIDTH, VIRTUAL_HEIGHT = 1280, 720
GAME_OVER = false
push = require 'push'
Class = require 'class'
anim8 = require 'anim8'
gamera = require 'gamera'
cron = require 'cron'
require 'Map'
require 'player'
require 'enemies'
require 'Util'
map = Map()
function love.load()
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
resizable = true
})
-- loads background image
background = love.graphics.newImage("background/BG/BG.png")
background:setWrap('repeat', 'repeat')
background_quad = love.graphics.newQuad(0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT,
background:getWidth(), background:getHeight())
--basic features
love.window.setTitle("Ninja Run")
--might use spritebatch later but I've spent hours trying to get the damn background to work
-- spriteBatch = love.graphics.newSpriteBatch(background )
--text (fonts, size, etc)
love.graphics.setDefaultFilter('nearest', 'nearest')
raleway_regular = love.graphics.newFont("fonts/Raleway-Regular.ttf", 12)
raleway_large = love.graphics.newFont("fonts/Raleway-Regular.ttf", 72)
love.keyboard.keysPressed = {}
love.keyboard.keysReleased = {}
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
love.keyboard.keysPressed[key] = true
end
function love.keyreleased(key)
love.keyboard.keysReleased[key] = true
end
function love.resize(w, h)
push:resize(w, h)
end
function love.keyboard.wasPressed(key)
if (love.keyboard.keysPressed[key]) then
return true
else
return false
end
end
-- global key released function
function love.keyboard.wasReleased(key)
if (love.keyboard.keysReleased[key]) then
return true
else
return false
end
end
function love.draw()
push:apply('start')
-- for i = 0, love.graphics.getWidth() / background:getWidth() do
-- for j = 0, love.graphics.getHeight() / background:getHeight() do
-- love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
-- end
-- end
love.graphics.draw(background, background_quad, 0, 0)
love.graphics.translate(math.floor(-map.camX + 0.5), math.floor(-map.camY + 0.5))
map:render()
push:apply('end')
end
function love.update(dt)
map:update(dt)
love.keyboard.keysPressed = {}
love.keyboard.keysReleased = {}
end
function dividedInto(divided_into, image_width)
return image_width * (1 / divided_into)
end