Realtime action question

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
Mochiron
Regular
Posts: 30
Joined: Fri May 09, 2008 9:46 am
Contact:

Realtime action question

#1 Post by Mochiron »

I've been fooling around with ways to add different kinds of gameplay to my program. Now I'm not a programmer so I don't fully understand how stuff works. I'm currently trying to let the user move an image around the screen. Here's the idea in quasicode.

Code: Select all

init:
   $ game_is_on:

label start
   while game_is_on != False:
      show image at position x,y
      configure player controls here that moves the image around

When I set this up it doesn't really seem to like the loop at all. I mean the program starts but it freezes and just keeps chewing as if the computer was working on something. But it doesn't want to actually obey the stuff written below the while(read:nothing is moving on the screen). So, I'm guessing, using While is a bad idea?
I mean you're supposed to make a loop right? So, the updated information can be used to print the image where the player moves it.
I think I should be able to sort out the syntax if only I knew if I was on the right track.

000
Regular
Posts: 94
Joined: Mon Dec 24, 2007 11:09 am
Projects: Ren'Py Russian distributive
Location: Уфа, РБ, Россия
Contact:

Re: Realtime action question

#2 Post by 000 »

Your example will obviously freeze the copm, as you are not changing anything, neither x/y nor game_is_on. Furthermore, I am surprised you was able to run it, as there are some vital parts missing (y'know, like definitions of image or position x/y. and, I think, you must initialize variables with values before you can yse them (game_is_on hinthint)). If you have a valid code what you think has a problem, post it.

While you ARE right with while, you CANNOT do anyting in realtime using pure Ren'Py. As current Ren'Py timer lives only for one interaction. Hm, you probably can set things up in the way user would not do more than one interaction in a main loop, but it is a thing that needs some thinking.
Proper way to handle interactive realtime action is AFAIK user-defined displayable, but it seems to me it requiries more than casual level of coding skills to pull off.
Alternatively, in pure Ren'Py you can go for turn-based approach (I mean "draw the image - infinitely wait for user input - recalculate the position of image based on user input - draw the image - ..." and so on.) Actually, it is what your example will do after some straitening up.

Mochiron
Regular
Posts: 30
Joined: Fri May 09, 2008 9:46 am
Contact:

Re: Realtime action question

#3 Post by Mochiron »

Well, the example was in quasicode so it won't run as it is. I just wanted to know if While would do the trick.

I think you answered my question here though. ;-)
000 wrote:...but it seems to me it requiries more than casual level of coding skills to pull off.
I think I'll stick to turnbased then, since I already worked that out. Thanks 000!

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Realtime action question

#4 Post by Jake »

000 wrote: Proper way to handle interactive realtime action is AFAIK user-defined displayable, but it seems to me it requiries more than casual level of coding skills to pull off.
Or Renpygame, which is a Ren'Py-compatible wrapper around PyGame, and thus probably a far better idea for the 'minigame' kind of realtime interactions. But again, that's more complex to program.
Server error: user 'Jake' not found

Mochiron
Regular
Posts: 30
Joined: Fri May 09, 2008 9:46 am
Contact:

Re: Realtime action question

#5 Post by Mochiron »

Thanks Jake. I looked through the Renpygame stuff, but since I'm still new at programming I think I 'll keep taking babysteps towards understanding things. I actually started this part of my project to learn the basics of For and While and thought I might be able to do something easy with them.

esrix
Regular
Posts: 28
Joined: Wed May 28, 2008 11:12 pm
Contact:

Re: Realtime action question

#6 Post by esrix »

It might help to use the renpy.pause() statement like so:

Code: Select all

$renpy.pause(0.0)
Got a bit of work here that might prove useful to you... It uses Ren'Py and RenPyGame together, but Ren'Py still maintains most of the control. You basically can use the arrow keys to move around and whatnot and it seems to work well in Ren'Py 6.5. Haven't tested it in the most recent version, though.

Code: Select all

# You can place the script of your game in this file.

init:
    # Declare images below this line, using the image statement.
    image eileen small = "eileen_small.png"
    image text1 = renpy.ParameterizedText()
    
    # Declare characters used by this game.
    $ import renpygame
    $ from renpygame.locals import *
    $ e = Character('Eileen', color="#c8ffc8")
    
    python:
         x_pos = 1
         y_pos = 1

# The game starts here.
label start:
    e "Welcome to the Ren'Py walking demo!"
    e "This demostrates how to get primative movement in Ren'Py using a mixture of Ren'Py and RenPyGame."
    e "It's not perfect... there are still some hiccups yet to be ironed out."
    e "Use the arrow keys to move the miniature Eileen around!"
    e "As a bonus, I added in some text that follows the mouse pointer around."
    e "When you are done, hit the Escape key to exit out of the demo."

label wait:
    $ walking = 1
    
    show eileen small
    $ renpy.pause(0.0)
    
    while walking:
        $ dx = 0
        $ dy = 0
        $ mpos = [0, 0]
        
        python:
            if renpygame.key.get_pressed()[K_UP]:
                dy-=2
                walking = 1
            if renpygame.key.get_pressed()[K_DOWN]:
                dy+=2
                walking = 1
            if renpygame.key.get_pressed()[K_RIGHT]:
                dx+=2
                walking = 1
            if renpygame.key.get_pressed()[K_LEFT]:
                dx-=2
                walking = 1
            if renpygame.key.get_pressed()[K_ESCAPE]:
                walking = 0
            mpos = renpygame.mouse.get_pos()
            
        show eileen small at Move((x_pos, y_pos, 0.0, 0.0), (x_pos + dx, y_pos + dy, 0.0, 0.0), .1, repeat=False, bounce=False)
        show text1 "Blah" at Position(xpos=mpos[0], xanchor='left', ypos=mpos[1], yanchor='top')
        $ x_pos += dx
        $ y_pos += dy
        
        $ renpy.pause(0.0)

#label go:
    e "Thanks for using the demo!  Good bye!"
I plan on using this a bit for my own game, but I'm still playing around with it. The worse part so far is that Ren'Py tends to hiccup every now and then and the movement jerks a bit. I'm open to suggestions myself, but hopefully it will help you too!

Mochiron
Regular
Posts: 30
Joined: Fri May 09, 2008 9:46 am
Contact:

Re: Realtime action question

#7 Post by Mochiron »

Wow, that's awesome esrix. I'm definitely gonna play around with that. :o
Thanks!

Post Reply

Who is online

Users browsing this forum: Google [Bot]