Page 1 of 1

Point-and-click adventure framework

Posted: Sat Mar 23, 2019 9:05 pm
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

Re: Point-and-click adventure framework

Posted: Thu May 02, 2019 11:44 am
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

Re: Point-and-click adventure framework

Posted: Wed Nov 10, 2021 8:44 pm
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

Re: Point-and-click adventure framework

Posted: Thu Nov 11, 2021 3:26 am
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.