Skip to content

Commit 3ae7495

Browse files
committed
proper camera controls
1 parent 1dc904d commit 3ae7495

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/Main.as

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ package
105105
Input.define("next", Key.TAB);
106106
Input.define("restart", Key.R);
107107
Input.define("tas", Key.T);
108-
Input.define("camleft", Key.Q);
109-
Input.define("camright", Key.E);
110108

109+
Input.define("cam_up", Key.I);
110+
Input.define("cam_left", Key.J);
111+
Input.define("cam_down", Key.K);
112+
Input.define("cam_right", Key.L);
113+
Input.define("cam_reset", Key.Q);
111114

112115
instance = this;
113116
BDScreen = new ImgScreen().bitmapData;

src/game/Player.as

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ package game
249249

250250
public function cameraFollow() : void
251251
{
252-
FP.camera.x = Math.min(Math.max(x - 160,0),this.level.width - 320) + FP.cameraOffset;
253-
FP.camera.y = Math.min(Math.max(y + this.cameraOffsetY - 120,0),this.level.height - 240);
252+
FP.camera.x = Math.min(Math.max(x - 160,0),this.level.width - 320) + FP.cameraOffset.x;
253+
FP.camera.y = Math.min(Math.max(y + this.cameraOffsetY - 120,0),this.level.height - 240) + FP.cameraOffset.y;
254254
}
255255

256256
private function dropJetpack(flash:Boolean = true) : void

src/net/flashpunk/FP.as

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
*/
8080
public static var camera:Point = new Point;
8181

82-
public static var cameraOffset:Number = 0;
82+
public static var cameraOffset:Point = new Point;
83+
84+
public static var oldCamera:Point = new Point;
8385

8486
public static var tas:TAS;
8587

src/net/flashpunk/debug/Console.as

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package net.flashpunk.debug
1717
import net.flashpunk.utils.Key;
1818
import game.tas.TASUtility;
1919
import game.Player;
20+
import flash.geom.Point;
2021

2122
/**
2223
* FlashPunk debug console; can use to log information or pause the game and view/move Entities and step the frame.
@@ -305,20 +306,44 @@ package net.flashpunk.debug
305306
if (Input.pressed("pause"))
306307
{
307308
FP.engine.paused = !FP.engine.paused; _butPlay.visible = FP.engine.paused; _butPause.visible = !FP.engine.paused;
309+
if (FP.engine.paused) FP.oldCamera = FP.camera.clone();
310+
else FP.oldCamera = new Point;
308311
}
309312
if (Input.pressed("frameadvance1")) stepFrame();
310313
else if (Input.check("frameadvance")) stepFrame();
311314
if (Input.pressed("hitboxes")) _renderBoxes = !_renderBoxes;
312315

313-
if (Input.pressed("camleft"))
316+
var mod:Number = 3;
317+
318+
if (Input.check("cam_right"))
319+
{
320+
FP.cameraOffset.x += mod;
321+
if (FP.engine.paused) panCamera(mod, 0);
322+
}
323+
else if (Input.check("cam_left"))
324+
{
325+
FP.cameraOffset.x += -mod;
326+
if (FP.engine.paused) panCamera(-mod, 0);
327+
}
328+
329+
if (Input.check("cam_up"))
314330
{
315-
FP.cameraOffset -= 20;
316-
if (paused) panCamera(-20, 0);
331+
FP.cameraOffset.y += -mod;
332+
if (FP.engine.paused) panCamera(0, -mod);
317333
}
318-
else if (Input.pressed("camright"))
334+
else if (Input.check("cam_down"))
319335
{
320-
FP.cameraOffset += 20;
321-
if (paused) panCamera(20, 0);
336+
FP.cameraOffset.y += mod;
337+
if (FP.engine.paused) panCamera(0, mod);
338+
}
339+
340+
if (Input.pressed("cam_reset"))
341+
{
342+
FP.cameraOffset = new Point;
343+
if (FP.engine.paused)
344+
{
345+
panCamera(FP.oldCamera.x - FP.camera.x, FP.oldCamera.y - FP.camera.y)
346+
}
322347
}
323348
}
324349

0 commit comments

Comments
 (0)