This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: viewport and camera parallax tweaks (#15)
- Loading branch information
1 parent
7772c7e
commit c95495d
Showing
7 changed files
with
1,025 additions
and
876 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
class CameraDebugger extends RectangleComponent { | ||
CameraDebugger({ | ||
super.position, | ||
}) : super( | ||
paint: Paint()..color = Colors.pink, | ||
size: Vector2.all(150), | ||
priority: 100, | ||
); | ||
|
||
final _direction = Vector2.zero(); | ||
double _speed = 300; | ||
|
||
@override | ||
void update(double dt) { | ||
super.update(dt); | ||
|
||
position += _direction * _speed * dt; | ||
} | ||
|
||
@override | ||
FutureOr<void> onLoad() async { | ||
await super.onLoad(); | ||
|
||
add( | ||
KeyboardListenerComponent( | ||
keyDown: { | ||
LogicalKeyboardKey.keyW: (_) { | ||
_direction.y = -1; | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyS: (_) { | ||
_direction.y = 1; | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyA: (_) { | ||
_direction.x = -1; | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyD: (_) { | ||
_direction.x = 1; | ||
return false; | ||
}, | ||
LogicalKeyboardKey.space: (_) { | ||
_speed = 900; | ||
return false; | ||
}, | ||
}, | ||
keyUp: { | ||
LogicalKeyboardKey.keyW: (_) { | ||
if (_direction.y == -1) { | ||
_direction.y = 0; | ||
} | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyS: (_) { | ||
if (_direction.y == 1) { | ||
_direction.y = 0; | ||
} | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyA: (_) { | ||
if (_direction.x == -1) { | ||
_direction.x = 0; | ||
} | ||
return false; | ||
}, | ||
LogicalKeyboardKey.keyD: (_) { | ||
if (_direction.x == 1) { | ||
_direction.x = 0; | ||
} | ||
return false; | ||
}, | ||
LogicalKeyboardKey.space: (_) { | ||
_speed = 300; | ||
return false; | ||
}, | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'camera_debugger.dart'; | ||
export 'enemies.dart'; | ||
export 'items.dart'; | ||
export 'player.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters