updateMouseBorderControl

This commit is contained in:
2022-06-22 00:08:14 +00:00
parent cee2e30230
commit 736a1982b4
5 changed files with 37 additions and 6 deletions

View File

@@ -97,4 +97,5 @@
->{FlxG.keys.pressed.LEFT} ->{FlxG.keys.pressed.LEFT}
->{FlxG.keys.pressed.RIGHT} ->{FlxG.keys.pressed.RIGHT}
->{FlxG.keys.pressed.UP} ->{FlxG.keys.pressed.UP}
->{FlxG.keys.pressed.DOWN})) ->{FlxG.keys.pressed.DOWN})
(worldCamera.updateMouseBorderControl elapsed CAMERA_SPEED 0.15))

View File

@@ -159,6 +159,7 @@ class Scenario {
stream.tracePosition(); stream.tracePosition();
var townIdx = 0; var townIdx = 0;
// TODO find an end condition for this loop
while (true) { while (true) {
var name = stream.readCString(); var name = stream.readCString();
@@ -170,7 +171,10 @@ class Scenario {
towns[townIdx++] = map; scen.towns[townIdx++] = map;
// TODO don't
break;
} }
// 1E274: Fort Talrus (name of town 0) // 1E274: Fort Talrus (name of town 0)

View File

@@ -29,7 +29,7 @@ class TileMap {
public function wallSheet(num:Int) { public function wallSheet(num:Int) {
return switch (type) { return switch (type) {
case Town(det): case Town(underground, det):
if (num == 1) if (num == 1)
det.wallSheet1; det.wallSheet1;
else else

View File

@@ -11,6 +11,8 @@
(+= camera.scroll.x movement.x) (+= camera.scroll.x movement.x)
(+= camera.scroll.y movement.y))) (+= camera.scroll.y movement.y)))
(var :Map<FlxCamera,FlxCamera> borderCameras (new Map))
// Add a border sprite on top of this camera's viewport, scaling the border to frame the viewport, // Add a border sprite on top of this camera's viewport, scaling the border to frame the viewport,
// and downsizing and shifting the viewport to fit within the border's opaque frame // and downsizing and shifting the viewport to fit within the border's opaque frame
(function addBorder [:FlxCamera camera :FlxSprite border] (function addBorder [:FlxCamera camera :FlxSprite border]
@@ -37,6 +39,7 @@
(border.setGraphicSize camera.width camera.height) (border.setGraphicSize camera.width camera.height)
(border.updateHitbox) (border.updateHitbox)
(FlxG.cameras.add borderCamera false) (FlxG.cameras.add borderCamera false)
(dictSet borderCameras camera borderCamera)
(set border.cameras [borderCamera]) (set border.cameras [borderCamera])
(set borderCamera.bgColor FlxColor.TRANSPARENT) (set borderCamera.bgColor FlxColor.TRANSPARENT)
(FlxG.state.add border) (FlxG.state.add border)
@@ -45,6 +48,29 @@
(+= camera.x dx) (+= camera.x dx)
(+= camera.y dy) (+= camera.y dy)
(-= camera.width dx (* border.scale.x borderSizeRight)) (-= camera.width dx (* border.scale.x borderSizeRight))
(-= camera.height dx (* border.scale.y borderSizeBottom))))) (-= camera.height dy (* border.scale.y borderSizeBottom)))))
// TODO updateMouseBorderControl (function updateMouseBorderControl [:FlxCamera camera :Float elapsed :Float speed :Float heightFraction]
(let [viewport (ifLet [bc (dictGet borderCameras camera)] bc camera)
left viewport.x
top viewport.y
right (+ viewport.x viewport.width)
bottom (+ viewport.y viewport.height)
// Use the same margin size for x and y, and calculate it based on height
// (in a landscape view, this just makes more sense to me)
margin (* viewport.height heightFraction)
mPos (FlxG.mouse.getScreenPosition)]
(updateKeyControl camera elapsed speed
// when the camera takes the whole screen, count the letterbox zones as margin
->(if (= left 0)
(<= mPos.x (+ left margin))
(<= left mPos.x (+ left margin)))
->(if (= right FlxG.width)
(<= (- right margin) mPos.x)
(<= (- right margin) mPos.x right))
->(if (= top 0)
(<= mPos.y (+ top margin))
(<= top mPos.y (+ top margin)))
->(if (= bottom FlxG.height)
(<= (- bottom margin) mPos.y)
(<= (- bottom margin) mPos.y bottom)))))

View File

@@ -127,7 +127,7 @@
->{FlxG.keys.pressed.RIGHT} ->{FlxG.keys.pressed.RIGHT}
->{FlxG.keys.pressed.UP} ->{FlxG.keys.pressed.UP}
->{FlxG.keys.pressed.DOWN}) ->{FlxG.keys.pressed.DOWN})
(FlxG.camera.updateMouseBorderControl elapsed KEYBOARD_SCROLL_SPEED 0.15)
// don't move the ui camera before ui has been placed -- new UI elements could appear offscreen // don't move the ui camera before ui has been placed -- new UI elements could appear offscreen
(when (> uiGroup.length 0) (when (> uiGroup.length 0)
(unless (and textInput textInput.hasFocus) (unless (and textInput textInput.hasFocus)