Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
GitAcc0unt123 committed Jan 22, 2021
1 parent ab60615 commit 19e97a8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/ai/aggressive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 0 additions & 15 deletions src/characters/bullet.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
77 changes: 56 additions & 21 deletions src/utils/level_generator/level-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand All @@ -31,36 +45,53 @@ 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
for (let x = 0; x < width; x++) {
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);
}
}
Expand All @@ -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);

// точка появления игроков
Expand All @@ -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);
Expand All @@ -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}
}
36 changes: 26 additions & 10 deletions src/utils/level_generator/quad-space-partitioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 19e97a8

Please sign in to comment.