Skip to content

Instantly share code, notes, and snippets.

@HimeWorks
Last active January 27, 2016 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HimeWorks/be6271a3636ae4d72cac to your computer and use it in GitHub Desktop.
Save HimeWorks/be6271a3636ae4d72cac to your computer and use it in GitHub Desktop.
Hime ATB: Super Simple Version
// A super simple implementation of an ATB. Used for tutorial purposes.
// Read the tutorial here: http://himeworks.com/2016/01/tutorial-designing-a-simple-active-battle-system/
var Imported = Imported || {} ;
var TH = TH || {};
Imported.TH_ActiveTimeBattle = 1;
TH.ActiveTimeBattle = TH.ActiveTimeBattle || {};
(function ($) {
var TH_GameBattler_initMembers = Game_Battler.prototype.initMembers;
Game_Battler.prototype.initMembers = function() {
TH_GameBattler_initMembers.call(this);
this._atb = 0;
};
var TH_GameBattler_onBattleStart = Game_Battler.prototype.onBattleStart
Game_Battler.prototype.onBattleStart = function() {
TH_GameBattler_onBattleStart.call(this);
this._atb = 0;
};
Game_Battler.prototype.atb = function() {
return this._atb
};
Game_Battler.prototype.atbMax = function() {
return 100;
};
Game_Battler.prototype.atbRate = function() {
return this._atb / this.atbMax();
};
Game_Battler.prototype.atbFillRate = function() {
return 1;
};
Game_Battler.prototype.clearAtb = function() {
this._atb = 0;
};
var TH_GameBattler_canInput = Game_Battler.prototype.canInput;
Game_Battler.prototype.canInput = function() {
return this._atb === this.atbMax() && TH_GameBattler_canInput.call(this);
}
Game_Battler.prototype.updateAtb = function() {
this._atb = Math.min(this._atb + this.atbFillRate(), this.atbMax());
};
Game_Battler.prototype.updateFrame = function() {
this.updateAtb();
};
/***************************************************************************/
Game_Unit.prototype.updateFrame = function() {
var members = this.members();
for (var i = 0; i < members.length; i++) {
members[i].updateFrame();
}
};
/***************************************************************************/
BattleManager.actor = function() {
return this._subject;
};
BattleManager.selectNextCommand = function() {
this._phase = 'turn';
};
BattleManager.selectPreviousCommand = function() {
this._phase = 'turn';
};
BattleManager.startInput = function() {
if (this._subject) {
this._subject.makeActions();
if (this._subject.isActor() && this._subject.canInput()) {
this._subject.setActionState('inputting');
this._phase = 'input'
}
}
else {
this._phase = 'turn'
}
};
BattleManager.updateTurn = function() {
if (this._subject) {
if (this._subject.currentAction()) {
this.processTurn();
}
else {
this.endSubjectTurn();
}
}
else {
this.updateFrame();
}
};
BattleManager.updateFrame = function() {
var members = this.allBattleMembers();
for (var i = 0; i < members.length; i++) {
if (members[i].canInput()) {
this._subject = members[i];
this.startInput();
break;
}
}
if (!this._subject) {
$gameParty.updateFrame();
$gameTroop.updateFrame();
}
}
BattleManager.endSubjectTurn = function() {
this._subject.clearAtb()
this._subject = null;
};
/***************************************************************************/
Window_BattleStatus.prototype.drawActorAtb = function(actor, x, y, width) {
width = width || 186;
var color1 = this.hpGaugeColor1();
var color2 = this.hpGaugeColor2();
this.drawGauge(x, y, width, actor.atbRate(), color1, color2);
this.changeTextColor(this.systemColor());
this.drawText("ATB", x, y, 44);
};
Window_BattleStatus.prototype.drawGaugeAreaWithTp = function(rect, actor) {
this.drawActorHp(actor, rect.x + 0, rect.y, 108);
this.drawActorMp(actor, rect.x + 123, rect.y, 96);
this.drawActorAtb(actor, rect.x + 234, rect.y, 96);
};
var TH_WindowBattleStatus_update = Window_BattleStatus.prototype.update;
Window_BattleStatus.prototype.update = function() {
TH_WindowBattleStatus_update.call(this);
this.refresh();
}
})(TH.ActiveTimeBattle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment