This commit is contained in:
OfficialCHenry 2022-04-24 15:15:33 -04:00
commit a65873c349
11 changed files with 239 additions and 118 deletions

View File

@ -52,7 +52,7 @@
"possibility": 1
}
],
"checkPoint": [5, 19, 5, 5]
"startCheckPoint": [25, 19, 5, 5]
},
"exit": {
"width": 30,
@ -76,7 +76,8 @@
"width": 3,
"alt_tile": [0, 478]
}
]
],
"endCheckPoint": [20, 16, 5, 5]
},
"rooms": [
{

View File

@ -3,7 +3,7 @@
"spriteSheetImage": "Hiro.png",
"spriteWidth": 64,
"spriteHeight": 64,
"columns": 7,
"columns": 8,
"rows": 7,
"durationType": "time",
"animations": [
@ -75,12 +75,12 @@
]
},
{
"name": "JUMP",
"name": "JUMP2",
"repeat": false,
"frames": [
{
"index": 30,
"duration": 10
"duration": 5
},
{
"index": 31,
@ -96,12 +96,12 @@
},
{
"index": 30,
"duration": 10
"duration": 5
}
]
},
{
"name": "JUMP_RIGHT",
"name": "JUMP",
"repeat": false,
"frames": [
{
@ -303,6 +303,32 @@
"duration": 10
}
]
},
{
"name": "DASH",
"repeat": false,
"frames": [
{
"index": 46,
"duration": 5
},
{
"index": 47,
"duration": 5
},
{
"index": 48,
"duration": 5
},
{
"index": 49,
"duration": 5
},
{
"index": 50,
"duration": 10
}
]
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -27,7 +27,9 @@ import WeaponTypeRegistry from "./shattered_sword/Registry/WeaponTypeRegistry";
{name: "inventory", keys: ["i","b"]},
{name: "pause", keys: ["escape"]},
{name: "tab", keys: ["tab"]},
{name: "spawn", keys: ["q"]} //debug feature to test enemy spawning, press q to spawn enemy at current location
{name: "buff1", keys: ["1"]},
{name: "buff2", keys: ["2"]},
{name: "buff3", keys: ["3"]}
],
useWebGL: false, // Tell the game we want to use webgl
showDebug: false // Whether to show debug messages. You can change this to true if you want

View File

@ -39,6 +39,8 @@ import { TiledTilemapData } from "../../Wolfie2D/DataTypes/Tilesets/TiledData";
import AttackAction from "../AI/EnemyActions/AttackAction";
import Move from "../AI/EnemyActions/Move";
import GameOver from "./GameOver";
import Porcelain from "./Porcelain";
import Tutorial from "./Tutorial";
// TODO
/**
@ -99,36 +101,45 @@ export default class GameLevel extends Scene {
protected gameStateStack: Stack<GameState>;
// Story
private storytextLabel: Label;
private storyLayer: Layer;
private story: Story;
private storyProgress: number;
private storySprites: Array<Sprite>;
private storyBGMs: Array<string>;
private currentSpeaker: string;
private currentContent: string;
protected storytextLabel: Label;
protected storyLayer: Layer;
protected story: Story;
protected storyProgress: number;
protected storySprites: Array<Sprite>;
protected storyBGMs: Array<string>;
protected currentSpeaker: string;
protected currentContent: string;
//buffs layer
buffLayer: Layer;
buffButton1 : Button;
buffLabel1 : Label;
buffButton2 : Button;
buffLabel2 : Label;
buffButton3 : Button;
buffLabel3: Label;
buffs: Array<Buff>;
protected buffLayer: Layer;
protected buffButton1 : Button;
protected buffLabel1 : Label;
protected buffButton2 : Button;
protected buffLabel2 : Label;
protected buffButton3 : Button;
protected buffLabel3: Label;
protected buffs: Array<Buff>;
//pause layer
pauseLayer: Layer;
pauseText: Label;
pauseInput: TextInput;
pauseSubmit: Label;
pauseCheatText: Label;
protected pauseLayer: Layer;
protected pauseText: Label;
protected pauseInput: TextInput;
protected pauseSubmit: Label;
protected pauseCheatText: Label;
protected randomSeed: number;
protected rmg: RandomMapGenerator;
protected map: TiledTilemapData;
protected startCheckPoint: Rect;
protected endCheckPoint: Rect;
protected touchedStartCheckPoint: boolean = false;
protected touchedEndCheckPoint: boolean = false;
protected static gameTimer: number = 0;
protected gameStarted: boolean = false;
protected timerLable: Label;
protected levelEnded: boolean = false;
startpos: Vec2;
loadScene(): void {
//can load player sprite here
@ -198,8 +209,10 @@ export default class GameLevel extends Scene {
this.subscribeToEvents();
this.addUI();
const checkPoint = this.rmg.getCheckPoint();
this.addLevelEnd(new Vec2(checkPoint[0], checkPoint[1]), new Vec2(checkPoint[2], checkPoint[3]));
let startCheckPoint = this.rmg.getStartCheckPoint();
this.startCheckPoint = this.addCheckPoint(new Vec2(startCheckPoint[0], startCheckPoint[1]), new Vec2(startCheckPoint[2], startCheckPoint[3]), "startStory", "startTimer");
let endCheckPoint = this.rmg.getEndCheckPoint();
this.endCheckPoint = this.addCheckPoint(new Vec2(endCheckPoint[0], endCheckPoint[1]), new Vec2(endCheckPoint[2], endCheckPoint[3]), "endStory", "nextLevel");
// Create an enemies array
// Send the player and enemies to the battle manager
@ -250,6 +263,29 @@ export default class GameLevel extends Scene {
updateScene(deltaT: number){
if (this.gameStateStack.peek() === GameState.GAMING) {
if (this.gameStarted) {
GameLevel.gameTimer += deltaT;
this.timerLable.textColor = Color.BLACK;
}
else {
this.timerLable.textColor = Color.RED;
}
let minutes = Math.floor(GameLevel.gameTimer / 60);
if (minutes >= 10) {
this.timerLable.text = minutes.toString();
}
else {
this.timerLable.text = "0" + minutes.toString();
}
let seconds = Math.floor(GameLevel.gameTimer % 60);
if (seconds >= 10) {
this.timerLable.text += ":" + seconds.toString();
}
else {
this.timerLable.text += ":0" + seconds.toString();
}
}
// Handle events and update the UI if needed
while(this.receiver.hasNextEvent()){
@ -321,9 +357,23 @@ export default class GameLevel extends Scene {
this.respawnPlayer();
}
else{ //no more lives
this.viewport.setZoomLevel(1);
this.sceneManager.changeToScene(GameOver, {});
InputWrapper.enableInput();
}
break;
case "startStory":
this.playStartStory();
break;
case "endStory":
this.playEndStory();
break;
case "startTimer":
this.startTimer();
break;
case "nextLevel":
this.goToNextLevel();
break;
}
}
@ -366,6 +416,16 @@ export default class GameLevel extends Scene {
}
}
if (InputWrapper.isBuff1JustPresed()) {
this.emitter.fireEvent("buff1");
}
if (InputWrapper.isBuff2JustPresed()) {
this.emitter.fireEvent("buff2");
}
if (InputWrapper.isBuff3JustPresed()) {
this.emitter.fireEvent("buff3");
}
//update health UI
let playerAI = (<PlayerController>this.player.ai);
this.healthLabel.text = "Health: "+ Math.round(playerAI.CURRENT_HP) +'/' + Math.round(playerAI.MAX_HP +playerAI.CURRENT_BUFFS.hp);
@ -398,7 +458,7 @@ export default class GameLevel extends Scene {
// this.expLabel.sizeToText();
//update level ui
this.playerLevelLabel.text = "lv." + playerAI.level;
this.playerLevelLabel.text = "Lv." + playerAI.level;
//update lives ui
this.livesCountLabel.text = "Lives: " + playerAI.lives;
@ -410,36 +470,6 @@ export default class GameLevel extends Scene {
const baseViewportSize = this.viewport.getHalfSize().scaled(2);
//check position of player
this.playerFalloff(viewportCenter, baseViewportSize);
// Update player safe position
if (this.player.onGround) {
this.playerSpawn = this.player.position.clone();
}
//TODO - this is for testing
/*
if(InputWrapper.isSpawnJustPressed()){
console.log("trying to spawn enemy");
this.addEnemy("test_dummy",this.player.position,{player: this.player,
health :100,
tilemap: "Main",
//actions:actions,
goal: Statuses.REACHED_GOAL,
actions: [new AttackAction(3, [Statuses.IN_RANGE], [Statuses.REACHED_GOAL]),
new Move(2, [], [Statuses.IN_RANGE], {inRange: 60})],
status : [Statuses.CAN_RETREAT, Statuses.CAN_BERSERK],
weapon : this.createWeapon("knife")
});
}
*/
if (InputWrapper.isInventoryJustPressed()) {
console.log("LoadingStory");
this.storyLoader("shattered_sword_assets/jsons/story.json");
}
}
// TODO put UI changes in here
@ -501,6 +531,10 @@ export default class GameLevel extends Scene {
this.receiver.subscribe("buff2");
this.receiver.subscribe("buff3");
this.receiver.subscribe("cheat");
this.receiver.subscribe("startStory");
this.receiver.subscribe("startTimer");
this.receiver.subscribe("endStory");
this.receiver.subscribe("nextLevel");
}
// TODO -
@ -543,8 +577,12 @@ export default class GameLevel extends Scene {
this.playerLevelLabel = <Label> this.add.uiElement(UIElementType.LABEL, "UI",{position: new Vec2(30, 95), text: "lv. "+ (<PlayerController>this.player.ai).level });
this.playerLevelLabel = <Label> this.add.uiElement(UIElementType.LABEL, "UI",{position: new Vec2(20, 95), text: "Lv. "+ (<PlayerController>this.player.ai).level });
this.playerLevelLabel.size.set(0, 50);
this.playerLevelLabel.setHAlign(HAlign.LEFT);
this.playerLevelLabel.textColor = Color.BLUE;
this.playerLevelLabel.font = "PixelSimple";
this.playerLevelLabel.fontSize = 25;
this.expLabel = <Label> this.add.uiElement(UIElementType.LABEL, "UI",{position: new Vec2(100, 95), text: "EXP: "+ (<PlayerController>this.player.ai).CURRENT_EXP });
this.expLabel.size.set(200, 50);
@ -691,9 +729,12 @@ export default class GameLevel extends Scene {
this.pauseSubmit.onClickEventId = "cheat";
this.pauseSubmit.borderWidth = 3;
this.livesCountLabel = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(600, 30), text:"Lives: "});
this.livesCountLabel = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(this.viewport.getHalfSize().x*2 - 100, 30), text:"Lives: "});
this.livesCountLabel.textColor = Color.YELLOW;
this.livesCountLabel.fontSize = 25;
this.timerLable = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(Math.floor(this.viewport.getHalfSize().x), 30), text: "00:00"});
this.timerLable.fontSize = 60;
}
//TODO - determine whether we will have weapon datatype
@ -736,8 +777,6 @@ export default class GameLevel extends Scene {
* Initializes the player
*/
protected initPlayer(): void {
//create the inventory
let inventory = new InventoryManager(this, 1, "inventorySlot", new Vec2(16, 16), 4, "slots1", "items1");
@ -848,8 +887,6 @@ export default class GameLevel extends Scene {
//TODO - give each enemy unique weapon
protected initializeEnemies( enemies: Enemy[]){
let actionsDefault = [new AttackAction(3, [Statuses.IN_RANGE], [Statuses.REACHED_GOAL]),
new Move(2, [], [Statuses.IN_RANGE], {inRange: 60}),
];
@ -934,11 +971,12 @@ export default class GameLevel extends Scene {
}
protected addLevelEnd(startingTile: Vec2, size: Vec2): void {
this.levelEndArea = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: startingTile.scale(32), size: size.scale(32)});
this.levelEndArea.addPhysics(undefined, undefined, false, true);
// this.levelEndArea.setTrigger("player", somelevelendevent, null);
this.levelEndArea.color = new Color(0, 0, 0, 0);
protected addCheckPoint(startingTile: Vec2, size: Vec2, enter: string, exit: string): Rect {
let checkPoint = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: startingTile.scale(32), size: size.scale(32)});
checkPoint.addPhysics(undefined, undefined, false, true);
checkPoint.setTrigger("player", enter, null);
checkPoint.color = new Color(0, 0, 0, 0);
return checkPoint;
}
@ -1003,7 +1041,7 @@ export default class GameLevel extends Scene {
* @param viewportCenter The center of the viewport
* @param viewportSize The size of the viewport
*/
playerFalloff(viewportCenter: Vec2, viewportSize: Vec2):void{
protected playerFalloff(viewportCenter: Vec2, viewportSize: Vec2):void{
if(this.player.position.y >= viewportCenter.y +viewportSize.y/2.0){
this.player.position.set(this.playerSpawn.x,this.playerSpawn.y);
@ -1016,7 +1054,37 @@ export default class GameLevel extends Scene {
}
async storyLoader(storyPath: string) {
protected playStartStory() {
if (!this.touchedStartCheckPoint) {
this.touchedStartCheckPoint = true;
this.storyLoader("shattered_sword_assets/jsons/story.json");
this.startTimer();
}
}
protected playEndStory() {
if (!this.touchedEndCheckPoint) {
this.touchedEndCheckPoint = true;
this.storyLoader("shattered_sword_assets/jsons/story.json");
this.endTimer();
this.levelEnded = true;
}
}
protected startTimer() {
this.gameStarted = true;
}
protected endTimer() {
this.gameStarted = false;
}
protected goToNextLevel() {
// this.sceneManager.changeToScene(Porcelain);
}
protected async storyLoader(storyPath: string) {
if (this.gameStateStack.peek() === GameState.STORY) {
return;
}
@ -1053,11 +1121,11 @@ export default class GameLevel extends Scene {
this.updateStory();
}
hasNextStory(): boolean {
protected hasNextStory(): boolean {
return this.gameStateStack.peek() === GameState.STORY && this.storyProgress + 1 < this.story.texts.length;
}
updateStory() {
protected updateStory() {
if (this.hasNextStory()) {
this.storyProgress++;
let tmp = undefined;
@ -1130,11 +1198,14 @@ export default class GameLevel extends Scene {
this.story = undefined;
this.storytextLabel = undefined;
// this.storyLayer = undefined;
if (this.levelEnded) {
this.goToNextLevel();
}
}
}
// Cheat
enableCheat() {
protected enableCheat() {
if (this.pauseInput.text.toUpperCase() === "UUDDLRLRBABA") {
(<PlayerController>this.player._ai).godMode = true;
}

View File

@ -1,18 +1,31 @@
import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
import Input from "../../Wolfie2D/Input/Input";
import Label from "../../Wolfie2D/Nodes/UIElements/Label";
import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes";
import Scene from "../../Wolfie2D/Scene/Scene";
import Color from "../../Wolfie2D/Utils/Color";
import { GameState } from "../sword_enums";
import InputWrapper from "../Tools/InputWrapper";
import MainMenu from "./MainMenu";
export default class GameOver extends Scene {
startScene() {
InputWrapper.setState(GameState.PAUSE);
const center = this.viewport.getCenter();
this.addUILayer("primary");
const gameOver = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y), text: "Game Over"});
gameOver.textColor = Color.WHITE;
const gameOver = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y), text: "YOU DIED"});
gameOver.textColor = Color.RED;
gameOver.fontSize = 100;
const hint = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y + 100), text: "Click to go back to Main Menu"});
hint.textColor = Color.WHITE;
}
updateScene(){
if(InputWrapper.isLeftMouseJustPressed()){
this.sceneManager.changeToScene(MainMenu);
}
}
}

View File

@ -22,9 +22,6 @@ export default class MainMenu extends Scene {
private control: Layer;
// private rmg: RandomMapGenerator;
animatedSprite: AnimatedSprite;
loadScene(): void {
// Load the menu song
//this.load.audio("menu", "shattered_sword_assets/music/menu.mp3");
@ -33,24 +30,6 @@ export default class MainMenu extends Scene {
//TODO
startScene(): void{
// this.config = new ConfigManager();
// this.save = new SaveManager();
// console.log(this.config.getVolume());
// this.config.setVolume(100);
// console.log(this.config.getVolume());
// console.log(this.save.getLevel());
// this.save.setLevel(10);
// console.log(this.save.getLevel());
// this.rmg = new RandomMapGenerator("shattered_sword_assets/jsons/forest_template.json", 114514);
// this.rmg.getMap();
// Scene has started, so start playing music
//this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "menu", loop: true, holdReference: true});
const center = this.viewport.getCenter();
// The main menu

View File

@ -13,6 +13,8 @@ import EnemyAI from "../AI/EnemyAI";
import BattlerAI from "../AI/BattlerAI";
import AttackAction from "../AI/EnemyActions/AttackAction";
import Move from "../AI/EnemyActions/Move";
import Porcelain from "./Porcelain";
import MainMenu from "./MainMenu";
export default class Tutorial extends GameLevel {
loadScene(): void {
@ -54,4 +56,9 @@ export default class Tutorial extends GameLevel {
})
}
}
protected goToNextLevel(): void {
this.viewport.setZoomLevel(1);
this.sceneManager.changeToScene(Porcelain);
}
}

View File

@ -50,7 +50,8 @@ export class RoomTemplate {
topLayer: Array<number>;
entrances: Array<Entrance>;
sprites?: Array<Sprite>;
checkPoint?: [number, number, number, number];
startCheckPoint?: [number, number, number, number];
endCheckPoint?: [number, number, number, number];
}
export class Corner {

View File

@ -103,15 +103,25 @@ export default class InputWrapper {
return false;
}
static isSpawnJustPressed(): boolean {
if (InputWrapper.gameState != GameState.GAMING) {
static isBuff1JustPresed(): boolean{
if (InputWrapper.gameState != GameState.BUFF) {
return false;
}
return Input.isJustPressed("buff1");
}
if (Input.isJustPressed("spawn")) {
return true;
static isBuff2JustPresed(): boolean{
if (InputWrapper.gameState != GameState.BUFF) {
return false;
}
return false;
return Input.isJustPressed("buff2");
}
static isBuff3JustPresed(): boolean{
if (InputWrapper.gameState != GameState.BUFF) {
return false;
}
return Input.isJustPressed("buff3");
}
static isPauseJustPressed(): boolean {

View File

@ -25,7 +25,8 @@ export default class RandomMapGenerator {
private exitFacing: Facing;
private enemies: Array<Enemy>;
private player: Vec2;
private checkPoint: [number, number, number, number];
private startCheckPoint: [number, number, number, number];
private endCheckPoint: [number, number, number, number];
constructor(JSONFilePath: string, seed: any) {
let xhr = new XMLHttpRequest();
@ -45,7 +46,8 @@ export default class RandomMapGenerator {
this.rooms = new Array();
this.enemies = new Array();
this.player = new Vec2();
this.checkPoint = [0,0,0,0];
this.startCheckPoint = [0,0,0,0];
this.endCheckPoint = [0, 0, 0, 0];
let gen = require('random-seed');
this.gen = new gen(seed);
this.hasExit = false;
@ -117,8 +119,12 @@ export default class RandomMapGenerator {
return new Vec2(this.player.x - this.minX, this.player.y - this.minY);
}
getCheckPoint(): [number, number, number, number] {
return [this.checkPoint[0] - this.minX, this.checkPoint[1] - this.minY, this.checkPoint[2], this.checkPoint[3]];
getStartCheckPoint(): [number, number, number, number] {
return [this.startCheckPoint[0] - this.minX, this.startCheckPoint[1] - this.minY, this.startCheckPoint[2], this.startCheckPoint[3]];
}
getEndCheckPoint(): [number, number, number, number] {
return [this.endCheckPoint[0] - this.minX, this.endCheckPoint[1] - this.minY, this.endCheckPoint[2], this.endCheckPoint[3]];
}
getEnemies(): Array<Enemy> {
@ -378,10 +384,15 @@ export default class RandomMapGenerator {
}
}
}
if (old.checkPoint) {
this.checkPoint = [...old.checkPoint];
this.checkPoint[0] += posX;
this.checkPoint[1] += posY;
if (old.startCheckPoint) {
this.startCheckPoint = [...old.startCheckPoint];
this.startCheckPoint[0] += posX;
this.startCheckPoint[1] += posY;
}
if (old.endCheckPoint) {
this.endCheckPoint = [...old.endCheckPoint];
this.endCheckPoint[0] += posX;
this.endCheckPoint[1] += posY;
}
if (posX < this.minX)
this.minX = posX;