0
\$\begingroup\$

My game is very similar to the hidden game in chromes web browser. I have a character that needs to jump over incoming enemies. Is there any way i can know when to send an incoming enemy? Some of the factors to take in to account i guess are the speed of enemies, height of jump, speed of jump, and dimensions of bitmaps (that represent character, and enemies).

Thanks

\$\endgroup\$
1
  • \$\begingroup\$ I'm guessing you're talking about an infinite runner? \$\endgroup\$ – jzx Aug 3 '15 at 8:42
1
\$\begingroup\$

Something as simple as this would give you the rough time the player will have to react if you were to spawn an enemy right now.

minReactionTime = 0.5; //Give the player half a second to react
closingSpeed = enemySpeed + playerSpeed;

if ( (enemySpawn - playerPosition) / closingSpeed >= minReactionTime )
{
   spawnEnemy();
}
\$\endgroup\$
2
  • \$\begingroup\$ looks good but can you explain in words what that is going to do? \$\endgroup\$ – Izak Aug 3 '15 at 15:26
  • \$\begingroup\$ Basically it just calculates how long it will take the player and enemy to collide if they continue moving forward at max speed. This gives you a rough estimate of how long the player will have to react if you spawn an enemy at the "enemySpawn" point in that code. \$\endgroup\$ – cfehunter Aug 6 '15 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.