The creatures in the game include a goblin, a snake, a wizard, and a dragon. The creature attacks are all located in a single function, and the attack initiated depends on the level you are on. The attacks happen on a clock schedule.
void creatureAttack()
{
float miss;
float hit;
passedAttackTime = millis() - savedAttackTime;
if (passedAttackTime > totalAttackTime)
…
Let's look at the goblin attack on level 1:
if (level == 1)
{
enemySound = minim.loadFile("SWORD.wav");
miss = random(1,10);
if (miss < 7)
{
hit = random(5,15);
damage = round(hit);
hp -= damage;
fill(255,0,0,40);
stroke(255,0,0,40);
rect(0,0,width,height);
if (!attaText)
{
attaText = !attaText;
}
}
else
{
fill(255,0,0,10);
stroke(255,0,0,10);
rect(0,0,width,height);
if (!missText)
{
missText = !missText;
}
}
}
The goblin attacks with an axe, so a 'sword' sound effect is used to represent a goblin attack. Then, a random number determines whether the goblin actually hits or misses the player. The goblin thus has a 30% chance of missing.
If the goblin hits you, a random number is generated between 5 and 15.
The round command will round the number to an integer, so you can't lose 7.33423521 HP. The damage then be deducted from the player HP.
Finally, a transparent red light will fill the screen, to represent the hit, and a boolean is set to display text in a later function. If the goblin misses, the red light is even more transparent, and a different boolean is set.
Now, let's look at the snake attack.
else if (level == 2)
{
miss = random(1,10);
enemySound = minim.loadFile("SNAKE.wav");
if (miss < 9)
{
hit = random(8,25);
damage = round(hit);
hp -= damage * playerResistanceP;
fill(255,0,0,40);
stroke(255,0,0,40);
rect(0,0,width,height);
if (!attaText)
{
attaText = !attaText;
}
}
It looks identical to the goblin attack, just with different variables (more damage, less chance of missing). However, notice that hp is deducted by damage * playerResistanceP, so if a poison shield is generated (setting your wand to cast poison), it cuts the blow into half of the generated damage.
No comments:
Post a Comment