View Source

com

arm

package {
    import com.globals;
    import flash.events.Event;
    import com.myMath.myAngle;
    import com.globalFunctions;
    import flash.display.MovieClip;
    public class arm extends weaponControl {
        private var parentClip:MovieClip;
        public function arm(parentClip:MovieClip):void {
            this.parentClip=parentClip;
            addEventListener(Event.ENTER_FRAME, armRotation, false, 0, true);
        }
        public function armRotation(e:Event):void {
            x=parentClip.x;
            y=parentClip.y-35;
            rotation=myAngle.getAngle(globalFunctions.getX(this), globals.main.stage.mouseX,globalFunctions.getY(this),globals.main.stage.mouseY);
        }
    }
}

classCompiler

package {
    //this class contains several object of classes that i need to dynamically load with getDefinitionByName. 
    //the problem was that in order to use that method, i needed to have some kind of reference to the class somewhere else already
    //so this is a useless class, just used to compile 'dynamic' classes, instead of messing up my important classes. 
    //http://nwebb.co.uk/blog/?p=186
    import com.levels.*;
    public class classCompiler {
        private var comp1:level1Control;
        private var comp2:level2Control;
        private var comp3:level3Control;
        public function classCompiler():void {
        }
    }
}

Control
package {
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.MovieClip;
    import com.globals;
    public class Controls {
        static var upArrowPress:Boolean=false;
        static var downArrowPress:Boolean=false;
        static var rightArrowPress:Boolean=false;
        static var leftArrowPress:Boolean=false;
        private var keyListener:MovieClip;
        public function Controls(keyListener:MovieClip) {
            this.keyListener=keyListener;
            globals.main.stage.addEventListener(KeyboardEvent.KEY_DOWN,checkDown,false, 0, true);
            globals.main.stage.addEventListener(KeyboardEvent.KEY_UP,checkUp,false, 0, true);
        }
        protected function checkDown(e:KeyboardEvent):void {
            switch (e.keyCode) {
                case 87 :
                    //keyUp
                    if (! upArrowPress) {
                        upArrowPress=true;
                        keyListener.upPress();
                    }
                    break;
                case 83 :
                    //keyDown
                    if (! downArrowPress) {
                        downArrowPress=true;
                        keyListener.downPress();
                    }
                    break;
                case 68 :
                    //keyRight
                    keyListener.rightHold();
                    if (! rightArrowPress) {
                        rightArrowPress=true;
                        keyListener.rightPress();
                    }
                    break;
                case 65 :
                    //keyLeft
                    if (! leftArrowPress) {
                        leftArrowPress=true;
                        keyListener.leftPress();
                    }
                    break;
            }
        }
        protected function checkUp(e:KeyboardEvent):void {
            switch (e.keyCode) {
                case 87 :
                    //keyUp
                    if (upArrowPress) {
                        upArrowPress=false;
                    }
                    break;
                case 83 :
                    //keyDown
                    if (downArrowPress) {
                        downArrowPress=false;

                    }
                    break;
                case 68 :
                    //keyUp
                    if (rightArrowPress) {
                        rightArrowPress=false;
                        keyListener.rightUp();
                    }
                    break;
                case 65 :
                    //keyLeft
                    if (leftArrowPress) {
                        leftArrowPress=false;
                        keyListener.leftUp();
                    }
                    break;
            }
        }
    }
}

gameStart

package {
    import com.levels.*;
    import com.globals;
    import flash.utils.getDefinitionByName;
    public class gameStart {
        private var currentLevelObj:level;
        private var currentLevelID:int;
        private var currentLevelControl:levelControl;
        private var compiler:classCompiler;
        public function gameStart():void {
            currentLevelID=1;
            compiler = new classCompiler();
            buildLevel();
        }
        private function buildLevel():void {
            currentLevelObj=level(loadLevel("level"+currentLevelID));
            currentLevelControl=new (loadClass("com.levels.level"+currentLevelID+"Control"))(currentLevelObj);
            globals.setLevel(currentLevelObj);
            globals.setVars();
            globals.main.addChild(currentLevelObj);

        }
        private function loadClass(objString:String):Class {
            var classType:Class=getDefinitionByName(objString) as Class;
            return classType;
        }
        private function loadLevel(objectString:String):Object {
            var classType:Class=getDefinitionByName(objectString) as Class;
            var newObject:Object = new classType();
            return newObject;
        }
    }
}

