-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": ["env"], | ||
"plugins": ["transform-object-rest-spread"] | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<div id="game"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,84 @@ | ||
import * as PIXI from "pixi.js"; | ||
const map = ` | ||
****************** | ||
*................* | ||
*................* | ||
*................* | ||
*................* | ||
*................* | ||
****************** | ||
******************** | ||
*..................* | ||
*..................* | ||
*..................* | ||
*..................* | ||
*..................* | ||
******************** | ||
`; | ||
|
||
function initScene() { | ||
const renderer = PIXI.autoDetectRenderer(1000, 1000, null, { | ||
noWebGl: true, | ||
antialias: false | ||
}); | ||
document.getElementById("game").appendChild(renderer.view); | ||
return { | ||
map: map, | ||
sprites: {}, | ||
textures: {}, | ||
renderer, | ||
stage: new PIXI.Container() | ||
}; | ||
} | ||
|
||
function loadGraphics() { | ||
return new Promise((resolve, reject) => { | ||
PIXI.loader | ||
.add("tile", "./img/tile.png") | ||
.add("wall", "./img/wall.png") | ||
.load((loader, resources) => { | ||
resolve({ loader, resources }); | ||
}); | ||
}); | ||
} | ||
|
||
function start() { | ||
const scene = initScene(); | ||
Promise.all([loadGraphics()]).then(([{ loader, resources }]) => { | ||
onLoadResources(loader, resources, scene); | ||
}); | ||
} | ||
|
||
function onLoadResources(loader, resources, scene) { | ||
const terrain = ['tile', 'wall']; | ||
const textures = terrain.reduce((acc, name) => { | ||
acc[name] = new PIXI.Texture(resources[name].texture, new PIXI.Rectangle(0, 0, 50, 50)) | ||
return acc | ||
}, {}); | ||
render({ | ||
...scene, | ||
textures | ||
}); | ||
} | ||
|
||
function render(scene) { | ||
const rows = scene.map.split("\n").filter(row => row !== ''); | ||
rows.map((row, idx) => { | ||
console.log(row.split("")); | ||
row.split("").map((tileChar, column) => { | ||
let tile; | ||
switch (tileChar) { | ||
case ".": | ||
tile = new PIXI.Sprite(scene.textures.tile); | ||
break; | ||
case "*": | ||
tile = new PIXI.Sprite(scene.textures.wall); | ||
break; | ||
default: | ||
throw `Unrecognized tile char ${tileChar}`; | ||
} | ||
tile.position.x = column * 50; | ||
tile.position.y = idx * 50; | ||
scene.stage.addChild(tile); | ||
}); | ||
}); | ||
scene.renderer.render(scene.stage); | ||
var result = "abc".repeat(2); | ||
} | ||
|
||
console.log(map); | ||
|
||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters