As a small mini-event for a game I'm working I was thinking of adding QTE mini-game to determine if an action is successful or not. I was surprised when I couldn't find a script for this online. I could do this through events but I think a script would be much-much better solution if anyone wants to help.
Background is 416x56
Hitbox is 48x48
Pointer is 8x48
The pointer should move from one end to another waiting for the player to press the confirmation button. If the button is pressed at the time the pointer is inside the hitbox, player wins, if it's outside the box or time runs out (615 is turned off). Time/duration(in seconds) will be sent when the script is called inside an event script call.
if player wins (x switch is turned on, good sound plays, script closes)
if player loses (x switch is turned off, bad sound plays, script closes)
The position of the hitbox should be randomized(should fit within the background picture dimensions)
The size of the hitbox should also vary based on difficulty which should be set manually (maybe also as a variable through event script call). Difficulties: 1 through 3. One being 1/3 of the full hitbox picture size, 2 being 2/3, and 3 being full size.
The speed of the pointer should also vary to make it more difficult to hit. (Maybe also set it through an event script call)
The position of the whole script should be around the middle of the screen both H and V.
Pictures are located inside Graphics/system
Thanks in advance for any suggestions/help.
I went ahead and attempted to make my script for it (it's half ai, half me 🙁). The script as it is works now but I'm not sure I'm doing this correctly. I don't want to have the black background. Is it possilbe for the background to be transparent? I tried adding a transparent 544x416 picture in the background but it's not working.
Background is 416x56
Hitbox is 48x48
Pointer is 8x48
The pointer should move from one end to another waiting for the player to press the confirmation button. If the button is pressed at the time the pointer is inside the hitbox, player wins, if it's outside the box or time runs out (615 is turned off). Time/duration(in seconds) will be sent when the script is called inside an event script call.
if player wins (x switch is turned on, good sound plays, script closes)
if player loses (x switch is turned off, bad sound plays, script closes)
The position of the hitbox should be randomized(should fit within the background picture dimensions)
The size of the hitbox should also vary based on difficulty which should be set manually (maybe also as a variable through event script call). Difficulties: 1 through 3. One being 1/3 of the full hitbox picture size, 2 being 2/3, and 3 being full size.
The speed of the pointer should also vary to make it more difficult to hit. (Maybe also set it through an event script call)
The position of the whole script should be around the middle of the screen both H and V.
Pictures are located inside Graphics/system
Thanks in advance for any suggestions/help.
I went ahead and attempted to make my script for it (it's half ai, half me 🙁). The script as it is works now but I'm not sure I'm doing this correctly. I don't want to have the black background. Is it possilbe for the background to be transparent? I tried adding a transparent 544x416 picture in the background but it's not working.
Ruby:
class Scene_QTE
def initialize
# Set up the images
@background = Sprite.new
@background.bitmap = Cache.system("background")
@background.x = (544 - 416) / 2 # Center the background horizontally
@background.y = (416 - 64) / 2 # Center the background vertically
@hitbox = Sprite.new
@hitbox.bitmap = Cache.system("hitbox")
@hitbox.x = @background.x + (416 - 48) / 2 # Center hitbox inside background
@hitbox.y = @background.y + 4
@pointer = Sprite.new
@pointer.bitmap = Cache.system("pointer")
@pointer.y = @background.y + 4
# Initialize pointer movement variables
@pointer_speed = 6
@pointer_direction = 1
@pointer_start_x = @background.x + 8 # Pointer starts moving from left edge
@pointer_end_x = @background.x + 416 - 8
@pointer.x = @pointer_start_x
@running = true
end
def main
# Main loop
Graphics.transition(0)
while @running
Graphics.update # Update the screen
Input.update
update_pointer
check_player_input
end
Graphics.freeze
end
def update_pointer
@pointer.x += @pointer_speed * @pointer_direction
if @pointer.x <= @pointer_start_x || @pointer.x >= @pointer_end_x
@pointer_direction *= -1 # Reverse direction when hitting edges
end
end
# Check if the player has pressed the confirm button (Z key by default)
def check_player_input
if Input.trigger?(Input::C) # C corresponds to the "confirm" button (Z key)
if @pointer.x >= @hitbox.x && @pointer.x <= @hitbox.x + 48 - 8
Audio.se_play("Audio/SE/Decision", 80, 100) # Play success sound
else
Audio.se_play("Audio/SE/Buzzer", 80, 100) # Play failure sound
end
@running = false # Stop the loop if the button is pressed
$scene = Scene_Map.new # Return to scene before
end
end
def terminate
# Dispose of all sprites when finished
@background.bitmap.dispose
@background.dispose
@hitbox.bitmap.dispose
@hitbox.dispose
@pointer.bitmap.dispose
@pointer.dispose
end
end