Back to main page: http://stencyl-nator.blogspot.com/p/endless-scenes.html
This version supports (physics mode = minimal) actors.
Here is the code:
Script.Game_context is get resource numbers with arbitrary resource names.
Hint: scripts.G0Text is not needed if you want to use original com.stencyl.graphics.G
For more info about the G0Text: http://stencyl-nator.blogspot.com/p/text-drawing-arbitrary-code-for-stencyl.html
package scripts; //pxpy=q0, pxny=q1, nxny=q2, nxpy = q3
import com.stencyl.behavior.Script;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;
import com.stencyl.Engine; //initial header for arbritary code
import com.stencyl.graphics.G;
import com.stencyl.models.Actor;
import com.stencyl.utils.Utils;
import scripts.G0text;
import scripts.Game_context;
class Abg_sce_behav extends SceneScript //found in preview code in scene behaviors,
{
@:attribute("name = 'scene id '") // attribute blanks
public var scene_id:Int;
import com.stencyl.behavior.Script;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;
import com.stencyl.Engine; //initial header for arbritary code
import com.stencyl.graphics.G;
import com.stencyl.models.Actor;
import com.stencyl.utils.Utils;
import scripts.G0text;
import scripts.Game_context;
class Abg_sce_behav extends SceneScript //found in preview code in scene behaviors,
{
@:attribute("name = 'scene id '") // attribute blanks
public var scene_id:Int;
public var camx:Int; public var camy:Int;
public var f:G0text = new G0text(); //custom drawing code
public var half_sceh:Int; public var half_scrh:Int;
public var half_scew:Int; public var half_scrw:Int;
public var initile_xmax:Int; public var initile_ymax:Int;
public var initile_xmin:Int; public var initile_ymin:Int;
public var noa:Int;
public var offsx:Float; public var offsy:Float;
public var player:Actor;
public var sceh:Int; public var scew:Int;
public var scrh:Int; public var scrw:Int;
public var scrm_xmax:Int; public var scrm_xmin:Int;
public var scrm_ymax:Int; public var scrm_ymin:Int;
public var shifting: Bool;
public var tdat_actors:Array <Dynamic> = []; // actors cannot be saved. So negative index values are acceptable.
public var tdat_ids_q0:Array <Dynamic> = []; // index values cannot be negative otherwise the data cannot be saved.
public var tdat_ids_q1:Array <Dynamic> = [];
public var tdat_ids_q2:Array <Dynamic> = [];
public var tdat_ids_q3:Array <Dynamic> = [];
public var tdat_rota_q0:Array <Dynamic> = [];
public var tdat_rota_q1:Array <Dynamic> = [];
public var tdat_rota_q2:Array <Dynamic> = [];
public var tdat_rota_q3:Array <Dynamic> = [];
public var testlag:Int = 0;
public var upd:Bool = false;
public function new(dummy:Int, dummy2:Engine){super();}
override public function init() //All events except advanced
{
this.f.lesp = -1; // custom drawing code:
this.f.setFont(Script.getFont(101));
this.sceh = Std.int(Engine.engine.scene.sceneHeight);
public var f:G0text = new G0text(); //custom drawing code
public var half_sceh:Int; public var half_scrh:Int;
public var half_scew:Int; public var half_scrw:Int;
public var initile_xmax:Int; public var initile_ymax:Int;
public var initile_xmin:Int; public var initile_ymin:Int;
public var noa:Int;
public var offsx:Float; public var offsy:Float;
public var player:Actor;
public var sceh:Int; public var scew:Int;
public var scrh:Int; public var scrw:Int;
public var scrm_xmax:Int; public var scrm_xmin:Int;
public var scrm_ymax:Int; public var scrm_ymin:Int;
public var shifting: Bool;
public var tdat_actors:Array <Dynamic> = []; // actors cannot be saved. So negative index values are acceptable.
public var tdat_ids_q0:Array <Dynamic> = []; // index values cannot be negative otherwise the data cannot be saved.
public var tdat_ids_q1:Array <Dynamic> = [];
public var tdat_ids_q2:Array <Dynamic> = [];
public var tdat_ids_q3:Array <Dynamic> = [];
public var tdat_rota_q0:Array <Dynamic> = [];
public var tdat_rota_q1:Array <Dynamic> = [];
public var tdat_rota_q2:Array <Dynamic> = [];
public var tdat_rota_q3:Array <Dynamic> = [];
public var testlag:Int = 0;
public var upd:Bool = false;
public function new(dummy:Int, dummy2:Engine){super();}
override public function init() //All events except advanced
{
this.f.lesp = -1; // custom drawing code:
this.f.setFont(Script.getFont(101));
this.sceh = Std.int(Engine.engine.scene.sceneHeight);
this.scrh = Std.int(Engine.screenHeight);
this.scew = Std.int(Engine.engine.scene.sceneWidth);
this.scew = Std.int(Engine.engine.scene.sceneWidth);
this.scrw = Std.int(Engine.screenWidth);
this.half_sceh = Std.int(this.sceh/2);
this.half_scew = Std.int(this.scew/2);
this.noa =0; this.shifting = false;
Script.createRecycledActor(Script.getActorType(59), this.scrw-86, 0, Script.FRONT);
Script.createRecycledActor(Script.getActorType(57), this.scrw-86, 57, Script.FRONT);
Script.runLater(20, function(t:TimedTask):Void
{
Script.createRecycledActorOnLayer(Script.getActorType(6), this.half_scew-20, this.half_sceh-20, Engine.engine.getLayerById(1));
this.player = Script.lastCreatedActor;
//this.empty_ratio = Init_udg_scedata.sce_empty_ratio(this.scene_id);
this.load_data();
}, null);
addWhenDrawingListener(null, function(g:G, x:Float, y:Float, list:Array<Dynamic>):Void
{
this.f.drawString("testlag "+this.testlag,105,0); this.f.drawString("num of actors"+this.noa,310,0);
this.f.drawString("initile_xmax"+this.initile_xmax,105,25);
this.f.drawString("initile_xmin"+this.initile_xmin,105,45);
this.f.drawString("initile_ymax"+this.initile_ymax,105,65);
this.f.drawString("initile_ymin"+this.initile_ymin,105,85);
this.f.drawString("cam x"+this.camx,105,105);
this.f.drawString("cam y"+this.camy,305,105);
this.f.drawString("xmax margin: "+ this.scrm_xmax, 105, 130);
this.f.drawString("xmin margin: "+ this.scrm_xmin, 315, 130);
this.f.drawString("ymax margin: "+ this.scrm_ymax, 105, 150);
this.f.drawString("ymin margin: "+ this.scrm_ymin, 315, 150);
this.f.drawString("offsx: "+ this.offsx, 105, 170); this.f.drawString("offsy : "+ this.offsy, 315, 170);
});
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
this.testlag += 1;
if(this.upd && !(this.shifting))
{
this.camx = Std.int(Engine.cameraX); this.camy = Std.int(Engine.cameraY);
this.scrm_xmax = Std.int(this.initile_xmax * 64 - this.camx + this.half_scew - this.scrw - this.offsx);
this.scrm_xmin = Std.int(this.camx - this.initile_xmin* 64 - this.half_scew + this.offsx);
this.scrm_ymax = Std.int(this.initile_ymax * 64 - this.camy + this.half_sceh - this.scrh - this.offsy);
this.scrm_ymin = Std.int(this.camy - this.initile_ymin*64 - this.half_sceh + this.offsy);
if(this.scrm_xmax < 128)
{
this.p_tdat_v(this.initile_xmax);
this.initile_xmax += 1;
}
else if(this.scrm_xmax > 192)
{
this.initile_xmax -= 1;
this.r_tdat_v(this.initile_xmax);
}
if(this.scrm_xmin < 128)
{
this.initile_xmin -= 1;
this.p_tdat_v(this.initile_xmin);
}
else if(this.scrm_xmin > 192)
{
this.r_tdat_v(this.initile_xmin);
this.initile_xmin += 1;
}
if(this.scrm_ymax < 128)
{
this.p_tdat_h(this.initile_ymax);
this.initile_ymax += 1;
}
else if(this.scrm_ymax > 192)
{
this.initile_ymax -= 1;
this.r_tdat_h(this.initile_ymax);
}
if(this.scrm_ymin < 128)
{
this.initile_ymin -= 1;
this.p_tdat_h(this.initile_ymin);
}
else if(this.scrm_ymin > 192)
{
this.r_tdat_h(this.initile_ymin);
this.initile_ymin += 1;
}
if(this.camx < 128){this.shift_right();}
else if(this.camx + this.scrw > this.scew - 128){this.shift_left();}
if(this.camy < 128){this.shift_down();}
else if(this.camy + this.scrh > this.sceh - 128){this.shift_up();}
this.upd = false;
Script.runLater(128, function(t:TimedTask):Void // delay miliconds
{
this.upd = true;
}, null);
}
});
}
public function init_data():Void //initailise all the scene variables
{
if(""+this.offsx=="null" ||""+this.offsx=="undefined" ||""+this.offsx=="NaN"){this.offsx=0;}
if(""+this.offsy=="null" ||""+this.offsy=="undefined" ||""+this.offsy=="NaN"){this.offsy=0;}
if(""+this.tdat_ids_q0 == "null"||""+this.tdat_ids_q0 == "undefined"){this.tdat_ids_q0 = [];}
if(""+this.tdat_ids_q1 == "null"||""+this.tdat_ids_q1 == "undefined"){this.tdat_ids_q1 = [];}
if(""+this.tdat_ids_q2 == "null"||""+this.tdat_ids_q2 == "undefined"){this.tdat_ids_q2 = [];}
if(""+this.tdat_ids_q3 == "null"||""+this.tdat_ids_q3 == "undefined"){this.tdat_ids_q3 = [];}
if(""+this.tdat_rota_q0 == "null"||""+this.tdat_rota_q0 == "undefined"){this.tdat_rota_q0 = [];}
if(""+this.tdat_rota_q1 == "null"||""+this.tdat_rota_q1 == "undefined"){this.tdat_rota_q1 = [];}
if(""+this.tdat_rota_q2 == "null"||""+this.tdat_rota_q2 == "undefined"){this.tdat_rota_q2 = [];}
if(""+this.tdat_rota_q3 == "null"||""+this.tdat_rota_q3 == "undefined"){this.tdat_rota_q3 = [];}
this.init_popu_scene();
}
public function init_popu_scene():Void //initially populate the scene
{
var a:Int=0; var b:Int=0; var c:Int=0; var d:Int=0;
Script.runLater(20,function(t:TimedTask):Void
{
this.camx = Std.int(Engine.cameraX); this.camy = Std.int(Engine.cameraY);
this.initile_xmax = Std.int((this.camx + this.scrw - this.half_sceh)/64 - this.offsx) + 2;
this.initile_xmin = Std.int((this.camx - this.half_sceh)/64 + this.offsx) - 2;
this.initile_ymax = Std.int((this.camy + this.scrh - this.half_sceh - this.offsy)/64) + 2;
this.initile_ymin = Std.int((this.camy - this.half_sceh)/64 + this.offsy) - 2;
a = this.initile_xmin; b = this.initile_xmax;
c = this.initile_ymin; d = this.initile_ymax;
while(c < d)
{
this.p_tdat_h(c); c = c+1;
}
this.upd = true;
},null);
}
public function load_data():Void // load from saved game
{
this.tdat_ids_q0 = Engine.engine.getGameAttribute("abg_tdat_ids_q0")[this.scene_id];
this.tdat_ids_q1 = Engine.engine.getGameAttribute("abg_tdat_ids_q1")[this.scene_id];
this.tdat_ids_q2 = Engine.engine.getGameAttribute("abg_tdat_ids_q2")[this.scene_id];
this.tdat_ids_q3 = Engine.engine.getGameAttribute("abg_tdat_ids_q3")[this.scene_id];
this.tdat_rota_q0 = Engine.engine.getGameAttribute("abg_tdat_rot_q0")[this.scene_id];
this.tdat_rota_q1 = Engine.engine.getGameAttribute("abg_tdat_rot_q1")[this.scene_id];
this.tdat_rota_q2 = Engine.engine.getGameAttribute("abg_tdat_rot_q2")[this.scene_id];
this.tdat_rota_q3 = Engine.engine.getGameAttribute("abg_tdat_rot_q3")[this.scene_id];
this.offsx = Engine.engine.getGameAttribute("abg_offsx")[this.scene_id];
this.offsy = Engine.engine.getGameAttribute("abg_offsy")[this.scene_id];
this.init_data();
}
public function p_tdat_h(y:Int):Void
{
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var create_x:Float = 0; var create_y: Float = y*64 + this.half_sceh - this.offsy;
var r:Float=0; var s:String = "";
while(x < xmax)
{
create_x = x*64 + this.half_scew - this.offsx;
if(""+this.tdat_actors[x]=="null"||""+this.tdat_actors[x]=="undefined"){this.tdat_actors[x] = [];}
if(x < 0)
{
if(y < 0)
{
if(""+this.tdat_ids_q2[0-x]=="null"||""+this.tdat_ids_q2[0-x]=="undefined"){this.tdat_ids_q2[0-x]=[];}
if(""+this.tdat_ids_q2[0-x][0-y]=="null"||""+this.tdat_ids_q2[0-x][0-y]=="undefined"){this.tdat_ids_q2[0-x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q2[0-x]=="null"||""+this.tdat_rota_q2[0-x]=="undefined"){this.tdat_rota_q2[0-x]=[];}
if(""+this.tdat_rota_q2[0-x][0-y]=="null"||""+this.tdat_rota_q2[0-x][0-y]=="undefined"){this.tdat_rota_q2[0-x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q2[0-x][0-y]; s = this.tdat_ids_q2[0-x][0-y];
}
else
{
if(""+this.tdat_ids_q3[0-x]=="null"||""+this.tdat_ids_q3[0-x]=="undefined"){this.tdat_ids_q3[0-x]=[];}
if(""+this.tdat_ids_q3[0-x][y]=="null"||""+this.tdat_ids_q3[0-x][y]=="undefined"){this.tdat_ids_q3[0-x][y]= this.randgen_tdat_ids();}
if(""+this.tdat_rota_q3[0-x]=="null"||""+this.tdat_rota_q3[0-x]=="undefined"){this.tdat_rota_q3[0-x]=[];}
if(""+this.tdat_rota_q3[0-x][y]=="null"||""+this.tdat_rota_q3[0-x][y] =="undefined"){this.tdat_rota_q3[0-x][y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q3[0-x][y]; s = this.tdat_ids_q3[0-x][y];
}
}
else
{
if(y < 0)
{
if(""+this.tdat_ids_q1[x]=="null"||""+this.tdat_ids_q1[x]=="undefined"){this.tdat_ids_q1[x]=[];}
if(""+this.tdat_ids_q1[x][0-y]=="null"||""+this.tdat_ids_q1[x][0-y]=="undefined"){this.tdat_ids_q1[x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q1[x]=="null"||""+this.tdat_rota_q1[x]=="undefined"){this.tdat_rota_q1[x]=[];}
if(""+this.tdat_rota_q1[x][0-y]=="null"||""+this.tdat_rota_q1[x][0-y]=="undefined"){this.tdat_rota_q1[x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q1[x][0-y]; s = this.tdat_ids_q1[x][0-y];
}
else
{
if(""+this.tdat_ids_q0[x]=="null"||""+this.tdat_ids_q0[x]=="undefined"){this.tdat_ids_q0[x]=[];}
if(""+this.tdat_ids_q0[x][y]=="null"||""+this.tdat_ids_q0[x][y]=="undefined"){this.tdat_ids_q0[x][y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q0[x]=="null"||""+this.tdat_rota_q0[x]=="undefined"){this.tdat_rota_q0[x]=[];}
if(""+this.tdat_rota_q0[x][y]=="null"||""+this.tdat_rota_q0[x][y]=="undefined"){this.tdat_rota_q0[x][y]= Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q0[x][y]; s = this.tdat_ids_q0[x][y];
}
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
x = x+1;
}
}
public function p_tdat_v(x:Int):Void
{
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
var create_x:Float = x*64 + this.half_scew - this.offsx; var create_y:Float = 0;
var r:Float=0; var s:String = "";
if(""+this.tdat_actors[x]=="null"||""+this.tdat_actors[x]=="undefined"){this.tdat_actors[x]=[];}
if (x < 0)
{
while (y < ymax)
{
create_y = y*64 + this.half_sceh - this.offsy;
if(y < 0)
{
if(""+this.tdat_ids_q2[0-x]=="null"||""+this.tdat_ids_q2[0-x]=="undefined"){this.tdat_ids_q2[0-x]=[];}
if(""+this.tdat_ids_q2[0-x][0-y]=="null"||""+this.tdat_ids_q2[0-x][0-y]=="undefined"){this.tdat_ids_q2[0-x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q2[0-x]=="null"||""+this.tdat_rota_q2[0-x]=="undefined"){this.tdat_rota_q2[0-x]=[];}
if(""+this.tdat_rota_q2[0-x][0-y]=="null"||""+this.tdat_rota_q2[0-x][0-y]=="undefined"){this.tdat_rota_q2[0-x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q2[0-x][0-y]; s = this.tdat_ids_q2[0-x][0-y];
}
else
{
if(""+this.tdat_ids_q3[0-x]=="null"||""+this.tdat_ids_q3[0-x]=="undefined"){this.tdat_ids_q3[0-x]=[];}
if(""+this.tdat_ids_q3[0-x][y]=="null"||""+this.tdat_ids_q3[0-x][y]=="undefined"){this.tdat_ids_q3[0-x][y]= this.randgen_tdat_ids();}
if(""+this.tdat_rota_q3[0-x]=="null"||""+this.tdat_rota_q3[0-x]=="undefined"){this.tdat_rota_q3[0-x]=[];}
if(""+this.tdat_rota_q3[0-x][y]=="null"||""+this.tdat_rota_q3[0-x][y] =="undefined"){this.tdat_rota_q3[0-x][y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q3[0-x][y]; s = this.tdat_ids_q3[0-x][y];
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
y = y+1;
}
}
else
{
while (y < ymax)
{
create_y = y*64 + this.half_sceh - this.offsy;
if(y < 0)
{
this.half_sceh = Std.int(this.sceh/2);
this.half_scew = Std.int(this.scew/2);
this.noa =0; this.shifting = false;
Script.createRecycledActor(Script.getActorType(59), this.scrw-86, 0, Script.FRONT);
Script.createRecycledActor(Script.getActorType(57), this.scrw-86, 57, Script.FRONT);
Script.runLater(20, function(t:TimedTask):Void
{
Script.createRecycledActorOnLayer(Script.getActorType(6), this.half_scew-20, this.half_sceh-20, Engine.engine.getLayerById(1));
this.player = Script.lastCreatedActor;
//this.empty_ratio = Init_udg_scedata.sce_empty_ratio(this.scene_id);
this.load_data();
}, null);
addWhenDrawingListener(null, function(g:G, x:Float, y:Float, list:Array<Dynamic>):Void
{
this.f.drawString("testlag "+this.testlag,105,0); this.f.drawString("num of actors"+this.noa,310,0);
this.f.drawString("initile_xmax"+this.initile_xmax,105,25);
this.f.drawString("initile_xmin"+this.initile_xmin,105,45);
this.f.drawString("initile_ymax"+this.initile_ymax,105,65);
this.f.drawString("initile_ymin"+this.initile_ymin,105,85);
this.f.drawString("cam x"+this.camx,105,105);
this.f.drawString("cam y"+this.camy,305,105);
this.f.drawString("xmax margin: "+ this.scrm_xmax, 105, 130);
this.f.drawString("xmin margin: "+ this.scrm_xmin, 315, 130);
this.f.drawString("ymax margin: "+ this.scrm_ymax, 105, 150);
this.f.drawString("ymin margin: "+ this.scrm_ymin, 315, 150);
this.f.drawString("offsx: "+ this.offsx, 105, 170); this.f.drawString("offsy : "+ this.offsy, 315, 170);
});
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
this.testlag += 1;
if(this.upd && !(this.shifting))
{
this.camx = Std.int(Engine.cameraX); this.camy = Std.int(Engine.cameraY);
this.scrm_xmax = Std.int(this.initile_xmax * 64 - this.camx + this.half_scew - this.scrw - this.offsx);
this.scrm_xmin = Std.int(this.camx - this.initile_xmin* 64 - this.half_scew + this.offsx);
this.scrm_ymax = Std.int(this.initile_ymax * 64 - this.camy + this.half_sceh - this.scrh - this.offsy);
this.scrm_ymin = Std.int(this.camy - this.initile_ymin*64 - this.half_sceh + this.offsy);
if(this.scrm_xmax < 128)
{
this.p_tdat_v(this.initile_xmax);
this.initile_xmax += 1;
}
else if(this.scrm_xmax > 192)
{
this.initile_xmax -= 1;
this.r_tdat_v(this.initile_xmax);
}
if(this.scrm_xmin < 128)
{
this.initile_xmin -= 1;
this.p_tdat_v(this.initile_xmin);
}
else if(this.scrm_xmin > 192)
{
this.r_tdat_v(this.initile_xmin);
this.initile_xmin += 1;
}
if(this.scrm_ymax < 128)
{
this.p_tdat_h(this.initile_ymax);
this.initile_ymax += 1;
}
else if(this.scrm_ymax > 192)
{
this.initile_ymax -= 1;
this.r_tdat_h(this.initile_ymax);
}
if(this.scrm_ymin < 128)
{
this.initile_ymin -= 1;
this.p_tdat_h(this.initile_ymin);
}
else if(this.scrm_ymin > 192)
{
this.r_tdat_h(this.initile_ymin);
this.initile_ymin += 1;
}
if(this.camx < 128){this.shift_right();}
else if(this.camx + this.scrw > this.scew - 128){this.shift_left();}
if(this.camy < 128){this.shift_down();}
else if(this.camy + this.scrh > this.sceh - 128){this.shift_up();}
this.upd = false;
Script.runLater(128, function(t:TimedTask):Void // delay miliconds
{
this.upd = true;
}, null);
}
});
}
public function init_data():Void //initailise all the scene variables
{
if(""+this.offsx=="null" ||""+this.offsx=="undefined" ||""+this.offsx=="NaN"){this.offsx=0;}
if(""+this.offsy=="null" ||""+this.offsy=="undefined" ||""+this.offsy=="NaN"){this.offsy=0;}
if(""+this.tdat_ids_q0 == "null"||""+this.tdat_ids_q0 == "undefined"){this.tdat_ids_q0 = [];}
if(""+this.tdat_ids_q1 == "null"||""+this.tdat_ids_q1 == "undefined"){this.tdat_ids_q1 = [];}
if(""+this.tdat_ids_q2 == "null"||""+this.tdat_ids_q2 == "undefined"){this.tdat_ids_q2 = [];}
if(""+this.tdat_ids_q3 == "null"||""+this.tdat_ids_q3 == "undefined"){this.tdat_ids_q3 = [];}
if(""+this.tdat_rota_q0 == "null"||""+this.tdat_rota_q0 == "undefined"){this.tdat_rota_q0 = [];}
if(""+this.tdat_rota_q1 == "null"||""+this.tdat_rota_q1 == "undefined"){this.tdat_rota_q1 = [];}
if(""+this.tdat_rota_q2 == "null"||""+this.tdat_rota_q2 == "undefined"){this.tdat_rota_q2 = [];}
if(""+this.tdat_rota_q3 == "null"||""+this.tdat_rota_q3 == "undefined"){this.tdat_rota_q3 = [];}
this.init_popu_scene();
}
public function init_popu_scene():Void //initially populate the scene
{
var a:Int=0; var b:Int=0; var c:Int=0; var d:Int=0;
Script.runLater(20,function(t:TimedTask):Void
{
this.camx = Std.int(Engine.cameraX); this.camy = Std.int(Engine.cameraY);
this.initile_xmax = Std.int((this.camx + this.scrw - this.half_sceh)/64 - this.offsx) + 2;
this.initile_xmin = Std.int((this.camx - this.half_sceh)/64 + this.offsx) - 2;
this.initile_ymax = Std.int((this.camy + this.scrh - this.half_sceh - this.offsy)/64) + 2;
this.initile_ymin = Std.int((this.camy - this.half_sceh)/64 + this.offsy) - 2;
a = this.initile_xmin; b = this.initile_xmax;
c = this.initile_ymin; d = this.initile_ymax;
while(c < d)
{
this.p_tdat_h(c); c = c+1;
}
this.upd = true;
},null);
}
public function load_data():Void // load from saved game
{
this.tdat_ids_q0 = Engine.engine.getGameAttribute("abg_tdat_ids_q0")[this.scene_id];
this.tdat_ids_q1 = Engine.engine.getGameAttribute("abg_tdat_ids_q1")[this.scene_id];
this.tdat_ids_q2 = Engine.engine.getGameAttribute("abg_tdat_ids_q2")[this.scene_id];
this.tdat_ids_q3 = Engine.engine.getGameAttribute("abg_tdat_ids_q3")[this.scene_id];
this.tdat_rota_q0 = Engine.engine.getGameAttribute("abg_tdat_rot_q0")[this.scene_id];
this.tdat_rota_q1 = Engine.engine.getGameAttribute("abg_tdat_rot_q1")[this.scene_id];
this.tdat_rota_q2 = Engine.engine.getGameAttribute("abg_tdat_rot_q2")[this.scene_id];
this.tdat_rota_q3 = Engine.engine.getGameAttribute("abg_tdat_rot_q3")[this.scene_id];
this.offsx = Engine.engine.getGameAttribute("abg_offsx")[this.scene_id];
this.offsy = Engine.engine.getGameAttribute("abg_offsy")[this.scene_id];
this.init_data();
}
public function p_tdat_h(y:Int):Void
{
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var create_x:Float = 0; var create_y: Float = y*64 + this.half_sceh - this.offsy;
var r:Float=0; var s:String = "";
while(x < xmax)
{
create_x = x*64 + this.half_scew - this.offsx;
if(""+this.tdat_actors[x]=="null"||""+this.tdat_actors[x]=="undefined"){this.tdat_actors[x] = [];}
if(x < 0)
{
if(y < 0)
{
if(""+this.tdat_ids_q2[0-x]=="null"||""+this.tdat_ids_q2[0-x]=="undefined"){this.tdat_ids_q2[0-x]=[];}
if(""+this.tdat_ids_q2[0-x][0-y]=="null"||""+this.tdat_ids_q2[0-x][0-y]=="undefined"){this.tdat_ids_q2[0-x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q2[0-x]=="null"||""+this.tdat_rota_q2[0-x]=="undefined"){this.tdat_rota_q2[0-x]=[];}
if(""+this.tdat_rota_q2[0-x][0-y]=="null"||""+this.tdat_rota_q2[0-x][0-y]=="undefined"){this.tdat_rota_q2[0-x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q2[0-x][0-y]; s = this.tdat_ids_q2[0-x][0-y];
}
else
{
if(""+this.tdat_ids_q3[0-x]=="null"||""+this.tdat_ids_q3[0-x]=="undefined"){this.tdat_ids_q3[0-x]=[];}
if(""+this.tdat_ids_q3[0-x][y]=="null"||""+this.tdat_ids_q3[0-x][y]=="undefined"){this.tdat_ids_q3[0-x][y]= this.randgen_tdat_ids();}
if(""+this.tdat_rota_q3[0-x]=="null"||""+this.tdat_rota_q3[0-x]=="undefined"){this.tdat_rota_q3[0-x]=[];}
if(""+this.tdat_rota_q3[0-x][y]=="null"||""+this.tdat_rota_q3[0-x][y] =="undefined"){this.tdat_rota_q3[0-x][y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q3[0-x][y]; s = this.tdat_ids_q3[0-x][y];
}
}
else
{
if(y < 0)
{
if(""+this.tdat_ids_q1[x]=="null"||""+this.tdat_ids_q1[x]=="undefined"){this.tdat_ids_q1[x]=[];}
if(""+this.tdat_ids_q1[x][0-y]=="null"||""+this.tdat_ids_q1[x][0-y]=="undefined"){this.tdat_ids_q1[x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q1[x]=="null"||""+this.tdat_rota_q1[x]=="undefined"){this.tdat_rota_q1[x]=[];}
if(""+this.tdat_rota_q1[x][0-y]=="null"||""+this.tdat_rota_q1[x][0-y]=="undefined"){this.tdat_rota_q1[x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q1[x][0-y]; s = this.tdat_ids_q1[x][0-y];
}
else
{
if(""+this.tdat_ids_q0[x]=="null"||""+this.tdat_ids_q0[x]=="undefined"){this.tdat_ids_q0[x]=[];}
if(""+this.tdat_ids_q0[x][y]=="null"||""+this.tdat_ids_q0[x][y]=="undefined"){this.tdat_ids_q0[x][y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q0[x]=="null"||""+this.tdat_rota_q0[x]=="undefined"){this.tdat_rota_q0[x]=[];}
if(""+this.tdat_rota_q0[x][y]=="null"||""+this.tdat_rota_q0[x][y]=="undefined"){this.tdat_rota_q0[x][y]= Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q0[x][y]; s = this.tdat_ids_q0[x][y];
}
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
x = x+1;
}
}
public function p_tdat_v(x:Int):Void
{
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
var create_x:Float = x*64 + this.half_scew - this.offsx; var create_y:Float = 0;
var r:Float=0; var s:String = "";
if(""+this.tdat_actors[x]=="null"||""+this.tdat_actors[x]=="undefined"){this.tdat_actors[x]=[];}
if (x < 0)
{
while (y < ymax)
{
create_y = y*64 + this.half_sceh - this.offsy;
if(y < 0)
{
if(""+this.tdat_ids_q2[0-x]=="null"||""+this.tdat_ids_q2[0-x]=="undefined"){this.tdat_ids_q2[0-x]=[];}
if(""+this.tdat_ids_q2[0-x][0-y]=="null"||""+this.tdat_ids_q2[0-x][0-y]=="undefined"){this.tdat_ids_q2[0-x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q2[0-x]=="null"||""+this.tdat_rota_q2[0-x]=="undefined"){this.tdat_rota_q2[0-x]=[];}
if(""+this.tdat_rota_q2[0-x][0-y]=="null"||""+this.tdat_rota_q2[0-x][0-y]=="undefined"){this.tdat_rota_q2[0-x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q2[0-x][0-y]; s = this.tdat_ids_q2[0-x][0-y];
}
else
{
if(""+this.tdat_ids_q3[0-x]=="null"||""+this.tdat_ids_q3[0-x]=="undefined"){this.tdat_ids_q3[0-x]=[];}
if(""+this.tdat_ids_q3[0-x][y]=="null"||""+this.tdat_ids_q3[0-x][y]=="undefined"){this.tdat_ids_q3[0-x][y]= this.randgen_tdat_ids();}
if(""+this.tdat_rota_q3[0-x]=="null"||""+this.tdat_rota_q3[0-x]=="undefined"){this.tdat_rota_q3[0-x]=[];}
if(""+this.tdat_rota_q3[0-x][y]=="null"||""+this.tdat_rota_q3[0-x][y] =="undefined"){this.tdat_rota_q3[0-x][y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q3[0-x][y]; s = this.tdat_ids_q3[0-x][y];
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
y = y+1;
}
}
else
{
while (y < ymax)
{
create_y = y*64 + this.half_sceh - this.offsy;
if(y < 0)
{
if(""+this.tdat_ids_q1[x]=="null"||""+this.tdat_ids_q1[x]=="undefined"){this.tdat_ids_q1[x]=[];}
if(""+this.tdat_ids_q1[x][0-y]=="null"||""+this.tdat_ids_q1[x][0-y]=="undefined")
{this.tdat_ids_q1[x][0-y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q1[x]=="null"||""+this.tdat_rota_q1[x]=="undefined") {this.tdat_rota_q1[x]=[];}
if(""+this.tdat_rota_q1[x][0-y]=="null"||""+this.tdat_rota_q1[x][0-y]=="undefined"){this.tdat_rota_q1[x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q1[x][0-y]; s = this.tdat_ids_q1[x][0-y];
}
else
{
if(""+this.tdat_ids_q0[x]=="null"||""+this.tdat_ids_q0[x]=="undefined"){this.tdat_ids_q0[x]=[];}
if(""+this.tdat_ids_q0[x][y]=="null"||""+this.tdat_ids_q0[x][y]=="undefined")
if(""+this.tdat_rota_q1[x]=="null"||""+this.tdat_rota_q1[x]=="undefined") {this.tdat_rota_q1[x]=[];}
if(""+this.tdat_rota_q1[x][0-y]=="null"||""+this.tdat_rota_q1[x][0-y]=="undefined"){this.tdat_rota_q1[x][0-y] = Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q1[x][0-y]; s = this.tdat_ids_q1[x][0-y];
}
else
{
if(""+this.tdat_ids_q0[x]=="null"||""+this.tdat_ids_q0[x]=="undefined"){this.tdat_ids_q0[x]=[];}
if(""+this.tdat_ids_q0[x][y]=="null"||""+this.tdat_ids_q0[x][y]=="undefined")
{this.tdat_ids_q0[x][y] = this.randgen_tdat_ids();}
if(""+this.tdat_rota_q0[x]=="null"||""+this.tdat_rota_q0[x]=="undefined"){this.tdat_rota_q0[x]=[];}
if(""+this.tdat_rota_q0[x][y]=="null"||""+this.tdat_rota_q0[x][y]=="undefined"){this.tdat_rota_q0[x][y]= Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q0[x][y]; s = this.tdat_ids_q0[x][y];
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
y = y+1;
}
}
}
public function r_tdat_h(y:Int):Void
{
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
while (x < xmax)
{
if(Std.is(this.tdat_actors[x][y], Actor))
{
Script.recycleActor(this.tdat_actors[x][y]);
this.tdat_actors[x][y] = "no actor"; this.noa -=1;
} x += 1;
}
}
public function r_tdat_v(x:Int):Void
{
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{
Script.recycleActor(this.tdat_actors[x][y]);
this.tdat_actors[x][y] = "no actor"; this.noa -=1;
}
y +=1;
}
}
public function randgen_tdat_ids():String
{
var a:Int = Std.int(Math.floor(Math.random()*9.99));
if(a == 0){return "gr0";}
if(a == 1){return "gr1";}
if(a == 2){return "gr2";}
if(a == 3){return "gr3";}
if(a == 4){return "gr4";}
if(a == 5){return "gr5";}
if(a == 6){return "gr6";}
if(a == 7){return "gr7";}
if(a == 8){return "gr8";}
if(a == 9){return "gr9";}
return "";
}
public function shift_down():Void
{
var a:Actor; this.shifting = true; this.offsy -= this.half_sceh;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setY(this.player.getY() + this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
if(""+this.tdat_rota_q0[x]=="null"||""+this.tdat_rota_q0[x]=="undefined"){this.tdat_rota_q0[x]=[];}
if(""+this.tdat_rota_q0[x][y]=="null"||""+this.tdat_rota_q0[x][y]=="undefined"){this.tdat_rota_q0[x][y]= Math.floor(Math.random()*3.99)*90;}
r = this.tdat_rota_q0[x][y]; s = this.tdat_ids_q0[x][y];
}
Script.createRecycledActorOnLayer(Game_context.ab_tdat_ids(s), create_x, create_y, Engine.engine.getLayerById(0));
Script.lastCreatedActor.setAngle(Utils.RAD*r);
this.tdat_actors[x][y] = Script.lastCreatedActor; this.noa += 1;
y = y+1;
}
}
}
public function r_tdat_h(y:Int):Void
{
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
while (x < xmax)
{
if(Std.is(this.tdat_actors[x][y], Actor))
{
Script.recycleActor(this.tdat_actors[x][y]);
this.tdat_actors[x][y] = "no actor"; this.noa -=1;
} x += 1;
}
}
public function r_tdat_v(x:Int):Void
{
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{
Script.recycleActor(this.tdat_actors[x][y]);
this.tdat_actors[x][y] = "no actor"; this.noa -=1;
}
y +=1;
}
}
public function randgen_tdat_ids():String
{
var a:Int = Std.int(Math.floor(Math.random()*9.99));
if(a == 0){return "gr0";}
if(a == 1){return "gr1";}
if(a == 2){return "gr2";}
if(a == 3){return "gr3";}
if(a == 4){return "gr4";}
if(a == 5){return "gr5";}
if(a == 6){return "gr6";}
if(a == 7){return "gr7";}
if(a == 8){return "gr8";}
if(a == 9){return "gr9";}
return "";
}
public function shift_down():Void
{
var a:Actor; this.shifting = true; this.offsy -= this.half_sceh;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setY(this.player.getY() + this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{a = this.tdat_actors[x][y]; a.setY(a.getY() + this.half_sceh);} y = y+1;
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_left():Void
{
var a:Actor; this.shifting = true; this.offsx += this.half_scew;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setX(this.player.getX() - this.half_scew);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_left():Void
{
var a:Actor; this.shifting = true; this.offsx += this.half_scew;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setX(this.player.getX() - this.half_scew);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{a = this.tdat_actors[x][y]; a.setX(a.getX() - this.half_scew);} y = y+1;
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_right():Void
{
var a: Actor; this.shifting = true; this.offsx -= this.half_scew;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setX(this.player.getX() + this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_right():Void
{
var a: Actor; this.shifting = true; this.offsx -= this.half_scew;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setX(this.player.getX() + this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{a = this.tdat_actors[x][y]; a.setX(a.getX() + this.half_scew);} y = y+1;
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_up():Void
{
var a:Actor; this.shifting = true; this.offsy += this.half_sceh;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setY(this.player.getY() - this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
public function shift_up():Void
{
var a:Actor; this.shifting = true; this.offsy += this.half_sceh;
var xmax:Int = this.initile_xmax; var xmin:Int = this.initile_xmin; var x:Int = xmin;
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin;
this.player.setY(this.player.getY() - this.half_sceh);
while (x < xmax)
{
y = ymin;
while (y < ymax)
{
if(Std.is(this.tdat_actors[x][y],Actor))
{a = this.tdat_actors[x][y]; a.setY(a.getY() - this.half_sceh);} y = y+1;
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
}
}
x = x+1;
}
Script.runLater(16,function(t:TimedTask):Void
{
this.shifting = false;
},null) ;
}
}
No comments:
Post a Comment