Skip to content

Commit

Permalink
added ranger sean
Browse files Browse the repository at this point in the history
  • Loading branch information
xjyribro committed Feb 27, 2024
1 parent f84632a commit ba67e27
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 899 deletions.
2 changes: 1 addition & 1 deletion assets/yarn/himiko.yarn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Himiko: Remember if you get any wrong, you get a fine from the city!
Himiko: Here is a bigger bag for you to hold more rubbish.
Himiko: Let's go clean up Gomiland! Here is a map for you if you are lost
Himiko: Oh and don't forget to stop and talk to people. Some need help!
<<increaseBagSize 10>>
<<increaseBagSize>>
<<changeState "level_2">>
===
title: level_1_incorrect
Expand Down
25 changes: 25 additions & 0 deletions assets/yarn/ranger.yarn
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!
===
893 changes: 0 additions & 893 deletions lib/assets.dart

This file was deleted.

3 changes: 3 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const int playerFastSpeed = 6;
const double npcSpeed = 2;
const double maxRaycastDist = 40;
const int maxCoinAmount = 999999;
const int smallBagSize = 10;
const int mediumBagSize = 30;
const int largeBagSize = 50;

// day cycle
const gameMinToRealSecond = 0.1;
Expand Down
6 changes: 3 additions & 3 deletions lib/game/npcs/himiko.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class Himiko extends Npc with HasGameReference<GomilandGame> {
game.dialogueControllerComponent;
YarnProject yarnProject = YarnProject();
yarnProject
..commands.addCommand0('increaseBagSize', increaseBagSize)
..commands.addCommand1('changeState', changeState)
..commands.addCommand1('increaseBagSize', increaseBagSize)
..variables.setVariable('\$dayOfWeek', getDayOfWeek())
..parse(await rootBundle.loadString(Assets.assets_yarn_himiko_yarn));
DialogueRunner dialogueRunner = DialogueRunner(
Expand All @@ -149,8 +149,8 @@ class Himiko extends Npc with HasGameReference<GomilandGame> {
game.progressStateBloc.add(SetNeighbourState(newState));
}

void increaseBagSize(int newSize) {
game.gameStateBloc.add(SetBagSize(newSize));
void increaseBagSize() {
game.gameStateBloc.add(const SetBagSize(smallBagSize));
}

String getDialogueName() {
Expand Down
91 changes: 91 additions & 0 deletions lib/game/npcs/ranger.dart
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);
}
}
9 changes: 7 additions & 2 deletions lib/game/npcs/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ String getFriendDialogue(OtherPlayer friendInfo, GomilandGame game) {
int playerSpeed = game.playerStateBloc.state.playerSpeed;
int bagSize = game.gameStateBloc.state.bagSize;
if (playerCompletedMainQuests) {
if (playerSpeed > playerBaseSpeed && bagSize > 10) {
if (playerSpeed > playerBaseSpeed && bagSize > largeBagSize) {
return 'seasoned_player';
} else {
if (playerSpeed > playerBaseSpeed) {
return 'buy_bag';
// only allow buying a big bag if player has a medium bag
if (bagSize == mediumBagSize) {
return 'buy_bag';
} else {
return 'progress_player';
}
} else if (bagSize > 10) {
return 'buy_shoe';
}
Expand Down

0 comments on commit ba67e27

Please sign in to comment.