1. create a new project (i used the legacy theme)
2. copy this and overwrite the script.rpy file
3. have fun.
Code: Select all
# You can place the script of your game in this file.
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
# The game starts here. With some default values. Declaring defaults of variables before the start label is kung fu.
default roomlocks=[0,0,1,1,0,1] #list how rooms are, from first to last, where: 0 is locked and 1 is unlocked. Note the square brackets. This is a LIST. With round brackets will be a tuple, an immutable type you cannot change later.
default position=0 #where 0 is the first room, 1 the second, 2 the third (is a python thing to count lists from 0, mandatory).
default oldposition=0 #this is a convenient variable to go back to the room if the next is closed. Keep faith.
default roomlabels=["kitchen","roof","garden","gym","crypt","bathroom"] #label of each room, in strict order.
#Well, not. The game starts here, instead.
label start:
"Welcome to the domestic dungeon!"
"If you add music, sound, images, a GUI, a plot, animations, screens, sprites..."
"...pointers, icons, characters..."
"...functions, debug, packaging, galleries..."
"...and some love, you can release it to the underworld!"
"Now explore this dungeon!"
#start from a safe and unlocked location. In that given case, the garden.
jump garden
label movemenu:
###########THIS IS THE ROUTINE THAT ALLOW MOVEMENT
call screen movetheguy #at first, call a screen to decide direction
$ direction=_return #the value returned by the screen is stored here. It's the number of the target room.
$renpy.jump(roomlabels[direction]) #this nice thing jump to the correct label, as stored in roomlabels
label kitchen:
###########THE FORMULA FOR EACH ROOM IS:
# update position
# tell the position
# call verifydoor function, that verify is the room is unlocked.
# if unlocked, do whatever
# then jump back to the movemenu routine
$ position=0
"You're now in the kitchen!"
call verifydoor
"It's a very nice kitchen. Anyway, nothing to eat."
jump movemenu
label roof:
$ position=1
"You're up on the roof!"
call verifydoor
"You can see MY house from there!"
"And if you reach that point in the game, you've seen everything."
"It's time for a goodbye. Lemme know if you need something else!"
"-coded in 17 minutes by Gas."
$ renpy.full_restart() #<---USE THIS INSTEAD of a return statement to end the game, as you never know (believe me you NEVER know) if the return stack is void.
label garden:
$ position=2
"You reach the garden!"
call verifydoor
"I have a bad feeling about those carnivorous plants"
jump movemenu
label gym:
$ position=3
"You're in the gym!"
call verifydoor
"HO HO ... Macho macho man! I gotta be a macho man!"
#now an example of how unlock a locked room. Of course once.
if roomlocks[0]==0: #if the target room is locked...
"Hey, you found the key for the kitchen!"
$ roomlocks[0]=1 #...now is unlocked
jump movemenu
label crypt:
$ position=4
"You're down in the crypt!"
call verifydoor
"No, wait, it's not really a crypt, is more like a depot of old manga."
if roomlocks[1]==0: #now we unlock the roof...
"In the lower area of the house, you found the higher key, the roof one!"
$ roomlocks[1]=1 #the roof is unlocked
jump movemenu
label bathroom:
$ position=5
"You're in the bathroom!"
call verifydoor
"It's not a common bathroom. In fact those lasers are out of context."
if roomlocks[4]==0:
"A skeleton key hang from an hook. Are you sure this is a bathroom??"
$ roomlocks[4]=1
jump movemenu
label verifydoor:
###################### THIS LABEL CHECK IF THE ROOM IS LOCKED
if roomlocks[position]==0: #if it's locked...
"This room, however, is closed for some reason." #...sadness...
$ position=oldposition #with this, go back to the previous room. No movement happen.
jump movemenu #...and go back search elsewhere
$ oldposition=position #update the old position, from that point on is where you're now. A little contrived, but is logic. And logic is not logical.
return #if unlocked, continue with whatever else is narrated in that room
screen movetheguy():
modal True #well, no need for that now, but is good practice
$ yourroom=roomlabels[position] #where you're now
text "You're in the [yourroom]" xalign 0.3 yalign 0.1 size 30
vbox:
xalign 0.5
yalign 0.5
text "Go to..."
for i in range(len(roomlocks)): #for each damned room in this game...
$daroom=roomlabels[i] #store the label name...
if position != i: #of course, you skip the position you're are in now
textbutton "[daroom]" action Return(i) #...and return the number of the room you want to go, from 0 to x.