-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xjyribro
committed
Feb 27, 2024
1 parent
f84632a
commit ba67e27
Showing
7 changed files
with
130 additions
and
899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<<character "Ranger Sean" Ranger>> | ||
title: buy_bag | ||
--- | ||
Ranger: Hello adventurer! I'm Ranger Sean, Gomiland National Park's Chief Park Ranger. | ||
Ranger: Recently there has been a bit of rubbish that park goers leave behind. | ||
Ranger: Could you help make the park a cleaner place? I can sell you a big bag that you can hold more trash in! | ||
Ranger: I costs 500 coins for the bag. Do you want it? | ||
-> No | ||
Ranger: No problem. The one you have works fine! | ||
Ranger: But if you want to pick up more, come buy the bag from me next time. | ||
-> Yes | ||
<<if $coins < 500>> | ||
Ranger: Looks like you don't have enough coins. Come back when you do! | ||
<<else>> | ||
<<upgradeBag>> | ||
Ranger: Here you go! A bag that can hold 30 pieces of trash. | ||
Ranger: You can give your old one to Himiko. She will hand them out to people who don't have one. | ||
<<endif>> | ||
=== | ||
title: greeting | ||
--- | ||
Ranger: Hello again adventurer! Gomiland National Park offers a great variety of attractions. | ||
Ranger: Visit the Bamboo Forest and shrine, Park Castle or World Forest! | ||
Ranger: There is never ending places to explore. Remember to pick up the trash along the way! | ||
=== |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flame/collisions.dart'; | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/flame.dart'; | ||
import 'package:flame/sprite.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:gomiland/assets.dart'; | ||
import 'package:gomiland/constants/constants.dart'; | ||
import 'package:gomiland/controllers/game_state/game_state_bloc.dart'; | ||
import 'package:gomiland/game/game.dart'; | ||
import 'package:gomiland/game/npcs/npc.dart'; | ||
import 'package:gomiland/game/npcs/utils.dart'; | ||
import 'package:gomiland/game/ui/dialogue/dialogue_controller_component.dart'; | ||
import 'package:gomiland/utils/directions.dart'; | ||
import 'package:jenny/jenny.dart'; | ||
|
||
class Ranger extends Npc with HasGameReference<GomilandGame> { | ||
Ranger({required super.position}); | ||
|
||
late SpriteAnimation idleUp; | ||
late SpriteAnimation idleDown; | ||
late SpriteAnimation idleLeft; | ||
late SpriteAnimation idleRight; | ||
|
||
@override | ||
void onLoad() async { | ||
final image = await Flame.images.load(Assets.assets_images_npcs_ranger_png); | ||
final spriteSheet = SpriteSheet( | ||
image: image, | ||
srcSize: Vector2.all(tileSize), | ||
); | ||
|
||
idleUp = | ||
spriteSheet.createAnimation(row: 1, stepTime: stepTime, from: 0, to: 1); | ||
idleDown = | ||
spriteSheet.createAnimation(row: 0, stepTime: stepTime, from: 0, to: 1); | ||
idleLeft = | ||
spriteSheet.createAnimation(row: 3, stepTime: stepTime, from: 0, to: 1); | ||
idleRight = | ||
spriteSheet.createAnimation(row: 2, stepTime: stepTime, from: 0, to: 1); | ||
|
||
animation = idleDown; | ||
addAll([npcObstacle(Vector2.zero()), RectangleHitbox()]); | ||
} | ||
|
||
void _facePlayer(Vector2 playerPosition) { | ||
Direction direction = | ||
getDirection(getPlayerAngle(playerPosition, position)); | ||
switch (direction) { | ||
case Direction.up: | ||
animation = idleUp; | ||
break; | ||
case Direction.down: | ||
animation = idleDown; | ||
break; | ||
case Direction.left: | ||
animation = idleLeft; | ||
break; | ||
case Direction.right: | ||
animation = idleRight; | ||
break; | ||
} | ||
} | ||
|
||
@override | ||
Future<void> startConversation(Vector2 playerPosition) async { | ||
game.freezePlayer(); | ||
_facePlayer(playerPosition); | ||
|
||
DialogueControllerComponent dialogueControllerComponent = | ||
game.dialogueControllerComponent; | ||
YarnProject yarnProject = YarnProject(); | ||
|
||
int bagSize = game.gameStateBloc.state.bagSize; | ||
yarnProject.strictCharacterNames = false; | ||
|
||
yarnProject | ||
..variables.setVariable('\$coins', game.gameStateBloc.state.coinAmount) | ||
..commands.addCommand0('upgradeBag', upgradeBag) | ||
..parse(await rootBundle.loadString(Assets.assets_yarn_friend_yarn)); | ||
DialogueRunner dialogueRunner = DialogueRunner( | ||
yarnProject: yarnProject, dialogueViews: [dialogueControllerComponent]); | ||
await dialogueRunner | ||
.startDialogue(bagSize == smallBagSize ? 'buy_bag' : 'greeting'); | ||
game.unfreezePlayer(); | ||
} | ||
|
||
void upgradeBag() { | ||
game.gameStateBloc.add(const SetBagSize(20)); | ||
deductCoins(game, 500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters