From ae8149833015c2616aa9f00e42d8765d367e854e Mon Sep 17 00:00:00 2001 From: devpedrofurquim Date: Sat, 7 Dec 2024 19:54:13 -0300 Subject: [PATCH] feat: Adiciona Wife Mother and Wife Father on LevelOne --- assets/tiles/Level-01.tmx | 22 +++++++++------- lib/components/WifesFather.dart | 26 +++++++++++++++++++ lib/components/WifesMom.dart | 26 +++++++++++++++++++ lib/components/level_one.dart | 46 +++++++++++++++++++++++++++++++++ lib/components/npc.dart | 3 +++ 5 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 lib/components/WifesFather.dart create mode 100644 lib/components/WifesMom.dart diff --git a/assets/tiles/Level-01.tmx b/assets/tiles/Level-01.tmx index eca3f2b..d99bbea 100644 --- a/assets/tiles/Level-01.tmx +++ b/assets/tiles/Level-01.tmx @@ -1,5 +1,5 @@ - + @@ -40,22 +40,26 @@ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24 - + - - - - + + + + + + + + + + - - - + diff --git a/lib/components/WifesFather.dart b/lib/components/WifesFather.dart new file mode 100644 index 0000000..9fa14d8 --- /dev/null +++ b/lib/components/WifesFather.dart @@ -0,0 +1,26 @@ +import 'dart:ui'; + +import 'package:moonshiner_game/components/npc.dart'; +import 'package:flame/components.dart'; + +class WifesFather extends AbstractNPC { + WifesFather({required Vector2 position}) + : super( + npcCharacter: 'Wifes Father', + dialogues: [ + "Goodbye, my son-in-law!", + "Take care of our daughter and future grandchild.", + ], + position: position, + ); + + @override + Color getColorForNPC() => const Color(0xFFAA0000); // Dark red for the father + + @override + void updateMovement(double dt) { + // This NPC does not move, so velocity is always zero + current = NPCState.idle; + velocity = Vector2.zero(); + } +} diff --git a/lib/components/WifesMom.dart b/lib/components/WifesMom.dart new file mode 100644 index 0000000..002ad8f --- /dev/null +++ b/lib/components/WifesMom.dart @@ -0,0 +1,26 @@ +import 'dart:ui'; + +import 'package:moonshiner_game/components/npc.dart'; +import 'package:flame/components.dart'; + +class WifesMom extends AbstractNPC { + WifesMom({required Vector2 position}) + : super( + npcCharacter: 'Wifes Mother', + dialogues: [ + "Farewell, my dear daughter!", + "Please take care of yourself and your husband.", + ], + position: position, + ); + + @override + Color getColorForNPC() => const Color(0xFFFFAAAA); // Light pink for the mom + + @override + void updateMovement(double dt) { + // This NPC does not move, so velocity is always zero + current = NPCState.idle; + velocity = Vector2.zero(); + } +} diff --git a/lib/components/level_one.dart b/lib/components/level_one.dart index 52528a5..05d90fc 100644 --- a/lib/components/level_one.dart +++ b/lib/components/level_one.dart @@ -2,6 +2,8 @@ import 'package:moonshiner_game/components/background_tile.dart'; import 'package:moonshiner_game/components/clouds.dart'; import 'package:moonshiner_game/components/npc.dart'; import 'package:moonshiner_game/moonshiner.dart'; +import 'package:moonshiner_game/components/WifesFather.dart'; +import 'package:moonshiner_game/components/WifesMom.dart'; import 'package:moonshiner_game/components/player.dart'; import 'package:moonshiner_game/components/wife.dart'; import 'package:flame/components.dart'; @@ -30,6 +32,9 @@ class LevelOne extends Level { // Customize dialogues for the Wife in LevelOne _customizeWifeDialogues(); + + // Spawn the Wife's parents (Father and Mom) + _spawnParents(); } // Override _setupBackground for LevelOne @@ -85,4 +90,45 @@ class LevelOne extends Level { print("Wife component not found in children."); } } + + void _spawnParents() { + // Position them based on your map or desired coordinates + final fatherPosition = Vector2(100, 200); // Example position + final motherPosition = Vector2(150, 200); // Example position + + // Create the father and mother NPCs + final wifesFather = WifesFather(position: fatherPosition); + final wifesMom = WifesMom(position: motherPosition); + + // Add them to the game world + add(wifesFather); + add(wifesMom); + + // Optional: Handle goodbye logic (see next section) + wifesFather.onPlayerInteraction = _onGoodbyeFather; + wifesMom.onPlayerInteraction = _onGoodbyeMother; + } + + bool saidGoodbyeToFather = false; + bool saidGoodbyeToMother = false; + + void _onGoodbyeFather() { + saidGoodbyeToFather = true; + _checkAllGoodbyes(); + } + + void _onGoodbyeMother() { + saidGoodbyeToMother = true; + _checkAllGoodbyes(); + } + + void _checkAllGoodbyes() { + if (saidGoodbyeToFather && saidGoodbyeToMother) { + gameRef + .showDeveloperMessage("You said goodbye to everyone. Time to leave!"); + Future.delayed(Duration(seconds: 2), () { + endLevelAndMoveToMoonshiner(); + }); + } + } } diff --git a/lib/components/npc.dart b/lib/components/npc.dart index 30d74d4..18cd8c8 100644 --- a/lib/components/npc.dart +++ b/lib/components/npc.dart @@ -30,6 +30,9 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent int maxStillnessDuration = 60; int currentDialogueIndex = 0; + // Add this field for player interaction callbacks + void Function()? onPlayerInteraction; + AbstractNPC({ required this.npcCharacter, required this.dialogues,