From 5c21eeea522265fe7faeea53fca49bfbbdf41384 Mon Sep 17 00:00:00 2001 From: Blake Lingenau Date: Mon, 11 Apr 2016 03:13:01 -0400 Subject: [PATCH] Player gets on his bicycle when entering a cycling road tile --- Source/FullScreenPokemon.d.ts | 15 +++++++++++++++ Source/FullScreenPokemon.js | 26 +++++++++++++++++++++----- Source/FullScreenPokemon.ts | 29 +++++++++++++++++++++++------ Source/settings/objects.js | 6 ++++-- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Source/FullScreenPokemon.d.ts b/Source/FullScreenPokemon.d.ts index 77197762..1782a0d8 100644 --- a/Source/FullScreenPokemon.d.ts +++ b/Source/FullScreenPokemon.d.ts @@ -1792,6 +1792,11 @@ declare module FullScreenPokemon { */ allowDirectionAsKeys?: boolean; + /** + * Whether the player is allowed to dismount the bicycle. + */ + canDismountBicycle: boolean; + /** * Whether this is allowed to start walking via user input. */ @@ -2075,6 +2080,16 @@ declare module FullScreenPokemon { routine?: string; } + /** + * A Detector that forces the Player onto his/her bicycle. + */ + export interface ICyclingTriggerer extends IDetector { + /** + * Whether the Player should always be moving. + */ + alwaysMoving?: boolean; + } + /** * General attributes for all menus. */ diff --git a/Source/FullScreenPokemon.js b/Source/FullScreenPokemon.js index 9cf58d15..f251f189 100644 --- a/Source/FullScreenPokemon.js +++ b/Source/FullScreenPokemon.js @@ -1018,11 +1018,11 @@ var FullScreenPokemon; * Starts the Player cycling if the current Area allows it. * * @param thing A Player to start cycling. - * @param area The current Area. + * @param message Whether to display a message box. * @returns Whether the properties were changed. */ - FullScreenPokemon.prototype.startCycling = function (thing) { - if (thing.surfing) { + FullScreenPokemon.prototype.startCycling = function (thing, message) { + if (thing.surfing || thing.cycling) { return false; } if (!this.AreaSpawner.getArea().allowCycling) { @@ -1032,7 +1032,9 @@ var FullScreenPokemon; thing.speedOld = thing.speed; thing.speed = this.MathDecider.compute("speedCycling", thing); thing.FSP.addClass(thing, "cycling"); - thing.FSP.displayMessage(thing, "%%%%%%%PLAYER%%%%%%% got on the bicycle!"); + if (message) { + thing.FSP.displayMessage(thing, "%%%%%%%PLAYER%%%%%%% got on the bicycle!"); + } return true; }; /** @@ -1041,6 +1043,10 @@ var FullScreenPokemon; * @param thing A Player to stop cycling. */ FullScreenPokemon.prototype.stopCycling = function (thing) { + if (!thing.canDismountBicycle) { + thing.FSP.displayMessage(thing, "You can't get off here."); + return; + } thing.cycling = false; thing.speed = thing.speedOld; thing.FSP.removeClass(thing, "cycling"); @@ -1059,7 +1065,7 @@ var FullScreenPokemon; return true; } else { - return thing.FSP.startCycling(thing); + return thing.FSP.startCycling(thing, true); } }; /* General animations @@ -2584,6 +2590,16 @@ var FullScreenPokemon; } } }; + /** + * Activates a Detector to force the Player onto the bike and optionally to keep moving. + * + * @param player The Player. + * @param thing A Detector triggered by player. + */ + FullScreenPokemon.prototype.activateCyclingTriggerer = function (player, thing) { + thing.FSP.startCycling(player); + player.canDismountBicycle = false; + }; /* Physics */ /** diff --git a/Source/FullScreenPokemon.ts b/Source/FullScreenPokemon.ts index b3d83cb6..169e4558 100644 --- a/Source/FullScreenPokemon.ts +++ b/Source/FullScreenPokemon.ts @@ -1351,11 +1351,11 @@ module FullScreenPokemon { * Starts the Player cycling if the current Area allows it. * * @param thing A Player to start cycling. - * @param area The current Area. + * @param message Whether to display a message box. * @returns Whether the properties were changed. */ - startCycling(thing: IPlayer): boolean { - if (thing.surfing) { + startCycling(thing: IPlayer, message?: boolean): boolean { + if (thing.surfing || thing.cycling) { return false; } @@ -1369,7 +1369,9 @@ module FullScreenPokemon { thing.FSP.addClass(thing, "cycling"); - thing.FSP.displayMessage(thing, "%%%%%%%PLAYER%%%%%%% got on the bicycle!"); + if (message) { + thing.FSP.displayMessage(thing, "%%%%%%%PLAYER%%%%%%% got on the bicycle!"); + } return true; } @@ -1379,6 +1381,11 @@ module FullScreenPokemon { * @param thing A Player to stop cycling. */ stopCycling(thing: IPlayer): void { + if (!thing.canDismountBicycle) { + thing.FSP.displayMessage(thing, "You can't get off here."); + return; + } + thing.cycling = false; thing.speed = thing.speedOld; @@ -1399,7 +1406,7 @@ module FullScreenPokemon { thing.FSP.stopCycling(thing); return true; } else { - return thing.FSP.startCycling(thing); + return thing.FSP.startCycling(thing, true); } } @@ -3358,6 +3365,17 @@ module FullScreenPokemon { } } + /** + * Activates a Detector to force the Player onto the bike and optionally to keep moving. + * + * @param player The Player. + * @param thing A Detector triggered by player. + */ + activateCyclingTriggerer(player: IPlayer, thing: ICyclingTriggerer): void { + thing.FSP.startCycling(player); + player.canDismountBicycle = false; + } + /* Physics */ @@ -3504,7 +3522,6 @@ module FullScreenPokemon { thing.shouldWalk = true; } - /* Spawning */ diff --git a/Source/settings/objects.js b/Source/settings/objects.js index 26deeb91..453729d6 100644 --- a/Source/settings/objects.js +++ b/Source/settings/objects.js @@ -72,6 +72,7 @@ FullScreenPokemon.FullScreenPokemon.settings.objects = { "Cabinet": {}, "CollisionDetector": { "CutsceneTriggerer": {}, + "CyclingTriggerer": {}, "MenuTriggerer": {}, "SightDetector": {}, "ThemePlayer": {}, @@ -801,6 +802,7 @@ FullScreenPokemon.FullScreenPokemon.settings.objects = { "Player": { "id": "player", "player": true, + "canDismountBicycle": true, "canKeyWalking": true, "direction": 2, "speed": FullScreenPokemon.FullScreenPokemon.unitsize / 2, @@ -1134,8 +1136,8 @@ FullScreenPokemon.FullScreenPokemon.settings.objects = { }, "ElderBack": [14, 14], "PlayerBack": [14, 14], - "CyclingRoad": { - "activate": FullScreenPokemon.FullScreenPokemon.prototype.activateCyclingRoad, + "CyclingTriggerer": { + "activate": FullScreenPokemon.FullScreenPokemon.prototype.activateCyclingTriggerer, "requireOverlap": true, "hidden": true },