Skip to content

Commit

Permalink
feat: implement basic map with programmatically added conveyer belt o…
Browse files Browse the repository at this point in the history
…bjects
  • Loading branch information
dawsonc623 committed Jul 20, 2020
1 parent 6ce78e0 commit 1b0255a
Show file tree
Hide file tree
Showing 11 changed files with 814 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"license": "MIT",
"private": true,
"scripts": {
"extrude": "node scripts/extrude.js",
"watch": "parcel -p 8080 watch src/ui/index.html"
},
"devDependencies": {
"parcel-bundler": "^1.12.4",
"sass": "^1.26.10",
"tile-extruder": "^2.0.6",
"typescript": "^3.9.7"
},
"dependencies": {
Expand Down
37 changes: 37 additions & 0 deletions scripts/extrude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const {
extrudeTilesetToImage
} = require("tile-extruder");

const assetsPath = `${__dirname}/../src/ui/assets`;
const distPath = `${__dirname}/../dist/assets`;

const extrusionAssets = new Map([
[
`${assetsPath}/environment.png`,
{
"tileHeight": 32,
"tileWidth": 32
}
],
[
`${assetsPath}/objects1.png`,
{
"tileHeight": 32,
"tileWidth": 32
}
]
]);

for (let [asset, options] of extrusionAssets) {
const {
tileHeight,
tileWidth
} = options;

extrudeTilesetToImage(
tileWidth,
tileHeight,
asset,
asset.replace(".png", "-extruded.png")
);
}
Binary file added src/ui/assets/environment-extruded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ui/assets/environment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ui/assets/objects1-extruded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ui/assets/objects1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions src/ui/assets/proto1-landscape.json

Large diffs are not rendered by default.

105 changes: 103 additions & 2 deletions src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,51 @@ import {
Scene
} from "phaser";

import environmentImage from "./assets/environment-extruded.png";
import landscapeJson from "./assets/proto1-landscape.json";
import objects1Image from "./assets/objects1.png";

import "./index.scss";

class BootScene extends Scene
{
public constructor()
{
super("boot");
}

public preload()
{
// Landscape

this.load.tilemapTiledJSON(
"environmentTilemap",
landscapeJson
);

this.load.image(
"environmentTileset",
environmentImage
);

// Objects

this.load.spritesheet(
"objects1",
objects1Image,
{
"frameHeight" : 32,
"frameWidth" : 32
}
);
}

public create() : void
{
this.scene.start("helloWorld");
}
}

class HelloWorldScene extends Scene
{
public constructor()
Expand All @@ -14,8 +57,65 @@ class HelloWorldScene extends Scene

public create()
{
const helloMessage = this.add.text(this.scale.width / 2, 100, "Hello, World!");
helloMessage.setOrigin(0.5);
// Landscape

const tileMap = this.make.tilemap({
"key" : "environmentTilemap",
});

const tiles = tileMap.addTilesetImage(
"environment",
"environmentTileset",
32,
32,
1,
2
);

tileMap.createStaticLayer(
"Base 1",
tiles
);

// Animations

// Conveyer belt
this.anims.create({
"key" : "conveyerBelt",
"frameRate" : 6,
"repeat" : -1,
"frames" : this.anims.generateFrameNumbers(
"objects1",
{
"frames" : [0, 8, 16, 24]
}
)
});

// Scene

// Conveyer belts
this.placeConveyerBelt(128, 96);
this.placeConveyerBelt(160, 96);
this.placeConveyerBelt(192, 96);
this.placeConveyerBelt(224, 96);
}

private placeConveyerBelt(
x : number,
y : number
) : void
{
const conveyerBelt = this.add.sprite(
x,
y,
"objects1",
0
);

conveyerBelt.play(
"conveyerBelt"
);
}
}

Expand All @@ -36,6 +136,7 @@ new Game({
},

"scene" : [
BootScene,
HelloWorldScene
]
});
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"downlevelIteration": true,
"esModuleInterop": true,
"noEmitOnError": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"strict": true,
"typeRoots": [
"./node_modules/@types",
"./types"
]
},
"include": [
"./src/**/*.ts"
]
}
2 changes: 2 additions & 0 deletions types/static/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "*.png";
declare module "*.json";
Loading

0 comments on commit 1b0255a

Please sign in to comment.