Hey all, I have a small game i’m coding, and basically I have it so that I can spawn powerups every time an enemy is killed - the powerup spawns and bounces around the stage until it’s picked up. I want it to have a chance of spawn (let’s say 1/10). I can’t seem to achieve this. I’ve tried setting a random number and running a check for it, but it doesn’t seem to read the random number.
Inside the explode() function, an explosion graphic is played, the ship is removed from the scene, and a powerup is spawned.
Can anyone help? I’ve attached the code.
class EnemyShip extends MovieClip
{
var speed;
var shootTimer;
function onLoad()
{
_y = -93;
_x = Math.random()*200+50;
speed = Math.random()*5+5;
shootTimer = 0;
}
function onEnterFrame()
{
_y += speed;
if(_y > 500)
{
this.removeMovieClip();
}
if(this.hitTest(_root.ship))
{
if(_root.ship.shield._visible == false)
{
_root.ship.updateHealth(-20);
}
explode();
}
shootTimer += 1;
if(shootTimer > 30)
{
shootTimer = 0;
var missile = _root.attachMovie("EnemyMissile","EnemyMissile" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
missile._x = _x;
missile._y = _y;
}
}
function explode()
{
var reward = _root.attachMovie("RewardPoints","RewardPoints" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
reward._x = _x;
reward._y = _y;
reward.field.text = 50;
var explosion = _root.attachMovie("Explosion","Explosion" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
explosion._x = _x;
explosion._y = _y;
this.removeMovieClip();
_root.ship.updateScore(50);
var powerup = _root.attachMovie("PowerUp","PowerUp" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
powerup._x = explosion._x;
powerup._y = explosion._y;
}
function takeDamage()
{
explode();
}
}