Skip to content

Commit

Permalink
some more minor code cleanup + comments
Browse files Browse the repository at this point in the history
  • Loading branch information
searlm committed Dec 1, 2012
1 parent 9add51b commit 9e26f43
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 34 deletions.
10 changes: 8 additions & 2 deletions src/AmmoHost.as
Expand Up @@ -12,14 +12,20 @@ package
import net.flashpunk.tweens.misc.ColorTween;
import net.flashpunk.utils.Ease;

/**
* A host entity that drops ammo on rupture.
*/
public class AmmoHost extends Entity
{
private static const LAYER:int = 50;
private static const RUPTURE_TIME:Number = 1.5; // seconds to rupture
private static const SPEED:uint = 80; // pixels per second

[Embed(source='assets/ammo_host_96x128.png')] private const HOST:Class;
[Embed(source='assets/bullet_17x17.png')] private const BULLET:Class;
[Embed(source='assets/ammo_host_96x128.png')]
private const HOST:Class;

[Embed(source='assets/bullet_17x17.png')]
private const BULLET:Class;

private var hostImage:Image;
private var explosionEmitter:Emitter;
Expand Down
6 changes: 5 additions & 1 deletion src/Bullet.as
Expand Up @@ -7,12 +7,16 @@ package
import net.flashpunk.Sfx;
import net.flashpunk.graphics.Image;

/**
* The basic player weapon.
*/
public class Bullet extends Entity
{
private static const LAYER:int = 100;
private static const SPEED:uint = 300;

[Embed(source='assets/bullet_17x17.png')] private const BULLET:Class;
[Embed(source='assets/bullet_17x17.png')]
private const BULLET:Class;

private var bulletImage:Image;

Expand Down
10 changes: 8 additions & 2 deletions src/CloneHost.as
Expand Up @@ -12,14 +12,20 @@ package
import net.flashpunk.tweens.misc.ColorTween;
import net.flashpunk.utils.Ease;

/**
* A host entity to spew clones on rupture.
*/
public class CloneHost extends Entity
{
private static const LAYER:int = 50;
private static const RUPTURE_TIME:Number = 1.5; // seconds to rupture
private static const SPEED:uint = 70; // pixels per second

[Embed(source='assets/clone_host_128x126.png')] private const HOST:Class;
[Embed(source='assets/hero_clone_16x18.png')] private const CLONE:Class;
[Embed(source='assets/clone_host_128x126.png')]
private const HOST:Class;

[Embed(source='assets/hero_clone_16x18.png')]
private const CLONE:Class;

private var hostImage:Image;
private var explosionEmitter:Emitter;
Expand Down
7 changes: 6 additions & 1 deletion src/Enemy.as
Expand Up @@ -12,13 +12,18 @@ package
import net.flashpunk.tweens.misc.ColorTween;
import net.flashpunk.utils.Ease;

/**
* The basic enemy entity -- chases the player, kills
* on contact.
*/
public class Enemy extends Entity
{
private static const LAYER:int = 100;
private static const MIN_Y_COORD:int = 0;
private static const SPEED:uint = 40;

[Embed(source='assets/bad_dude_64x64.png')] private const BAD_DUDE:Class;
[Embed(source='assets/bad_dude_64x64.png')]
private const BAD_DUDE:Class;

private var enemyImage:Image;
private var explosionEmitter:Emitter;
Expand Down
6 changes: 6 additions & 0 deletions src/HumanOutline.as
Expand Up @@ -9,6 +9,9 @@ package
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Text;

/**
* Helper class for drawing the overall progress bar.
*/
public class HumanOutline
{
// the outline should be behind pretty much everything else
Expand Down Expand Up @@ -50,6 +53,9 @@ package
world.add(percentTextEntity);
}

/**
* Update the completion percentage.
*/
public function set progress(percent:uint):void
{
percentComplete = percent;
Expand Down
4 changes: 2 additions & 2 deletions src/MyWorld.as
Expand Up @@ -193,7 +193,7 @@ package
progressChart.toForeground();

var directionsText:Text = new Text(directions);
directionsText.font = "Blackout Midnight";
directionsText.font = "TitleFont";
directionsText.color = 0xdddddd;
directionsText.size = 24;

Expand All @@ -205,7 +205,7 @@ package
add(directionsEntity);

var mainText:Text = new Text(label);
mainText.font = "Blackout Midnight";
mainText.font = "TitleFont";
mainText.color = 0xffffff;
mainText.size = 72;

Expand Down
62 changes: 43 additions & 19 deletions src/Player.as
Expand Up @@ -12,6 +12,9 @@ package
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;

/**
* The controllable player entity.
*/
public class Player extends Entity
{
private static const LAYER:int = 100;
Expand Down Expand Up @@ -76,15 +79,53 @@ package
return;
}

handlePickups();
handleMovement();
handleWeapons();
}

/**
* Process powerup collisions.
*/
private function handlePickups():void
{
// TODO multiple powerup collisions in a frame?
var p:Powerup = collide("powerup", x, y) as Powerup;
if (p) {
//pickupSound.play();
bullets++;
(FP.world as MyWorld).ammoCollected++;
p.destroy();
}
}

/**
* Process weapons input.
*/
private function handleWeapons():void
{
if (bulletWait > 0) {
bulletWait -= FP.elapsed;
}

if (bulletWait <= 0 && bullets > 0 && Input.pressed(Key.SPACE)) {
var bullet:Bullet = FP.world.create(Bullet, false) as Bullet;//new Bullet();
bullet.reset();
bullet.x = x + width / 2 - bullet.width / 2;
bullet.y = y - 16;
FP.world.add(bullet);

bullets--;
(FP.world as MyWorld).shotsFired++;
bulletWait = 0.1;
}
}

/**
* Process movement controls, and update the graphics accordingly.
*/
private function handleMovement():void
{
image = IMAGE_DOWN;
mask = MASK_DOWN;

Expand All @@ -94,8 +135,7 @@ package
if (Input.check(Key.UP)) { yOffset = -offset; image = IMAGE_UP; mask = MASK_UP;}
if (Input.check(Key.DOWN)) { yOffset = offset; image = IMAGE_DOWN; mask = MASK_DOWN;}
if (Input.check(Key.LEFT)) { xOffset = -offset; image = IMAGE_LEFT; mask = MASK_LEFT;}
if (Input.check(Key.RIGHT)) { xOffset = offset; image = IMAGE_RIGHT; mask = MASK_RIGHT;}

if (Input.check(Key.RIGHT)) { xOffset = offset; image = IMAGE_RIGHT; mask = MASK_RIGHT;}
moveBy(xOffset, yOffset);

graphic = image;
Expand All @@ -105,23 +145,7 @@ package

var myWorld:MyWorld = FP.world as MyWorld;
y = Math.max(y, 0);
y = Math.min(y, FP.screen.height - height);

if (bulletWait > 0) {
bulletWait -= FP.elapsed;
}

if (bulletWait <= 0 && bullets > 0 && Input.pressed(Key.SPACE)) {
var bullet:Bullet = FP.world.create(Bullet, false) as Bullet;//new Bullet();
bullet.reset();
bullet.x = x + width / 2 - bullet.width / 2;
bullet.y = y - 16;
FP.world.add(bullet);

bullets--;
(FP.world as MyWorld).shotsFired++;
bulletWait = 0.1;
}
y = Math.min(y, FP.screen.height - height);
}
}
}
7 changes: 6 additions & 1 deletion src/Powerup.as
Expand Up @@ -6,12 +6,17 @@ package
import net.flashpunk.Sfx;
import flash.display.BitmapData;

/**
* The ammo pickup entity.
*/
public class Powerup extends Entity
{
private static const LAYER:int = 100;
private static const SPEED:uint = 60; // pixels per second

[Embed(source='assets/bullet_17x17.png')] private const BULLET:Class;
[Embed(source='assets/bullet_17x17.png')]
private const BULLET:Class;

private var powerupImage:Image;

public function Powerup()
Expand Down
11 changes: 5 additions & 6 deletions src/TitleScreen.as
Expand Up @@ -17,16 +17,15 @@ package
[Embed(source='assets/hero_400x439.png')]
private const HERO:Class;

[Embed(source = 'assets/Blackout Midnight.ttf', embedAsCFF="false", fontFamily = 'Blackout Midnight')]
[Embed(source = 'assets/Blackout Midnight.ttf', embedAsCFF="false", fontFamily = 'TitleFont')]
private const MAIN_FONT:Class;

private var mainText:Text = new Text("infeckshun");
private var directionsText:Text = new Text("press the spacebar to begin");
private var copyrightText:Text = new Text("(C) S. Martin & L. Briguglio, 2012");

public function TitleScreen()
{
// TODO figure out dat CSS (?)
{
FP.screen.color = 0x2b2b2b;

var hero:Entity = new Entity;
Expand All @@ -41,17 +40,17 @@ package

mainText.color = 0xf9f9f9;
mainText.size = 56;
mainText.font = "Blackout Midnight";
mainText.font = "TitleFont";
addText(mainText, 32, FP.screen.height / 2);

directionsText.color = 0xdddddd;
directionsText.size = 20;
directionsText.font = "Blackout Midnight";
directionsText.font = "TitleFont";
addText(directionsText, 32, FP.screen.height / 2 + 64);

copyrightText.color = 0x999999;
copyrightText.size = 18;
copyrightText.font = "Blackout Midnight";
copyrightText.font = "TitleFont";
addText(copyrightText, FP.screen.width - copyrightText.textWidth - 8, FP.screen.height - copyrightText.textHeight - 4);
}

Expand Down

0 comments on commit 9e26f43

Please sign in to comment.