Jump to content

Spawning frequency change, based on game speed


chris1986m
 Share

Recommended Posts

Hi to all,

i've tried and tested a lot the last days, but now I don't have any ideas... and may be someone can help me.
I build a game with moving elements from right to left, like jetpack joyride. The "rate" value is my game level (it's the game difficulty). By changing this value, the game will be faster/slower. This means the velocity of each moving element depends on the "rate". Also the frequency on which seconds the next element will spawn.

I've adjusted the space between two elements by view (not by px). Tested for "rate 0" and "rate 100". I've found a good frequency by 15000ms and 2500ms.

My goal is, to get always the same space between two spawning elements whatever rate and speed is set.

-----------------------

rate = 25

sMin = 50
sMax = 300

fMin = 15000
fMax = 2500

speed = Math.max(sMin - (sMin - sMax) * rate / 100, sMin);

frequency = Math.max(fMin - (fMin - fMax) * rate / 100, fMax);
nextSpawn  = this.game.time.now + frequency;

------------------------

Rate: 25
speed: 112.5
frequency: 11875

------------------------

The results are correct, but this is not that what I needed.
With the increasing speed by rate, I've to adjust the frequency by speed.

This means:

rate: 0
speed: 50
frequency: 15000
CORRECT!

rate: 100
speed: 300
frequency: 2500
CORRECT!

rate: 25
speed: 112.5
frequency: 11875
TO SLOW! The frequency should be round about 7000 for the same space between the two elements.


I've tried to adjust the fMin and fMax values before frequency calculation and the frequency value after the calculation.
Both via percentage calculation, based on the "rate" or other values... It is not possible to get correct results between "rate 0" and "rate 100".
Spawning is always to fast or to slow.

11875 * 25 / 100 = 2968.75
11875 - 2968.75 = 8906.25
TO SLOW! The space between the two elements is greater than the default space. 7000 would be a good value....

I think i've to adjust the frequency by the game speed. But I don't know how!
On creating each element, the sprite gets the speed value for the velocity.x.

But how can I handle "speed 112.5" to increase/decrease the spawn frequency in the correct proportion.

I hope this is clear, because it is not very easy to explain this problem.

Please look at the attached image.

 

Thanks for help.

Chris

post-9977-0-08637100-1427106447.jpg

Link to comment
Share on other sites

If you don't want spawn frequency to change with game speed, why change it?  Just spawn a new item every n milliseconds and just use speed to determine how quickly things are moving.  Or am I missing the point?

Link to comment
Share on other sites

hi,

 

distance is relative to the time and velocity.

distance = time * velocity;// if you want to keep equal distance between objectsnext_spawn_at = this.game.time.now + distance / velocity;// You will need to change your code to fit that formula// something like:// distance = base_dist_px / frequency; higher frequency - smaller distance// velocity = base_velocity + rate * X; next_spawn_at = this.game.time.now + (base_dist_px / frequency) / (base_velocity + rate * X);
Link to comment
Share on other sites

Hi stauzs,

 

i have some problems with your calculation.

 

 

What do you mean with time? Frequency, game.time.now?

distance = time * velocity;

 

 

base_velocity is the default start velocity?

The velocity in game is from 50 to 300, based on the spawning time (15000 to 2500).

 

 

What do you mean with X?

 

base_dist_px = 300

frequency = 15000

base_velocity = 50

rate = 0

X = ?

 

next_spawn_at = this.game.time.now + (base_dist_px / frequency) / (base_velocity + rate * X);

 

Thanks for your help!!!

Chris

Link to comment
Share on other sites

with time I meant interval between 2 events  - in your case time between 1st spawn and 2nd spawn it's same as 1/frequency

it's from speed formula actually: v = d / t
 

this was just an example - how you could make changes to your code.

base_velocity is the default start velocity? - Yes

What do you mean with X?

X is just a coefficient - to increase rate per object - you can remove it ( basically same as x = 1 )  - or call it something like base_koeeficient_per_rate :)

Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...