feat: implemented InputWrapper and replace Input
This commit is contained in:
parent
dca4b275bb
commit
f584280f50
|
@ -12,11 +12,11 @@ import Walk from "./PlayerStates/Walk";
|
||||||
import Debug from "../../Wolfie2D/Debug/Debug";
|
import Debug from "../../Wolfie2D/Debug/Debug";
|
||||||
import Item from "../GameSystems/items/Item";
|
import Item from "../GameSystems/items/Item";
|
||||||
import InventoryManager from "../GameSystems/InventoryManager";
|
import InventoryManager from "../GameSystems/InventoryManager";
|
||||||
import Input from "../../Wolfie2D/Input/Input";
|
|
||||||
import BattlerAI from "../AI/BattlerAI";
|
import BattlerAI from "../AI/BattlerAI";
|
||||||
import MathUtils from "../../Wolfie2D/Utils/MathUtils";
|
import MathUtils from "../../Wolfie2D/Utils/MathUtils";
|
||||||
import Weapon from "../GameSystems/items/Weapon";
|
import Weapon from "../GameSystems/items/Weapon";
|
||||||
import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
|
import InputWrapper from "../Tools/InputWrapper";
|
||||||
|
|
||||||
|
|
||||||
export enum PlayerType {
|
export enum PlayerType {
|
||||||
|
@ -104,15 +104,6 @@ export default class PlayerController extends StateMachineAI implements BattlerA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns three legal random generate buffs based on current state
|
|
||||||
* @returns Three buffs
|
|
||||||
*/
|
|
||||||
static getBuffs(): Buffs {
|
|
||||||
// TODO
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO - balance buff value generation
|
//TODO - balance buff value generation
|
||||||
/**
|
/**
|
||||||
* returns an array of three randomly generated buffs
|
* returns an array of three randomly generated buffs
|
||||||
|
@ -241,7 +232,7 @@ export default class PlayerController extends StateMachineAI implements BattlerA
|
||||||
Debug.log("player Coords:", "Player Coords:" +this.owner.position );
|
Debug.log("player Coords:", "Player Coords:" +this.owner.position );
|
||||||
|
|
||||||
//testing the attacks here, may be moved to another place later
|
//testing the attacks here, may be moved to another place later
|
||||||
if(Input.isJustPressed("attack")){
|
if(InputWrapper.isAttackJustPressed()){
|
||||||
let item = this.inventory.getItem();
|
let item = this.inventory.getItem();
|
||||||
(<AnimatedSprite>this.owner).animation.playIfNotAlready("ATTACK", true);
|
(<AnimatedSprite>this.owner).animation.playIfNotAlready("ATTACK", true);
|
||||||
//TODO - get proper look direction
|
//TODO - get proper look direction
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
import InAir from "./InAir";
|
import InAir from "./InAir";
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
|
|
||||||
export default class Fall extends InAir {
|
export default class Fall extends InAir {
|
||||||
owner: AnimatedSprite;
|
owner: AnimatedSprite;
|
||||||
|
@ -15,7 +15,7 @@ export default class Fall extends InAir {
|
||||||
|
|
||||||
//TODO - testing doublejump, may have to move to InAir instead
|
//TODO - testing doublejump, may have to move to InAir instead
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
// If we jump, move to the Jump state, give a burst of upwards velocity
|
||||||
if( this.parent.airjumps>0 && Input.isJustPressed("jump")){
|
if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){
|
||||||
this.parent.airjumps --;
|
this.parent.airjumps --;
|
||||||
this.finished("jump");
|
this.finished("jump");
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
this.parent.velocity.y = -600; // basically jump height
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
import { PlayerStates } from "../PlayerController";
|
import { PlayerStates } from "../PlayerController";
|
||||||
import OnGround from "./OnGround";
|
import OnGround from "./OnGround";
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { GameEventType } from "../../../Wolfie2D/Events/GameEventType";
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
import { EaseFunctionType } from "../../../Wolfie2D/Utils/EaseFunctions";
|
import { EaseFunctionType } from "../../../Wolfie2D/Utils/EaseFunctions";
|
||||||
import { Player_Events } from "../../sword_enums";
|
import { Player_Events } from "../../sword_enums";
|
||||||
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
import { PlayerStates } from "../PlayerController";
|
import { PlayerStates } from "../PlayerController";
|
||||||
import InAir from "./InAir";
|
import InAir from "./InAir";
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
|
||||||
|
|
||||||
export default class Jump extends InAir {
|
export default class Jump extends InAir {
|
||||||
owner: AnimatedSprite;
|
owner: AnimatedSprite;
|
||||||
|
@ -27,7 +27,7 @@ export default class Jump extends InAir {
|
||||||
|
|
||||||
//TODO - testing doublejump, may have to move to InAir instead
|
//TODO - testing doublejump, may have to move to InAir instead
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
// If we jump, move to the Jump state, give a burst of upwards velocity
|
||||||
if( this.parent.airjumps>0 && Input.isJustPressed("jump")){
|
if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){
|
||||||
this.parent.airjumps --;
|
this.parent.airjumps --;
|
||||||
this.finished("jump");
|
this.finished("jump");
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
this.parent.velocity.y = -600; // basically jump height
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
|
||||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
||||||
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
import PlayerState from "./PlayerState";
|
import PlayerState from "./PlayerState";
|
||||||
|
|
||||||
export default class OnGround extends PlayerState {
|
export default class OnGround extends PlayerState {
|
||||||
|
@ -26,7 +26,7 @@ export default class OnGround extends PlayerState {
|
||||||
|
|
||||||
|
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
// If we jump, move to the Jump state, give a burst of upwards velocity
|
||||||
if(Input.isJustPressed("jump")){
|
if(InputWrapper.isJumpJustPressed()){
|
||||||
this.finished("jump");
|
this.finished("jump");
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
this.parent.velocity.y = -600; // basically jump height
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ import State from "../../../Wolfie2D/DataTypes/State/State";
|
||||||
import StateMachine from "../../../Wolfie2D/DataTypes/State/StateMachine";
|
import StateMachine from "../../../Wolfie2D/DataTypes/State/StateMachine";
|
||||||
import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
|
import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
|
||||||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
|
||||||
import GameNode from "../../../Wolfie2D/Nodes/GameNode";
|
import GameNode from "../../../Wolfie2D/Nodes/GameNode";
|
||||||
import Timer from "../../../Wolfie2D/Timing/Timer";
|
import Timer from "../../../Wolfie2D/Timing/Timer";
|
||||||
import { Player_Events } from "../../sword_enums";
|
import { Player_Events } from "../../sword_enums";
|
||||||
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
import PlayerController from "../PlayerController";
|
import PlayerController from "../PlayerController";
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ export default abstract class PlayerState extends State {
|
||||||
*/
|
*/
|
||||||
getInputDirection(): Vec2 {
|
getInputDirection(): Vec2 {
|
||||||
let direction = Vec2.ZERO;
|
let direction = Vec2.ZERO;
|
||||||
direction.x = (Input.isPressed("left") ? -1 : 0) + (Input.isPressed("right") ? 1 : 0);
|
direction.x = (InputWrapper.isLeftPressed() ? -1 : 0) + (InputWrapper.isRightPressed() ? 1 : 0);
|
||||||
direction.y = (Input.isJustPressed("jump") ? -1 : 0);
|
direction.y = (InputWrapper.isJumpJustPressed() ? -1 : 0);
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Input from "../../../Wolfie2D/Input/Input";
|
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
import { Player_Events } from "../../sword_enums";
|
import { Player_Events } from "../../sword_enums";
|
||||||
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
import { PlayerStates } from "../PlayerController";
|
import { PlayerStates } from "../PlayerController";
|
||||||
import OnGround from "./OnGround";
|
import OnGround from "./OnGround";
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ export default class Walk extends OnGround {
|
||||||
this.parent.velocity.x = dir.x * (this.parent.speed + this.parent.CURRENT_BUFFS.speed);
|
this.parent.velocity.x = dir.x * (this.parent.speed + this.parent.CURRENT_BUFFS.speed);
|
||||||
|
|
||||||
//TODO - decide how to implement dash - could be a flash - maybe allow in air as well
|
//TODO - decide how to implement dash - could be a flash - maybe allow in air as well
|
||||||
if(Input.isJustPressed("dash")){
|
if(InputWrapper.isDashJustPressed()){
|
||||||
//play dash anim maybe
|
//play dash anim maybe
|
||||||
//TODO - might give buffed speed stat to dash speed
|
//TODO - might give buffed speed stat to dash speed
|
||||||
this.parent.velocity.x = dir.x * 1000; //give sidewards velocity
|
this.parent.velocity.x = dir.x * 1000; //give sidewards velocity
|
||||||
|
|
|
@ -2,7 +2,6 @@ import AABB from "../../Wolfie2D/DataTypes/Shapes/AABB";
|
||||||
import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
|
import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
|
||||||
import Debug from "../../Wolfie2D/Debug/Debug";
|
import Debug from "../../Wolfie2D/Debug/Debug";
|
||||||
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
||||||
import Input from "../../Wolfie2D/Input/Input";
|
|
||||||
import { TweenableProperties } from "../../Wolfie2D/Nodes/GameNode";
|
import { TweenableProperties } from "../../Wolfie2D/Nodes/GameNode";
|
||||||
import { GraphicType } from "../../Wolfie2D/Nodes/Graphics/GraphicTypes";
|
import { GraphicType } from "../../Wolfie2D/Nodes/Graphics/GraphicTypes";
|
||||||
import Point from "../../Wolfie2D/Nodes/Graphics/Point";
|
import Point from "../../Wolfie2D/Nodes/Graphics/Point";
|
||||||
|
@ -16,7 +15,7 @@ import Color from "../../Wolfie2D/Utils/Color";
|
||||||
import { EaseFunctionType } from "../../Wolfie2D/Utils/EaseFunctions";
|
import { EaseFunctionType } from "../../Wolfie2D/Utils/EaseFunctions";
|
||||||
import PlayerController from "../Player/PlayerController";
|
import PlayerController from "../Player/PlayerController";
|
||||||
import MainMenu from "./MainMenu";
|
import MainMenu from "./MainMenu";
|
||||||
import { Player_Events, Statuses } from "../sword_enums";
|
import { GameState, Player_Events, Statuses } from "../sword_enums";
|
||||||
import RegistryManager from "../../Wolfie2D/Registry/RegistryManager";
|
import RegistryManager from "../../Wolfie2D/Registry/RegistryManager";
|
||||||
import WeaponType from "../GameSystems/items/WeaponTypes/WeaponType";
|
import WeaponType from "../GameSystems/items/WeaponTypes/WeaponType";
|
||||||
import Weapon from "../GameSystems/items/Weapon";
|
import Weapon from "../GameSystems/items/Weapon";
|
||||||
|
@ -30,6 +29,8 @@ import Button from "../../Wolfie2D/Nodes/UIElements/Button";
|
||||||
import { Buff } from "../Player/PlayerController";
|
import { Buff } from "../Player/PlayerController";
|
||||||
import CanvasNode from "../../Wolfie2D/Nodes/CanvasNode";
|
import CanvasNode from "../../Wolfie2D/Nodes/CanvasNode";
|
||||||
import { Enemy } from "../Tools/RandomMapGenerator";
|
import { Enemy } from "../Tools/RandomMapGenerator";
|
||||||
|
import Stack from "../../Wolfie2D/DataTypes/Stack";
|
||||||
|
import InputWrapper from "../Tools/InputWrapper";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,6 +76,8 @@ export default class GameLevel extends Scene {
|
||||||
// A list of enemies
|
// A list of enemies
|
||||||
protected enemies: Array<AnimatedSprite>;
|
protected enemies: Array<AnimatedSprite>;
|
||||||
|
|
||||||
|
protected gameStateStack: Stack<GameState>;
|
||||||
|
|
||||||
//buffs layer
|
//buffs layer
|
||||||
buffLayer: Layer;
|
buffLayer: Layer;
|
||||||
buffButton1 : Button;
|
buffButton1 : Button;
|
||||||
|
@ -170,49 +173,62 @@ export default class GameLevel extends Scene {
|
||||||
//TODO - uncomment when done testing
|
//TODO - uncomment when done testing
|
||||||
// Initially disable player movement
|
// Initially disable player movement
|
||||||
//Input.disableInput();
|
//Input.disableInput();
|
||||||
Input.enableInput();
|
this.gameStateStack = new Stack();
|
||||||
|
this.setGameState(GameState.GAMING);
|
||||||
|
InputWrapper.enableInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateScene(deltaT: number){
|
updateScene(deltaT: number){
|
||||||
|
|
||||||
// Handle events and update the UI if needed
|
// Handle events and update the UI if needed
|
||||||
while(this.receiver.hasNextEvent()){
|
while(this.receiver.hasNextEvent()){
|
||||||
let event = this.receiver.getNextEvent();
|
let event = this.receiver.getNextEvent();
|
||||||
|
|
||||||
switch(event.type){
|
|
||||||
case Player_Events.ENEMY_KILLED:
|
|
||||||
|
|
||||||
let node = this.sceneGraph.getNode(event.data.get("owner"));//get enemy id
|
|
||||||
//remove enemy from enemies
|
|
||||||
this.enemies = this.enemies.filter(item => item !== event.data.get("ai"));
|
|
||||||
this.battleManager.removeEnemy(event.data.get("ai"));
|
|
||||||
node.destroy();
|
|
||||||
//TODO - this is for testing, add some chance here later
|
|
||||||
this.emitter.fireEvent(Player_Events.GIVE_BUFF);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Player_Events.GIVE_BUFF:
|
if (this.gameStateStack.peek() == GameState.GAMING) {
|
||||||
this.buffs = PlayerController.generateBuffs();
|
switch(event.type){
|
||||||
this.buffButton1.text = "Increase "+this.buffs[0].type.toString() + " by "+this.buffs[0].value;
|
case Player_Events.ENEMY_KILLED:
|
||||||
this.buffButton2.text = "Increase "+this.buffs[1].type + " by "+this.buffs[1].value;
|
|
||||||
this.buffButton3.text = "Increase "+this.buffs[2].type + " by "+this.buffs[2].value;
|
let node = this.sceneGraph.getNode(event.data.get("owner"));//get enemy id
|
||||||
|
//remove enemy from enemies
|
||||||
//pause game here
|
this.enemies = this.enemies.filter(item => item !== event.data.get("ai"));
|
||||||
this.buffLayer.enable();
|
this.battleManager.removeEnemy(event.data.get("ai"));
|
||||||
|
node.destroy();
|
||||||
break;
|
//TODO - this is for testing, add some chance here later
|
||||||
case "buff1":
|
this.emitter.fireEvent(Player_Events.GIVE_BUFF);
|
||||||
(<PlayerController>this.player._ai).addBuff(this.buffs[0]);
|
break;
|
||||||
this.buffLayer.disable();
|
|
||||||
break;
|
case Player_Events.GIVE_BUFF:
|
||||||
case "buff2":
|
this.buffs = PlayerController.generateBuffs();
|
||||||
(<PlayerController>this.player._ai).addBuff(this.buffs[1]);
|
this.buffButton1.text = "Increase "+this.buffs[0].type.toString() + " by "+this.buffs[0].value;
|
||||||
this.buffLayer.disable();
|
this.buffButton2.text = "Increase "+this.buffs[1].type + " by "+this.buffs[1].value;
|
||||||
break;
|
this.buffButton3.text = "Increase "+this.buffs[2].type + " by "+this.buffs[2].value;
|
||||||
case "buff3":
|
|
||||||
(<PlayerController>this.player._ai).addBuff(this.buffs[2]);
|
//pause game here
|
||||||
this.buffLayer.disable();
|
this.setGameState(GameState.BUFF);
|
||||||
break;
|
this.buffLayer.enable();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.gameStateStack.peek() == GameState.BUFF) {
|
||||||
|
switch(event.type){
|
||||||
|
case "buff1":
|
||||||
|
(<PlayerController>this.player._ai).addBuff(this.buffs[0]);
|
||||||
|
this.buffLayer.disable();
|
||||||
|
this.setGameState();
|
||||||
|
break;
|
||||||
|
case "buff2":
|
||||||
|
(<PlayerController>this.player._ai).addBuff(this.buffs[1]);
|
||||||
|
this.buffLayer.disable();
|
||||||
|
this.setGameState();
|
||||||
|
break;
|
||||||
|
case "buff3":
|
||||||
|
(<PlayerController>this.player._ai).addBuff(this.buffs[2]);
|
||||||
|
this.buffLayer.disable();
|
||||||
|
this.setGameState();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +247,7 @@ export default class GameLevel extends Scene {
|
||||||
this.playerFalloff(viewportCenter, baseViewportSize);
|
this.playerFalloff(viewportCenter, baseViewportSize);
|
||||||
|
|
||||||
//TODO - this is for testing
|
//TODO - this is for testing
|
||||||
if(Input.isJustPressed("spawn")){
|
if(InputWrapper.isSpawnJustPressed()){
|
||||||
console.log("trying to spawn enemy");
|
console.log("trying to spawn enemy");
|
||||||
this.addEnemy("test_dummy",this.player.position,{player: this.player,
|
this.addEnemy("test_dummy",this.player.position,{player: this.player,
|
||||||
health :100,
|
health :100,
|
||||||
|
@ -245,6 +261,18 @@ export default class GameLevel extends Scene {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO put UI changes in here
|
||||||
|
protected setGameState(gameState?: GameState) {
|
||||||
|
if (gameState) {
|
||||||
|
this.gameStateStack.push(gameState);
|
||||||
|
InputWrapper.setState(gameState);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.gameStateStack.pop();
|
||||||
|
InputWrapper.setState(this.gameStateStack.peek());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialzes the layers
|
* Initialzes the layers
|
||||||
*/
|
*/
|
||||||
|
@ -603,7 +631,7 @@ export default class GameLevel extends Scene {
|
||||||
GameLevel.livesCount += amt;
|
GameLevel.livesCount += amt;
|
||||||
this.livesCountLabel.text = "Lives: " + GameLevel.livesCount;
|
this.livesCountLabel.text = "Lives: " + GameLevel.livesCount;
|
||||||
if (GameLevel.livesCount == 0){
|
if (GameLevel.livesCount == 0){
|
||||||
Input.disableInput();
|
InputWrapper.disableInput();
|
||||||
this.player.disablePhysics();
|
this.player.disablePhysics();
|
||||||
this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "player_death", loop: false, holdReference: false});
|
this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "player_death", loop: false, holdReference: false});
|
||||||
this.player.tweens.play("death");
|
this.player.tweens.play("death");
|
||||||
|
@ -617,7 +645,7 @@ export default class GameLevel extends Scene {
|
||||||
GameLevel.livesCount = 3;
|
GameLevel.livesCount = 3;
|
||||||
this.emitter.fireEvent(GameEventType.STOP_SOUND, {key: "level_music"});
|
this.emitter.fireEvent(GameEventType.STOP_SOUND, {key: "level_music"});
|
||||||
this.sceneManager.changeToScene(MainMenu, {});
|
this.sceneManager.changeToScene(MainMenu, {});
|
||||||
Input.enableInput();
|
InputWrapper.enableInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -636,4 +664,5 @@ export default class GameLevel extends Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Color from "../../Wolfie2D/Utils/Color";
|
||||||
import Layer from "../../Wolfie2D/Scene/Layer";
|
import Layer from "../../Wolfie2D/Scene/Layer";
|
||||||
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
||||||
import Input from "../../Wolfie2D/Input/Input";
|
import InputWrapper from "../Tools/InputWrapper";
|
||||||
|
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
|
@ -20,7 +20,6 @@ export default class SceneWithStory extends Scene {
|
||||||
private currentMode: Mode = Mode.GAME_MODE;
|
private currentMode: Mode = Mode.GAME_MODE;
|
||||||
private storytextLabel: Label;
|
private storytextLabel: Label;
|
||||||
private storyLayer: Layer;
|
private storyLayer: Layer;
|
||||||
private primary: Layer;
|
|
||||||
private story: Story;
|
private story: Story;
|
||||||
private storyProgress: number;
|
private storyProgress: number;
|
||||||
private storySprites: Array<Sprite>;
|
private storySprites: Array<Sprite>;
|
||||||
|
@ -29,12 +28,8 @@ export default class SceneWithStory extends Scene {
|
||||||
private currentContent: string;
|
private currentContent: string;
|
||||||
|
|
||||||
startScene(): void {
|
startScene(): void {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The code below are for testing only. Please comment them when submit
|
// The code below are for testing only. Please comment them when submit
|
||||||
|
|
||||||
this.primary = this.addUILayer("primary");
|
|
||||||
const center = this.viewport.getCenter();
|
const center = this.viewport.getCenter();
|
||||||
const loadStory = this.add.uiElement(UIElementType.BUTTON, "primary", { position: new Vec2(center.x, center.y), text: "LoadStory" });
|
const loadStory = this.add.uiElement(UIElementType.BUTTON, "primary", { position: new Vec2(center.x, center.y), text: "LoadStory" });
|
||||||
loadStory.size.set(200, 50);
|
loadStory.size.set(200, 50);
|
||||||
|
@ -56,21 +51,12 @@ export default class SceneWithStory extends Scene {
|
||||||
* @param storyPath The path to the story JSON
|
* @param storyPath The path to the story JSON
|
||||||
*/
|
*/
|
||||||
async storyLoader(storyPath: string) {
|
async storyLoader(storyPath: string) {
|
||||||
// I may want to load multiple stories in a single scene, but this
|
|
||||||
// Layer with name story already exists
|
|
||||||
// so can i detect whether this layer exists?
|
|
||||||
const response = await (await fetch(storyPath)).json();
|
const response = await (await fetch(storyPath)).json();
|
||||||
this.story = <Story>response;
|
this.story = <Story>response;
|
||||||
console.log("story:", this.story);
|
console.log("story:", this.story);
|
||||||
if (this.story.bgm) {
|
if (this.story.bgm) {
|
||||||
this.storyBGMs = new Array;
|
this.storyBGMs = new Array;
|
||||||
this.story.bgm.forEach((bgm) => {
|
this.story.bgm.forEach((bgm) => {
|
||||||
// this.load.audio(bgm.key, bgm.path);
|
|
||||||
// console.log("audio:", bgm.key, "path:", bgm.path);
|
|
||||||
// this.load.loadResourcesFromQueue(() => {
|
|
||||||
// console.log("finished loading audio");
|
|
||||||
// this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (this.load.getAudio(bgm.key)) {
|
if (this.load.getAudio(bgm.key)) {
|
||||||
this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
||||||
|
@ -115,13 +101,6 @@ export default class SceneWithStory extends Scene {
|
||||||
this.story.texts[this.storyProgress].actions.forEach(action => {
|
this.story.texts[this.storyProgress].actions.forEach(action => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "loadSprite":
|
case "loadSprite":
|
||||||
// this.load.image(action.key, action.path);
|
|
||||||
// this.load.loadResourcesFromQueue(() => {
|
|
||||||
// tmp = this.add.sprite(action.key, "story");
|
|
||||||
// tmp.position.set(action.positon[0], action.positon[1]);
|
|
||||||
// tmp.scale.set(action.scale[0], action.scale[1]);
|
|
||||||
// this.storySprites.push(tmp);
|
|
||||||
// });
|
|
||||||
if (this.load.getImage(action.key)) {
|
if (this.load.getImage(action.key)) {
|
||||||
tmp = this.add.sprite(action.key, "story");
|
tmp = this.add.sprite(action.key, "story");
|
||||||
tmp.position.set(action.positon[0], action.positon[1]);
|
tmp.position.set(action.positon[0], action.positon[1]);
|
||||||
|
@ -137,15 +116,6 @@ export default class SceneWithStory extends Scene {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// case "loadAnimatedSprite":
|
|
||||||
// this.load.spritesheet(action.key, action.path);
|
|
||||||
// this.load.loadResourcesFromQueue(() => {
|
|
||||||
// tmp = this.add.animatedSprite(action.key, "story");
|
|
||||||
// tmp.position.set(action.positon[0], action.positon[1]);
|
|
||||||
// tmp.scale.set(action.scale[0], action.scale[1]);
|
|
||||||
// this.storySprites.push(tmp);
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
case "moveSprite":
|
case "moveSprite":
|
||||||
tmp = this.storySprites.find(function (sprite) {
|
tmp = this.storySprites.find(function (sprite) {
|
||||||
return sprite.imageId === action.key;
|
return sprite.imageId === action.key;
|
||||||
|
@ -208,7 +178,7 @@ export default class SceneWithStory extends Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Testing code
|
// Testing code
|
||||||
if (Input.isMouseJustPressed() && this.currentMode === Mode.STORY_MODE) {
|
if (InputWrapper.isNextJustPressed() && this.currentMode === Mode.STORY_MODE) {
|
||||||
this.updateStory();
|
this.updateStory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import Color from "../../Wolfie2D/Utils/Color";
|
||||||
import Layer from "../../Wolfie2D/Scene/Layer";
|
import Layer from "../../Wolfie2D/Scene/Layer";
|
||||||
import Label from "../../Wolfie2D/Nodes/UIElements/Label";
|
import Label from "../../Wolfie2D/Nodes/UIElements/Label";
|
||||||
import Levels from "./Levels";
|
import Levels from "./Levels";
|
||||||
import Input from "../../Wolfie2D/Input/Input";
|
import InputWrapper from "../Tools/InputWrapper";
|
||||||
|
|
||||||
|
|
||||||
export default class MainMenu extends Scene {
|
export default class MainMenu extends Scene {
|
||||||
|
@ -73,7 +73,7 @@ export default class MainMenu extends Scene {
|
||||||
while(this.receiver.hasNextEvent()){
|
while(this.receiver.hasNextEvent()){
|
||||||
let event = this.receiver.getNextEvent();
|
let event = this.receiver.getNextEvent();
|
||||||
console.log(event);
|
console.log(event);
|
||||||
if (Input.isMouseJustPressed(0)) { //if left click
|
if (InputWrapper.isMouseJustPressed(0)) { //if left click
|
||||||
this.sceneManager.changeToScene(MainMenu, {}, {});
|
this.sceneManager.changeToScene(MainMenu, {}, {});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,58 @@
|
||||||
import Input from "../../Wolfie2D/Input/Input";
|
import Input from "../../Wolfie2D/Input/Input";
|
||||||
|
import {GameState} from "../sword_enums";
|
||||||
|
|
||||||
export default class InputWrapper {
|
export default class InputWrapper {
|
||||||
private static isInStoryMode: boolean;
|
private static gameState: GameState = GameState.GAMING;
|
||||||
|
|
||||||
constructor() {
|
static isUpPressed(): boolean {
|
||||||
InputWrapper.isInStoryMode = false;
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isPressed("up")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static isDownPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isPressed("down")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static isLeftPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isPressed("left")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static isRightPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isPressed("right")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static isJumpJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("jump")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,15 +60,96 @@ export default class InputWrapper {
|
||||||
* @returns True if the attack key is pressed, false otherwise
|
* @returns True if the attack key is pressed, false otherwise
|
||||||
*/
|
*/
|
||||||
static isAttackJustPressed(): boolean {
|
static isAttackJustPressed(): boolean {
|
||||||
if (InputWrapper.isInStoryMode) {
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
return undefined;
|
if (Input.isJustPressed("attack")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setStoryMode(storyMode: boolean): void {
|
static isDashJustPressed(): boolean {
|
||||||
InputWrapper.isInStoryMode = storyMode;
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("dash")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isSkillJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("skill")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isInventoryJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("attack")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isSpawnJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("spawn")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isPauseJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING && InputWrapper.gameState != GameState.PAUSE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("pause")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isNextJustPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.STORY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isJustPressed("attack") || Input.isMouseJustPressed()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isMouseJustPressed(mouseButton?: number): boolean{
|
||||||
|
return Input.isMouseJustPressed(mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
static disableInput() {
|
||||||
|
Input.disableInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
static enableInput() {
|
||||||
|
Input.enableInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
static setState(gameState: GameState): void {
|
||||||
|
InputWrapper.gameState = gameState;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,4 +23,11 @@ export enum Statuses {
|
||||||
LOW_HEALTH = "LOW_HEALTH",
|
LOW_HEALTH = "LOW_HEALTH",
|
||||||
CAN_RETREAT = "CAN_RETREAT",
|
CAN_RETREAT = "CAN_RETREAT",
|
||||||
REACHED_GOAL = "GOAL"
|
REACHED_GOAL = "GOAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GameState {
|
||||||
|
GAMING = "gaming",
|
||||||
|
STORY = "story",
|
||||||
|
BUFF = "buff",
|
||||||
|
PAUSE = "pause"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user