Saturday, January 2, 2010

Enemy Stats Roller

Enemies need stats that are relevant to the player's level. We are going to random generate an enemy based on similarly generated hero stats.

In the future this code will pull enemy name, level and image from a database. Players will be able to create enemies by giving them stats and images so that other players in the same level gap as their enemy can fight. Users should also be allowed to search for and target enemies outside of their level gap and other players (who are within their level gap).

Here is how it works:



// Enemy Generator appropriate for level
$rangeModifier = rand(0, $level);
$nmeMind = rand(4,$mind) + $rangeModifier;
$nmeBody = rand(4,$body) + $rangeModifier;
$nmeSoul = rand(4,$soul) + $rangeModifier;

//Generate Stats for enemy
$nmeTotal = ($nmeMind + $nmeBody + $nmeSoul);
$nmeLevel = ($nmeTotal) / 10;
$nmeLevel = round($nmeLevel);
$nmeHealth = ($nmeBody + $nmeSoul) * 5;
$nmeDefense = ($nmeTotal)/3 - 2;
$nmeDefense = round($nmeDefense);
$nmeAttack = ($nmeTotal)/3;
$nmeAttack = round($nmeAttack);
$nmeAgility = ($nmeBody + $nmeMind)/2;
$nmeAgility = round($nmeAgility);

//Generate enemy appropriate for level name and image
if ($level == 2){ $enemy = "Slime"; }
if ($level == 1){ $enemy = "Bug"; }
if ($level == 3){ $enemy = "Skeleton"; }



As you can see, the enemy is going to be around the player level, having randomly produced stats all within a close range to the player. The same script that generates a level 1-3 player can generate a level 1-3 enemy, or any level player and enemy combination for that matter.

No comments:

Post a Comment