0

I am in the extremely early stages of designing a game (so early that I haven't even committed to it yet). The idea is an RPG with a Quick Time Event for attacking and defending that relies on precise mouse movements or timed button presses to reduce damage taken or increase the damage of an attack (similar to Mario and Luigi or Paper Mario). I'm wondering the best way to go about programming a class that can handle this. Ultimately, I'd like to be able to write code such as this when I call the attack function, where all of the functionality of the QTE occurs in a single function call;

//Example code.
int attackPower = 23;
double qteSucessPercent = -1;
//more code
if(e.getSource == player.sword()) //when the player chooses to execute a sword attack.
{
    qteSucessPercent = QTE.Jump();
    if(qteSucessPercent< 0)
        throw BadQTEException;
    else if(qteSucessPercent>= .9)
        player.attack(enemy[0], attackPower*2);
    else if(qteSucessPercent>= .75)
        player.attack(enemy[0], attackPower*1.5);
    else if(qteSucessRate>= .5)
        player.attack(enemy[0], attackPower);
    else
        System.out.println("Attack Failed");
}

This class needs to do several things.

  • It needs to be able to draw itself.

  • The QTE class needs to be able to handle key pressing or mouse motion events. I can handle the code for each type of QTE I wish to implement, but they need to be able to detect, on their own, where the mouse is and what buttons are being pressed.

  • Whatever it is drawing needs to delete itself once the QTE is over.

  • There will be multiple types of Quick Time Events. Each one will be drawn differently, have different victory conditions (one may require you to hit a sequence of buttons in the correct order, another may make you press a single button in rapid succession as many times as you can, ect), and modify the attack in various ways. The basic design of all QTEs is that they return a double value between 0 and 1, depending on how well the player did (generally, the higher the number, the better; if the attack returns 0, then the QTE received no input at all). In some situations, the QTE may be pass/fail, but the rest of the program is just watching for a non-0 number to be passed from the function call. For the sword, the attack's power is being modified by how well you do.

  • I know Swing isn't thread-safe (which, to my knowledge, means components won't update properly if you try to activate parts of their code from a thread other than the one you called them with, meaning I can't have two blocks of code executing at the same time if I want both sets of code to display animations), which is why I've written the code the way I have. The main thread gets to line 6, and executes QTE.Sword(). Until QTE.Sword() returns (which could be as long as five seconds), the rest of the program will freeze and not animate. I plan to use this to my advantage to achieve a bullet time effect, where the only thing animating is the QTE and the players and enemies remain stationary - though if I wanted an animation, like for a Mario and Luigi-like jump QTE, I'd set the player's sprite to be an animated gif that only plays once and only for as long as the QTE goes off.

Note that I am NOT ASKING FOR CODE. I'm asking for either pseudo-code or just a paragraph explanation of how I could program this. I think I can find a dead, open-sourced project on Github or Google Code and figure out the basics of the rest of the engine from there, but this is really the sticking point for me. Also, I am not asking for help handling mouse movements or keyboard presses. I have enough knowledge to code these on my own - I'm just not sure how to implement this in the context of an RPG. I know this isn't really stackoverflow's thing, and this question will probably get deleted, but I figure this is the best place to ask this sort of thing.

chif-ii
  • 995
  • 1
  • 6
  • 12
  • I think you might want to migrate your question to GameDev.SE, as it currently stands your question isn't a good fit for SO. And even then, I don't believe the people at GameDev will consider this question as being a good fit either. – Laf Dec 11 '14 at 17:07
  • dont do this if(e.getSource == player.sword()) set up a listener pattern or just call a method when the player hits a key or something but to just keep checking for sword is stupid. –  Dec 11 '14 at 17:36
  • you can use jbuttons or if you must the mouseListener on your frame can tell you where the mouse is and you can store the box where the buttons are and check if the mouse is within the button every time the use clicks –  Dec 11 '14 at 17:38
  • use JFrame or something they are very versatile just make sure the threads are done before you pass it to the frame –  Dec 11 '14 at 17:40

0 Answers0