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 »

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 8291 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
Regular
Posts: 30
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 »

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

User avatar
luat1995
Newbie
Posts: 24
Joined: Mon Nov 07, 2016 8:27 am
Completed: Home Alone
Github: https://github.com/luatsenpai
itch: https://luatsenpai.i
Location: vietnamese
Contact:

Re: Point-and-click adventure framework

#3 Post by luat1995 »

Hello I have tried your code. But had some problem

Code: Select all

I'm sorry, but an uncaught exception occurred.

While processing the hover_color property of style _hyperlink:
  File "renpy/common/00start.rpy", line 80, in _init_language
    renpy.change_language(language)
Exception: Not a color: (34, 68, 204, 255)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/bootstrap.py", line 331, in bootstrap
    renpy.main.main()
  File "renpy/main.py", line 652, in main
    run(restart)
  File "renpy/main.py", line 78, in run
    renpy.translation.init_translation()
  File "renpy/translation/__init__.py", line 561, in init_translation
    renpy.store._init_language() # @UndefinedVariable
  File "renpy/common/00start.rpy", line 80, in _init_language
    renpy.change_language(language)
  File "renpy/translation/__init__.py", line 639, in change_language
    renpy.style.rebuild() # @UndefinedVariable
  File "style.pyx", line 795, in renpy.style.rebuild
  File "style.pyx", line 788, in renpy.style.build_styles
  File "style.pyx", line 680, in renpy.style.build_style
  File "style.pyx", line 709, in renpy.style.build_style
  File "style.pyx", line 706, in renpy.style.build_style
  File "gen-static/style_hover_functions.pyx", line 540, in style_hover_functions.hover_color_property
  File "renpy/color.py", line 194, in __new__
    raise Exception("Not a color: %r" % (color,))
Exception: Not a color: (34, 68, 204, 255)

Windows-7-6.1.7601-SP1
Ren'Py 7.4.10.2178
rpg framework 1.0
Thu Nov 11 07:39:42 2021
[\code]
How to fix it?
sorry my bad english

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Point-and-click adventure framework

#4 Post by Imperf3kt »

Code: Select all

Exception: Not a color: (34, 68, 204, 255)
Ren'Py only accepts colors as hex values, use

Code: Select all

#2244CC
instead.

This is probably somewhere in gui.rpy, as referenced by this line in the traceback:

Code: Select all

While processing the hover_color property of style _hyperlink
I'd look for anything with hover_color in it and make sure it is using hex values.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users