mirror of
https://github.com/chase-manning/pokemon-js.git
synced 2025-11-03 09:28:58 +00:00
🚀 engage trainers by talking to them
This commit is contained in:
parent
4cc0793007
commit
11a29e6d69
3 changed files with 27 additions and 5 deletions
3
TODO.md
3
TODO.md
|
|
@ -1,7 +1,5 @@
|
|||
===========
|
||||
|
||||
- Add ability to engage trainers by talking to them
|
||||
- Add ability to talk to trainers after having beaten them
|
||||
- Add support for app refreshing when there is an update
|
||||
- Encounter frequency seems off
|
||||
- battle sounds
|
||||
|
|
@ -23,6 +21,7 @@
|
|||
- Make RPCs walk
|
||||
- Don't show number for non-countable items
|
||||
- Add Option Menu
|
||||
- Add ability to talk to trainers after having beaten them
|
||||
- Animate water
|
||||
- Abstract all the maths stuff out into a separate folder for easier contributions
|
||||
- Animate flowers
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export const isTrainer = (
|
|||
return trainers.some((trainer) => trainer.pos.x === x && trainer.pos.y === y);
|
||||
};
|
||||
|
||||
const directionModifier = (direction: Direction): PosType => {
|
||||
export const directionModifier = (direction: Direction): PosType => {
|
||||
if (direction === Direction.Down) return { x: 0, y: 1 };
|
||||
if (direction === Direction.Up) return { x: 0, y: -1 };
|
||||
if (direction === Direction.Left) return { x: -1, y: 0 };
|
||||
|
|
|
|||
|
|
@ -4,13 +4,18 @@ import {
|
|||
encounterPokemon,
|
||||
encounterTrainer,
|
||||
selectDefeatedTrainers,
|
||||
selectDirection,
|
||||
selectMap,
|
||||
selectPokemonEncounter,
|
||||
selectPos,
|
||||
selectTrainerEncounter,
|
||||
} from "../state/gameSlice";
|
||||
import { useEffect, useState } from "react";
|
||||
import { isTrainerEncounter } from "../app/map-helper";
|
||||
import {
|
||||
directionModifier,
|
||||
isTrainer,
|
||||
isTrainerEncounter,
|
||||
} from "../app/map-helper";
|
||||
import Frame from "./Frame";
|
||||
import useEvent from "../app/use-event";
|
||||
import { Event } from "../app/emitter";
|
||||
|
|
@ -35,6 +40,7 @@ const TrainerEncounter = () => {
|
|||
const encounter = useSelector(selectTrainerEncounter);
|
||||
const pokemonEncounter = useSelector(selectPokemonEncounter);
|
||||
const defeatedTrainers = useSelector(selectDefeatedTrainers);
|
||||
const direction = useSelector(selectDirection);
|
||||
|
||||
const [introIndex, setIntroIndex] = useState(-1);
|
||||
|
||||
|
|
@ -52,7 +58,6 @@ const TrainerEncounter = () => {
|
|||
);
|
||||
|
||||
if (!encounter_) return;
|
||||
|
||||
dispatch(encounterTrainer(encounter_));
|
||||
setTimeout(() => {
|
||||
setIntroIndex(0);
|
||||
|
|
@ -60,6 +65,24 @@ const TrainerEncounter = () => {
|
|||
}, [trainers, walls, fences, pos, dispatch, defeatedTrainers]);
|
||||
|
||||
useEvent(Event.A, () => {
|
||||
const facingPos = directionModifier(direction);
|
||||
if (
|
||||
map.trainers &&
|
||||
isTrainer(map.trainers, pos.x + facingPos.x, pos.y + facingPos.y) &&
|
||||
!encounter
|
||||
) {
|
||||
const trainer = map.trainers.find(
|
||||
(trainer) =>
|
||||
trainer.pos.x === pos.x + facingPos.x &&
|
||||
trainer.pos.y === pos.y + facingPos.y
|
||||
);
|
||||
if (!trainer) throw new Error("Trainer not found");
|
||||
dispatch(encounterTrainer(trainer));
|
||||
setTimeout(() => {
|
||||
setIntroIndex(0);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
if (!encounter || !!pokemonEncounter) return;
|
||||
|
||||
if (introIndex === encounter.intro.length - 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue