Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override public function update():void
- {
- //do not update the player if we've won
- if (Global.completed) { return; }
- super.update();
- if (inControl)
- {
- FP.camera.y -= Math.round((FP.camera.y + (FP.height - 550)));
- if (shootingDirection.x == 1)
- {
- FP.camera.x -= Math.round((FP.camera.x - (x - FP.width + 600)) / 20);
- }
- else if (shootingDirection.x == -1)
- {
- FP.camera.x -= Math.round((FP.camera.x - ((x - 500) - FP.width + 600)) / 20);
- }
- FP.camera.x = FP.clamp(FP.camera.x, Global.level.minXCamera, Global.level.maxXCamera-800);
- //accelerate
- if (!dead)
- {
- setHitbox(64, 96, 32, 48);
- while (positionList.length > maxPositions)
- {
- delete positionList.shift();
- }
- //shootingDirection.x = 0; shootingDirection.y = 0;
- if (Input.check(Key.RIGHT))
- {
- velocity.x += ACCELERATION;
- shootingDirection.x = 1;
- positionList.push(new Vector2(x, y));
- }
- else if (Input.check(Key.LEFT))
- {
- velocity.x -= ACCELERATION;
- shootingDirection.x = -1;
- positionList.push(new Vector2(x, y));
- }
- else if(Input.check(Key.UP) || Input.check(Key.DOWN)){
- shootingDirection.x = 0;
- }
- if (Input.check(Key.UP))
- {
- shootingDirection.y = -1;
- }
- else if ((Input.check(Key.DOWN) && !collide("Ground", x, y + 1)) ||
- (Input.check(Key.DOWN) && shootingDirection.x != 0))
- {
- shootingDirection.y = 1;
- }
- else if(Input.check(Key.DOWN) && collide("Ground", x, y+1))
- {
- shootingDirection.y = 0;
- setHitbox(64, 64, 32, 32);
- }
- else
- {
- shootingDirection.y = 0;
- }
- shootingDirection.x = shootingDirection.x == 0 && shootingDirection.y == 0 ? 1 : shootingDirection.x;
- //Normal jump. If jump key pressed, and we collide with a wall below us, JUMP
- if (Input.pressed(Key.X) && collide("Ground", x, y + 1)) { velocity.y = - 6; jumpSound.play(); }
- if ((powerUp.press && Input.check(Key.Z)) || (!powerUp.press && Input.pressed(Key.Z)))
- {
- attacking = true;
- if (inControl)
- {
- if (powerUp.ammo == 0)
- {
- world.remove(powerUp);
- powerUp = null;
- powerUp = defaultPowerUp;
- }
- else
- {
- powerUp.shoot(new Vector2(shootingDirection.x * 1000, shootingDirection.y * 1000));
- }
- }
- }
- else
- {
- attacking = false;
- powerUp.shootTimer = 0.0;
- }
- }
- //friction (if we are NOT moving left/right)
- if ((!Input.check(Key.LEFT) && !Input.check(Key.RIGHT)) || dead)
- {
- //reduce speed
- //FP.sign returns -1, 0, or 1 based on the speed.x
- velocity.x -= FP.sign(velocity.x) * FRICTION;
- //if the speed is less than the friction, stop moving (to avoid
- //us starting to move in the other direction, which causes a shake/jitter effect)
- if (Math.abs(velocity.x) < FRICTION) { velocity.x = 0; }
- //set the sprite to the right standing position (based on our current direction)
- if (shootingDirection.x > 0) { /*sprite.play("StandRight"); } else { sprite.play("StandLeft");*/ }
- if (positionList.length > 0)
- {
- positionList.length = 0;
- }
- }
- //maxspeed (stop us from going too fast)
- if (Math.abs(velocity.x) > MAXSPEED.x) { velocity.x = FP.sign(velocity.x) * MAXSPEED.x; }
- if (Math.abs(velocity.y) > MAXSPEED.y) { velocity.y = FP.sign(velocity.y) * MAXSPEED.y; }
- //Pixel Perfect Moving
- //Loop through the following code for how fast our speed (Left/Right) is
- //(ex. if our speed is 3, repeat the following code 3 times)
- for (var i:int = 0; i < Math.abs(velocity.x); i ++)
- {
- //If we DID NOT hit a wall left/right of us (based on our speed (FP.sign)),
- //then move a single pixel in the correct direction.
- //OTHERWISE (else) set our speed to 0 (we hit a wall)
- if (!collide("Ground", x + FP.sign(velocity.x), y)) { x += FP.sign(velocity.x); } else { velocity.x = 0; }
- }
- //this loop is exactly the same as the one above, except for moving UP/DOWN
- for (var j:int = 0; j < Math.abs(Math.floor(velocity.y)); j ++)
- {
- if (!collide("Ground", x, y + FP.sign(velocity.y))) { y += FP.sign(velocity.y); } else { velocity.y = 0; }
- }
- //gravity. increase Y speed so we move down
- velocity.y += GRAVITY;
- }
- else
- {
- if (positionList.length > 0)
- {
- positionList.length = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment