Skip to content

Commit

Permalink
addIsometricLevel: Mirror width and height property names from addLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
gugiserman committed Nov 16, 2021
1 parent 8946d47 commit abead06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions demo/isometricLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const level = addIsometricLevel([
'@@@@@@@@@@@@@@@',
], {
// The size of each grid
tileWidth: 144,
tileHeight: 71,
width: 144,
height: 71,
// Define what each symbol means (in components)
'@': () => [
sprite('grass'),
Expand All @@ -56,8 +56,8 @@ const level2 = addIsometricLevel([
'@@@@@@@@@@@@@@@',
'@@@@@@@@@@@@@@@',
], {
tileWidth: 144,
tileHeight: 71,
width: 144,
height: 71,
'@': () => [
sprite('grass'),
],
Expand Down
14 changes: 7 additions & 7 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2479,15 +2479,15 @@ function addLevel(map: string[], opt: LevelOpt): Level {
}

function addIsometricLevel(map: string[], options: IsometricLevelOpt): IsometricLevel {
if (!options.tileWidth || !options.tileHeight) {
if (!options.width || !options.height) {
throw new Error("Must provide isometric level tile width & height.");
}

const objects: GameObj[] = [];
const offset = vec2(options.pos || vec2(0));

const halfTileWidth = Math.floor(options.tileWidth / 2);
const halfTileHeight = Math.floor(options.tileHeight / 2);
const halfTileWidth = Math.floor(options.width / 2);
const halfTileHeight = Math.floor(options.height / 2);

const maxWidthInTiles = map.reduce((width, row): number => Math.max(width, row.length), 0)
const heightInTiles = map.length;
Expand All @@ -2498,11 +2498,11 @@ function addIsometricLevel(map: string[], options: IsometricLevelOpt): Isometric
},

gridWidth() {
return options.tileWidth;
return options.width;
},

gridHeight() {
return options.tileHeight;
return options.height;
},

fromIsometricCoordsToWorldPos: (row: number, col: number): Vec2 => {
Expand Down Expand Up @@ -2553,11 +2553,11 @@ function addIsometricLevel(map: string[], options: IsometricLevelOpt): Isometric
},

width() {
return maxWidthInTiles * options.tileWidth;
return maxWidthInTiles * options.width;
},

height() {
return heightInTiles * options.tileHeight;
return heightInTiles * options.height;
},

destroy() {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3814,11 +3814,11 @@ export interface IsometricLevelOpt {
/**
* Width of each block.
*/
tileWidth: number,
width: number,
/**
* Height of each block.
*/
tileHeight: number,
height: number,
/**
* Position of the first block.
*/
Expand Down

0 comments on commit abead06

Please sign in to comment.