Here is the code for multiple enemies in your action game.
//multiple enemies follow you
for(var i in enemies)
{
if(enemies[i]._x < player._x) {
enemies[i]._x +=1;
}
if(enemies[i]._x > player._x) {
enemies[i]._x -=1;
}
if(enemies[i]._y < player._y) {
enemies[i]._y +=1;
}
if(enemies[i]._y > player._y) {
enemies[i]._y -=1;
}
}
// if the multiple enemies hits you
for(var i in enemies)
{
if(player.hitTest(enemies[i]) && enemies[i]._visible == true)
{
score = score - 1;
scoreDisplay.text = score;
player._x = 450;
player._y = 250;
enemies[i]._x = 0 - enemies._x;
enemies[i]._y = 0 - enemies._y;
}
}
Followers
Showing posts with label actionscript2. Show all posts
Showing posts with label actionscript2. Show all posts
Thursday, May 15, 2014
Wednesday, May 14, 2014
Flash: Code for Enemy and Walls
If you'd like to make your enemy not go through the walls, below is the code for that.
// code to make enemy follow you and not go through maze walls
if(enemy._x < player._x) {
enemy._x +=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._x-=1;
}
}
}
if(enemy._x > player._x) {
enemy._x -=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._x+=1;
}
}
}
if(enemy._y < player._y) {
enemy._y +=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._y-=1;
}
}
}
if(enemy._y > player._y) {
enemy._y -=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._y+=1;
}
}
}
// code to make enemy follow you and not go through maze walls
if(enemy._x < player._x) {
enemy._x +=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._x-=1;
}
}
}
if(enemy._x > player._x) {
enemy._x -=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._x+=1;
}
}
}
if(enemy._y < player._y) {
enemy._y +=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._y-=1;
}
}
}
if(enemy._y > player._y) {
enemy._y -=1;
for(var w in maze)
{
if(enemy.hitTest(maze[w]))
{
enemy._y+=1;
}
}
}
Friday, February 14, 2014
Flash: Splash Screen
People are wondering how to make an intro screen for their games.
The code below works like this. There's a movie clip called splash. Inside that movie clip, is a button with instance name of playbtn. When you click it, the intro screen disappears. You can find this code by searching the wiki for Splash Screen. You want the button to be inside the splash page movie clip because you want that button to disappear as well.
splash.playbtn.onRelease = function() {
splash._visible = false;
}
The code below works like this. There's a movie clip called splash. Inside that movie clip, is a button with instance name of playbtn. When you click it, the intro screen disappears. You can find this code by searching the wiki for Splash Screen. You want the button to be inside the splash page movie clip because you want that button to disappear as well.
splash.playbtn.onRelease = function() {
splash._visible = false;
}
Subscribe to:
Posts (Atom)