Simple car chase event

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
cursedarchi
Newbie
Posts: 7
Joined: Tue Feb 27, 2024 9:47 am
Projects: Грёзы Фантома 3: Война в Ярославле/Sweet Dreams of Fantom 3: Yaroslavl' at War
Discord: cursedarchi
Contact:

Simple car chase event

#1 Post by cursedarchi »

anyone know how to made a simple car chase? i can explain

at scene beginning the car appear on screen. the car have 10 hp for example. every moment that we hit it and make damage (like -1hp) it moving in random direction on OX. respectively, when hp reach 0, car dissapears.

i dont know enough, can renpy move imagebutton by transform operator? and can i put digits from renpy.random.randint(a, b) into xalign?

thanks in advance for your answer

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Simple car chase event

#2 Post by jeffster »

It's probably possible:

The transform may have a list of parameters, which must be supplied when it is called.
https://renpy.org/doc/html/atl.html#transform-statement

Another way is to use sprites
Sprites are much faster than transforms
https://renpy.org/doc/html/sprites.html

or CDD
The most complex, but most powerful, way of customizing Ren'Py's behavior is to use a creator-defined displayable.
https://renpy.org/doc/html/cdd.html

Yet another way to move a displayable it to set it as drag and apply snap():
https://renpy.org/doc/html/drag_drop.html

User avatar
cursedarchi
Newbie
Posts: 7
Joined: Tue Feb 27, 2024 9:47 am
Projects: Грёзы Фантома 3: Война в Ярославле/Sweet Dreams of Fantom 3: Yaroslavl' at War
Discord: cursedarchi
Contact:

Re: Simple car chase event

#3 Post by cursedarchi »

for beginning i made this shitty code:

Code: Select all

label start:
    image woods = 'woods.jpg'
    show woods:
        zoom 7.0
    e 'the knight is chasing us! kill him!'

    label chase:
        call screen knight_chase
        if enemyHP != 0:
            jump chase
            if _return ('click'):
                $ randomX = renpy.random.randint (0.3,0.8)
                $ enemyHP = enemyHP - 1
                $ _return = 0

and this in other file:

Code: Select all

default enemyHP = 10
default randomX = 0.5

show text 'hp of enemy: [enemyHP]' at right
screen knight_chase():

    if enemyHP:

        imagebutton:
            idle 'knight.png'
            ypos 0.5
            xpos [randomX]
            action Return('click')
now its must just teleport the enemy without any animation. the game is swearing that it doesnt recognize [randomX] as a position. can u help me with that and with adding an ATL in this shit??

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Simple car chase event

#4 Post by jeffster »

cursedarchi wrote: Wed Mar 13, 2024 1:19 pm for beginning i made this shitty code:

Code: Select all

label start:
    image woods = 'woods.jpg'
    show woods:
        zoom 7.0
    e 'the knight is chasing us! kill him!'

    label chase:
        call screen knight_chase
        if enemyHP != 0:
            jump chase
            if _return ('click'):
                $ randomX = renpy.random.randint (0.3,0.8)
                $ enemyHP = enemyHP - 1
                $ _return = 0

and this in other file:

Code: Select all

default enemyHP = 10
default randomX = 0.5

show text 'hp of enemy: [enemyHP]' at right
screen knight_chase():

    if enemyHP:

        imagebutton:
            idle 'knight.png'
            ypos 0.5
            xpos [randomX]
            action Return('click')
now its must just teleport the enemy without any animation. the game is swearing that it doesnt recognize [randomX] as a position. can u help me with that and with adding an ATL in this shit??
Please read "Screens and Screen Language"
https://renpy.org/doc/html/screens.html

to understand what all these syntax constructions mean.
Otherwise it looks like some random mix of code fragments.

xpos [randomX] doesn't make sense because square brackets here mean, like in Python, "a list with one element, randomX".

Very differently, square brackets inside Ren'Py texts mean substitution:
text 'hp of enemy: [enemyHP]' means "print value of enemyHP in that text string'.

You can't be sloppy and use "something similar", because it wouldn't work properly unless you put the syntax right.

In screens,

Code: Select all

    action Return('click')
means return from the screen and set "return value" as the value in parentheses. In this case, string value 'click' is set as the return value.

When the program returns from the called screen, you can find the return value in the special variable: _return.

Then you can check what is the value of that variable:

Code: Select all

            if _return == 'click':
                # The return value equals 'click'
But this syntax doesn't make sense:

Code: Select all

            if _return ('click'):
In Python it's like you try to call here function "_return" with parameter 'click'. (Obviously such function doesn't exist).

Code: Select all

renpy.random.randint (0.3,0.8)
wouldn't work, because "randint" gives random integer. There are no integer numbers between 0.3 and 0.8.
https://renpy.org/doc/html/other.html#renpy-random

