Confira o Videos Épicos #45!
10 Respostas   347 Visualizações
0 Membros e 1 Visitante estão vendo este tópico.
//=============================================================================// Spring_Simple_Formation.js//=============================================================================/*: * @plugindesc Spring's Simple Formation Code. * @author Tony Hart * * @help This plugin does not provide plugin commands. */(function() { "use strict"; //--------------------------------------------------------------------------- // Formation // // Classe de controle a rotina dos personagens do jogo function Formation() { throw new Error('This is a static class'); } /* * Região permitida para os followers andarem */ Formation.regionID = 1; /* * Posicao x,y e direção inicial do player */ Formation.playerDir = 2; Formation.playerX = 0; Formation.playerY = 0; /* * Posições que serão pesquisadas para os followers em relação * ao Player (P) * * | | | |D| | | | * | | |I|9|K| | | * | |H|5|3|6|J| | * |G|C|1|P|2|B|F| * | |L|7|4|8|N| | * | | |M|A|O| | | * | | | |E| | | | * */ var _Game_Followers_initialize = Game_Followers.prototype.initialize; Game_Followers.prototype.initialize = function() { _Game_Followers_initialize.call(this); this._followersPosition = [ {x: -1, y: 0, dirBlocked: 4}, // 1 {x: 1, y: 0, dirBlocked: 6}, // 2 {x: 0, y: -1, dirBlocked: 8}, // 3 {x: 0, y: 1, dirBlocked: 2}, // 4 {x: -1, y: -1, dirBlocked: 4}, // 5 {x: 1, y: -1, dirBlocked: 6}, // 6 {x: -1, y: 1, dirBlocked: 4}, // 7 {x: 1, y: 1, dirBlocked: 6}, // 8 {x: 0, y: -2, dirBlocked: 8}, // 9 {x: 0, y: 2, dirBlocked: 2}, // A {x: 2, y: 0, dirBlocked: 6}, // B {x: -2, y: 0, dirBlocked: 4}, // C {x: 0, y: -3, dirBlocked: 8}, // D {x: 0, y: 3, dirBlocked: 2}, // E {x: 3, y: 0, dirBlocked: 6}, // F {x: -3, y: 0, dirBlocked: 4}, // G {x: -2, y: -1, dirBlocked: 4}, // H {x: -1, y: -2, dirBlocked: 4}, // I {x: 2, y: -1, dirBlocked: 6}, // J {x: 1, y: -2, dirBlocked: 6}, // K {x: -2, y: 1, dirBlocked: 4}, // L {x: -1, y: 2, dirBlocked: 4}, // M {x: 2, y: 1, dirBlocked: 6}, // N {x: 1, y: 2, dirBlocked: 6} // O ] }; /* * Verifica se tal posição já está ocupada por algum follower * ou na frente do Player */ Game_Followers.prototype.isOccupied = function(x, y, member) { for (var i = $gamePlayer._followers._data.length - 1; i >= 0; i--) { var f = $gamePlayer._followers._data[i]; // Ocupado se outro membro já estiver na posição x,y if(f.nextX == x && f.nextY == y && f._memberIndex != member) { return true; } // Ocupado se o player já estiver na posição x,y if(Formation.playerX == x && Formation.playerY == y) { return true; } // Ocupado se o a posição x,y estiver na frente do player switch(Formation.playerDir) { case 8 : for(var pos = -1; pos >= -3; pos--) { if(Formation.playerX == x && (Formation.playerY + pos) == y) { return true; } } break; case 6 : for(var pos = 1; pos <= 3; pos++) { if((Formation.playerX + pos) == x && Formation.playerY == y) { return true; } } break; case 2 : for(var pos = 1; pos <= 3; pos++) { if(Formation.playerX == x && (Formation.playerY + pos) == y) { return true; } } break; case 4 : for(var pos = -1; pos >= -3; pos--) { if((Formation.playerX + pos) == x && Formation.playerY == y) { return true; } } break; } } return false; }; /* * Retorna a posição x,y que o follower deve ficar */ Game_Followers.prototype.getDirections = function(x, y, member) { var thisFollowers = this; for(var i = 0; i < this._followersPosition.length; i++) { var newX = this._followersPosition[i].x+x; var newY = this._followersPosition[i].y+y; var sameDirectionPlayer = this._followersPosition[i].dirBlocked == Formation.playerDir; // Retorna posicao x,y se a região for igual a 1, não está ocupada por outro follower e não está na mesma direcao que o player if($gameMap.regionId(newX, newY) == Formation.regionID && !thisFollowers.isOccupied(newX, newY, member) && !sameDirectionPlayer) { return {x: newX, y: newY}; } } return {x: x, y: y}; }; /* * Salva a posicaoe direção do player */ var _Game_Player_moveStraight = Game_Player.prototype.moveStraight; Game_Player.prototype.moveStraight = function(d) { _Game_Player_moveStraight.call(this, d); if (this.canPass(this.x, this.y, d)) { Formation.playerX = $gameMap.roundXWithDirection(this.x, d); Formation.playerY = $gameMap.roundYWithDirection(this.y, d); Formation.playerDir = d; } }; /* * Sobrescreve comportamento padrão (Catterpillar) */ Game_Followers.prototype.updateMove = function() {}; /* * Sobrescreve comportamento padrão moveTowardCharacter para follower se mover * em direçao proxima ao player */ Game_Follower.prototype.moveTowardCharacter = function(character, i) { var position = character._followers.getDirections(character.x, character.y, this._memberIndex); this.nextX = position.x; this.nextY = position.y; var sx = this.deltaXFrom(position.x); var sy = this.deltaYFrom(position.y); if (Math.abs(sx) > Math.abs(sy)) { this.moveStraight(sx > 0 ? 4 : 6); if (!this.isMovementSucceeded() && sy !== 0) { this.moveStraight(sy > 0 ? 8 : 2); } } else if (sy !== 0) { this.moveStraight(sy > 0 ? 8 : 2); if (!this.isMovementSucceeded() && sx !== 0) { this.moveStraight(sx > 0 ? 4 : 6); } } }; /* * Mover em direção ao proxima ao player */ var _Game_Follower_update = Game_Follower.prototype.update; Game_Follower.prototype.update = function() { _Game_Follower_update.call(this); if(this.isStopping()) { this._through = false; this.moveTowardCharacter($gamePlayer, this._memberIndex); // Set direção ao finalizar movimento if(this._x == this._realX && this._y == this._realY) { this.setDirection(Formation.playerDir); } } };})();