Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zabuzard committed Feb 23, 2016
1 parent c3d8215 commit 8215a23
Show file tree
Hide file tree
Showing 26 changed files with 2,561 additions and 0 deletions.
34 changes: 34 additions & 0 deletions \trunk/source/Spacer/src/BallisticEntity.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package {
import SceneCollisionReaction;

/**
* Form for basic ballistic sprites. Is fast can collide with scenes bounds and then will get destroyed.
**/
public final class BallisticEntity implements PhysicForm {
/**
* Inertia factor of this form.
**/
private static const INERTIA: Number = 0.55;
/**
* Speed of this form.
**/
private static const SPEED: Number = 11;

//@Override
public function getInertia(): Number {
return INERTIA;
}
//@Override
public function isCollidesWithSceneBound(): Boolean {
return true;
}
//@Override
public function getSpeed(): Number {
return SPEED;
}
//@Override
public function getSceneCollisionReaction(): String {
return SceneCollisionReaction.DESTROY;
}
}
}
96 changes: 96 additions & 0 deletions \trunk/source/Spacer/src/Bullet.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package {
import LevelScene;
import PhysicEngine;
import PhysicForm;
import BallisticEntity;
import Utils;

/**
* Sprite class of a bullet that is used by the player while shooting.
**/
public final class Bullet extends Sprite {
/**
* Atackpower of the sprite.
**/
private static const ATACKPOWER: Number = 1;

/**
* Scene of this sprite.
**/
private var levelScene: LevelScene;
/**
* Physically form of this sprite.
**/
private var form: PhysicForm = new BallisticEntity();
/**
* Current facing of the bullet in radians.
**/
private var facingInRadians: Number;
/**
* True if the bullet is currently destroyed triggers an death animation if so.
* Which is not equals alive because the bullet should get removed after the death animation.
**/
private var isDestroyed: Boolean = false;

/**
* Creates a new bullet that flies into a facing direction.
* @param thatLevelScene Scene of the bullet
* @param spawnX X-coordinate the bullet spawns at
* @param spawnY Y-coordinate the bullet spawns at
* @param facingInDegrees Direction bullet should fly into in degrees
* @param thatPhysic Physic engine that affects this bullet
**/
public function Bullet(thatLevelScene: LevelScene, spawnX: int, spawnY: int, facingInDegrees: Number, thatPhysic: PhysicEngine): void {
super(thatLevelScene, thatPhysic, form);
stop();
this.levelScene = thatLevelScene;
setLifepoints(NO_LIFEPOINTS);
setAtackPower(ATACKPOWER);

setX(spawnX);
setY(spawnY);
this.rotation = facingInDegrees;
facingInRadians = Utils.degreesToRadians(facingInDegrees);
thatLevelScene.addBullet(this);
}

/**
* Overrides the default behavior and triggers a death animation before the bullet gets removed from stage by calling super.die().
**/
public override function die(): void {
isDestroyed = true;
}
//@Override
public override function move(): void {
setXA(Math.cos(facingInRadians) * form.getSpeed());
setYA(Math.sin(facingInRadians) * form.getSpeed());
}
//@Override
public override function tick(): void {
if (isAlive()) {
if (!isDestroyed) {
if(!levelScene.isPaused()) {
setXOld(getX());
setYOld(getY());

move();
updateCoords();
}
} else {
animateDeath();
}
}
}
/**
* Animates the death of the bullet and calls super.die() at animations end to remove the bullet from the scene.
**/
private function animateDeath(): void {
if (currentLabel != "destroyed" && currentLabel != "destroyedComplete") {
gotoAndPlay("destroyed");
} else if (currentLabel == "destroyedComplete") {
stop();
super.die();
}
}
}
}
56 changes: 56 additions & 0 deletions \trunk/source/Spacer/src/Digit.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package {
import flash.display.MovieClip;

/**
* Basic class for a ten based digit.
**/
public final class Digit extends MovieClip {
/**
* Upper bound of valid digits.
**/
public static const UPPER_BOUND: Number = 9;
/**
* Lower bound of valid digits.
**/
public static const LOWER_BOUND: Number = 0;

/**
* Current value of the digit.
**/
private var value: Number;

/**
* Creates a new digit with a given starting value or LOWER_BOUND if no provided.
* @param thatDigit Starting value between LOWER_BOUND and UPPER_BOUND
**/
public function Digit(thatValue: Number = LOWER_BOUND): void {
stop();
setValue(thatValue);
}
/**
* Gets the current value of the digit.
* @ Current value of the digit between LOWER_BOUND and UPPER_BOUND
**/
public function getValue(): Number {
return value;
}
/**
* Sets the current value of the digit.
* @param thatValue Value to set between LOWER_BOUND and UPPER_BOUND
**/
public function setValue(thatValue: Number): void {
if(thatValue < LOWER_BOUND || thatValue > UPPER_BOUND) {
thatValue = LOWER_BOUND;
}
this.value = thatValue;
animate();
}
/**
* Updates the animation of the digit by setting the correct texture for the current value.
**/
private function animate(): void {
gotoAndStop("digit" + getValue());
}
}

}
133 changes: 133 additions & 0 deletions \trunk/source/Spacer/src/Fly.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package {
import Utils;
import PhysicEngine;
import PhysicForm;
import NormalEntity;
import LevelScene;

/**
* Sprite class for a basic Fly-typed enemy.
**/
public final class Fly extends Sprite {
/**
* Atackpower of the sprite.
**/
private static const ATACKPOWER: Number = 1;
/**
* Lifepoints of the sprite.
**/
private static const LIFEPOINTS: Number = 5;

/**
* Movement variation in positive and negative degrees of direction.
**/
private static var MOVE_DIR_VARIATION = 60;
/**
* Factor for the upper bound of movement variation from speed.
**/
private static var MOVE_SPEED_UPPER_VARIATION = 3.0;
/**
* Factor for the lower bound of movement variation from speed.
**/
private static var MOVE_SPEED_LOWER_VARATION = 0.5;
/**
* Scene of this sprite.
**/
private var levelScene: LevelScene;
/**
* Physic engine that affects this sprite.
**/
private var physic: PhysicEngine;
/**
* Physically form of this sprite.
**/
private var form: PhysicForm = new NormalEntity();
/**
* True if the animation of this sprite is currently stopped.
**/
private var isAnimLabelStopped: Boolean = true;
/**
* True if the fly is currently destroyed triggers an death animation if so.
* Which is not equals alive because the fly should get removed after the death animation.
**/
private var isDestroyed: Boolean = false;

/**
* Creates a new Fly-typed enemy.
* @param thatLevelScene Scene of this sprite
* @param spawnX X-coordinate the fly spawns at
* @param spawnY Y-coordinate the fly spawns at
* @param thatPhysic Physic engine that affects this sprite
**/
public function Fly(thatLevelScene: LevelScene, spawnX: int, spawnY: int, thatPhysic: PhysicEngine): void {
super(thatLevelScene, thatPhysic, form);
stop();
this.levelScene = thatLevelScene;
this.physic = thatPhysic;
setLifepoints(LIFEPOINTS);
setAtackPower(ATACKPOWER);

setX(spawnX);
setY(spawnY);
thatLevelScene.addFly(this);
}

/**
* Overrides the default behavior and triggers a death animation before the fly gets removed from stage by calling super.die().
**/
public override function die(): void {
isDestroyed = true;
}

//@Override
public override function move(): void {
var moveDirInDeg = this.rotation;
var moveSpeed = form.getSpeed();

//Variation of movement parameters
moveDirInDeg = (moveDirInDeg - MOVE_DIR_VARIATION) + Math.floor(Math.random() * (MOVE_DIR_VARIATION * 2)) + 1;
moveDirInDeg %= Utils.CIRCLE_FULL_DEG;
moveSpeed *= MOVE_SPEED_LOWER_VARATION + (Math.random() * (MOVE_SPEED_UPPER_VARIATION - MOVE_SPEED_LOWER_VARATION));

var moveDirInRad = Utils.degreesToRadians(moveDirInDeg);
setXA(Math.cos(moveDirInRad) * moveSpeed);
setYA(Math.sin(moveDirInRad) * moveSpeed);
}
//@Override
public override function tick(): void {
if (isAlive()) {
if (!isDestroyed) {
if(!levelScene.isPaused()) {
setXOld(getX());
setYOld(getY());

move();
updateCoords();
}
lookAtPlayer();
} else {
animateDeath();
}
}
}
/**
* Animates the death of the fly and calls super.die() at animations end to remove the fly from the scene.
**/
private function animateDeath(): void {
if (currentLabel != "destroyed" && currentLabel != "destroyedComplete") {
gotoAndPlay("destroyed");
} else if (currentLabel == "destroyedComplete") {
stop();
super.die();
}
}
/**
* Changes flys facing to players position.
**/
private function lookAtPlayer(): void {
var xDifference: Number = levelScene.getPlayerX() - getX();
var yDifference: Number = levelScene.getPlayerY() - getY();
this.rotation = Utils.radiansToDegrees(Math.atan2(yDifference, xDifference));
}
}
}
Loading

0 comments on commit 8215a23

Please sign in to comment.