I'm trying my darnedest to make a Dance QTE happen in my short VN and my first attempt to make something happen using only screens and timers did not work (ending with a laggy playback and an obnoxious amount of timing issues).
So I took to the interwebs and found this:
viewtopic.php?p=348727#p348727
I wanted to utilize it (giving proper credit of course) but when testing this code, I found that it's an eternal loop. Since the song the mini game is used for is only 63 seconds, this is an issue.
This is my edit to the code, but it's still unfortunately looping forever. My GOAL for it is two conditions:
1. If the player consistently hits the dance button successfully on it's marker during the duration of that 63 seconds, the game ends and the story continues (Label "dance_success")
2. If the player misses THREE times (whether it be misclicking or letting the target run past the marker), the game ends and the story goes to a bad end (Label "dance_failure")
Regardless, the loop needs to break and I have NO clue how to even do that.
Code: Select all
init python:
config.screen_width=1280
config.screen_height=800
import time
import pygame
MOUSEBUTTONDOWN=pygame.MOUSEBUTTONDOWN
class RhythmD(object):
def __init__(self, sprite, speed, delay, ypos=0):
self.sprite = sprite
self.speed = speed
self.delay = delay
self.show = manager.create(sprite)
self.show.x = -200
self.show.y = ypos
self.moving = False # No point in checking if it isn't.
def update(self):
if store.t + self.delay < time.time():
self.moving = True
self.x = self.x + self.speed
else:
pass
@property
def x(self):
return self.show.x
@x.setter
def x(self, value):
self.show.x = value
@property
def y(self):
return self.show.y
@y.setter
def y(self, value):
self.show.y = value
def sprites_update(st):
for sprite in sprites[:]:
sprite.update()
if sprite.x > config.screen_width:
sprite.show.destroy()
sprites.remove(sprite)
return 0.05
def sprites_event(ev, x, y, st):
if ev.type == MOUSEBUTTONDOWN:
if ev.button == 1:
hit = False
for sprite in sprites[:]:
if sprite.moving:
if int(sprite.x) in store.targets:
store.hits += 1
hit = True
sprite.show.destroy()
sprites.remove(sprite)
break
if not hit:
store.misses += 1
renpy.restart_interaction()
screen show_vars:
text "Misses: [misses], Hits: [hits]" xalign 0.5
add "practicebutton.png":
pos (1000, 100)
timer 63.0 action Jump("omgyayyoudidit") #63 seconds is the length of the song. GAME MUST END AT END OF SONG.
label rhythm_qte:
play music "WALTZ.ogg"
python:
hits = 0
misses = 0
t = time.time()
manager = SpriteManager(update=sprites_update, event=sprites_event)
sprite = Image("practicebutton1.png")
targets = set(1000+i for i in xrange(-200, 200))
sprites = []
td = 0
for i in xrange(100):
td += renpy.random.choice([0.5, 1, 2]) #TIMED SPACING
sprites.append(RhythmD(Image("practicebutton.png"), 31, td, 100)) #image, time of distance, time of spawn, ypos
renpy.show_screen("show_vars")
renpy.show("_", what=manager, zorder=1)
while True:
$ result = ui.interact()