Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.KeyboardEvent;
- import flash.ui.Keyboard;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- public class Skirmish extends MovieClip
- {
- var pressed1:Boolean = false;
- var timer:int = 0;
- var enemyTimer:int = 0;
- var yourSpendingPoints:int = 100;
- var enemySpendingPoints:int = 100;
- var textPoints:TextField=new TextField();
- var Enemies:Array = [];
- var Allies:Array = [];
- public function Skirmish()
- {
- stage.addEventListener(Event.ENTER_FRAME,MainLoop);
- stage.addEventListener(KeyboardEvent.KEY_DOWN,KeysDown);
- }
- public function MainLoop(e:Event)
- {
- textPoints.x=10;
- textPoints.y=10;
- addChild(textPoints);
- textPoints.text="VicePoints:"+yourSpendingPoints;
- timer++;
- enemyTimer++;
- handleUserSpawning();
- handleEnemySpawning();
- doYourSpawnedAi();
- doEnemySpawnedAi();
- handleSkirmishes();
- addSpendingPoints();
- }
- function KeysDown(e:KeyboardEvent)
- {
- switch (e.keyCode)
- {
- case 49 :
- pressed1 = true;
- trace("pressed 1");
- //spawnEnemy(1);
- break;
- // eventually ill expand this to do cases 49-56 keys 1-8
- // each key will summon a new entity
- }
- }
- public function handleUserSpawning()
- {
- if (pressed1==true&&(yourSpendingPoints-25)>=0&&timer%60==0)
- {//&&timer%60==0
- var e = new Enemy(0,2,50,1);
- addChild(e);
- Enemies.push(e);
- yourSpendingPoints -= 25;
- pressed1 = false;
- }
- }
- public function handleEnemySpawning()
- {
- if ((enemySpendingPoints-25)>=0&&timer%60==0)
- {
- var a = new Enemy(330,-2,50,-1);
- addChild(a);
- Allies.push(a);
- enemySpendingPoints -= 25;
- }
- }
- public function doYourSpawnedAi()
- {
- for (var i:int=Enemies.length-1; i>=0; i--)
- {
- Enemies[i].doAi();
- if (Enemies[i].x >= 330)
- {
- Enemies[i].canMove = false;
- Enemies[i].shouldAttack = true;
- trace("time to stop moving and start attacking");
- }
- }
- }
- public function addSpendingPoints()
- {
- if (timer%24==0)
- {
- yourSpendingPoints += 5;
- }
- if (timer%36==0)
- {
- enemySpendingPoints += 5;
- }
- }
- public function doEnemySpawnedAi()
- {
- for (var i:int=Allies.length-1; i>=0; i--)
- {
- Allies[i].doAi();
- if (Allies[i].x <= 30+Allies[i].width/2)
- {
- Allies[i].x+=2;
- Allies[i].shouldAttack = true;
- if(Allies[i].shouldAttack ==true&&timer%200==0)
- {
- removeChild(Allies[i]);
- Allies.splice(i,1);
- }
- trace("time to stop moving and start attacking");
- }
- for(var j=i-1;j>=0;j--)
- {
- if(Allies[j].hitTestObject(Allies[i]))
- {
- // Allies[i].canMove = false;
- Allies[i].x+=2;
- }
- }
- }
- }
- public function handleSkirmishes()
- {
- for (var i:int =Enemies.length-1; i>=0; i--)
- {
- for (var j:int =Allies.length-1; j>=0; j--)
- {
- if (Enemies[i].hitTestObject(Allies[j]))
- {
- Enemies[i].canMove = false;
- Enemies[i].shouldAttack = true;
- removeChild(Enemies[i]);
- Enemies.splice(i,1);
- removeChild(Allies[j]);
- Allies.splice(j,1);
- // was getting a bug here error 1010
- // the for loop was trying to check the removed bullet and enemy for collision
- // break statement inserted to fix the error becuase if they are removed no need to check
- break;
- }
- }
- }
- }
- ///*************************************************************************
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment