-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvires.lua
109 lines (94 loc) · 3.92 KB
/
vires.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
-- Virtual Resolution System
-- Part of Live Simulator: 2
-- See copyright notice in main.lua
local love = require("love")
local NLay = require("libs.nlay")
local Vires = {
data = {
virtualW = 0,
virtualH = 0,
offX = 0,
offY = 0,
scaleOverall = 1
},
isInit = false
}
function Vires.init(width, height)
if Vires.isInit then return end
Vires.data.virtualW, Vires.data.virtualH = width, height
Vires.isInit = true
-- Create background sprite batch.
-- Cannot use async here because it's not available.
local thickness = 3
Vires.spriteBatch = love.graphics.newSpriteBatch(
love.graphics.newImage("assets/image/background/pattern.png"),
thickness * 26
)
local patternMyus = love.graphics.newQuad(0, 0, 128, 128, 256, 128)
local patternAqua = love.graphics.newQuad(128, 0, 128, 128, 256, 128)
for i = 0, thickness-1 do
-- Myus, left, Y start at 0
Vires.spriteBatch:add(patternMyus, -i * 128, 0, 0, 1, 1, 128, 0)
Vires.spriteBatch:add(patternMyus, -i * 128, 128, 0, 1, 1, 128, 0)
Vires.spriteBatch:add(patternMyus, -i * 128, 256, 0, 1, 1, 128, 0)
Vires.spriteBatch:add(patternMyus, -i * 128, 384, 0, 1, 1, 128, 0)
Vires.spriteBatch:add(patternMyus, -i * 128, 512, 0, 1, 1, 128, 0)
-- Aqua, right, Y start at 0
Vires.spriteBatch:add(patternAqua, 960 + i * 128, 0)
Vires.spriteBatch:add(patternAqua, 960 + i * 128, 128)
Vires.spriteBatch:add(patternAqua, 960 + i * 128, 256)
Vires.spriteBatch:add(patternAqua, 960 + i * 128, 384)
Vires.spriteBatch:add(patternAqua, 960 + i * 128, 512)
-- Myus, top, X start at -64
Vires.spriteBatch:add(patternMyus, -64, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 64, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 192, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 320, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 448, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 576, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 704, -i * 128, 0, 1, 1, 0, 128)
Vires.spriteBatch:add(patternMyus, 832, -i * 128, 0, 1, 1, 0, 128)
-- Aqua, bottom, X start at -64
Vires.spriteBatch:add(patternMyus, -64, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 64, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 192, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 320, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 448, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 576, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 704, 640 + i * 128)
Vires.spriteBatch:add(patternMyus, 832, 640 + i * 128)
end
NLay.update(0, 0, Vires.data.virtualW, Vires.data.virtualH)
end
function Vires.update(nw, nh)
if not(Vires.isInit) then return end
Vires.data.scaleOverall = math.min(nw / Vires.data.virtualW, nh / Vires.data.virtualH)
Vires.data.offX = (nw - Vires.data.scaleOverall * Vires.data.virtualW) / 2
Vires.data.offY = (nh - Vires.data.scaleOverall * Vires.data.virtualH) / 2
end
function Vires.screenToLogical(x, y)
if not(Vires.isInit) then return x, y end
return (x - Vires.data.offX) / Vires.data.scaleOverall, (y - Vires.data.offY) / Vires.data.scaleOverall
end
function Vires.logicalToScreen(x, y)
if not(Vires.isInit) then return x, y end
return x * Vires.data.scaleOverall + Vires.data.offX, y * Vires.data.scaleOverall + Vires.data.offY
end
function Vires.getScaling()
return Vires.data.scaleOverall
end
function Vires.getOffset()
return Vires.data.offX, Vires.data.offY
end
function Vires.set()
if not(Vires.isInit) then return end
love.graphics.translate(Vires.data.offX, Vires.data.offY)
love.graphics.scale(Vires.data.scaleOverall)
love.graphics.draw(Vires.spriteBatch)
end
function Vires.unset()
if not(Vires.isInit) then return end
love.graphics.scale(1/Vires.data.scaleOverall)
love.graphics.translate(-Vires.data.offX, -Vires.data.offY)
end
return Vires