refact
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Phaser from "phaser";
|
||||
import { Platform } from "./Platform";
|
||||
import { Platform } from "../Platform";
|
||||
|
||||
export class ObstaclePlatformDisappearing extends Phaser.GameObjects.TileSprite {
|
||||
static readonly TRIGGER_DISTANCE = 110;
|
||||
3
src/entities/obstacles/index.ts
Normal file
3
src/entities/obstacles/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { ObstaclePlatformDisappearing } from "./ObstaclePlatformDisappearing";
|
||||
export { ObstacleSpikeNormal } from "./ObstacleSpikeNormal";
|
||||
export { ObstacleSpikeTricky } from "./ObstacleSpikeTricky";
|
||||
19
src/levels/01_level.ts
Normal file
19
src/levels/01_level.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineLevel } from "../lib/levelTypes";
|
||||
|
||||
export const level01 = defineLevel("Ugorj a tüskén át", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E........^........P",
|
||||
"####################",
|
||||
"####################",
|
||||
]);
|
||||
19
src/levels/02_level.ts
Normal file
19
src/levels/02_level.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineLevel } from "../lib/levelTypes";
|
||||
|
||||
export const level02 = defineLevel("Csapda híd", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E.................P",
|
||||
"#######~~~##########",
|
||||
"#######~~~##########",
|
||||
]);
|
||||
19
src/levels/03_level.ts
Normal file
19
src/levels/03_level.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineLevel } from "../lib/levelTypes";
|
||||
|
||||
export const level03 = defineLevel("Csaló tüske és lépcső", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E..................",
|
||||
"#####...............",
|
||||
"....#####...........",
|
||||
"........#####.......",
|
||||
"............#####...",
|
||||
"...............####.",
|
||||
".........T........P#",
|
||||
"####################",
|
||||
]);
|
||||
6
src/levels/index.ts
Normal file
6
src/levels/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { LevelDef } from "../lib/levelTypes";
|
||||
import { level01 } from "./01_level";
|
||||
import { level02 } from "./02_level";
|
||||
import { level03 } from "./03_level";
|
||||
|
||||
export const LEVELS: readonly LevelDef[] = [level01, level02, level03];
|
||||
@@ -1,100 +0,0 @@
|
||||
export const TILE_SIZE = 40;
|
||||
export const LEVEL_COLS = 20;
|
||||
export const LEVEL_ROWS = 15;
|
||||
|
||||
export enum TileType {
|
||||
Empty = 0,
|
||||
Platform = 1,
|
||||
Player = 2,
|
||||
Exit = 3,
|
||||
DisappearingPlatform = 4,
|
||||
Spike = 5,
|
||||
TrickySpike = 6,
|
||||
}
|
||||
|
||||
export type LevelMatrix = TileType[][];
|
||||
|
||||
export interface LevelDef {
|
||||
name: string;
|
||||
matrix: LevelMatrix;
|
||||
}
|
||||
|
||||
const CHAR_TO_TILE: Record<string, TileType> = {
|
||||
".": TileType.Empty,
|
||||
"#": TileType.Platform,
|
||||
"P": TileType.Player,
|
||||
"E": TileType.Exit,
|
||||
"~": TileType.DisappearingPlatform,
|
||||
"^": TileType.Spike,
|
||||
"T": TileType.TrickySpike,
|
||||
};
|
||||
|
||||
function parseLevel(rows: string[]): LevelMatrix {
|
||||
return rows.map((row, rowIdx) =>
|
||||
[...row].map((c, colIdx) => {
|
||||
const tile = CHAR_TO_TILE[c];
|
||||
if (tile === undefined) {
|
||||
throw new Error(`Invalid tile char '${c}' at row ${rowIdx}, col ${colIdx}`);
|
||||
}
|
||||
return tile;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function defineLevel(name: string, rows: string[]): LevelDef {
|
||||
return { name, matrix: parseLevel(rows) };
|
||||
}
|
||||
|
||||
export const LEVELS: readonly LevelDef[] = [
|
||||
defineLevel("Ugorj a tüskén át", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E........^........P",
|
||||
"####################",
|
||||
"####################",
|
||||
]),
|
||||
defineLevel("Csapda híd", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E.................P",
|
||||
"#######~~~##########",
|
||||
"#######~~~##########",
|
||||
]),
|
||||
defineLevel("Csaló tüske és lépcső", [
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
"....................",
|
||||
".E..................",
|
||||
"#####...............",
|
||||
"....#####...........",
|
||||
"........#####.......",
|
||||
"............#####...",
|
||||
"...............####.",
|
||||
".........T........P#",
|
||||
"####################",
|
||||
]),
|
||||
];
|
||||
@@ -2,10 +2,12 @@ import Phaser from "phaser";
|
||||
import { Player } from "../entities/Player";
|
||||
import { Exit } from "../entities/Exit";
|
||||
import { Platform } from "../entities/Platform";
|
||||
import { ObstaclePlatformDisappearing } from "../entities/ObstaclePlatformDisappearing";
|
||||
import { ObstacleSpikeNormal } from "../entities/ObstacleSpikeNormal";
|
||||
import { ObstacleSpikeTricky } from "../entities/ObstacleSpikeTricky";
|
||||
import { LevelMatrix, TILE_SIZE, TileType } from "./levels";
|
||||
import {
|
||||
ObstaclePlatformDisappearing,
|
||||
ObstacleSpikeNormal,
|
||||
ObstacleSpikeTricky,
|
||||
} from "../entities/obstacles";
|
||||
import { LevelMatrix, TILE_SIZE, TileType } from "./levelTypes";
|
||||
|
||||
export interface LoadedLevel {
|
||||
player: Player;
|
||||
46
src/lib/levelTypes.ts
Normal file
46
src/lib/levelTypes.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
export const TILE_SIZE = 40;
|
||||
export const LEVEL_COLS = 20;
|
||||
export const LEVEL_ROWS = 15;
|
||||
|
||||
export enum TileType {
|
||||
Empty = 0,
|
||||
Platform = 1,
|
||||
Player = 2,
|
||||
Exit = 3,
|
||||
DisappearingPlatform = 4,
|
||||
Spike = 5,
|
||||
TrickySpike = 6,
|
||||
}
|
||||
|
||||
export type LevelMatrix = TileType[][];
|
||||
|
||||
export interface LevelDef {
|
||||
name: string;
|
||||
matrix: LevelMatrix;
|
||||
}
|
||||
|
||||
const CHAR_TO_TILE: Record<string, TileType> = {
|
||||
".": TileType.Empty,
|
||||
"#": TileType.Platform,
|
||||
"P": TileType.Player,
|
||||
"E": TileType.Exit,
|
||||
"~": TileType.DisappearingPlatform,
|
||||
"^": TileType.Spike,
|
||||
"T": TileType.TrickySpike,
|
||||
};
|
||||
|
||||
function parseLevel(rows: string[]): LevelMatrix {
|
||||
return rows.map((row, rowIdx) =>
|
||||
[...row].map((c, colIdx) => {
|
||||
const tile = CHAR_TO_TILE[c];
|
||||
if (tile === undefined) {
|
||||
throw new Error(`Invalid tile char '${c}' at row ${rowIdx}, col ${colIdx}`);
|
||||
}
|
||||
return tile;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function defineLevel(name: string, rows: string[]): LevelDef {
|
||||
return { name, matrix: parseLevel(rows) };
|
||||
}
|
||||
@@ -2,11 +2,13 @@ import Phaser from "phaser";
|
||||
import { Player } from "../entities/Player";
|
||||
import { Exit } from "../entities/Exit";
|
||||
import { Platform } from "../entities/Platform";
|
||||
import { ObstaclePlatformDisappearing } from "../entities/ObstaclePlatformDisappearing";
|
||||
import { ObstacleSpikeNormal } from "../entities/ObstacleSpikeNormal";
|
||||
import { ObstacleSpikeTricky } from "../entities/ObstacleSpikeTricky";
|
||||
import { LEVELS } from "../levels/levels";
|
||||
import { LevelLoader } from "../levels/LevelLoader";
|
||||
import {
|
||||
ObstaclePlatformDisappearing,
|
||||
ObstacleSpikeNormal,
|
||||
ObstacleSpikeTricky,
|
||||
} from "../entities/obstacles";
|
||||
import { LEVELS } from "../levels";
|
||||
import { LevelLoader } from "../lib/LevelLoader";
|
||||
|
||||
interface SceneData {
|
||||
levelIndex?: number;
|
||||
|
||||
Reference in New Issue
Block a user