-
Notifications
You must be signed in to change notification settings - Fork 1
/
window.lua
140 lines (108 loc) · 4.53 KB
/
window.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
local window = {}
local hud = require "hud"
local shader = require "shader"
local clouds = {}
window.load = function()
-- set up window
screen = {w = 600, h = 400, type = "Fullscreen", res = 1}
love.window.setFullscreen(true)
window.scale_screen()
canvas.game = love.graphics.newCanvas(screen.w, screen.h)
canvas.menu = love.graphics.newCanvas(screen.w, screen.h)
canvas.clouds = love.graphics.newCanvas(screen.w, screen.h)
canvas.background = love.graphics.newCanvas(screen.w, screen.h)
b_offset = 0
end
window.scale_screen = function()
screen.tw, screen.th = love.graphics.getDimensions()
if screen.w/screen.h < screen.tw/screen.th then
screen.scale = screen.th/screen.h
else
screen.scale = screen.tw/screen.w
end
screen.ox = math.floor((screen.tw/screen.scale - screen.w) / 2)
screen.oy = math.floor((screen.th/screen.scale - screen.h) / 2)
canvas.window = love.graphics.newCanvas(screen.tw/screen.scale, screen.th/screen.scale)
screen.res_txt = tostring(screen.tw).."x"..tostring(screen.th)
shader.shadow:send("offset", {screen.ox, screen.oy})
shader.shadow:send("screen", {screen.w, screen.h})
end
window.update = function(dt)
hud.update(dt)
if #clouds < 6 and math.random(0, 60) == 0 and not freeze then -- create new clouds
if level.scroll.v > 0 and math.random(0, 1) == 0 then
clouds[opening(clouds)] = {x = math.random(0, screen.h), y = 0, oy = -screen.h-48, v = (math.random(0, 1)-.5)*math.random(0, 2), img = math.random(1, 4), start = b_offset}
else
local dir = (math.random(0, 1)-.5)*2
clouds[opening(clouds)] = {x = screen.w/2-(screen.w/2+96)*dir, y = 0, oy = math.random(0, screen.h), v = dir*math.random(0, 2), img = math.random(1, 4), start = b_offset}
end
end
for i, v in pairs(clouds) do -- update clouds
if not freeze then
v.x = v.x + dt * 12 * v.v
v.y = (b_offset-v.start)*50 + v.oy
if v.x < -128 or v.x > screen.w+128 or v.y > screen.h+48 then
clouds[i] = nil
end
end
end
if love.graphics.getWidth() ~= screen.tw or love.graphics.getHeight() ~= screen.th then
window.scale_screen()
end
end
window.draw = function()
love.graphics.setCanvas(canvas.background)
love.graphics.clear()
-- draw background
for i = -math.ceil(screen.h/600/2), math.ceil(screen.h/600/2) do
love.graphics.draw(img.background, 0, math.floor((b_offset*25) % 600) + i*600)
end
love.graphics.setCanvas(canvas.clouds) -- seperate canvas for game shadow purposes
love.graphics.clear()
-- draw drifting clouds
for i, v in pairs(clouds) do
love.graphics.draw(img.clouds, quad.clouds[v.img], math.floor(v.x), math.floor(v.y), 0, 1, 1, 128, 48)
end
if state ~= "game" and not (freeze and oldstate == "game") then -- basic background if not game
love.graphics.setCanvas(canvas.game)
love.graphics.clear()
level.draw_background()
end
love.graphics.setCanvas(canvas.menu)
hud.draw()
love.graphics.setCanvas(canvas.window)
love.graphics.clear()
love.graphics.draw(canvas.background, screen.ox, screen.oy)
-- draw cloud shadows
shader.shadow:send("background", canvas.background)
love.graphics.setShader(shader.shadow)
for i, v in pairs(clouds) do
love.graphics.draw(img.clouds, quad.clouds[v.img], math.floor(v.x)+screen.ox, math.floor((v.y+screen.h)/2)+screen.oy, 0, .2, .2, 128, 48)
end
-- draw clouds
shader.cloud_shadow:send("game", canvas.game)
love.graphics.setShader(shader.cloud_shadow)
love.graphics.setColor(152, 219, 255)
love.graphics.draw(canvas.clouds, screen.ox, screen.oy)
love.graphics.setShader()
love.graphics.setColor(255, 255, 255)
-- draw game
love.graphics.draw(canvas.game, screen.ox, screen.oy)
-- draw verticle borders
for i = -math.ceil(screen.h/400/2), math.ceil(screen.h/400/2) do
love.graphics.draw(img.border, math.floor(screen.ox-600), math.floor(screen.oy+b_offset*100 % 400) + i*400)
love.graphics.draw(img.border, math.floor(screen.ox+screen.w+600), math.floor(screen.oy+(b_offset-2)*100 % 400) + i*400, 0, -1, 1)
end
-- draw menus
love.graphics.draw(canvas.menu, screen.ox, screen.oy)
-- draw horizontal borders
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("fill", 0, 0, screen.w, screen.oy)
love.graphics.rectangle("fill", 0, screen.h+screen.oy, screen.w, screen.oy)
love.graphics.setColor(255, 255, 255)
-- draw id
love.graphics.print("Flioneer Pre Alpha", 34+screen.ox, screen.h-font:getHeight()-2+screen.oy)
love.graphics.setCanvas()
love.graphics.draw(canvas.window, 0, 0, 0, screen.scale, screen.scale)
end
return window