Programming enemies
par CoolioJulio
Programming enemies
Tags pour Programming enemies
Description
Apprenez à créer un ennemi simple qui se déplace à l’écran.
Comment jouer
Touches fléchées pour déplacer le vaisseau principal !
Mises à jour des développeurs
Here is the code to paste in the enemy0:
onClipEvent(load)
{
function reset()
{
var timer = 12;
this.y = Math.random() * 300
this.x = 550
mySpeed = Math.ceil(Math.random() * 6) + 1;
}
reset();
}
onClipEvent(enterFrame)
{
//in every frame the enemy move left in the speed defined in the reset function.
this.x -= mySpeed;
if (this.x < -10)
{
//if the enemy is not on the screen, we reset it.
reset();
}
//if our timer is bigger than 12 we get a new
if (timer >= 12)
{
//direction to the Ship.
var dir = Math.ceil(Math.random() * 2)
//We get a random number, 1 or 2. 1 is up, 2 is down.
//Then we set timer to 0, so we only get a new dir when timer is bigger than 12
timer = 0;
}
if (dir == 1)
{
//if dir = 1, we move the ship up.
this.y -= 3;
} else if(dir == 2)
{
//if dir = 2, we move the ship down.
this.y = 3;
}
//increase timer by 1, so the timer gets equal to 12 and we get a new direction.
timer+
}
This is the code to paste in the main timeline:
var nrEnemies = 3;
for (i = 1; i < nrEnemies; i++)
{
_root.Enemy.duplicateMovieClip(“Enemy” + i, _root.getNextHighestDepth());
}
Commentaires
SamTheGod
Dec. 19, 2014
OMGMGGMGGMMGGMGMGMGMGMGM SOOOOOOOOO PROOOOOO
motionman
Sep. 02, 2009
very handy
bugalugs
Jun. 21, 2009
It dusnt work!
CoolioJulio
May. 18, 2009
This is definitely no where the same as kongregate's shootorials.
linc98
May. 18, 2009
(not really love its a joke)