Skip to content

Commit

Permalink
feat: Começa a trabalhar no lvl 01
Browse files Browse the repository at this point in the history
  • Loading branch information
devpedrofurquim committed Nov 3, 2024
1 parent 6250271 commit 4eb8ca0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
12 changes: 0 additions & 12 deletions lib/components/level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Level extends World with HasGameRef<Moonshiner> {
level = await TiledComponent.load('$levelName.tmx', Vector2.all(16));
add(level);

_setupBackground();
_spawnObjects();
_addCollisionBlocks();
}
Expand All @@ -69,17 +68,6 @@ class Level extends World with HasGameRef<Moonshiner> {
removeFromParent();
}

void _setupBackground() {
// Create the background tile directly without checking for color
final backgroundTile = BackgroundTile(position: Vector2(0, 50));
add(backgroundTile);

// Add the clouds layer with different speed
final clouds =
Clouds(position: Vector2(0, 50)); // Adjust position as needed
add(clouds);
}

void _spawnObjects() {
final spawnPointsLayer = level.tileMap.getLayer<ObjectGroup>('SpawnPoints');

Expand Down
21 changes: 21 additions & 0 deletions lib/components/level_one.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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/player.dart';
Expand All @@ -6,6 +8,7 @@ import 'package:flame/components.dart';
import 'level.dart';

class LevelOne extends Level {
bool developerMessageVisible = true;
LevelOne({required String levelName, required Player player})
: super(levelName: levelName, player: player);

Expand All @@ -22,10 +25,20 @@ class LevelOne extends Level {
gameRef.hasShownLevelOneIntro = true;
}

// Call the customized background setup for LevelOne
_setupBackground();

// Customize dialogues for the Wife in LevelOne
_customizeWifeDialogues();
}

// Override _setupBackground for LevelOne
void _setupBackground() {
// Define the background specific to LevelOne
final backgroundTile = BackgroundTile(position: Vector2(0, 50));
add(backgroundTile);
}

void _showIntroMessageWhenReady() async {
while (gameRef.size.x == 0 || gameRef.size.y == 0) {
await Future.delayed(Duration(milliseconds: 100));
Expand Down Expand Up @@ -59,6 +72,14 @@ class LevelOne extends Level {
"Whatever happens, I’ll always be by your side.",
"Let’s make the most of our new life, one day at a time."
];

// Add interaction logic
wife.onPlayerInteraction = () {
if (developerMessageVisible) {
gameRef.hideDeveloperMessage();
developerMessageVisible = false;
}
};
} catch (e) {
// Handle the case where Wife component is not found
print("Wife component not found in children.");
Expand Down
14 changes: 14 additions & 0 deletions lib/components/wife.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Wife extends SpriteAnimationGroupComponent
double minDistance = 50;
bool hasDialogue = false;
bool hasSpokenOnCollision = false;
bool hasFirstInteracted = false;
VoidCallback? onPlayerInteraction;

CustomHitbox hitbox = CustomHitbox(
offsetX: 10,
Expand Down Expand Up @@ -91,6 +93,14 @@ class Wife extends SpriteAnimationGroupComponent
super.update(dt);
}

// Call this method when the player interacts with the wife
void interactWithPlayer() {
// Trigger the onPlayerInteraction callback, if it's set
if (onPlayerInteraction != null) {
onPlayerInteraction!();
}
}

void _showDialogue(String message) {
if (dialogueComponent != null) {
gameRef.remove(dialogueComponent!);
Expand All @@ -113,6 +123,10 @@ class Wife extends SpriteAnimationGroupComponent
if (other.hasInteracted) {
// Move to the next dialogue, loop back if at the end
currentDialogueIndex = (currentDialogueIndex + 1) % dialogues.length;
if (!hasFirstInteracted) {
onPlayerInteraction?.call();
hasFirstInteracted = true;
}

// Show the next dialogue message
_showDialogue(dialogues[currentDialogueIndex]);
Expand Down
6 changes: 2 additions & 4 deletions lib/moonshiner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ class Moonshiner extends FlameGame
)..priority = 100; // Set a high priority to render above other components

add(developerMessageComponent);
developerMessageComponent
.showWithTimeout(Duration(seconds: 4)); // Display for 4 seconds

print("Developer message added to the game.");
}

// Method to hide the developer message overlay
void hideDeveloperMessage() {
overlays.remove('DeveloperMessage'); // Remove the overlay
children.removeWhere((component) => component is DeveloperMessageComponent);
print("Developer message removed from the game.");
}

void _setupCamera(Level level) {
Expand Down

0 comments on commit 4eb8ca0

Please sign in to comment.