//matterjs kullanılaacak phaser3 de /* const controls = { jump: false, left: false,…
- User
//matterjs kullanılaacak phaser3 de /* const controls = { jump: false, left: false, right: false, shoot: false };
phaser matterjs deki setData ve getData ile karakter objesinin özellikleri ayarlanacak böylece npc yi kendi klasına veri taşınacak ve kontrolleri ben gerçekleştireceğim
setData(key: unknown, data?: any): Phaser.Physics.Matter.Sprite The key to set the value for. Or an object of key value pairs. If an object the data argument is ignored. this.character.setData("controls",controls);
this.character.setData("anger",1); this.character.setData("anger",2); this.character.setData("anger",3); this.character.setData("anger",4); this.character.setData("anger",5);
getData(key: string | string[]): any The key of the value to retrieve, or an array of keys.
const DangerLevel = this.character.getData("anger");
düşmanın zarar verme katsayısına göre gecikme azalır ve bizi yakalama gücü de artacak const currentDangerK = defaultDangerK * DangerLevel; ile bulunur
her mermi yediğinde düşmanımızın kızgınlı artar ve bu oyunu zorlaştırır
son olarak karakter destroyed ise class çalışmaz
tüm hareketler const controls = ... ile olur
*/ class PathFinder { constructor(character,my_map,tiles, finder,phaser_timer) { this.my_map = my_map; // Harita nesnesini depoluyoruz this.tiles = tiles; this.finder = finder; // Yol bulma algoritması nesnesini depoluyoruz this.character = character; this.phaser_timer = phaser_timer;
/*this.phaser_timer.addEvent({
}) */
} iterateWay(){ const grid = []; for(var y = 0; y < this.my_map.height; y++){ var col = []; for(var x = 0; x < this.my_map.width; x++){ // In each cell we store the ID of the tile, which corresponds // to its index in the tileset of the map ("ID" field in Tiled) col.push(this.getTileID(x,y)); } grid.push(col); } this.finder.setGrid(grid); } findWay(){ const tileset = this.my_map.tilesets[0]; const properties = tileset.tileProperties; const acceptableTiles = []; for(let i = tileset.firstgid-1; i < this.tiles.total; i++){ // firstgid and total are fields from Tiled that indicate the range of IDs that the tiles can take in that tileset if(!properties.hasOwnProperty(i)) { // If there is no property indicated at all, it means it's a walkable tile acceptableTiles.push(i+1); continue; } if(!properties[i].collide) acceptableTiles.push(i+1); if(properties[i].cost) this.finder.setTileCost(i+1, properties[i].cost); // If there is a cost attached to the tile, let's register it } this.finder.setAcceptableTiles(acceptableTiles); } getTileID = function(x,y){ const tile = this.my_map.getTileAt(x, y); return tile.index; } - Assistant