Skip to content

Commit

Permalink
feat: Implementa Wife Mom and Wife Father on lvl 01
Browse files Browse the repository at this point in the history
  • Loading branch information
devpedrofurquim committed Jan 1, 2025
1 parent f893cc1 commit 30b0e41
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 17 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions lib/components/CharacterShadow.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:ui';

import 'package:flame/components.dart';
import 'package:flutter/material.dart';

class CharacterShadow extends PositionComponent {
@override
void render(Canvas canvas) {
// Draw an ellipse for the shadow
final paint = Paint()..color = Colors.black.withOpacity(0.5);
canvas.drawOval(
Rect.fromCenter(
center: Offset(size.x / 2, size.y),
width: size.x * 0.8,
height: size.y * 0.2,
),
paint,
);
}
}
61 changes: 56 additions & 5 deletions lib/components/WifesFather.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:math';
import 'dart:ui';

import 'package:moonshiner_game/components/CharacterShadow.dart';
import 'package:moonshiner_game/components/npc.dart';
import 'package:flame/components.dart';
import 'package:moonshiner_game/components/utils.dart';

class WifesFather extends AbstractNPC {
WifesFather({required Vector2 position})
Expand All @@ -15,12 +17,61 @@ class WifesFather extends AbstractNPC {
);

@override
Color getColorForNPC() => const Color(0xFFAA0000); // Dark red for the father
Future<void> onLoad() async {
loadAllAnimations();

// Create a shadow component
final shadow = CharacterShadow()
..size = Vector2(16, 4) // Adjust size based on your character
..position =
Vector2(8, size.y - 4); // Position the shadow below the character

// Add the shadow as a child
add(shadow);
return super.onLoad();
}

@override
void updateMovement(double dt) {
// This NPC does not move, so velocity is always zero
Color getColorForNPC() => const Color(0xFFFFAAAA); // Light pink for the mom

@override
void loadAllAnimations() {
final idleAnimation = spriteAnimation('Idle', 11);
final walkingAnimation = spriteAnimation('Run', 11);

animations = {
NPCState.idle: idleAnimation,
NPCState.walking: walkingAnimation,
};
current = NPCState.idle;
velocity = Vector2.zero();
}

@override
SpriteAnimation spriteAnimation(String state, int amount) {
return SpriteAnimation.fromFrameData(
game.images.fromCache('Main Characters/Wife Father/$state (32x32).png'),
SpriteAnimationData.sequenced(
amount: amount,
stepTime: 0.05,
textureSize: Vector2.all(32),
),
);
}

@override
void update(double dt) {
checkCollisions();

velocity = Vector2.all(0);

super.update(dt);
}

@override
void checkCollisions() {}

@override
void updateMovement(double dt) {
// TODO: implement updateMovement
}
}
61 changes: 56 additions & 5 deletions lib/components/WifesMom.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
import 'dart:math';
import 'dart:ui';

import 'package:moonshiner_game/components/CharacterShadow.dart';
import 'package:moonshiner_game/components/npc.dart';
import 'package:flame/components.dart';
import 'package:moonshiner_game/components/utils.dart';

class WifesMom extends AbstractNPC {
WifesMom({required Vector2 position})
: super(
npcCharacter: 'Wifes Mother',
npcCharacter: 'Wife\'s Mother',
dialogues: [
"Farewell, my dear daughter!",
"Please take care of yourself and your husband.",
],
position: position,
);

@override
Future<void> onLoad() async {
loadAllAnimations();

// Create a shadow component
final shadow = CharacterShadow()
..size = Vector2(16, 4) // Adjust size based on your character
..position =
Vector2(8, size.y - 4); // Position the shadow below the character

// Add the shadow as a child
add(shadow);
return super.onLoad();
}

@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
void loadAllAnimations() {
final idleAnimation = spriteAnimation('Idle', 11);
final walkingAnimation = spriteAnimation('Run', 11);

animations = {
NPCState.idle: idleAnimation,
NPCState.walking: walkingAnimation,
};
current = NPCState.idle;
velocity = Vector2.zero();
}

@override
SpriteAnimation spriteAnimation(String state, int amount) {
return SpriteAnimation.fromFrameData(
game.images.fromCache('Main Characters/Wife Mom/$state (32x32).png'),
SpriteAnimationData.sequenced(
amount: amount,
stepTime: 0.05,
textureSize: Vector2.all(32),
),
);
}

@override
void update(double dt) {
checkCollisions();

velocity = Vector2.all(0);

super.update(dt);
}

@override
void checkCollisions() {}

@override
void updateMovement(double dt) {
// TODO: implement updateMovement
}
}
1 change: 1 addition & 0 deletions lib/components/level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_tiled/flame_tiled.dart';
import 'package:moonshiner_game/components/WifesMom.dart';
import 'package:moonshiner_game/components/background_tile.dart';
import 'package:moonshiner_game/components/baker.dart';
import 'package:moonshiner_game/components/clouds.dart';
Expand Down
17 changes: 10 additions & 7 deletions lib/components/npc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent

@override
Future<void> onLoad() async {
_loadAllAnimations();
// Only load default animations if they haven't been overridden by a subclass
if (animations == null || animations!.isEmpty) {
loadAllAnimations();
}
add(RectangleHitbox()..debugMode = false);
return super.onLoad();
}
Expand All @@ -54,9 +57,9 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent
width: 14,
);

