So I created this game, it’s kinda fun (not really). Just kind of having trouble with coming up with ideas to make it better other than graphically. Basically you are a little archer who shoots an arrow at zombies who cross the screen. If you don’t get em then your gotAway counter goes up. Anyway the only thing I have been thinking that would make it better would be for the enemies to take multiple hits before they are removed. Anyway take a look and let me know what you think.
/*-----------------------------------------
****** t0W's ARROW SHOOTER! ******
*-----------------------------------------*/
var heroHealth = 100; // heros starting health
var enemyHealth = 0; //will be used to make enemies take multiple hits, not yet in effect
var num = 1; //arrows shot, starting at 1
var i = 0; //enemy spawned, starting at 0
var gotAway = 0; //zombies that got away, displayed in text ( see (4)ACTION)
var zombieK = 0; //number of zombies killed, displayed in text ( see (4)ACTION)
/*-----------------------------------------
* (1) BEGIN HERO
*-----------------------------------------*/
//Hero's default stance (when not shooting an arrow)
heroDefault = function()
{
hero.armLoose._visible = true;
hero.bowString2._visible = false;
hero.armAttack._visible = true;
hero.bowString._visible = true;
}
//hero should be in default state at start, so call it now
heroDefault();
//Hero's stance when shooting
heroAttack = function()
{
hero.armAttack._visible = false;
hero.armLoose._visible = true;
hero.bowString._visible = false;
hero.bowString2._visible = true;
}
//Character movement (WASD, Arrow keys) & make sure he stays in bounds
hero.onEnterFrame = function()
{
//left
if (Key.isDown(Key.LEFT) || Key.isDown(65))
{
this._x -= 10;
}
//left boundary
if (this._x<30)
{
this._x = 30;
}
//right
if (Key.isDown(Key.RIGHT) || Key.isDown(68))
{
this._x += 10;
}
//right boundary
if (this._x>Stage.width)
{
this._x = Stage.width;
}
//up
if (Key.isDown(Key.UP) || Key.isDown(87))
{
this._y -= 10;
}
//upper boundary
if (this._y<90)
{
this._y = 90;
}
//down
if (Key.isDown(Key.DOWN) || Key.isDown(83))
{
this._y += 10;
}
//lower boundary
if (this._y>Stage.height-50)
{
this._y = Stage.height-50;
}
//angle the hero towards mouse position
var x:Number = _xmouse-this._x;
var y:Number = _ymouse-this._y;
var angleRad:Number = Math.atan2(y, x);
var angleDeg:Number = angleRad/Math.PI*180;
this._rotation = angleDeg;
}
/*-----------------------------------------
* END HERO
*-----------------------------------------*/
/*------------------------------------------------------------------------------
* (2) BEGIN ENEMY
* Note: Enemies death occurs in the shootArrow function (see (3) ARROWS )
*-------------------------------------------------------------------------------*/
var enemyArray = new Array(); //stores movie clip instances of enemies as they spawn
//Enemy function
newEnemy = function ()
{
//create a new movieClip instance of enemy when this function is called
var enemy = _root.attachMovie("angryEyes", "zombie"+i, _root.getNextHighestDepth());
enemy._y = 80+random(475); //enemy start position (y axis)
enemy._x = 800; //enemy start position (x axis)
enemy.onEnterFrame = function()
{
//enemy moves slightly upwards if player is above them
if (this._y>_root.hero._y)
{
this._y -= 1;
}
//enemy moves slightly downwards if player is below them
if (this._y<_root.hero._y)
{
this._y += 1;
}
//enemy's movement speed left
this._x -= 5+random(5);
//If enemy and hero (hero's hat) touch each other
if (this.hitTest(_root.hero.heroHat))
{
//Decrease health and make sure the health cannot be less than 0
if (heroHealth>=0)
{
heroHealth--; //take away 1 health for every frame that the hero is touching an enemy
_root.healthBar._x = 18; //healthbar location on the x axis (so that it stays in one place when health changes)
_root.healthBar._width -= 2.37; //2.37 is 1/100th the length of the health bar, it decreases with heroHealth
}
//Make sure health cannot be less than 0
if (heroHealth<=0)
{
heroHealth = 0;
}
//Enemies push hero back, but not out of stage
if (_root.hero._x>=30)
{
_root.hero._x -= 12;
}
}
//Give enemies some random movement on the y-axis (makes them stagger) and keep them in bounds
if (this._y > 80 && this._y < Stage.height-50)
{
this._y += -2.5+random(5);
}
//Upper boundary, keeps enemies below hero's status bar
if (this._y < 80)
{
this._y = 80;
}
//Lower boundary
if (this._y > Stage.height-50)
{
this._y = Stage.height-50;
}
//*Note: left and right boundaries are enemies' exit and spawn points respectively
//Remove enemies if they go out of stage and increase gotAway counter
if (wall.wall1.hitTest(this))
{
removeMovieClip(this);
gotAway++;
this.addListener(gotAway); //variable reused in a text string in (4)ACTION, listener is needed
}
}
//increment zombie value for creating unique instances and add enemy to array
i++;
addEnemy = enemyArray.push(enemy);
}
/*-----------------------------------------
* END ENEMY
*-----------------------------------------*/
/*-----------------------------------------
* (3) BEGIN ARROWS
*-----------------------------------------*/
shootArrow = function ()
{
//create a new movieClip instance of bullet (an arrow, which is a reserved term by flash)
var bullet = _root.attachMovie("bullet", "bullet"+num, _root.getNextHighestDepth());
var point = {x:this.hero.gunTip._x, y:this.hero.gunTip._y};//gunTip is a nested invisible movie clip in hero
this.hero.localToGlobal(point);
bullet._x = point.x;
bullet._y = point.y;
bullet._rotation = _root.hero._rotation; //bullet rotates based on hero rotation
//the arrow on the hero movieClip is a graphic that's hidden when shootArrow is called in (4) ACTION
heroAttack(); //changes graphics
bullet.onEnterFrame = function()
{
bullet._x += Math.cos(bullet._rotation*(Math.PI/180))*35; //x-axis speed based on rotation
bullet._y += Math.sin(bullet._rotation*(Math.PI/180))*35; //y-axis speed based on rotation
//remove arrows when they go off screen so they don't fly forever and bog down system
//instead of using StageWidth and Height there is a movieClip (wall) further out so that you can't see arrows dissapear
if (wall.wall1.hitTest(bullet) || wall.wall2.hitTest(bullet) || wall.wall3.hitTest(bullet) || wall.wall4.hitTest(bullet))
{
removeMovieClip(this);
}
//Loop through enemy array and check for hit between arrows (x,y) and zombies
for (i=0; i<_root.enemyArray.length; i++)
{
//Check for hit
if (_root.enemyArray*.hitTest(this._x, this._y, true))
{
//Remove arrow if it hits
removeMovieClip(this);
//Steal 1 health when you shoot an enemy,
if (heroHealth<100)
{
heroHealth++;
_root.healthBar._width += 2.37;
}
//enemyHealth--; //not yet in effect
tutorial.text = enemyArray*; //just for testing, displays which zombie was hit in middle text on status bar
if (enemyHealth<=0)//this always evaluates true because enemy health is not yet in effect, set to 0 at top
{
//create a new movieClip instance of deadEnemy in the last place that our enemy was when he got hit
var deadEnemy = _root.attachMovie("deadEnemy", "deadEnemy"+num, _root.getNextHighestDepth(), {_x:enemyArray*._x, _y:enemyArray*._y});
//remove the enemy instance that was hit
removeMovieClip(enemyArray*);
zombieK++; //increment the number displayed in text for zombies killed
deadEnemy.blink.selectable = false;
deadEnemy.blink.text = " "; //Display text as enemy dies, such as +1 or "ouch" etc
}
}
}
num++; //unique identifier for each arrow
}
}
/*-----------------------------------
* END ARROWS
*-----------------------------------*/
/*----------------------------------------------
* ..... (4) ACTION
*----------------------------------------------*/
//Spawn new Enemy at predetermined interval in milliseconds (2nd parameter)
setInterval(newEnemy, 800); //800ms, interval works independent of the flash timeline - frames per second
//Shoot an arrow
onMouseDown = function ()
{
shootArrow();
}
//Return to default stance after shooting
onMouseUp = function ()
{
heroDefault();
}
//Dynamic text that is displayed on the status bar, may include more than text in the future
onEnterFrame = function ()
{
//text isn't selectable so you dont accidentally click it when moving around and shooting
zombieKilled.selectable = false;
zombieExit.selectable = false;
heroHealthText.selectable = false;
tutorial.selectable = false;
//Displays your health left over the health bar
heroHealthText.text = "Health +"+heroHealth;
//if only one zombie killed it says zombie rip instead of zombies rip, so english correct
if (zombieK == 1)
{
zombieKilled.text = zombieK+" Zombie RIP!";
}
if (zombieK>1)
{
zombieKilled.text = zombieK+" Zombies RIP!";
}
//Displays how many enemies escaped your clutches
if (gotAway>0)
{
zombieExit.text = gotAway+" ESCAPED!";
}
};
/*------------------------------------------------
* END ACTION
*/
Feel free to rip on it. Be honest.