Skip to content

Commit 90613de

Browse files
1 parent 546a97a commit 90613de

File tree

12 files changed

+78
-0
lines changed

12 files changed

+78
-0
lines changed

β€Žgame/examples/parallax.rpy

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# https://www.reddit.com/r/RenPy/comments/1br72fr/ingame_parallax_like_in_slay_the_princess/
2+
3+
init python:
4+
class MouseParallax(renpy.Displayable):
5+
def __init__(self, layer_info):
6+
super(renpy.Displayable, self).__init__()
7+
self.xoffset,self.yoffset = 0.0, 0.0
8+
self.sort_layer = sorted(layer_info, reverse=True)
9+
cflayer = []
10+
masteryet = False
11+
for m, n in self.sort_layer:
12+
if (not masteryet) and (m < 41):
13+
cflayer.append("master")
14+
masteryet = True
15+
cflayer.append(n)
16+
if not masteryet:
17+
cflayer.append("master")
18+
cflayer.extend(["transient", "screens", "overlay"])
19+
config.layers = cflayer
20+
config.overlay_functions.append(self.overlay)
21+
22+
def render(self, width, height, st, at):
23+
return renpy.Render(width, height)
24+
25+
def parallax(self, m):
26+
func = renpy.curry(trans)(disp=self, m=m)
27+
return Transform(function=func)
28+
29+
def overlay(self):
30+
ui.add(self)
31+
for m, n in self.sort_layer:
32+
renpy.layer_at_list([self.parallax(m)], n)
33+
34+
def event(self, ev, x, y, st):
35+
import pygame
36+
if persistent.parallax_on:
37+
if ev.type == pygame.MOUSEMOTION:
38+
self.xoffset, self.yoffset = ((float)(x) / (config.screen_width)) - 0.5, ((float)(y) / (config.screen_height)) - 0.5
39+
40+
def trans(d, st, at, disp=None, m=None):
41+
d.xoffset, d.yoffset = int(round(m * disp.xoffset)), int(round(m * disp.yoffset))
42+
return 0
43+
44+
label parallax:
45+
46+
scene black
47+
48+
init python:
49+
MouseParallax([
50+
(40, "farback"),
51+
(20, "01"),
52+
(0, "02"),
53+
(-20, "03"),
54+
(-40, "04"),
55+
(-60, "05"),
56+
(-80, "06"),
57+
(-100, "07"),
58+
(-120, "08"),
59+
(-140, "09"),
60+
])
61+
62+
scene bg sky onlayer farback at Position(ypos = 1080)
63+
show 01 forest onlayer 01 at Position(ypos = 1200)
64+
show 02 forest onlayer 02 at Position(ypos = 1140)
65+
show 03 forest onlayer 03 at Position(ypos = 1120)
66+
show 04 forest onlayer 04 at Position(ypos = 1080)
67+
show 05 particles onlayer 05 at Position(ypos = 1200)
68+
show 06 forest onlayer 06 at Position(ypos = 1140)
69+
show 07 particles onlayer 07 at Position(ypos = 1120)
70+
show 08 bushes onlayer 08 at Position(ypos = 1080)
71+
show 09 mist onlayer 09 at Position(ypos = 1200)
72+
73+
pause
74+
75+
return

β€Žgame/examples/start.rpy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ label start:
3333
"Map":
3434
jump map
3535

36+
"Parallax":
37+
jump parallax
38+
3639
"Python":
3740
jump python_example
3841

β€Žgame/images/parallax/01 forest.png

586 KB
Loading

β€Žgame/images/parallax/02 forest.png

310 KB
Loading

β€Žgame/images/parallax/03 forest.png

327 KB
Loading

β€Žgame/images/parallax/04 forest.png

1.51 MB
Loading
60.8 KB
Loading

β€Žgame/images/parallax/06 forest.png

1.09 MB
Loading
63.2 KB
Loading

β€Žgame/images/parallax/08 bushes.png

122 KB
Loading

β€Žgame/images/parallax/09 mist.png

242 KB
Loading

β€Žgame/images/parallax/bg sky.png

38.2 KB
Loading

0 commit comments

Comments
Β (0)