void _loadAllAnimations() {
final idleAnimation = _spriteAnimation('Idle', 11);
final walkingAnimation = _spriteAnimation('Run', 12);
void loadAllAnimations() {
final idleAnimation = spriteAnimation('Idle', 11);
final walkingAnimation = spriteAnimation('Run', 12);

animations = {
NPCState.idle: idleAnimation,
Expand All @@ -65,7 +68,7 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent
current = NPCState.walking;
}

SpriteAnimation _spriteAnimation(String state, int amount) {
SpriteAnimation spriteAnimation(String state, int amount) {
return SpriteAnimation.fromFrameData(
game.images.fromCache('Main Characters/Journal Guy/$state (32x32).png'),
SpriteAnimationData.sequenced(
Expand Down Expand Up @@ -148,7 +151,7 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent
final Vector2 playerPosition = gameRef.player.position;
final double distanceToPlayer = playerPosition.distanceTo(position);

_checkCollisions();
checkCollisions();

// Show dialogue if player is close, hide if far away
if (distanceToPlayer < 50) {
Expand All @@ -164,7 +167,7 @@ abstract class AbstractNPC extends SpriteAnimationGroupComponent
super.update(dt);
}

void _checkCollisions() {
void checkCollisions() {
for (final block in collisionBlocks) {
if (checkCollision(this, block)) {
if (velocity.x != 0 || velocity.y != 0) {
Expand Down
9 changes: 9 additions & 0 deletions lib/components/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flutter/services.dart';
import 'package:moonshiner_game/components/CharacterShadow.dart';
import 'package:moonshiner_game/components/custom_hitbox.dart';
import 'package:moonshiner_game/components/npc.dart';
import 'package:moonshiner_game/components/itemTip.dart';
Expand Down Expand Up @@ -58,6 +59,14 @@ class Player extends SpriteAnimationGroupComponent
add(RectangleHitbox(
position: Vector2(hitbox.offsetX, hitbox.offsetY),
size: Vector2(hitbox.width, hitbox.height)));
// Create a shadow component
final shadow = CharacterShadow()
..size = Vector2(16, 4) // Adjust size based on your character
..position =
Vector2(8, size.y - 4); // Position the shadow below the character

// Add the shadow as a child
add(shadow);
return super.onLoad();
}

Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ flutter:
- assets/images/Main Characters/Pink Man/
- assets/images/Main Characters/Journal Guy/
- assets/images/Main Characters/Virtual Guy/
- assets/images/Main Characters/Wife Mom/
- assets/images/Main Characters/Wife Father/
- assets/images/Main Characters/Guy/
- assets/images/HUD/
- assets/images/Items/Objects/
Expand Down

0 comments on commit 30b0e41

Please sign in to comment.