-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathracegame_template.rpy
160 lines (140 loc) · 5.17 KB
/
racegame_template.rpy
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
screen game_scr():
#### This part will let us interact with the screen.
# Put it under the "timer_on" trigger to be able to show it
# to the player without any interaction.
if timer_on:
#### Every 0.5 sec the game will change its state.
timer 0.5 action Return("smth") repeat True
key "a" action Return("a")
key "A" action Return("a")
key "d" action Return("d")
key "D" action Return("d")
#
####
#### The background of the game screen.
# If you have predefined image, like "image game bg = 'game_bg.png'",
# you'll be able to add it simple like:
# add "game bg"
# Note: it is up to you to set the proper position for the bg
# to let player know how far his car is from start and finish lines.
#
# But for now - some pseudographic bg
text " ================================== \n\n====================================" color "#c0c0c0" anchor (0.0, 0.0) pos (start_pos-125, 200)
text "#\n#" color "#c0c0c0" anchor (1.0, 0.0) pos (start_pos, 270)
text "#\n#" color "#c0c0c0" anchor (0.0, 0.0) pos (finish_pos, 270)
#
####
#### Some of the opponents.
# Use this part if you've set the "opponents" list.
# If not - then just comment or delete this part.
#
for i, each_opponent in enumerate(opponents):
####
# If you've set the opponent's car appearence as an image
# then show it as:
# add each_opponent["car"] anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 200-(len(opponents)-i)*5)
#
# But for pseudographic it will be
text (each_opponent["car"]) color (each_opponent["car_color"]) anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 200-(len(opponents)-i)*5)
#
####
#
####
#### Player's car.
# If you have predefined image, like "image car = 'my_car.png'",
# you'll be able to add it like:
# add "car" anchor (1.0, 0.0) pos (car_pos, 200)
#
# But for pseudographic car it will be
text "[car]" anchor (1.0, 0.0) pos (car_pos, 200)
#
####
# The game starts here.
label race_game:
#### Some variables that describes the game state.
$ car = "___/-----\_____\n=@====@="
$ start_pos = 200
$ finish_pos = 600
$ car_pos = (start_pos + finish_pos)/2
$ last_pressed = ""
$ timer_on = False
#### The list of the opponents
# (each one described by the dictionary).
# If you have predefined image, like "image red car = 'red_car.png'",
# you'll be able to set opponent's car appearence like:
# "car":"red car"
#
$ opponents = [
{"car_name":"Mr. Red", "car":car, "car_color":"#c00", "opp_car_pos":(start_pos + finish_pos)/2, "opp_car_move":(-5, 0, 5, 5, 5, 5, 5, 10, 10)},
{"car_name":"Mr. Green", "car":car, "car_color":"#0c0", "opp_car_pos":(start_pos + finish_pos)/2, "opp_car_move":(-5, 0, 5, 5, 5, 5, 5, 10, 10)}
]
#
####
scene black
"..."
#### Let's show the game screen.
#
show screen game_scr
"Let's begin! (push 'a' and 'd' buttons)"
#### And for now the player is able to interact with the game.
#
$ timer_on = True
#### The game loop that has all its logic.
#
label race_game_loop:
#### The result of interaction with the game.
#
$ res = ui.interact()
#### The game change its state by the timer.
#
if res == "smth":
$ car_pos -= 5
if car_pos <= start_pos:
#### Don't forget to turn off the ability to interact
# with the game before jump to the result of the game.
#
$ timer_on = False
jump race_lose
#### Let's change the opponents positions
# (if you've set the "opponents" list, ofcourse).
# If not - then just comment or delete this part.
#
python:
for i in range(len(opponents)):
opponents[i]["opp_car_pos"] += renpy.random.choice(opponents[i]["opp_car_move"])
if opponents[i]["opp_car_pos"] >= finish_pos:
winner = opponents[i]["car_name"]
timer_on = False
renpy.jump("race_over")
#
####
jump race_game_loop
#### Let's check if player has pressed the right button.
#
elif res == "a" and last_pressed != "a":
$ last_pressed = "a"
$ car_pos += 10
elif res == "d" and last_pressed != "d":
$ last_pressed = "d"
$ car_pos += 10
if car_pos >= finish_pos:
$ timer_on = False
jump race_win
jump race_game_loop
#### The results of the game.
#
label race_over:
$ renpy.pause(0.5, hard=True)
"[winner] finished first!"
hide screen game_scr
return
label race_lose:
$ renpy.pause(0.5, hard=True)
"Too slow..."
hide screen game_scr
return
label race_win:
$ renpy.pause(0.5, hard=True)
"You finished first!"
hide screen game_scr
return