Public Group

# Implementing Attack-Speed( Delay )- help please :-)

This topic is 5175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all! I am trying to implement an attackspeed(attack delay) formula from an other game(ro)! I have no idea how I can implement the delay to my game. (okay, i have.. but it isn't right! ^^ ) I am using SDL. Here is my code that calculates the delay:
    // variables the calculations are based on
// ASpd is improved by your Job, the Weapon Speed of the
// Weapon/s  you are wielding, your Agility
const int WeaponDelay = 70;
const int Agi = 10;
const int Dex = 10;
const float ImprovementPercentages = 0;

// calculat extra_speed from items
const float SPEED_MODS = (100-ImprovementPercentages)/100;

// get delay reduces from agi and dex
// agi helps more than dex!
const float delay_agi = floor( WeaponDelay* (Agi/25) );
const float delay_dex = floor( WeaponDelay* (Dex/100) );
const float delay_agi_dex =(delay_agi + delay_dex)/10;

// get final delay
const int delay = static_cast<int>( ceil(SPEED_MODS *(WeaponDelay - delay_agi_dex)) );


But how can I use the delay now? I am using SDL
if((SDL_GetTicks() - Ticks) >= 1000) // what here? :O
{
// strike..
}


Formula:
Delay = SpeedMods * (WeaponDelay - ([WeaponDelay*Agi/25] + [WeaponDelay*Dex/100])/10)

Extra-infos:
You can calculate your Swings/Minute as 60/(Delay/50).
This is because each point of Weapon Delay is equal
to 1 frame on the screen. There are 50 frames per second
and of course 60 seconds per minute.
This can be further simplified to 3000/Delay.


Thank you very much for your help guys! :-) [Edited by - rakoon2 on August 21, 2004 6:42:55 PM]

##### Share on other sites
Pseudo code :

if (SDL_GetTick() - PreviousTick > delay){    if (player asked for strike)    {        strike        player asked for strike = false        PreviousTick = SDL_GetTicks()    }]

HTH,

##### Share on other sites
yes! :-) but the delay number is so low.. (40-75) but 1 sec is 1000 in SDL. must i mulitplicate the number with 10? Or so?

##### Share on other sites
What I do is this

 delaycounter = 0; delay = 50;proc player_fire() if player fired then    if (delaycounter <= 0) then      fireweapon()      delaycounter = delay    end if end ifend procproc player_update(frameTick)  // Do movement stuff here, etc  if (delaycounter > 0) then    delaycounter -= frameTick;  end ifend proc

Each frame ticks in miliseconds and decreases the fire limiting timer, so to get your delay to be in seconds, instead of miliseconds simply multiply (desired seconds * 1000). So to wait around half a second, use delaycounter = 0.5 * 1000

##### Share on other sites
Oh! :) And frametick is: SDL_GetTick() - PreviousTick ? hm...
Thank you!

##### Share on other sites
Yup, that's the one. Unless you're using a fixed timestep, that is. I generally have the game do the tick caluculation and have each update routine take a tick as a paramter, that way you know they're all updating the same - plus you could put in fixed time stepping without breaking it too, if you need it.

##### Share on other sites
 frameTick = SDL_GetTicks() - Ticks; // this one is wrong too?! if( attack_with_bow > 0 ) {      if( delaycounter < 0 )    {       // FIRE !!       const int delay = player->getDelay_bow();              delaycounter = delay*10;  // this one is wrong!       attack_with_bow--;     } }  delaycounter -= frameTick; Ticks = SDL_GetTicks();

Can you tell me what I do wrong? Please :-) Thank you!

##### Share on other sites
Delay counter, Ticks and frameTick is in your class or is global, or passed as a parameter, right?

eg:class player{ public:  player() : delayCounter(0), fireDelay(0.5f)  {    // firedelay is set at 0.5 seconds  }  float delayCounter;  float fireDelay;  void updatePlayer(float frameTick)  {    if (delayCounter > 0 )       delayCounter -= frameTick;  }  void fireBow()  {    if (delayCounter <= 0)    {       // Fire!       delayCounter = fireDelay;    }  }};// Then in your game somewhereGame::Update(){  float frameTick = SDL_GetTick() - lastTicks;    if (fire_bow_key_pressed)  {     player->fireBow( frameTick );  }  // Reset keyboard, etc. lastTick = frameTick;}

##### Share on other sites
Well, that was just a test.. That code was in the game::gameLoop
code!

Delay is a number btwn 0 and WeaponDelay. WeaponDelay is 70 for bows.

float frameTick = SDL_GetTick() - lastTicks;

must be
UINT32 frameTick = SDL_GetTick() - lastTicks;
Delay = SpeedMods * (WeaponDelay - ([WeaponDelay*Agi/25] + [WeaponDelay*Dex/100])/10)

I don't care about design yet.. I want to get it to work first.

gameloop:
 int delaycounter = 0; int frameTick = 0; Uint32 Ticks = 0;   //...//...    const int delay = player->getDelay_bow();    frameTick = SDL_GetTicks() - Ticks;    if( delaycounter <= 0 )    {               // fire       delaycounter = delay*10; // what here? delay is a nr btw 0 and ~75( or more )// you shoot faster if the delay is lower!     }     if( delaycounter > 0 )      delaycounter -= frameTick;    Ticks = frameTick;

gives me crazy results!
delaycounter gets lower and lower
and frameTick higher and higher..!

Thank you!! :-/

##### Share on other sites
I forgot to say, I always scale the value I get back from GetTicks(), so Tick = GetTicks() / 1000; This way you get a fraction of a second and it can be used as a scalar.

If you use all ints however, you should still get the right results (I just prefer seeing it in 'real' seconds).

The effect you should be getting is that frameTick stays about the same and is linked to the speed of your game, and that delay counter should decrease if higher than 0. When delaycounter is 0 or less, the player can fire. If it's higher, it can't.

The problem is that frametick gets higher each time, I think. Are you sure it's getting calculated properly? I mean, is Ticks keeping it's value from the last frame?

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009811
• ### Who's Online (See full list)

There are no registered users currently online

×