Skip to content

Commit

Permalink
camera scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
discolingua committed Feb 14, 2012
1 parent 22e72d3 commit fbbc8f4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Assets.as
Expand Up @@ -11,5 +11,6 @@ package
// sprites

[Embed(source = "assets/graphics/boxer_spritesheet.png")] public static const SPR_BOXER:Class;
[Embed(source = "assets/graphics/tigershark.png")] public static const SPR_TIGERSHARK:Class;
}
}
19 changes: 11 additions & 8 deletions src/Boxer.as
Expand Up @@ -25,23 +25,20 @@ package

private var boxerSprite:Spritemap = new Spritemap(Assets.SPR_BOXER, 150, 300);

public function Boxer():void {
public function Boxer() {
layer = 50;
graphic = boxerSprite;
x = 60;
y = 250;
type = "boxer";
}

override public function update():void {
override public function update():void{
move();
}

private function move():void {
var newX:Number;
var newY:Number;
var mySpeed:Number = maxVel * FP.elapsed;


punchCooldown > 0 ? punchCooldown-- : 0;
blockCooldown > 0 ? blockCooldown-- : 0;
crouchCooldown > 0 ? crouchCooldown-- : 0;
Expand Down Expand Up @@ -74,18 +71,24 @@ package
if (y == floorY) { crouch(); }
}
}

// position = position + ( verticalVelocity + initialVerticalVelocity ) * 0.5 * dt;
x += xVel * FP.elapsed;
y += yVel * FP.elapsed;

if (xVel < 0) { xVel += 1; } else if (xVel > 0) { xVel -= 1; } // decelerate xVel
if (y < floorY) {
yVel += gravityConstant;
} else if (y > floorY) {
y = floorY;
yVel = 0;
}


// scroll camera
if ( (abs(xVel) > 0) && x > 100 ) {
FP.camera.x = x - 100;
}

}

private function abs( value:Number ):Number {
Expand Down
4 changes: 4 additions & 0 deletions src/GameWorld.as
Expand Up @@ -7,6 +7,7 @@ package
{

public static var boxer:Boxer;
public static var shark:Shark;
public static var level:Level;

public function GameWorld()
Expand Down Expand Up @@ -46,6 +47,9 @@ package

boxer = new Boxer;
add(boxer);

shark = new Shark;
add(shark);
//
// FP.world.add(new HUD);
}
Expand Down
18 changes: 14 additions & 4 deletions src/Shark.as
@@ -1,9 +1,19 @@
package
{
public class Shark
{
public function Shark()
{
import net.flashpunk.*;
import net.flashpunk.graphics.Image;

public class Shark extends Entity {

private var sharkSprite:Image = new Image(Assets.SPR_TIGERSHARK);

public function Shark():void {
layer = 60;
graphic = sharkSprite;
x = 500;
y = 120;
type = "shark";

}
}
}
Binary file added src/assets/graphics/tigershark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbbc8f4

Please sign in to comment.