Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
feat: improving hitboxes (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo authored Nov 2, 2023
1 parent 7e669bb commit 8d8a283
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/game/dash_run_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,13 @@ class DashRunGame extends LeapGame
score += 1000 * currentLevel;
currentLevel++;
}

void showHitBoxes() {
descendants()
.whereType<PhysicalEntity>()
.where(
(element) => element is Player || element is Item || element is Enemy,
)
.forEach((entity) => entity.debugMode = true);
}
}
6 changes: 4 additions & 2 deletions lib/game/entities/enemy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Enemy extends PhysicalEntity<DashRunGame> {

@override
Future<void> onLoad() async {
size = sprite.srcSize;
size = Vector2.all(gameRef.tileSize * .5);
position = Vector2(tiledObject.x, tiledObject.y);

final path =
Expand All @@ -33,8 +33,10 @@ class Enemy extends PhysicalEntity<DashRunGame> {

add(
SpriteComponent(
size: size,
size: Vector2.all(gameRef.tileSize),
sprite: sprite,
anchor: Anchor.center,
position: size / 2 - Vector2(0, size.y / 2),
),
);

Expand Down
6 changes: 3 additions & 3 deletions lib/game/entities/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Player extends JumperCharacter<DashRunGame> {
await super.onLoad();

input = gameRef.input;
size = Vector2.all(gameRef.tileSize);
size = Vector2.all(gameRef.tileSize * .5);
walkSpeed = gameRef.tileSize * 5;
minJumpImpulse = world.gravity * 0.5;
cameraAnchor = PlayerCameraAnchor(
Expand All @@ -68,10 +68,10 @@ class Player extends JumperCharacter<DashRunGame> {
);

runningAnimation = SpriteAnimationComponent(
size: size,
size: Vector2.all(gameRef.tileSize),
animation: animation,
anchor: Anchor.center,
position: size / 2,
position: size / 2 - Vector2(0, size.y / 2),
);

add(runningAnimation);
Expand Down
10 changes: 8 additions & 2 deletions lib/map_tester/view/map_tester_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class _MapTesterViewState extends State<MapTesterView> {
child: const Text('Load folder'),
)
else
Row(
mainAxisAlignment: MainAxisAlignment.center,
Wrap(
children: [
ElevatedButton(
onPressed: () {
Expand Down Expand Up @@ -93,6 +92,13 @@ class _MapTesterViewState extends State<MapTesterView> {
},
child: const Text('Teleport to end'),
),
const SizedBox(width: 16),
ElevatedButton(
onPressed: () {
game?.showHitBoxes();
},
child: const Text('Show hitboxes'),
),
],
),
const SizedBox(height: 16),
Expand Down

0 comments on commit 8d8a283

Please sign in to comment.