Author Topic: turn based battle, implementing speed  (Read 4538 times)

Asdayasman13

  • *
  • Posts: 161
    • View Profile
turn based battle, implementing speed
« on: 2007-07-30 23:37:24 »
I am posting this here, because I can think of no better place to put it.  Yes, I have googled it.

In coding a battle, (playable) what would the theoretic code be for speed?

That didn't make too much sense.  How about:

I want to write some code for a turn-based battle, how would I go about implementing speed?  Say there are two sides (r, b) and r's speed is 50, while b's speed is 25, so the turn order would be:  rrbrrbrrbrrb...  In plain english (i.e., get the variable x, decrease it by 4...) what would I do?

Any help would be appreciated.

Mod Edit: Moved to Tech-related.
« Last Edit: 2007-08-01 00:48:41 by Alhexx »

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: turn based battle, implementing speed
« Reply #1 on: 2007-08-01 01:12:52 »
You have a WAIT time before they can enter commands.  So R gets to enter commands 66% of the time and B gets to enter commands 34% of the time in the above case. This is how many of the FF series games handled 'speed'.

Cyb

Mod Edit: Corrected/Removed quote-tag.
« Last Edit: 2007-08-01 16:00:02 by Alhexx »

Hades

  • *
  • Posts: 43
    • View Profile
Re: turn based battle, implementing speed
« Reply #2 on: 2007-08-01 11:07:11 »
As Cyb said, you need a timer. A crude example in pseudo code:

Code: [Select]
character1_speed = 25;
character2_speed = 50;

lamest_wait_time = 30;

For sake of ease I would use the speed points as a percentage of the wait time they DONT have to wait.
so in this example character 1 has to wait 22.5 seconds (75% of the wait time), and character 2 has
to wait 15 seconds (50%)

Code: [Select]
loop {
   
    if(time_has_passed(100 - character1_speed as % of lamest_wait_time)) {
        ShowCharacter1Menu();
    }

    if(time_has_passed(100 - character2_speed as % of lamest_wait_time)) {
        ShowCharacter2Menu();
    }

}

Sorry for leaving a lot to the imagination but I'm not much of a game programmer and a lot of this code would normally be wrapped up in all kinds of timer objects and your game loop etc etc.



Micky

  • *
  • Posts: 300
    • View Profile
Re: turn based battle, implementing speed
« Reply #3 on: 2007-08-03 19:51:02 »
I'd try to look up scheduling algorithms for multithreading to get some ideas. And rulebooks for pen+paper RPGs should have some info about player order based on speed.

Quick and dirty:
Have a wait-time per character. Slower characters have a bigger wait time, faster characters have a smaller wait time. All characters have a "current wait counter" initialised to 0. All characters are in a list.

1) process the first character in your list with a current wait counter <= 0
2) after processing him add his wait time to his current wait counter and add him to the end of the list
3) loop 1) until all character's current wait counter is > 0
3) find the lowest current wait counter and subtract it from all characters's current wait counter
4) loop to 1)
« Last Edit: 2007-08-03 20:07:53 by Micky »

Asdayasman13

  • *
  • Posts: 161
    • View Profile
Re: turn based battle, implementing speed
« Reply #4 on: 2007-08-09 19:27:16 »
Oops, I still have this signed up to the wrong email address.  Didn't get alerts.

Some good ideas here, which I'll implement when I have ATB.

For now, I've come up with something else.

http://sara.and.zuka.googlepages.com/Arc.zip  For anyone with VB.NET SDK (EE) and an interest.

(Visual Studio 2005 Express Edition is free software, provided on the Microshaft website.  You must have the .NET framework 2.0 or higher for my app to run.  The build is in /Arc/bin/debug/Arc.exe.  Have fun) - Whew!

Hades

  • *
  • Posts: 43
    • View Profile
Re: turn based battle, implementing speed
« Reply #5 on: 2007-08-09 19:53:47 »
Microsoft software will never be free my friend... Free as in beer - perhaps.. Free as in Willy - nope, never, nada, nup.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Re: turn based battle, implementing speed
« Reply #6 on: 2007-08-10 00:05:00 »


(Visual Studio 2005 Express Edition is free software, provided on the Microshaft website.  You must have the .NET framework 2.0 or higher for my app to run.  The build is in /Arc/bin/debug/Arc.exe.  Have fun) - Whew!

Amusingly enough, I'm developing Pineapple Chronicles on two  Linux computers. What does that say about me and my ability to run .net?

You sit and mock Microsoft's name, and then turn around an use a propitiatory technology of theirs. If that's not hypocritical I don't know what is ^_^