Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.display.Sprite;
- public class TestUnit extends MovieClip{
- var collideMarker:Sprite = new Sprite();
- var walkSpeed:Number = 1;
- var unitWidth:int = 10;
- var laneNumber:int;
- var unitsInLane:Array = [];
- var colliding:Boolean
- var playerControlled:Boolean;
- var parentClass:BattleScreen
- public function TestUnit() {
- // constructor code
- this.addChild(collideMarker)
- }
- public function setupUnit(laneNum:int,pClass,pCon:Boolean){
- laneNumber = laneNum
- this.y = 250+(laneNumber*50) - this.height
- parentClass = pClass
- playerControlled = pCon
- }
- public function updateUnit(){
- moveForward();
- }
- public function moveForward(){
- //collideMarker.graphics.clear();
- collideMarker.graphics.lineStyle(1,0xFF0000)
- if(playerControlled){
- collideMarker.graphics.drawCircle(unitWidth,0,3)
- }
- else{
- collideMarker.graphics.drawCircle(-unitWidth,0,3)
- }
- colliding = false;
- getUnitsInLane();
- for(var i:int = 0;i<=unitsInLane.length-1;i++){
- if(collideMarker.hitTestObject(unitsInLane[i].unitBody)){
- colliding = true;
- }
- }
- if(!colliding){
- if(playerControlled){
- this.x += walkSpeed
- }
- else{
- this.x -= walkSpeed
- }
- }
- }
- function getUnitsInLane(){
- unitsInLane = [];
- for(var i:int = 0;i<= parentClass.playerUnits.length-1;i++){
- if(parentClass.playerUnits[i].laneNumber == this.laneNumber && parentClass.playerUnits[i] != this){
- unitsInLane.push(parentClass.playerUnits[i])
- }
- }
- for(var j:int = 0;j<= parentClass.enemyUnits.length-1;j++){
- if(parentClass.enemyUnits[j].laneNumber == this.laneNumber && parentClass.enemyUnits[j] != this){
- unitsInLane.push(parentClass.enemyUnits[j])
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement