Sign in to follow this  
  • entries
    90
  • comments
    66
  • views
    72299

I Has Enemies!

Sign in to follow this  
Tesseract

85 views

Attack of the iPods of DOOM

After a beautiful weekend in northern Michigan (Blissfest, Harbor Springs, Petoskey) with the girlfriend, I am back in the saddle coding into the wee hours of the morning.

Clicking the screenshot will take you to the latest prototype. I just ported the Enemy class from AS2 to AS3 (total time: 1 hour), and have things working pretty well. Next step: collision detection with the player shots. After that: The enemies shoot back.

Here is the Enemy class, thus far:

package{
import flash.display.*;
public class Enemy extends Sprite {
private var game:Gyruss;
private var index:Number;
private var radius:Number = 0;
private var minRadius:Number = 10;
private var maxRadius:Number = 160;
private var centerX:Number;
private var centerY:Number;
private var angle:Number;
private var direction:Number; // clockwise or counterclockwise
private var approachDirection:Number = 1; // approaching or receding
private var APPROACH_SPEED:Number = .3; // approach speed
private var SPEED:Number = Math.PI*2/300; // rotation speed
private var THETA:Number = Math.PI * 2;
private var RAD_DEG:Number = Math.PI/180;

public var health:Number = 100;

public var isDead:Boolean = false;

public function Enemy($game:Gyruss) {
game = $game;
centerX = game.centerX;
centerY = game.centerY;

x = centerX;
y = centerY;

setRandomDirection();
graphics.beginFill(0xcccccc,100);
graphics.drawRoundRect(-25,-10,50,20,5,5);
graphics.endFill();

graphics.beginFill(0xff0000,100);
graphics.drawCircle(0,0,7);
graphics.endFill();

graphics.beginFill(0x000000,100);
graphics.drawCircle(0,0,3);
graphics.endFill();

}

public function setDirection($d:Number):void {
direction = $d;
}
public function setRandomDirection():void {
direction = (Math.round(Math.random())*2)-1;
direction = 1;
}

public function move():void {
THETA += (SPEED * direction);
x = centerX + (radius * Math.cos(THETA));
y = centerY + (radius * Math.sin(THETA));
rotation = Math.atan2(y-centerY,x-centerX)/RAD_DEG;
scaleX = scaleY = radius/maxRadius;
if((radius < maxRadius && approachDirection==1) || (radius > minRadius && approachDirection == -1)) {
radius += (APPROACH_SPEED*approachDirection);
} else {
approachDirection *= -1;
}
}

public function takeDamage($d:Number):void {
health -= $d;
if(health <= 0) explode();
}
public function explode():void {
isDead = true;
}
}
}
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now