home *** CD-ROM | disk | FTP | other *** search
- class Player extends Position
- {
- var color;
- var current_target;
- var bubble;
- static var crosshair;
- var left = false;
- var right = false;
- var up = false;
- var down = false;
- var space = false;
- var ex = false;
- var zed = false;
- var space_down = false;
- var target_count = 0;
- var tutorial = false;
- var speed_x = 0;
- var speed_y = 0;
- var speed_z = 10;
- static var air_resistance_factor = 0.12;
- static var acceleration = 2.5;
- static var missiles_left = 5;
- var health = 100;
- var whited_out = false;
- var white = {ra:100,rb:255,ga:100,gb:255,ba:100,bb:255,aa:100,ab:255};
- var normal = {ra:100,rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0};
- var dead_y = 0;
- function Player()
- {
- super();
- Position.camera_x = 0;
- Position.camera_y = 0;
- Position.camera_z = 0;
- _global.game_paused = false;
- this.color = new Color(this);
- Player.crosshair = this._parent.attachMovie("crosshair","crosshair",this._parent.getNextHighestDepth());
- this._x = Position.center_x;
- this._y = Position.center_y + Position.center_y_offset;
- }
- function usePlayer()
- {
- if(this.health > 0)
- {
- this.useControls();
- }
- else
- {
- this.dying();
- }
- this.drawToScreen();
- this.cameraFollow(this);
- if(this.health <= 0)
- {
- Position.camera_y = this.dead_y;
- }
- var _loc5_ = false;
- var _loc4_ = 0;
- while(_loc4_ < this._parent.enemies.length)
- {
- if(this._parent.enemies[_loc4_].hitTest(Player.crosshair.fill))
- {
- _loc5_ = true;
- this.current_target = this._parent.enemies[_loc4_];
- if(this._parent.enemies[_loc4_].attack_clip.tonsil.hitTest(Player.crosshair.fill))
- {
- this.current_target = this._parent.enemies[_loc4_].tonsil_target;
- }
- }
- _loc4_ = _loc4_ + 1;
- }
- if(this.zed)
- {
- if(_loc5_)
- {
- this.target_count = this.target_count + 1;
- Player.crosshair.gotoAndStop(2);
- }
- else
- {
- this.target_count = 0;
- Player.crosshair.gotoAndStop(1);
- }
- }
- else if(_loc5_ && this.target_count > 5)
- {
- this.fireMissile(this.current_target);
- this.target_count = 0;
- Player.crosshair.gotoAndStop(1);
- }
- else
- {
- this.target_count = 0;
- Player.crosshair.gotoAndStop(1);
- }
- this.moveCrosshair();
- this.fireCannon();
- if(this.whited_out)
- {
- this.whited_out = null;
- }
- else if(this.whited_out == null)
- {
- this.unWhite();
- }
- if(this.space)
- {
- if(!this.space_down)
- {
- _global.game_paused = true;
- _root.hud.play();
- }
- }
- else
- {
- this.space_down = false;
- }
- if(this.render_z > 500)
- {
- _root.play();
- }
- }
- function checkInput()
- {
- if(!this.tutorial)
- {
- if(_global.control_type == 1)
- {
- this.left = Key.isDown(37);
- this.right = Key.isDown(39);
- if(_global.updown == "reverse")
- {
- this.up = Key.isDown(38);
- this.down = Key.isDown(40);
- }
- else
- {
- this.up = Key.isDown(40);
- this.down = Key.isDown(38);
- }
- this.ex = Key.isDown(88);
- this.zed = Key.isDown(90);
- }
- else if(_global.control_type == 2)
- {
- this.left = Key.isDown(65);
- this.right = Key.isDown(68);
- if(_global.updown == "reverse")
- {
- this.up = Key.isDown(87);
- this.down = Key.isDown(83);
- }
- else
- {
- this.up = Key.isDown(83);
- this.down = Key.isDown(87);
- }
- this.ex = Key.isDown(78);
- this.zed = Key.isDown(77);
- }
- this.space = Key.isDown(32);
- }
- else
- {
- this.speed_z = 0;
- }
- }
- function useControls()
- {
- this.checkInput();
- if(this.left)
- {
- this.accelerateX(- Player.acceleration);
- }
- else if(this.right)
- {
- this.accelerateX(Player.acceleration);
- }
- else
- {
- this.accelerateX(this.speed_x * (Player.air_resistance_factor * 0.6));
- }
- if(this.up)
- {
- this.accelerateY(Player.acceleration);
- }
- else if(this.down)
- {
- this.accelerateY(- Player.acceleration);
- }
- else
- {
- this.accelerateY(this.speed_y * (Player.air_resistance_factor * 0.6));
- }
- if(this.left)
- {
- if(this._rotation - 8 > -50)
- {
- this._rotation -= 8;
- }
- else
- {
- this._rotation = -50;
- }
- }
- else if(this.right)
- {
- if(this._rotation + 8 < 50)
- {
- this._rotation += 8;
- }
- else
- {
- this._rotation = 50;
- }
- }
- else
- {
- this._rotation -= this._rotation / 6;
- }
- if(this.up)
- {
- if(this._currentframe > 1)
- {
- this.gotoAndStop(this._currentframe - 1);
- }
- }
- else if(this.down)
- {
- if(this._currentframe < 20)
- {
- this.gotoAndStop(this._currentframe + 1);
- }
- }
- else
- {
- if(this._currentframe > 10)
- {
- this.gotoAndStop(this._currentframe - 1);
- }
- else if(this._currentframe < 10)
- {
- this.gotoAndStop(this._currentframe + 1);
- }
- this.bubble.blue.gotoAndStop(2);
- }
- if(this.left)
- {
- this.bubble.blue.gotoAndStop(3);
- }
- else if(this.right)
- {
- this.bubble.blue.gotoAndStop(4);
- }
- else if(this.up)
- {
- this.bubble.blue.gotoAndStop(6);
- }
- else if(this.down)
- {
- this.bubble.blue.gotoAndStop(5);
- }
- else
- {
- this.bubble.blue.gotoAndStop(2);
- }
- this.bubble.gotoAndStop(this._currentframe);
- this.moveX();
- this.moveY();
- this.moveZ();
- }
- function moveCrosshair()
- {
- Player.crosshair._x = this._x + this._rotation;
- Player.crosshair._y = this._y - 70 - 3 * (this._currentframe - 10);
- Player.crosshair.swapDepths(this.getDepth() - 1);
- var _loc3_ = Player.crosshair._x - this._x;
- var _loc2_ = this._y - Player.crosshair._y;
- Player.crosshair.gunfire._rotation = 180 * Math.atan2(_loc3_,_loc2_) / 3.141592653589793;
- Player.crosshair.gunfire._yscale = _loc2_;
- }
- function fireCannon()
- {
- if(this.ex)
- {
- Player.crosshair.gunfire.gotoAndPlay(2);
- for(var _loc2_ in this._parent.enemies)
- {
- if(this._parent.enemies[_loc2_].hitTest(Player.crosshair.fill))
- {
- this._parent.enemies[_loc2_].getShot(Player.crosshair.fill);
- }
- else
- {
- this._parent.enemies[_loc2_].unWhite();
- }
- }
- }
- else if(Player.crosshair.gunfire._currentframe != 1)
- {
- for(_loc2_ in this._parent.enemies)
- {
- this._parent.enemies[_loc2_].unWhite();
- }
- Player.crosshair.gunfire.gotoAndStop(1);
- }
- }
- function fireMissile(p_target)
- {
- if(Player.missiles_left > 0)
- {
- Player.missiles_left--;
- var _loc2_ = this._parent.attachMovie("player_missile","missile" + this._parent.objects.length,-1000 + this._parent.objects.length);
- _loc2_.launch(this,p_target,70,this.speed_z + 10);
- this._parent.addObject(_loc2_);
- }
- }
- function getShot()
- {
- this.whiteOut();
- this.reduceHealth(1);
- }
- function getMissiled()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(4);
- }
- function getEnergyBalled()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(3);
- }
- function getObstacled()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(1);
- }
- function getBitten()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(10);
- }
- function getBarreled()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(1);
- }
- function getRocked()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(1);
- }
- function getLasered()
- {
- this._parent.badComment();
- this.whiteOut();
- this.reduceHealth(8);
- }
- function whiteOut()
- {
- if(!this.whited_out)
- {
- this.color.setTransform(this.white);
- this.whited_out = true;
- }
- }
- function increaseHealth(p_ammount)
- {
- this.health += p_ammount;
- if(this.health > 100)
- {
- this.health = 100;
- }
- this.updateHealthBar();
- }
- function increaseAmmo()
- {
- Player.missiles_left += 5;
- if(Player.missiles_left > 99)
- {
- Player.missiles_left = 99;
- }
- }
- function reduceHealth(p_ammount)
- {
- this.health -= p_ammount;
- if(this.health <= 0)
- {
- this.die();
- }
- this.updateHealthBar();
- }
- function updateHealthBar()
- {
- var _loc3_ = 101 - Math.ceil(this.health);
- _root.hud.elements.health_bar.gotoAndStop(_loc3_);
- }
- function unWhite()
- {
- this.color.setTransform(this.normal);
- this.whited_out = false;
- }
- function die()
- {
- this.bubble.gotoAndStop(10);
- this.bubble.blue.gotoAndStop(2);
- this.gotoAndStop(21);
- this._rotation = 0;
- this.speed_x = 0;
- this.speed_y = 5;
- this.dead_y = this.pos_y;
- this.die = function()
- {
- };
- }
- function dying()
- {
- this.moveY();
- this.moveZ();
- if(this._y > 500)
- {
- _root.fadeo.gotoAndPlay(1);
- _root.gotoAndPlay(_root._currentframe - 1);
- }
- }
- function moveX()
- {
- this.pos_x += this.speed_x;
- if(this.pos_x > 10000)
- {
- this._parent.shiftToX(-10000);
- }
- else if(this.pos_x < -10000)
- {
- this._parent.shiftToX(-10000);
- }
- }
- function moveY()
- {
- this.pos_y += this.speed_y;
- if(this.pos_y > 10000)
- {
- this._parent.shiftToY(-10000);
- }
- else if(this.pos_y < -10000)
- {
- this._parent.shiftToY(10000);
- }
- }
- function moveZ()
- {
- this.pos_z += this.speed_z;
- }
- function accelerateX(p_a)
- {
- this.speed_x += p_a;
- this.speed_x -= this.speed_x * Player.air_resistance_factor;
- }
- function accelerateY(p_a)
- {
- this.speed_y += p_a;
- this.speed_y -= this.speed_y * Player.air_resistance_factor;
- }
- function accelerateZ(p_a)
- {
- this.speed_z += p_a;
- }
- }
-