feat: make snow level slippery

This commit is contained in:
Renge 2022-05-09 13:55:47 -04:00
parent e220aa7e25
commit 251148251e
4 changed files with 21 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
import GameLevel from "../../Scenes/GameLevel";
import { PlayerStates } from "../PlayerController";
import OnGround from "./OnGround";
import PlayerState from "./PlayerState";
@ -28,7 +29,12 @@ export default class Idle extends OnGround {
this.finished(PlayerStates.WALK);
}
this.parent.velocity.x = 0;
if (GameLevel.currentLevel === "snow") {
this.parent.velocity.x = Math.sign(this.parent.velocity.x)*(Math.abs(this.parent.velocity.x) - 5 < 0 ? 0 : Math.abs(this.parent.velocity.x) - 5);
}
else {
this.parent.velocity.x = 0;
}
super.update(deltaT);
}

View File

@ -6,6 +6,7 @@ import OnGround from "./OnGround";
import PlayerState from "./PlayerState";
import { GameEventType } from "../../../Wolfie2D/Events/GameEventType";
import { GameState } from "../../sword_enums";
import GameLevel from "../../Scenes/GameLevel";
export default class Walk extends OnGround {
owner: AnimatedSprite;
@ -37,8 +38,16 @@ export default class Walk extends OnGround {
this.finished(PlayerStates.IDLE);
}
this.parent.velocity.x = dir.x * (this.parent.speed );
if (GameLevel.currentLevel === "snow") {
this.parent.velocity.x += dir.x * 5;
if (this.parent.velocity.x > this.parent.speed)
this.parent.velocity.x = this.parent.speed;
if (this.parent.velocity.x < -1 * this.parent.speed)
this.parent.velocity.x = -1 * this.parent.speed;
}
else {
this.parent.velocity.x = dir.x * (this.parent.speed );
}
super.update(deltaT);
}

View File

@ -142,6 +142,7 @@ export default class GameLevel extends Scene {
protected gameStarted: boolean = false;
protected timerLable: Label;
protected levelEnded: boolean = false;
static currentLevel: string = "";
startpos: Vec2;
loadScene(): void {
@ -184,6 +185,7 @@ export default class GameLevel extends Scene {
this.load.spritesheet("test_dummy","shattered_sword_assets/spritesheets/test_dummy.json")
this.enemies = new Array();
this.battleManager = new BattleManager();
GameLevel.currentLevel = "";
}
unloadScene(): void {

View File

@ -21,6 +21,7 @@ export default class Snow extends GameLevel {
this.map = this.rmg.getMap();
console.log(this.map);
this.load.tilemapFromObject("map", this.map);
GameLevel.currentLevel = "snow";
//load enemies