Point-and-click adventure framework

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
lacticacid
Regular
Posts: 36
Joined: Fri Nov 23, 2018 6:44 pm
Contact:

Point-and-click adventure framework

#1 Post by lacticacid » Sat Mar 23, 2019 9:05 pm

Using Per K Grok's code (Method 3), I was able to create a simple point-and-click adventure game framework featuring:
- Player-controlled walking using arrow keys (Credit for this one goes to Per K Grok! Remember to check out his posts and his channel! Also, this code includes his third method - using arrow keys and a movable background, so if you'd like to use a mouse click to move or include a still background and a movable character, you should look into the other methods his post provides)
- Ability to run if the player holds down shift
- A clickable object
- A "label" over the object that pops up when the player is near it
(Don't mind the random panorama background I ripped off google images)

Code: Select all

image bg panorama = "images/panorama.jpg"

image j right = "images/jright1.png"
image j left = "images/jleft1.png"
#Walking and running animations:
image j walkr:
    "images/jright1.png"
    0.25
    "images/jright2.png"
    0.25
    repeat
image j walkl:
    "images/jleft1.png"
    0.25
    "images/jleft2.png"
    0.25
    repeat

image j runr:
    "images/jright2.png"
    0.2
    "images/jright1.png"
    0.1
    "images/jrightrun1.png"
    0.2
    repeat

image j runl:
    "images/jleft2.png"
    0.2
    "images/jleft1.png"
    0.1
    "images/jleftrun1.png"
    0.2
    repeat

transform transparent:
    alpha 0.0

default object_encounter = False #explained later on

image button text = Text("Object", size=24, color="#ffffff", outlines=[ (2, "#000", 0, 0) ]) #label for our object
image buttontest = "images/note.png"
image buttontest text = Composite((260,260),
    (0, 37), "images/note.png",
    (58, -5), "button text")

screen buttonscreen(): #The reason I didn't put the image on this screen in the first place, instead separating it into a transparent imagebutton portion and visible regular image portion was because there was a slight delay in the motion of the imagebutton
    hbox xpos int(bX) yalign 0.7:
        imagebutton:
            idle "images/note.png" at transparent
            hover "images/note.png"
            action Jump('objectlabel')

default dirt = 0
default dir2 = 1
#Character's position:
define jX= 440
define jY= 130
default rX= -1000.0 #background's position

default bX= -500.0 #our clickable object's position

init python:
    import math
    import pygame, os
    from pygame.locals import *

    def keys():

        kdir=0
        pressed_key=pygame.key.get_pressed()

        if pressed_key[K_RIGHT]:
            kdir=1
        if pressed_key[K_LEFT]:
            kdir=-1
        if pressed_key[K_RIGHT] and pressed_key[K_RSHIFT] or pressed_key[K_RIGHT] and pressed_key[K_LSHIFT]:
            kdir=2
        if pressed_key[K_LEFT] and pressed_key[K_RSHIFT] or pressed_key[K_LEFT] and pressed_key[K_LSHIFT]:
            kdir=-2


        return kdir




label walklabel:
    $ quick_menu = False #disables the quick menu
    scene bg panorama
    show screen keyCheck
    show screen buttonscreen
    show buttontest
    jump walk


label walk:
    $ object_encounter = False #explained later on
    $ renpy.pause(delay=0.02, hard=True)
    scene bg panorama:
        xpos int(rX) #position of the background
    show buttontest:
        xpos int(bX) yalign 0.7
    if rX>-250 and rX<290: #makes the label on the object appear when you're near it
        show buttontest text

label upDate:

    $ dirt = keys()
# Controls the "speed of the character" - or rather, our moving background
    if dirt==-1:
        $ rX += 4.0
        $ bX += 4.0
    elif dirt==1:
        $ rX -= 4.0
        $ bX -= 4.0
# Running speed
    elif dirt==-2:
        $ rX += 8.0
        $ bX += 8.0
    elif dirt==2:
        $ rX -= 8.0
        $ bX -= 8.0
# Where the character stops
    if rX>400:
        $ rX=400
        $ bX=rX+500
        $ dirt=0
        $ dir2=1

    if rX<-4000:
        $ rX=-4000
        $ bX= rX+500
        $ dirt=0
        $ dir2=-1

    jump walk

screen keyCheck():
    if dirt==-1:
        $ dir2=-1
    elif dirt==1:
        $ dir2=1

    if dirt==-1:
        add "j walkl" xpos jX ypos jY

    elif dirt==1:
        add "j walkr" xpos jX ypos jY

    elif dirt==-2:
        add "j runl" xpos jX ypos jY

    elif dirt==2:
        add "j runr" xpos jX ypos jY

    else:
        if dir2==1:
            add "j right" xpos jX ypos jY
        elif dir2==-1 or dir2==-2:
            add "j left" xpos jX ypos jY



label objectlabel:
    if object_encounter==False: #The object_encounter thing doesn't need to be here. What is does is basically make the line act as if you clicked away from it if you click on the object again before it disappears. It just bothered me
        $ object_encounter = True
        "This sure is an object."
    jump walk
screenshot0008.png
screenshot0010.png
Attachments
panorama.jpg
note.png
note.png (21.7 KiB) Viewed 1320 times
jrightrun1.png
jright2.png
jright1.png
jleftrun1.png
jleft2.png
jleft1.png
~There is almost always a better, easier way to approach a problem.~

User avatar
sonictoad
Newbie
Posts: 19
Joined: Tue Mar 12, 2019 10:39 pm
Projects: It's Different When It's Your Own
Organization: Sonic Toad Media LLC
itch: nyhcmaven84
Location: Bronx, NY
Contact:

Re: Point-and-click adventure framework

#2 Post by sonictoad » Thu May 02, 2019 11:44 am

This looks really awesome and I can't wait to test it out in a different project! I gotta finish the two I'm committed to alas :D

Post Reply

Who is online

Users browsing this forum: No registered users