Skip to content

Commit

Permalink
feat: Adiciona Wife Mother and Wife Father on LevelOne
Browse files Browse the repository at this point in the history
  • Loading branch information
devpedrofurquim committed Dec 7, 2024
1 parent 4eb8ca0 commit ae81498
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 9 deletions.
22 changes: 13 additions & 9 deletions assets/tiles/Level-01.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="40" height="23" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="32">
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="40" height="23" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="34">
<tileset firstgid="1" name="Moonshiner" tilewidth="16" tileheight="16" tilecount="242" columns="22">
<image source="../images/Terrain/Terrain (16x16).png" width="352" height="176"/>
</tileset>
Expand Down Expand Up @@ -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
</data>
</layer>
<objectgroup id="2" name="SpawnPoints" visible="0">
<objectgroup id="2" name="SpawnPoints">
<object id="5" name="Player" type="Player" x="480" y="224" width="32.1917" height="31.0211"/>
<object id="14" name="Lamp" type="Objects" x="128" y="224" width="32" height="32"/>
<object id="17" name="Paper" type="Objects" x="224" y="224" width="32" height="32"/>
<object id="18" name="Gun" type="Objects" x="64" y="224" width="32" height="32"/>
<object id="26" name="Baker" type="NPC" x="320" y="224" width="32" height="32">
<object id="29" name="Door" type="Door" x="416" y="144" width="48" height="64"/>
<object id="31" name="Wife" type="Wife" x="528" y="208" width="32.1917" height="31.0211"/>
<object id="32" name="WifesFather" x="71.3333" y="220" width="32" height="32">
<properties>
<property name="isVertical" type="bool" value="false"/>
<property name="offPos" type="float" value="8"/>
<property name="offSetN" type="float" value="7"/>
</properties>
</object>
<object id="33" name="WifesMom" x="115.333" y="192" width="32" height="32">
<properties>
<property name="isVertical" type="bool" value="false"/>
<property name="offPos" type="float" value="8"/>
<property name="offSetN" type="float" value="7"/>
</properties>
</object>
<object id="29" name="Door" type="Door" x="416" y="144" width="48" height="64"/>
<object id="31" name="Wife" type="Wife" x="528" y="208" width="32.1917" height="31.0211"/>
</objectgroup>
<objectgroup id="3" name="Collisions" visible="0">
<objectgroup id="3" name="Collisions">
<object id="6" x="48" y="48" width="16" height="272"/>
<object id="7" x="48" y="304" width="544" height="16"/>
<object id="8" x="576" y="48" width="16" height="256"/>
Expand Down
26 changes: 26 additions & 0 deletions lib/components/WifesFather.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}
26 changes: 26 additions & 0 deletions lib/components/WifesMom.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}
46 changes: 46 additions & 0 deletions lib/components/level_one.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
}
}
}
3 changes: 3 additions & 0 deletions lib/components/npc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ae81498

Please sign in to comment.