From 19e97a83ed75ee70e7d90d737cc6841d4978eda3 Mon Sep 17 00:00:00 2001 From: 34oew9f8d623 Date: Fri, 22 Jan 2021 13:47:10 +0300 Subject: [PATCH] final --- src/ai/aggressive.js | 2 +- src/characters/bullet.js | 15 ---- src/utils/level_generator/level-build.js | 77 ++++++++++++++----- .../quad-space-partitioning.js | 36 ++++++--- 4 files changed, 83 insertions(+), 47 deletions(-) diff --git a/src/ai/aggressive.js b/src/ai/aggressive.js index 8f97969..0b139b7 100644 --- a/src/ai/aggressive.js +++ b/src/ai/aggressive.js @@ -57,7 +57,7 @@ export default class Aggressive{ const context = this; const target = context.targets.find(x => x.body.position.distance(context.me.body.position) < context.distance) - context.me.maxSpeed = 60; + context.me.maxSpeed = 30; context.me.steering = new Chase(context.me, [target], 1, context.distance); this.timer = 0; } diff --git a/src/characters/bullet.js b/src/characters/bullet.js index cce1a07..e69de29 100644 --- a/src/characters/bullet.js +++ b/src/characters/bullet.js @@ -1,15 +0,0 @@ -export default class Bullet extends Phaser.Physics.Arcade.Sprite { - - constructor (scene, x, y, vx, vy) { - super(scene, x, y, 'bullet'); - - this.body.reset(x, y); - this.body.mass = 3; - - this.setActive(true); - this.setVisible(true); - - this.setVelocityX(vx); - this.setVelocityY(vy); - } -} \ No newline at end of file diff --git a/src/utils/level_generator/level-build.js b/src/utils/level_generator/level-build.js index c89db38..b556fab 100644 --- a/src/utils/level_generator/level-build.js +++ b/src/utils/level_generator/level-build.js @@ -9,13 +9,27 @@ const TILES = { WALL_LEFT: 18, WALL_RIGHT: 16, - WALL_TOP: 39, - WALL_BOTTOM: 52, + WALL_TOP: 20, + WALL_BOTTOM: 36, - CORNER_TOP_LEFT: 0, - CORNER_TOP_RIGHT: 0, - CORNER_BOTTOM_LEFT: 35, - CORNER_BOTTOM_RIGHT: 37, + CORRIDOR_TOP: 39, + CORRIDOR_BOTTOM: 52, + + WALL_TOP_LEFT: 19, + WALL_TOP_RIGHT: 21, + WALL_BOTTOM_LEFT: 35, + WALL_BOTTOM_RIGHT: 37, + + UPPER_TOP: 4, + UPPER_BOTTOM1: 36, + UPPER_BOTTOM2: 52, + + UPPER_TOP_LEFT: 3, + UPPER_TOP_RIGHT: 5, + UPPER_BOTTOM_LEFT1: 35, + UPPER_BOTTOM_RIGHT1: 37, + UPPER_BOTTOM_LEFT2: 51, + UPPER_BOTTOM_RIGHT2: 53, } @@ -31,10 +45,11 @@ export default function buildLevel(width, height, scene, { rooms, corridors, mas const tileSet = scene.map.addTilesetImage("tiles", null, tileSize, tileSize); - // создаём уровни сцены + // создаём уровни сцены. какой порядок? const outsideLayer = scene.map.createBlankDynamicLayer("Outside", tileSet); const groundLayer = scene.map.createBlankDynamicLayer("Ground", tileSet); const wallsLayer = scene.map.createBlankDynamicLayer("Walls", tileSet); + //const upperLayer = scene.map.createBlankDynamicLayer("Upper", tileSet); // по маске уровня заполняем уровни outsideLayer, groundLayer // fill, putTileAt, weightedRandomize @@ -42,25 +57,41 @@ export default function buildLevel(width, height, scene, { rooms, corridors, mas for (let y = 0; y < height; y++) { if (mask[x][y] === 0) { outsideLayer.putTileAt(TILES.BLANK, x, y); - } else if (mask[x][y] === 2) { + } else if (mask[x][y] === 1) { + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + }/*else if (mask[x][y] === 2) { wallsLayer.putTileAt(TILES.WALL_LEFT, x, y); groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } else if (mask[x][y] === 3) { wallsLayer.putTileAt(TILES.WALL_RIGHT, x, y); groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } else if (mask[x][y] === 4) { - wallsLayer.putTileAt(TILES.WALL_TOP, x, y); + wallsLayer.putTileAt(TILES.WALL_TOP, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } else if (mask[x][y] === 5) { - wallsLayer.putTileAt(TILES.WALL_BOTTOM, x, y); + wallsLayer.putTileAt(TILES.CORRIDOR_BOTTOM, x, y); + //upperLayer.putTileAt(TILES.UPPER_BOTTOM1, x, y-1); + //upperLayer.putTileAt(TILES.UPPER_BOTTOM2, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } else if (mask[x][y] === 6) { - wallsLayer.putTileAt(TILES.CORNER_TOP_LEFT, x, y); + wallsLayer.putTileAt(TILES.WALL_TOP_LEFT, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } else if (mask[x][y] === 7) { - wallsLayer.putTileAt(TILES.CORNER_TOP_RIGHT, x, y); - } else if (mask[x][y] === 5) { - wallsLayer.putTileAt(TILES.CORNER_BOTTOM_LEFT, x, y); - } else if (mask[x][y] === 5) { - wallsLayer.putTileAt(TILES.CORNER_BOTTOM_RIGHT, x, y); - } else { + wallsLayer.putTileAt(TILES.WALL_TOP_RIGHT, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + } else if (mask[x][y] === 8) { + wallsLayer.putTileAt(TILES.WALL_BOTTOM_LEFT, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + } else if (mask[x][y] === 9) { + wallsLayer.putTileAt(TILES.WALL_BOTTOM_RIGHT, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + } else if (mask[x][y] === 10) { + wallsLayer.putTileAt(TILES.CORRIDOR_TOP, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + } else if (mask[x][y] === 11) { + wallsLayer.putTileAt(TILES.CORRIDOR_BOTTOM, x, y); + groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); + } */else { groundLayer.weightedRandomize(x, y, 1, 1, TILES.FLOOR); } } @@ -69,7 +100,8 @@ export default function buildLevel(width, height, scene, { rooms, corridors, mas // добавляем персонажа Аврору const startRoom = rooms[0]; scene.player = scene.characterFactory.buildCharacter('aurora', startRoom.x*32+32, startRoom.y*32+32, {player: true}); - scene.physics.add.collider(scene.player, wallsLayer); + //scene.physics.add.collider(scene.player, wallsLayer); + scene.physics.add.collider(scene.player, outsideLayer); scene.gameObjects.push(scene.player); // точка появления игроков @@ -87,7 +119,8 @@ export default function buildLevel(width, height, scene, { rooms, corridors, mas //const npc = scene.characterFactory.buildCharacter('green', roomNPC.x*32+32, roomNPC.y*32+32, { Steering: new Exploring(this) }); const npc = scene.characterFactory.buildCharacter('punk', roomNPC.x*32+32, roomNPC.y*32+32); npc.setAI(new Aggressive(npc, [scene.player]), 'idle'); - scene.physics.add.collider(npc, wallsLayer); + //scene.physics.add.collider(npc, wallsLayer); + scene.physics.add.collider(npc, outsideLayer); scene.physics.add.collider(npc, scene.player, scene.onNpcPlayerCollide.bind(scene)); scene.gameObjects.push(npc); scene.npc.push(npc); @@ -104,8 +137,10 @@ export default function buildLevel(width, height, scene, { rooms, corridors, mas // настройки столкновений с уровнями // https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html#setCollision__anchor scene.physics.world.setBounds(0, 0, scene.map.widthInPixels, scene.map.heightInPixels, true, true, true, true); - wallsLayer.setDepth(10); - wallsLayer.setCollisionBetween(0, 320); // столкновение с тайлами у которых индексы 0..320 + //wallsLayer.setDepth(10); + //wallsLayer.setCollisionBetween(0, 320); // столкновение с тайлами у которых индексы 0..320 + outsideLayer.setDepth(10); + outsideLayer.setCollision(TILES.BLANK); return {"Ground" : groundLayer, "Outside" : outsideLayer, "Walls" : wallsLayer} } \ No newline at end of file diff --git a/src/utils/level_generator/quad-space-partitioning.js b/src/utils/level_generator/quad-space-partitioning.js index 2a74015..7e28b9c 100644 --- a/src/utils/level_generator/quad-space-partitioning.js +++ b/src/utils/level_generator/quad-space-partitioning.js @@ -77,25 +77,41 @@ export default class QuadSpacePartitioning { if (0 < y && matrix[i][y-1] === 0) matrix[i][y-1] = 4; } for (let i = x; i < x+w; i++) { // нижняя стена - if (y+h < this.height-1 && matrix[i][y+h] === 0) matrix[i][y+h] = 5; + if (y+h < this.height && matrix[i][y+h] === 0) matrix[i][y+h] = 5; } for (let i = y; i < y+h; i++) { // левая стена if (0 < x && matrix[x-1][i] === 0) matrix[x-1][i] = 2; } for (let i = y; i < y+h; i++) { // правая стена - if (x+w < this.width-1 && matrix[x+w][i] === 0) matrix[x+w][i] = 3; + if (x+w < this.width && matrix[x+w][i] === 0) matrix[x+w][i] = 3; } if (0 < x && 0 < y && matrix[x-1][y-1] === 0) matrix[x-1][y-1] = 6; // верхний левый угол - if (x+w < this.width-1 && 0 < y && matrix[x+w][y-1] === 0) matrix[x+w][y-1] = 7; // верхний правый угол - if (0 < x && y+h < this.height-1 && matrix[x-1][y+h] === 0) matrix[x-1][y+h] = 8; // нижний левый угол - if (x+w < this.width-1 && y+h < this.height-1 && matrix[x+w][y+h] === 0) matrix[x+w][y+h] = 9; // нижний правый угол + if (x+w < this.width && 0 < y && matrix[x+w][y-1] === 0) matrix[x+w][y-1] = 7; // верхний правый угол + if (0 < x && y+h < this.height && matrix[x-1][y+h] === 0) matrix[x-1][y+h] = 8; // нижний левый угол + if (x+w < this.width && y+h < this.height && matrix[x+w][y+h] === 0) matrix[x+w][y+h] = 9; // нижний правый угол } - rooms.forEach(r => makeWall(r)); - corridors.forEach( ({ rect_dx, rect_dy }) => { - if (rect_dx) makeWall(rect_dx); - if (rect_dy) makeWall(rect_dy); - }); + //rooms.forEach(r => makeWall(r)); + + // 10-wall_top, 11-wall_bottom + const makeWall2 = ({ x,y,w,h }) => { + /*for (let i = x; i < x+w; i++) { // верхняя стена + if (0 < y && matrix[i][y-1] === 0) matrix[i][y-1] = 10; + }*/ + for (let i = x; i < x+w; i++) { // нижняя стена + if (y+h < this.height && matrix[i][y+h] === 0) matrix[i][y+h] = 11; + } + for (let i = y; i < y+h; i++) { // левая стена + if (0 < x && matrix[x-1][i] === 0) matrix[x-1][i] = 2; + } + for (let i = y; i < y+h; i++) { // правая стена + if (x+w < this.width && matrix[x+w][i] === 0) matrix[x+w][i] = 3; + } + } + /*corridors.forEach( ({ rect_dx, rect_dy }) => { + if (rect_dx) makeWall2(rect_dx); + if (rect_dy) makeWall2(rect_dy); + });*/ return { rooms: rooms, corridors:corridors, mask:matrix }; }