-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-28 Getting raycasts of viable locations
- Calculating viable locations for movement based on original positions.
- Loading branch information
Showing
10 changed files
with
431 additions
and
62 deletions.
There are no files selected for viewing
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
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
21 changes: 21 additions & 0 deletions
21
packages/phaser3-formation-generator/src/demo/scene/demo-sprite.js
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,21 @@ | ||
import Phaser from 'phaser'; | ||
import { v4 } from 'uuid'; | ||
|
||
const TEMP_SPEED = 250; | ||
|
||
export default class DemoSprite extends Phaser.GameObjects.Sprite { | ||
constructor(scene, x, y) { | ||
super(scene, x, y, 'enabled-sprite'); | ||
this.id = v4(); | ||
|
||
scene.gameObjectEnginePlugin.addEngineToGameObject(this, { | ||
rotateOnMove: false, | ||
rotateSpeed: 10, | ||
speed: TEMP_SPEED, | ||
gameObjectStoppingDistance: 128, | ||
}); | ||
scene.add.existing(this); | ||
scene.physics.world.enable(this); | ||
this.setInteractive(); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
packages/phaser3-formation-generator/src/demo/scene/tile-map.js
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,113 @@ | ||
import Phaser from 'phaser'; | ||
|
||
const WIDTH_TILES = 40; | ||
const HEIGHT_TILES = 30; | ||
const TILE_SIZE = 32; | ||
const MAP_CONFIG = { | ||
tileWidth: TILE_SIZE, | ||
tileHeight: TILE_SIZE, | ||
width: WIDTH_TILES, | ||
height: HEIGHT_TILES, | ||
}; | ||
const COLLISION_INDICES = new Array(24).fill('').map((d, i) => i); // Ignore the last item in ground_1x1 (grass) | ||
|
||
const STAGGERED_TILES = [ | ||
[20, 20], | ||
[21, 20], | ||
[21, 21], | ||
[22, 21], | ||
[22, 22], | ||
[23, 22], | ||
|
||
[25, 20], | ||
[26, 20], | ||
[26, 21], | ||
[27, 21], | ||
[27, 22], | ||
[28, 22], | ||
]; | ||
|
||
export default class DemoTileMap { | ||
bgLayer; | ||
collisionLayer; | ||
map; | ||
scene; | ||
tileSet; | ||
|
||
constructor(scene) { | ||
this.scene = scene; | ||
this.map = scene.make.tilemap(MAP_CONFIG); | ||
|
||
this.tileSet = this.map.addTilesetImage('demo-ground-tile-set', 'ground_1x1', TILE_SIZE, TILE_SIZE); | ||
|
||
this.initLayers(); | ||
this.drawBackgroundLayer(); | ||
this.drawGrid(); | ||
|
||
// Must be after we add the layer / tileSet | ||
this.map.setCollision(COLLISION_INDICES); | ||
} | ||
|
||
get collisionIndices() { | ||
return COLLISION_INDICES; | ||
} | ||
|
||
initLayers() { | ||
this.bgLayer = this.map.createBlankDynamicLayer('demo-bg-layer-id', this.tileSet); | ||
this.collisionLayer = this.map.createBlankDynamicLayer('demo-layer-id', this.tileSet); | ||
} | ||
|
||
drawBackgroundLayer() { | ||
const { width, height } = this.map; | ||
let y = 0; | ||
let x; | ||
|
||
for (y; y < height; y++) { | ||
x = 0; | ||
for (x; x < width; x++) { | ||
this.map.putTileAt(24, x, y, true, this.bgLayer); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @description Draws a random shape on the map for testing | ||
*/ | ||
drawGrid() { | ||
const { map } = this; | ||
const startAtX = 5; | ||
const startAtY = 5; | ||
const yLength = startAtY + 10; | ||
let y = startAtY; | ||
let xLength; | ||
let x; | ||
let tileIndex; | ||
|
||
for (y; y < yLength; y++) { | ||
x = startAtX; | ||
xLength = startAtX + 20; | ||
for (x; x < xLength; x++) { | ||
if (x !== startAtX && y !== startAtY && x !== xLength - 4 && y !== yLength - 1) { | ||
continue; | ||
} | ||
|
||
tileIndex = Math.floor(Phaser.Math.Between(0, COLLISION_INDICES.length - 1)); | ||
map.putTileAt(tileIndex, x, y, true, this.collisionLayer); | ||
} | ||
} | ||
|
||
STAGGERED_TILES.forEach(([tileX, tileY]) => { | ||
tileIndex = Math.floor(Phaser.Math.Between(0, COLLISION_INDICES.length - 1)); | ||
map.putTileAt(tileIndex, tileX, tileY, true, this.collisionLayer); | ||
}); | ||
} | ||
|
||
placeTileAtWorldPoint(worldPoint) { | ||
// Rounds down to nearest tile | ||
const pointerTileX = this.map.worldToTileX(worldPoint.x); | ||
const pointerTileY = this.map.worldToTileY(worldPoint.y); | ||
|
||
const tileIndex = Phaser.Math.Between(0, 23); | ||
this.map.putTileAt(tileIndex, pointerTileX, pointerTileY, true, this.collisionLayer); | ||
} | ||
} |
Oops, something went wrong.