//=============================================================================
//=============================================================================
var Lihinel = Lihinel || {};
Lihinel.Warfare = Lihinel.Warfare || {};
Lihinel.Warfare.SceneCommand = function() {
this.initialize.apply(this, arguments);
};
Lihinel.Warfare.SceneCommand.prototype = Object.create(Scene_Base.prototype);
Lihinel.Warfare.SceneCommand.prototype.constructor = Lihinel.Warfare.SceneCommand;
(function() {
Scene_Load.prototype.onLoadSuccess = function() {
SoundManager.playLoad();
this.fadeOutAll();
this.reloadMapIfUpdated();
SceneManager.goto(Lihinel.Warfare.SceneCommand);
this._loadSuccess = true;
};
ImageManager.loadLogo = function(filename, hue) {
return this.loadBitmap('img/logo/', filename, hue, true);
};
var parameters = PluginManager.parameters('Lihinel_Logo');
Lihinel.Warfare.SceneCommand.prototype.initialize = function() {
Scene_Base.prototype.initialize.call(this);
this.scenarios = [{x:200,y:200, scenario:"Test"}, {x:400,y:230, scenario:"Test1"}, {x:300,y:400, scenario:"Test2"}];
}
Lihinel.Warfare.SceneCommand.prototype.create = function() {
Scene_Base.prototype.create.call(this);
};
Lihinel.Warfare.SceneCommand.prototype.start = function() {
Scene_Base.prototype.start.call(this);
//SceneManager.clearStack();
this.startFadeIn(30,false);
/* var bgm = { name: "Epic", volume: 80, pitch: 100, pan: 100};
AudioManager.playBgm(bgm); */
this.selected = {X:-1,y:-1};
this.drawBG();
this.drawTargets();
this.drawDescription();
this.drawSave();
this.startFadeIn(this.fadeSpeed(), false);
};
Lihinel.Warfare.SceneCommand.prototype.stop = function() {
Scene_Base.prototype.stop.call(this);
this.startFadeOut(this.slowFadeSpeed(), false);
};
Lihinel.Warfare.SceneCommand.prototype.terminate = function() {
Scene_Base.prototype.terminate.call(this);
//SceneManager.snapForBackground();
};
Lihinel.Warfare.SceneCommand.prototype.drawBG = function() {
var bitmap = ImageManager.loadPicture("Green0");
var green0 = new Sprite(bitmap);
this._green0 = green0;
this.addChild(green0);
var bitmap = ImageManager.loadPicture("Green1");
var green1 = new Sprite(bitmap);
this._green1 = green1;
this._green0.addChild(green1);
var bitmap = ImageManager.loadPicture("Green2");
var green2 = new Sprite(bitmap);
this._green2 = green2;
this._green0.addChild(green2);
var bitmap = ImageManager.loadPicture("Map0");
var map0 = new Sprite(bitmap);
this._map0 = map0;
this.addChild(map0);
var bitmap = ImageManager.loadPicture("Map1");
var map1 = new Sprite(bitmap);
this._map1 = map1;
this.addChild(map1);
this._green1.x = -816;
this._green2.y = -624;
}
Lihinel.Warfare.SceneCommand.prototype.drawTargets = function() {
this._targets = [];
for(var index in this.scenarios){
var scenario = this.scenarios[index]
this.drawTarget(index, scenario.x, scenario.y);
}
}
Lihinel.Warfare.SceneCommand.prototype.drawTarget = function(index, x, y) {
var bitmap = ImageManager.loadPicture("Target");
var target = new Sprite(bitmap);
this._targets[index] = target;
this.addChild(target);
target.x = x;
target.y = y;
target.anchor.x = 0.5;
target.anchor.y = 0.5;
}
Lihinel.Warfare.SceneCommand.prototype.drawSave = function() {
var bitmap = ImageManager.loadPicture("Save");
var save = new Sprite(bitmap);
this._save = save;
this.addChild(save);
this._save.x = 16;
this._save.y = 16;
}
Lihinel.Warfare.SceneCommand.prototype.drawDescription = function() {
var bitmap = new Bitmap(716, 60);
var discription = new Sprite(bitmap);
this._discription = discription;
this.addChild(discription);
discription.bitmap.fillRect(0,0,716,60,"#000000");
discription.x = 50;
discription.y = 540;
this._discription.visible = false;
}
Lihinel.Warfare.SceneCommand.prototype.update = function() {
if (!this.isBusy()) {
var x = TouchInput.x;
var y = TouchInput.y;
if(TouchInput.isTriggered()){
if(x < 64 && y < 64){
SceneManager.push(Scene_Save);
}else{
this.checkForSelectedTargetAndStartMission(x,y);
}
}
if(TouchInput.isCancelled()){
this.selected.x = -1;
this.selected.y = -1;
this.updateDescription(null);
}
this.updateBG();
this.updateTargets();
}
Scene_Base.prototype.update.call(this);
};
Lihinel.Warfare.SceneCommand.prototype.checkForSelectedTargetAndStartMission = function(x,y) {
var target = this.checkTargets(x,y);
if(target != -1){
var scenario = this.scenarios[target].scenario;
if(this.selected.x == x && this.selected.y == y){
Lihinel.Warfare.scenario = scenario;
Lihinel.DataManager.setupWarfareUnitDataForMap(0);
if(Lihinel.Warfare.save_data[scenario] == null){
$gamePlayer._transferring = true;
$gamePlayer._newMapId = 2;
$gamePlayer._newDirection = 0;
$gamePlayer._newX = 0;
$gamePlayer._newY = 0;
//this.fadeOutAll();
SceneManager.goto(Scene_Map);
}else{
//this.fadeOutAll();
SceneManager.goto(Lihinel.Warfare.Scene);
}
console.log(this._fadeSprite)
}else{
this.selected.x = x;
this.selected.y = y;
this.updateDescription(scenario);
}
}else{
this.updateDescription(null);
}
}
Lihinel.Warfare.SceneCommand.prototype.checkTargets = function(x,y) {
var max = this._targets.length;
for(var i=0;i<max;i++){
var target = this.checkTarget(i,x,y);
if(target != -1){return target}
}
return -1;
}
Lihinel.Warfare.SceneCommand.prototype.checkTarget = function(index,x,y) {
console.log(index)
if(this._targets[index].x > x - 32 && this._targets[index].x < x + 32 && this._targets[index].y > y - 32 && this._targets[index].y < y + 32){
return index;
}
return -1;
}
Lihinel.Warfare.SceneCommand.prototype.updateBG = function() {
this._green1.x += 10;
this._green2.y -= 10;
if(this._green1.x >= 1800){this._green1.x = -816}
if(this._green2.y < -624){this._green2.y = 1400}
}
Lihinel.Warfare.SceneCommand.prototype.updateTargets = function() {
var max = this._targets.length;
for(var i=0;i<max;i++){
this.updateTarget(i);
}
}
Lihinel.Warfare.SceneCommand.prototype.updateTarget = function(index) {
this._targets[index].rotation += 0.025;
}
Lihinel.Warfare.SceneCommand.prototype.updateDescription = function(scenario) {
if(scenario != null){
this._discription.visible = true;
this._discription.bitmap.fillRect(0,0,716,60,"#000000");
this._discription.bitmap.drawText(scenario,50,0,616,60,"left");
if(Lihinel.Warfare.save_data[scenario] == null){
var text = "Start Mission";
}else{
var sec = Math.floor(Lihinel.Warfare.save_data[scenario].playtime / 60);
var min = Math.floor(sec / 60);
var hour = Math.floor(min / 60);
if(sec < 10){sec = "0" + sec};
if(min < 10){min = "0" + min};
var text = "Continue: " + hour + ":" + min + ":" + sec;
}
this._discription.bitmap.drawText(text,50,0,616,60,"right");
}else{
this._discription.visible = false;
}
}
Lihinel.Warfare.SceneCommand.prototype.updateTitle = function(zoom) {
if(zoom > 0){
var width = 816 * zoom / 624;
var height = 240 * zoom / 624;
this._title1.y = 312 - Math.floor(height/2);
this._title1.x = 408 - Math.floor(width/2);
this._title1.bitmap.clear();
var src_bitmap = ImageManager.loadTitle1("IntroTitle1");
this._title1.bitmap.bltImage(src_bitmap, 0, 0, src_bitmap.width, src_bitmap.height, 0, 0, width, height);
this._title1.opacity = (zoom / 2);
}
}
})();