-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.moon
More file actions
57 lines (36 loc) · 1.14 KB
/
background.moon
File metadata and controls
57 lines (36 loc) · 1.14 KB
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
{graphics: g} = love
-- paralax background thinger
class Background
new: =>
@viewport = Viewport scale: GAME_CONFIG.scale
@static = imgfy "images/bg1.png"
@clouds = with imgfy "images/bg_clouds2.png"
\set_wrap "repeat", "clamp"
@clouds2 = with imgfy "images/bg_clouds.png"
\set_wrap "repeat", "clamp"
@mountains = with imgfy "images/bg_mountains.png"
\set_wrap "repeat", "clamp"
@sun = with imgfy "images/bg_sun.png"
\set_wrap "repeat", "repeat"
update: (dt) =>
draw: (world_viewport) =>
@viewport\apply!
@draw_fit @static
@draw_paralax @sun, world_viewport.x / 16
@draw_paralax @mountains, world_viewport.x / 4
@draw_paralax @clouds, world_viewport.x / 3
@draw_paralax @clouds2, world_viewport.x / 3.2
@viewport\pop!
draw_paralax: (img, t) =>
w = img\width!
h = img\height!
q = g.newQuad t % w, 0, @viewport.w, @viewport.h, w, h
img\draw q, 0,0
draw_fit: (img) =>
w = img\width!
h = img\height!
scalex = @viewport.w / w
scaley = @viewport.h / h
scale = math.max scalex, scaley
img\draw 0, 0, 0, scale, scale
{ :Background }