finished all tasks
This commit is contained in:
parent
8abe52eca8
commit
2312b96115
@ -23,6 +23,7 @@ import { PathFinder } from "./Utils/PathFinding.utils";
|
||||
import { getNavigationGridTile } from "./World/NavigationGrid/NavigationGrid";
|
||||
import { TerrainManger } from "./WorldGenV2/TerrainManager/TerrainManager";
|
||||
import { generateFirstChunks } from "./WorldGenV2/WorldGenV2";
|
||||
import { CHUNK_LAYER_TERRAIN } from "./WorldGenV2/Chunk/Chunk";
|
||||
|
||||
export function generateWorld() {
|
||||
|
||||
@ -55,15 +56,7 @@ function setupInGameSelector() {
|
||||
BC_VIEWPORT.eventMode = "static";
|
||||
BC_VIEWPORT.onmousemove = (e) => {
|
||||
let t = screenToWorldCoordinates(e.data.global.x, e.data.global.y);
|
||||
// let tChunk = getWorldChunkAt(t.x, t.y);
|
||||
// let tTerrainTile = tChunk.getFromChunk(t.x, t.y, ChunkStorageTypes.TYPE_TERRAIN);
|
||||
// let terrainTile = getTileAt(t.x, t.y, ChunkStorageTypes.TYPE_TERRAIN);
|
||||
// console.log(terrainTile);
|
||||
// UISelectionInfo.update((s)=>{
|
||||
// s.types = [terrainTile.props.type];
|
||||
// });
|
||||
let tile = BC_TERRAIN_MANAGER.getTileAt(new PointInt2D(t.x, t.y));
|
||||
// console.log(tile);
|
||||
let tile = BC_TERRAIN_MANAGER.getTileAt(new PointInt2D(t.x, t.y), CHUNK_LAYER_TERRAIN);
|
||||
if(tile)
|
||||
{
|
||||
UISelectionInfo.update((s)=>{
|
||||
@ -141,6 +134,9 @@ export async function initGame() {
|
||||
createKeyboardBinding("KeyS", "Hold", [moveVertically]);
|
||||
createKeyboardBinding("KeyA", "Hold", [moveHorizontally]);
|
||||
createKeyboardBinding("KeyD", "Hold", [moveHorizontally]);
|
||||
// createKeyboardBinding("ArrowRight", "Down", [()=>{
|
||||
// BC_TERRAIN_MANAGER.changeTerrain(BC_TERRAIN_MANAGER.createNewTerrain());
|
||||
// }]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ const _keyboard_current_states = {};
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
_keyboard_current_states[event.code] = true;
|
||||
// console.log(event.code);
|
||||
});
|
||||
|
||||
window.addEventListener("keyup", (event) => {
|
||||
|
@ -210,7 +210,7 @@ export class NPCTask {
|
||||
this._resetAllActions();
|
||||
this._currentIndex = this._startIndex;
|
||||
clearTimeout(this._pauseTimeout);
|
||||
this.taskCallback(new NPCTaskCallbackResult(2, "reset", this._lastActionCallbackResult.clone(), this));
|
||||
this.taskCallback(new NPCTaskCallbackResult(2, "reset", this._lastActionCallbackResult?.clone(), this));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { GameObject } from "../../GameObject/GameObject";
|
||||
import { NPCTask_moveToTile } from "../../NPCTasks/Default/DefaultNPCTasks";
|
||||
import { PointInt2D } from "../../Utils/Math.utils";
|
||||
import { NavigationPath, PathFinder } from "../../Utils/PathFinding.utils";
|
||||
import { findPathOnNavigationGridIfExists } from "../../World/NavigationGrid/NavigationGrid";
|
||||
@ -29,32 +30,11 @@ export class NPCController extends GameObject {
|
||||
navigationFollowMidPoint = false;
|
||||
navigationCallback = () => {};
|
||||
|
||||
taskInstanceRef = new NPCTask(
|
||||
[
|
||||
new NPCAction(0, new PointInt2D(0, 0), undefined, undefined, undefined, false, true, 1000),
|
||||
new NPCAction(
|
||||
1,
|
||||
undefined,
|
||||
async (myOwner, action) => {
|
||||
console.log(myOwner);
|
||||
return new NPCActionCallbackResult(1, "", action);
|
||||
},
|
||||
"Привет!",
|
||||
undefined,
|
||||
false,
|
||||
false,
|
||||
0
|
||||
),
|
||||
],
|
||||
undefined,
|
||||
false
|
||||
);
|
||||
|
||||
behavior = new NPCBehavior(this, () => {});
|
||||
|
||||
constructor(tickAble = true) {
|
||||
super(tickAble);
|
||||
this.behavior.addTask("MoveToCursor", this.taskInstanceRef);
|
||||
this.behavior.addTask("MoveToCursor", NPCTask_moveToTile);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +84,8 @@ export class NPCController extends GameObject {
|
||||
}
|
||||
|
||||
tick(ticker) {
|
||||
this.taskInstanceRef.handleTaskTick(ticker);
|
||||
// this.taskInstanceRef.handleTaskTick(ticker);
|
||||
this.behavior.handleNPCBehaviorTick(ticker);
|
||||
if (this.navigationInProgress) {
|
||||
if (!this.navigationFollowMidPoint) {
|
||||
let target = this.navigationPathQueue.pop();
|
||||
|
@ -1,2 +0,0 @@
|
||||
|
||||
// export class NPCObserver
|
10
src/Game/NPCTasks/Default/DefaultNPCTasks.js
Normal file
10
src/Game/NPCTasks/Default/DefaultNPCTasks.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { NPCAction, NPCTask } from "../../NPC/NPCBehavior/NPCBehavior";
|
||||
import { PointInt2D } from "../../Utils/Math.utils";
|
||||
|
||||
export const NPCTask_moveToTile = new NPCTask(
|
||||
[
|
||||
new NPCAction(0, new PointInt2D(0, 0), undefined, undefined, undefined, false, false, 0)
|
||||
],
|
||||
undefined,
|
||||
false
|
||||
);
|
@ -62,15 +62,20 @@ export class Terrain extends SceneObject {
|
||||
/**
|
||||
*
|
||||
* @param {PointInt2D} point in world coordinates
|
||||
* @param {Number} layerId chunk layer id
|
||||
* @returns {Tile | undefined}
|
||||
*/
|
||||
getTileAt(point) {
|
||||
getTileAt(point, layerId) {
|
||||
let tileKey = Math.floor(point.getX() / BC_TERRAIN_SETTINGS.totalSize) * BC_TERRAIN_SETTINGS.totalSize + "_" + Math.floor(point.getY() / BC_TERRAIN_SETTINGS.totalSize) * BC_TERRAIN_SETTINGS.totalSize;
|
||||
let chunkKey = Math.floor(point.getX() / (BC_TERRAIN_SETTINGS.totalSize * BC_CHUNKS_SETTINGS.width)) + "_" + Math.floor(point.getY() / (BC_TERRAIN_SETTINGS.totalSize * BC_CHUNKS_SETTINGS.height));
|
||||
let chunk = this.chunkStorage.get(chunkKey);
|
||||
// console.log(tileKey);
|
||||
if (chunk) {
|
||||
return chunk.terrainLayer.get(tileKey);
|
||||
switch (layerId) {
|
||||
case CHUNK_LAYER_TERRAIN:
|
||||
return chunk.terrainLayer.get(tileKey);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ const terrainNavigationCostList = {
|
||||
export function createTerrainTileFromTileValue(value, position) {
|
||||
let t = new TerrainTile(false, position);
|
||||
t.spriteSheetPath = "assets/images/world/world_terrain_atlas_overlay.png";
|
||||
if (value.noiseValue < 0.5) {
|
||||
if (value.noiseValue < 0.3) {
|
||||
t.frame = selectRandomValueFromArray(TERRAIN_TILE_WATER_FRAMES, value.noiseValue);
|
||||
t.tileId = TERRAIN_TILE_WATER;
|
||||
t.zOrder = TERRAIN_TILE_WATER_Z;
|
||||
t.navigationCost = terrainNavigationCostList[TERRAIN_TILE_WATER];
|
||||
} else if (value.noiseValue < 0.6)
|
||||
} else if (value.noiseValue < 0.35)
|
||||
{
|
||||
t.frame = selectRandomValueFromArray(TERRAIN_TILE_SAND_FRAMES, value.noiseValue);
|
||||
t.tileId = TERRAIN_TILE_SAND;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { GameObject } from "../../GameObject/GameObject";
|
||||
import { addGameObjectToGameState } from "../../GameState/GameState";
|
||||
import { BC_CAMERA, BC_CHUNKS_SETTINGS, BC_TERRAIN_SETTINGS } from "../../GlobalVariables/GlobalVariables";
|
||||
import { BC_CAMERA, BC_CHUNKS_SETTINGS, BC_TERRAIN_SETTINGS, BC_VIEWPORT } from "../../GlobalVariables/GlobalVariables";
|
||||
import { PointInt2D } from "../../Utils/Math.utils";
|
||||
import { NavigationGridChunk } from "../../World/NavigationGrid/NavigationGrid";
|
||||
import { Chunk } from "../Chunk/Chunk";
|
||||
@ -40,6 +40,17 @@ export class TerrainManger {
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Terrain} terrain
|
||||
*/
|
||||
changeTerrain(terrain)
|
||||
{
|
||||
BC_VIEWPORT.removeChild(this.currentTerrain.drawObject);
|
||||
BC_VIEWPORT.addChild(terrain.drawObject);
|
||||
this.currentTerrain = terrain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {PointInt2D} pivot
|
||||
@ -98,10 +109,11 @@ export class TerrainManger {
|
||||
/**
|
||||
*
|
||||
* @param {PointInt2D} point in world coordinates
|
||||
* @param {Number} layerId chunk layer id
|
||||
* @returns {Tile | undefined}
|
||||
*/
|
||||
getTileAt(point) {
|
||||
return this.currentTerrain.getTileAt(point);
|
||||
getTileAt(point, layerId) {
|
||||
return this.currentTerrain.getTileAt(point, layerId);
|
||||
}
|
||||
|
||||
handleChunkVisibility() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user