Skip to content
Browse files

camera scroll

  • Loading branch information...
1 parent 22e72d3 commit fbbc8f4be35697931c22349ae73a4d04a6d590ae @discolingua committed Feb 13, 2012
Showing with 30 additions and 12 deletions.
  1. +1 −0 src/Assets.as
  2. +11 −8 src/Boxer.as
  3. +4 −0 src/GameWorld.as
  4. +14 −4 src/Shark.as
  5. BIN src/assets/graphics/tigershark.png
View
1 src/Assets.as
@@ -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;
}
}
View
19 src/Boxer.as
@@ -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;
@@ -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 {
View
4 src/GameWorld.as
@@ -7,6 +7,7 @@ package
{
public static var boxer:Boxer;
+ public static var shark:Shark;
public static var level:Level;
public function GameWorld()
@@ -46,6 +47,9 @@ package
boxer = new Boxer;
add(boxer);
+
+ shark = new Shark;
+ add(shark);
//
// FP.world.add(new HUD);
}
View
18 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";
+
}
}
}
View
BIN 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.
Something went wrong with that request. Please try again.