Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rudnev exam #16

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Binary file added Helper.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Deadline
Задание 1 **До 25.11.2020**

Задание 2 **До 16.12.2020**

Индивидуально:
1. Выбрать один из алгоритмов:
клеточный автомат,
генератор комнат,
random walk
свой
2. Реализовать класс для заполнения маски уровня:
матрицы, содержащей информацию о ячейках
Можно в группе
3. Составить JSON, который нужен для отображения
данных об уровне в массив тайлов
3а. Использовать свой или имеющийся в проекте набор тайлов
4. Сделать сцену, которая строится из маcки уровня и набора тайлов
(сцена обновляется при каждом запуске)
5. Проверить:
1. Камера следует за игроком
2. Можно посчитать метрики
(% заполнения, число комнат, связность, максимальный размер уровня, расстояние до цели...)
3. (Опционально) Заполнять несколько уровней карты: пол, украшения, враги/NPC.
# Development

```
Expand Down
6 changes: 6 additions & 0 deletions assets/animations/mine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Mine": {
"Blink": [0, 1],
"Boom": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
}
}
Binary file added assets/sprites/characters/bomb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tileset/Rudnev_Tileset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<style>
* { margin:0; padding:0; }
html, body { width:100%; height:100%; background: black; }
canvas {widht: 600px; display:block; background: black; margin: 0 auto; }

canvas { width: 600px; display:block; background: black; margin: 0 auto; }

</style>
</head>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import slimeSpriteSheet from '../assets/sprites/characters/slime.png'
import CharacterFactory from "../src/characters/character_factory";
import Footsteps from "../assets/audio/footstep_ice_crunchy_run_01.wav";
import {Shadowing} from "../src/ai/steerings/shadowing";
import {Exploration} from "../src/ai/steerings/exploration";
import {Exploring} from "../src/ai/steerings/exploring";


let explorationAndShadowingScene = new Phaser.Class({
let ExplorationAndShadowingScene = new Phaser.Class({

Extends: Phaser.scene,
initialize:
Expand All @@ -27,7 +27,6 @@ let explorationAndShadowingScene = new Phaser.Class({
//loading map tiles and json with positions
this.load.image("tiles", tilemapPng);
this.load.tilemapTiledJSON("map", dungeonRoomJson);

//loading spitesheets
this.load.spritesheet('aurora', auroraSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('blue', blueSpriteSheet, this.characterFrameConfig);
Expand Down Expand Up @@ -67,12 +66,12 @@ let explorationAndShadowingScene = new Phaser.Class({
this.characterFactory = new CharacterFactory(this);
console.log(this.characterFactory)

const walker = this.characterFactory.buildNpcCharacter(
"green","green",200,300,{Steering: new Exploration(this,this)}
const walker = this.characterFactory.buildNPCCharacter(
"green",200,300,{Steering: new Exploring(this)}
);

const shadowing = this.characterFactory.buildNpcCharacter(
"punk","punk",500,100,{Steering: new Shadowing(this,walker)}
const shadowing = this.characterFactory.buildNPCCharacter(
"punk",500,100,{Steering: new Shadowing(this,walker)}
);
this.gameObject.push(walker);
this.gameObject.push(shadowing);
Expand Down Expand Up @@ -102,4 +101,4 @@ let explorationAndShadowingScene = new Phaser.Class({
}
})

export default explorationAndShadowingScene
export default ExplorationAndShadowingScene
132 changes: 132 additions & 0 deletions scenes/miner-scene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import EasyStar from "easystarjs";

import tilemapPng from '../assets/tileset/Dungeon_Tileset.png'
import dungeonRoomJson from '../assets/dungeon_room.json'
import auroraSpriteSheet from '../assets/sprites/characters/aurora.png'
import punkSpriteSheet from '../assets/sprites/characters/punk.png'
import blueSpriteSheet from '../assets/sprites/characters/blue.png'
import yellowSpriteSheet from '../assets/sprites/characters/yellow.png'
import greenSpriteSheet from '../assets/sprites/characters/green.png'
import slimeSpriteSheet from '../assets/sprites/characters/slime.png'
import mineSpriteSheet from '../assets/sprites/characters/bomb.png'
import CharacterFactory from "../src/characters/character_factory";
import Footsteps from "../assets/audio/footstep_ice_crunchy_run_01.wav";

let MinerScene = new Phaser.Class({

Extends: Phaser.Scene,

initialize:

function StartingScene() {
Phaser.Scene.call(this, {key: 'MinerScene'});
},
characterFrameConfig: {frameWidth: 31, frameHeight: 31},
slimeFrameConfig: {frameWidth: 32, frameHeight: 32},
mineFrameConfig: { frameWidth: 130, frameHeight: 130 },
// boomFrameConfig: { frameWidth: 112, frameHeight: 112 },
preload: function () {

//loading map tiles and json with positions
this.load.image("tiles", tilemapPng);
this.load.tilemapTiledJSON("map", dungeonRoomJson);

//loading spitesheets
this.load.spritesheet('slime', slimeSpriteSheet, this.slimeFrameConfig);
this.load.spritesheet('aurora', auroraSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('blue', blueSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('green', greenSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('yellow', yellowSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('punk', punkSpriteSheet, this.characterFrameConfig);
this.load.spritesheet('mine', mineSpriteSheet, this.mineFrameConfig);
// this.load.spritesheet('boom', boomSpriteSheet, this.boomFrameConfig);
this.load.audio('footsteps', Footsteps);
},
create: function () {

this.gameObjects = [];
const map = this.make.tilemap({key: "map"});

// Parameters are the name you gave the tileset in Tiled and then the key of the tileset image in
// Phaser's cache (i.e. the name you used in preload)
const tileset = map.addTilesetImage("Dungeon_Tileset", "tiles");


// Parameters: layer name (or index) from Tiled, tileset, x, y
const belowLayer = map.createStaticLayer("Floor", tileset, 0, 0);
const worldLayer = map.createStaticLayer("Walls", tileset, 0, 0);
const aboveLayer = map.createStaticLayer("Upper", tileset, 0, 0);
this.tileSize = 32;
this.finder = new EasyStar.js();
let grid = [];
for(let y = 0; y < worldLayer.tilemap.height; y++){
let col = [];
for(let x = 0; x < worldLayer.tilemap.width; x++) {
const tile = worldLayer.tilemap.getTileAt(x, y);
col.push(tile ? tile.index : 0);
}
grid.push(col);
}

this.finder.setGrid(grid);
this.finder.setAcceptableTiles([0]);

worldLayer.setCollisionBetween(1, 500);
aboveLayer.setDepth(10);

this.physics.world.bounds.width = map.widthInPixels;
this.physics.world.bounds.height = map.heightInPixels;
this.characterFactory = new CharacterFactory(this);

// Creating characters
this.player = this.characterFactory.buildCharacter('punk', 100, 100, {player: true});
this.gameObjects.push(this.player);
this.physics.add.collider(this.player, worldLayer);

this.mines = this.physics.add.group();

this.slimes = this.physics.add.group();
let params = {};
params.useSteering = true;
// slimes amount !
for(let i = 0; i < 15; i++) {
const x = Phaser.Math.RND.between(50, this.physics.world.bounds.width - 50 );
const y = Phaser.Math.RND.between(50, this.physics.world.bounds.height -50 );
params.slimeType = Phaser.Math.RND.between(0, 4);
const slime = this.characterFactory.buildSlime(x, y, params);
this.slimes.add(slime);
this.physics.add.collider(slime, worldLayer);
this.gameObjects.push(slime);
}
this.physics.add.collider(this.player, this.slimes);

this.input.keyboard.once("keydown_D", event => {
// Turn on physics debugging to show player's hitbox
this.physics.world.createDebugGraphic();

const graphics = this.add
.graphics()
.setAlpha(0.75)
.setDepth(20);
});
},
update: function () {
if (this.gameObjects)
{
this.gameObjects.forEach( function(element) {
element.update();
});
}
const mineEntries = this.mines.children.entries;
if (mineEntries.length > 0) {
mineEntries.forEach(element => element.update());
}

},
tilesToPixels(tileX, tileY)
{
return [tileX*this.tileSize, tileY*this.tileSize];
}
});

export default MinerScene
Loading