Skip to content
Browse files

Cool stuff

  • Loading branch information...
1 parent 7635748 commit bd047fb7665e3fdaf597ce6f922eb482b5d8f56d @Draknek committed
Showing with 107 additions and 19 deletions.
  1. +1 −1 Enemy.as
  2. +44 −0 FollowPlayer.as
  3. +2 −9 KeyboardPlayer.as
  4. +21 −5 Level.as
  5. +8 −2 Menu.as
  6. +31 −0 MousePlayer.as
  7. +0 −2 Player.as
View
2 Enemy.as
@@ -38,7 +38,7 @@ package
public function hit (b:Bullet): void
{
- world.remove(this);
+ if (world) world.remove(this);
}
public override function update (): void
View
44 FollowPlayer.as
@@ -0,0 +1,44 @@
+package
+{
+ import net.flashpunk.*;
+ import net.flashpunk.graphics.*;
+ import net.flashpunk.masks.*;
+ import net.flashpunk.utils.*;
+
+ public class FollowPlayer extends Player
+ {
+ public var target:Player;
+
+ public function FollowPlayer (p:Player, _x:Number = 0, _y:Number = 0)
+ {
+ super(_x, _y, 0, 0, false);
+
+ target = p;
+ }
+
+ public override function update (): void
+ {
+ oldX = x;
+ oldY = y;
+
+ stun = Math.max(stun, target.stun);
+ target.stun = stun;
+
+ var dx:Number = target.x - x;
+ var dy:Number = target.y - y;
+ var dz:Number = FP.distance(dx, dy);
+ dx /= dz;
+ dy /= dz;
+
+ vx += dx * 0.01 * (dz - 100);
+ vy += dy * 0.01 * (dz - 100);
+
+ vx *= 0.9;
+ vy *= 0.9;
+
+ x += vx;
+ y += vy;
+ }
+ }
+}
+
View
11 KeyboardPlayer.as
@@ -14,6 +14,8 @@ package
private var leftKey:int;
private var rightKey:int;
+ public const SPEED:Number = 3;
+
public function KeyboardPlayer (_x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0, _arrowKeys:Boolean = true )
{
super(_x, _y, _vx, _vy, _arrowKeys);
@@ -31,15 +33,6 @@ package
leftKey = Key.A;
rightKey = Key.D;
}
-
- if (_arrowKeys) {
- image = new Image(P1_IMAGE);
- } else {
- image = new Image(P2_IMAGE);
- }
-
- image.centerOO();
- graphic = image;
}
public override function update (): void
View
26 Level.as
@@ -12,14 +12,27 @@ package
public var link:Link;
public var time:int = 0;
- public function Level (twoPlayer:Boolean = true)
+ public var twoPlayer:Boolean;
+ public var keyboard:Boolean;
+
+ public var gameOver:Boolean = false;
+
+ public function Level (twoPlayer:Boolean = true, keyboard:Boolean = true)
{
+ this.twoPlayer = twoPlayer;
+ this.keyboard = keyboard;
+
if (twoPlayer) {
add(p1 = new KeyboardPlayer(100, 100, 0, 0, false));
add(p2 = new KeyboardPlayer(540,380,0,0, true));
} else {
- add(p1 = new Player(100, 100, 0, 0, false));
- add(p2 = new Player(540,380,0,0, true));
+ if (keyboard) {
+ add(p1 = new KeyboardPlayer(320, 300, 0, 0, true));
+ } else {
+ add(p1 = new MousePlayer());
+ }
+
+ add(p2 = new FollowPlayer(p1, 320,240));
}
add(link = new Link(p1, p2));
@@ -27,7 +40,8 @@ package
public override function update (): void
{
- if (Input.pressed(Key.R)) FP.world = new Level;
+ if (Input.pressed(Key.ESCAPE)) FP.world = new Menu;
+ if (Input.pressed(Key.R)) FP.world = new Level(twoPlayer, keyboard);
time++;
time = time % 2300;
@@ -57,7 +71,9 @@ package
super.update();
- if (p1.stun > 0 && p2.stun > 0) {
+ if (!gameOver && p1.stun > 0 && p2.stun > 0) {
+ gameOver = true;
+
remove(p1);
remove(p2);
remove(link);
View
10 Menu.as
@@ -15,11 +15,17 @@ package
Text.size = 24;
- var two:Button = new Button(0, 0, new Text("Start"), function ():void {
+ var oneMouse:Button = new Button(0, 0, new Text("One player (mouse)"), function ():void {
+ FP.world = new Level(false, false);
+ });
+ var oneKeys:Button = new Button(0, 0, new Text("One player (arrows)"), function ():void {
+ FP.world = new Level(false, true);
+ });
+ var two:Button = new Button(0, 0, new Text("Two player (WASD/arrows)"), function ():void {
FP.world = new Level(true);
});
- addElements([title, two]);
+ addElements([title, oneMouse, oneKeys, two]);
}
private function addElements(list:Array):void
View
31 MousePlayer.as
@@ -0,0 +1,31 @@
+package
+{
+ import net.flashpunk.*;
+ import net.flashpunk.graphics.*;
+ import net.flashpunk.masks.*;
+ import net.flashpunk.utils.*;
+
+ public class MousePlayer extends Player
+ {
+ public function MousePlayer ()
+ {
+ super(Input.mouseX, Input.mouseY, 0, 0, true);
+ }
+
+ public override function update (): void
+ {
+ oldX = x;
+ oldY = y;
+
+ vx = Input.mouseX - x;
+ vy = Input.mouseY - y;
+
+ vx *= 0.6;
+ vx *= 0.6;
+
+ x += vx;
+ y += vy;
+ }
+ }
+}
+
View
2 Player.as
@@ -18,8 +18,6 @@ package
public var image:Image;
- public const SPEED:Number = 3;
-
public var radius:Number = 8;
public var oldX:Number = 0;

0 comments on commit bd047fb

Please sign in to comment.
Something went wrong with that request. Please try again.