Skip to content

Commit

Permalink
add dungeon-generator example.
Browse files Browse the repository at this point in the history
  • Loading branch information
tenpaMk2 committed Jul 18, 2022
1 parent 68e676d commit a9a64f6
Show file tree
Hide file tree
Showing 11 changed files with 4,575 additions and 0 deletions.
4,441 changes: 4,441 additions & 0 deletions examples/dungeon-generator/package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions examples/dungeon-generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "dungeon-generator",
"type": "module",
"scripts": {
"start": "parcel serve ./src/index.html",
"build": "parcel build ./src/index.html --dist-dir ./publish --public-url ./"
},
"author": "tenpaMk2",
"license": "MIT",
"dependencies": {
"excalibur": "^0.27.0"
},
"devDependencies": {
"parcel": "^2.6.2",
"prettier": "^2.7.1",
"typescript": "^4.7.4"
}
}
Binary file added examples/dungeon-generator/src/assets/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions examples/dungeon-generator/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const gameWidth = 1080 / 2;
const gameHeight = 1920 / 2;

export default {
gameWidth: gameWidth,
gameHeight: gameHeight,
};
1 change: 1 addition & 0 deletions examples/dungeon-generator/src/files.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "*.png";
13 changes: 13 additions & 0 deletions examples/dungeon-generator/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./style.css" />
<script defer type="module" src="./index.ts"></script>
<title>Example</title>
</head>
<body>
<canvas id="game"></canvas>
</body>
</html>
25 changes: 25 additions & 0 deletions examples/dungeon-generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DisplayMode, Engine, Loader } from "excalibur";
import config from "./config";
import { Resources } from "./resource";
import { GameScene } from "./scenes/game-scene";

const engine = new Engine({
width: config.gameWidth,
height: config.gameHeight,
canvasElementId: "game",
displayMode: DisplayMode.FitScreen,
});

engine.showDebug(false);

engine.add("game-scene", new GameScene());
engine.goToScene("game-scene");

const loader = new Loader();
for (const resource of Object.values(Resources)) {
loader.addResource(resource);
}

loader.suppressPlayButton = true;

engine.start(loader);
7 changes: 7 additions & 0 deletions examples/dungeon-generator/src/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ImageSource } from "excalibur";

import heart from "./assets/heart.png";

export const Resources = {
heart: new ImageSource(heart),
};
43 changes: 43 additions & 0 deletions examples/dungeon-generator/src/scenes/game-scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Color, Engine, Scene, Text, TileMap, Vector } from "excalibur";
import { PointerEvent } from "excalibur/build/dist/Input/PointerEvent";

export class GameScene extends Scene {
private tilemap!: TileMap;

onInitialize(engine: Engine): void {
this.tilemap = new TileMap({
pos: Vector.Zero,
rows: 24,
columns: 16,
tileWidth: 32,
tileHeight: 32,
});
engine.add(this.tilemap);

this.tilemap.tiles.forEach((tile) => {
tile.data.set("id", 0);
});

engine.input.pointers.primary.on("down", (event: PointerEvent): void => {
this.tilemap.tiles.forEach((tile) => {
const id = tile.data.get("id")!;
tile.data.set("id", id + 1);
});

this.updateTilemap();
});
}

updateTilemap(): void {
this.tilemap.tiles.forEach((tile) => {
const id = tile.data.get("id")!;

const text = new Text({
text: `${id}`,
color: Color.White,
});
tile.clearGraphics();
tile.addGraphic(text);
});
}
}
9 changes: 9 additions & 0 deletions examples/dungeon-generator/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* {
padding: 0;
margin: 0;
}

canvas {
-webkit-touch-callout: none !important;
-webkit-user-select: none !important;
}
11 changes: 11 additions & 0 deletions examples/dungeon-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "ES6",
"moduleResolution": "node",
"sourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true
}
}

0 comments on commit a9a64f6

Please sign in to comment.