Please check every statement in your code to understand what it does and how.
If some syntax is unknown, you can search Ren'Py docs:
https://renpy.org/doc/html/

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple car chase event

#5 Post by Alex »

cursedarchi wrote: Sun Mar 10, 2024 5:52 am ...i dont know enough, can renpy move imagebutton by transform operator? and can i put digits from renpy.random.randint(a, b) into xalign?...
Kind of sample to play with

Code: Select all

####
# Car Chase Game
#

####
# images
#
image car_img:
    Solid("#c0c0c0")
    size(400, 200)

image bg_road = Fixed(
    Solid("#000"),
    Text("  \  |  / \n –  o  – \n  /  |  \ ", align=(0.75, 0.15)),
    Text("~" * 100, align=(0.5, 0.5)),
    Text(" /" + " " * 100 + "\ ", align=(0.5, 0.55)),
    Text(" /" + " " * 110 + "\ ", align=(0.5, 0.6)),
    Text(" /" + " " * 120 + "\ ", align=(0.5, 0.65)),
    Text(" /" + " " * 130 + "\ ", align=(0.5, 0.7)),
    Text(" /" + " " * 140 + "\ ", align=(0.5, 0.75)),
    Text(" /" + " " * 150 + "\ ", align=(0.5, 0.8)),
    )

####
# car movement transform
#
transform car_chase_tr(car_align, t=0.5):
    on show:
        align car_align
    on update:
        linear t align car_align

####
# game variables
#
default car_hp = 10
default car_xalign = 0.5
default car_min_xalign = 0.2
default car_max_xalign = 0.8
default car_yalign = 0.7
default car_can_click = False

####
# game screen
#
screen car_chase_scr():
    # bg might be a part of screen
    add "bg_road"

    # some info (if needed)
    text "Car HP: [car_hp]" align (0.5, 0.05) size 35 color "#c00"

    # imagebutton that represents a car
    imagebutton:
        # apply transform to the button,
        # align tuple (xalign, yalign) and optionally a time
        # should be passed to this transform
        at car_chase_tr((car_xalign, car_yalign), 1.0)
        idle "car_img"
        action Return('click')
        sensitive car_can_click


label start:
    "..."

    menu:
        "Chase 1":
            # set game variables first
            $ car_hp = 10
            $ car_xalign = 0.5
            # then call a game label
            call car_chase_lbl
        "Chase 2":
            $ car_hp = 150
            $ car_xalign = 0.5
            call car_chase_lbl

    "Well done."
    jump start

label car_chase_lbl:
    # at first car-button is not sensitive
    $ car_can_click = False
    # show game screen
    show screen car_chase_scr
    # some text
    "Ready?.. {w=1.0}{nw}"
    extend "{i}GO!!!!11{/i}{p=0.5}{nw}"
    # hide say window
    window hide

    # game loop
    label car_chase_loop:
        # now player can click the car-button
        $ car_can_click = True
        # wait for player's interaction with screen
        # and store the result in 'res' variable
        $ res = ui.interact()
        # make car-button insensitive
        $ car_can_click = False
        # evaluate the result of interaction
        if res == 'click':
            # decrease car hp
            $ car_hp -= 1
            # check winning condition
            if car_hp < 1:
                jump car_chase_win
            # if winning condition is not met yet
            else:
                # change car position
                $ car_xalign += renpy.random.choice((-0.1, 0.1))
                # fix car position to not let it go outside the road
                $ car_xalign = max(car_min_xalign, min(car_xalign, car_max_xalign))
                # next iteration
                jump car_chase_loop

        # the other results of interaction with the screen can go here
        elif res == "???":
            "???"
        else:
            "???"

label car_chase_win:
    $ renpy.pause(0.5, hard=True)
    hide screen car_chase_scr with dissolve
    "Ha-Ha-Ha"
    # should return from the car chase game
    # 'cause the game label was called
    return
https://www.renpy.org/doc/html/displayables.html#Fixed

https://www.renpy.org/doc/html/atl.html#event-statement
https://www.renpy.org/doc/html/atl.html#external-events

https://www.renpy.org/doc/html/text.htm ... -text-tags

https://www.renpy.org/doc/html/screen_p ... i.interact

https://www.renpy.org/doc/html/other.html#renpy-random

https://www.renpy.org/doc/html/statemen ... html#pause

User avatar
cursedarchi
Newbie
Posts: 7
Joined: Tue Feb 27, 2024 9:47 am
Projects: Грёзы Фантома 3: Война в Ярославле/Sweet Dreams of Fantom 3: Yaroslavl' at War
Discord: cursedarchi
Contact:

Re: Simple car chase event

#6 Post by cursedarchi »

Kind of sample to play with


thank u, dude)

sometimes it’s better for a person, especially a shitty coder like me, to show it once than to try to hint a hundred times
i a little bit changed your manuscripts for myself
i'll pray for you

Post Reply

Who is online

Users browsing this forum: Google [Bot], munni