Code: Select all
init:
image upb = "upbutton.png"
image downb = "downbutton.png"
image leftb = "leftbutton.png"
image rightb = "rightbutton.png"
define xpy = 0
define ypy = 0
screen Upbutton(xpos, ypos):
button:
image "upb"
xpos xpos
ypos ypos
action SetVariable("exercise",exercise+1)
keysym "K_UP"
screen Downbutton(xpos, ypos):
button:
image "downb"
xpos xpos
ypos ypos
action SetVariable("exercise",exercise+1)
keysym "K_DOWN"
screen Leftbutton(xpos,ypos):
button:
image "leftb"
xpos xpos
ypos ypos
action SetVariable("exercise",exercise+1)
keysym "K_LEFT"
screen Rightbutton(xpos,ypos):
button:
image "rightb"
xpos xpos
ypos ypos
action SetVariable("exercise",exercise+1)
keysym "K_RIGHT"
screen workout():
timer 0.5 action [Return("loopy"), If (workout_timer>1, If(exercise > 8, Return("win"), SetVariable("workout_timer", workout_timer-0.4) ), Return("lose") ) ] repeat True
label start:
"This is a test"
$ exercise = 0
$ workout_timer = 10
show screen workout
label worktime:
$result = ui.interact()
$ workout_timer = workout_timer
$ randscr = renpy.random.randint(1,4)
if (randscr == 1):
call screen Upbutton(renpy.random.randint(200,1200),renpy.random.randint(200,750))
elif (randscr == 2):
call screen Downbutton(renpy.random.randint(200,1200),renpy.random.randint(200,750))
elif (randscr == 3):
call screen Leftbutton(renpy.random.randint(200,1200),renpy.random.randint(200,750))
elif (randscr == 4):
call screen Rightbutton(renpy.random.randint(200,1200),renpy.random.randint(200,750))
if result == "loopy":
jump worktime
if result == "win":
hide screen Upbutton
hide screen Downbutton
hide screen workout
"Grats [exercise]"
jump done
if result == "lose":
hide screen Upbutton
hide screen Downbutton
hide screen workout
"Fail [exercise]"
jump done
label done:
"Finished"
return
Ok so that is what I have atm, some of the display is debug stuff. I've tried about 15 different ways to do this so far, and while the above doesn't actually work properly, it's the closest I've managed to come. Also about 50% of that code is shamelessly stolen from other places.
Anyone who knows more than me can probably see what that does: Every 0.5s it displays a random image at a random location on the screen, if the correct key prompt (or click - I haven't figured out how to make it not clickable yet. I'll get there when I get the rest to work) is hit, it adds 1 to a counter. When the timer runs out, if enough have been hit, it advances to win, otherwise to lose.
What I want it to do: Run a timer in the background. Display a random image at a random location, and WAIT for a key press. If the correct key is hit, advance to another random image. (I also want to have it advance if an incorrect key is hit and just not increment the counter, but I'm not too worried about figuring that part out yet). If the target # of correct hits is achieved before time runs out, advance to win, if the timer runs out before that, advance to lose.
Basically I can not figure out how to have a timer run, but have it desynched from the actual key prompts, and still have them show up randomly. I've tried a bunch of different ways that all fail miserably. Some just make a single static image that never advances, some don't advance the count, some create infinite loops, some ignore the timer and advance images forever, some only advance the timer when a key press DOESN'T happen, and the rest just error out entirely because I'm still learning proper syntax.
If anyone can help me figure out how to do what I'm trying to do it'd be much appreciated. Also, if anyone can point me to good resources to learn how to do all this stuff properly, I'd appreciate that too. So far all I've found is the official documentation (which is useful, but lacking on a lot of explanations or examples which I find helps a ton), and these forums (I've been looking through the cookbook section a bit, I'd like to go through it more when I have some free time, but that's slightly more limited in that most of it is examples of specific tasks rather than how to use various functions, or stuff like that. Though maybe there's more too it, I just haven't had enough time to go through too much of it yet).