Hero

package {
    import com.interfaces.pausable;
    import com.interfaces.jetPackInterface;
    import com.physics.*;
    import flash.events.Event;
    import flash.display.MovieClip;
    import com.globals;
    import com.weapons.jetPack;
    public class Hero extends objMovement implements pausable,jetPackInterface {
        private var keyStrokes:Controls;
        private var jumpHeight:int;
        private var currentSprite:String;
        private var walking:Boolean;
        private var idle:Boolean;
        private var jetpack:jetPack;
        private var armCannon:arm;
        private var weaponInventory:Array;
        public function Hero():void {
            jumpHeight=20;
            armCannon = new arm(this);
            parent.addChild(armCannon);
            jetpack=new jetPack(this);
            walking=false;
            idle=false;
            globals.setHero(this);
            radius=10;
            speedMax=8;
            keyStrokes=new Controls(this);
            addEventListener(Event.ENTER_FRAME, update, false, 0, true);
        }
        public function modifySpeedX(mod:Number):void {
            if ((xSpeed<=speedMax) &&(xSpeed>=-speedMax)) {
                xSpeed+=mod;
                if(xSpeed>speedMax){
                    xSpeed=speedMax;
                }
                if(xSpeed<(-speedMax)){
                    xSpeed=-speedMax;
                }
            }
        }
        public function modifySpeedY(mod:Number):void {
            if ((ySpeed<speedMax) &&(ySpeed>-speedMax)) {
                ySpeed+=mod;
            }
        }
        private function update(e:Event):void {
            scaleX=dir;
            if(Controls.upArrowPress){
                jetpack.jetPackIgnite();
            }

            if (right) {
                modifySpeedX(Speed);
            }
            if (left) {
                modifySpeedX(-Speed);
            }
            movementUpdate();
            if (! haveAir) {
                if (! walking) {
                    if (right||left) {
                        walking=true;
                        gotoAndStop('run');
                    } else {
                        if (! idle) {
                            if ((xSpeed>2)||(xSpeed<(2*-1))) {
                                gotoAndStop('stop');
                            } else {
                                gotoAndStop('land');
                            }
                            idle=true;
                        }
                    }
                }

            } else {
                if (walking) {
                    gotoAndStop('fall');
                    walking=false;
                }
                idle=false;
            }
        }
        public function pauseSelf():void {
        }
        public function unpauseSelf():void {
        }
        public function upPress():void {
            if (! haveAir) {
                idle=false;
                gotoAndStop('jump');
                ySpeed=- jumpHeight;
            }else{
                if(ySpeed>0){
                ySpeed=0;
                }
            }
        }
        public function downPress():void {
        }
        public function rightHold():void {
        }
        public function leftHold():void {
        }
        public function rightPress():void {
            right=true;
            startWalk();
            dir=1;
        }
        private function startWalk():void {
            idle=false;
            if (! haveAir) {
                gotoAndStop('runStart');
            }
        }
        private function stopWalk():void {
            if (walking) {
                gotoAndStop('stop');
            }
        }
        public function leftPress():void {
            left=true;
            startWalk();
            dir=-1;
        }
        public function rightUp():void {
            stopWalk();
            right=false;
        }
        public function leftUp():void {
            stopWalk();
            left=false;
        }
        public function noFuel():void {
        }
    }
}

scrollerDocumentClass

package {
    import flash.display.MovieClip;
    import com.globals;
        import com.camera.Cam;

    public class scrollerDocumentClass extends MovieClip {
        private var camera:Cam;
        public function scrollerDocumentClass():void {

            globals.setMain(this);//must set before starting game. 
            globals.setGravity(1);//must set before starting game. 

            var startup:gameStart = new gameStart();
            camera = new HUD();
            globals.main.addChild(camera)
            globals.setCam(camera, 2);//must set before starting game.
        }
    }
}

weaponControl
package {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import com.globals;
    import com.weapons.*;
    public class weaponControl extends MovieClip{
        public function weaponControl():void {
            globals.main.stage.addEventListener(MouseEvent.CLICK, mouseClick, false, 0, true);

        }
        private function mouseClick(e:MouseEvent):void {
            var miss:missile= new missile(rotation, 5);
            //miss.x=globalFunctions.main.hero
            globals.main.addChild(miss);
        }
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License