Back to main topic page: http://stencyl-nator.blogspot.com/p/endless-scenes.html
Introduction.
This is the 3rd time the so-called endless scene has been built. Code mode is used to cancel the unnecessary imports to reduce lags and increase game efficiency. In older versions, we use q0,q1,q2 and q3 which were confusing. Now we use nxny, nxpy, pxny and pxpy as quarters in arrays since negative index data cannot be saved.
This is the 3rd time the so-called endless scene has been built. Code mode is used to cancel the unnecessary imports to reduce lags and increase game efficiency. In older versions, we use q0,q1,q2 and q3 which were confusing. Now we use nxny, nxpy, pxny and pxpy as quarters in arrays since negative index data cannot be saved.
How it works:
it functions similarly to previous 2 versions that does exactly the same. Does not include multi-tile objects that will use multiple actors per objects
code and explainations.
package scripts; // where the code is located
import com.stencyl.Engine; // the Stencyl engine
import com.stencyl.behavior.SceneScript; // all scene behaviors entends SceneScript
import com.stencyl.behavior.Script; // A script for most tasks. Not as hard to bypass as the engine
import com.stencyl.behavior.TimedTask;
import com.stencyl.models.Scene;
import com.stencyl.models.Actor; // this code will produce many actors
import com.stencyl.utils.motion.Easing;
import scripts.Interbehav;
//The main advantage of code mode is ability to cancel the unnecessary imports to optimize the gameplay.
import scripts.Conte; //a freeform code with only public static functions.
class Sur_sce_behav extends SceneScript
{
public var texts:Array<Dynamic>=[]; public var cheklag: Int = 0; public var shifting:Bool = false;
public var sceh:Float = Engine.sceneHeight; public var scew:Float = Engine.sceneWidth;
public var scrh:Float = Engine.screenHeight; public var scrw:Float = Engine.screenWidth;
public var player:Actor; public var player_positile_x:Int; public var player_positile_y:Int;
public var offsx:Float=0; public var offsy:Float=0;
public var marg_xmax:Float; public var marg_xmin:Float; public var marg_ymax:Float; public var marg_ymin:Float;
public var initile_xmax:Int; public var initile_xmin:Int;
public var initile_ymax:Int; public var initile_ymin:Int;
public var half_scrh:Float = Engine.screenHeight/2; public var half_scrw:Float = Engine.screenWidth/2;
public var half_sceh:Float = Engine.sceneHeight/2; public var half_scew:Float = Engine.sceneWidth/2;
// The tile data for saving and loading
public var grdat_ids_nxny:Array<Dynamic>; public var grdat_ids_nxpy:Array<Dynamic>; public var grdat_ids_pxny:Array<Dynamic>; public var grdat_ids_pxpy:Array<Dynamic>;
public var grdat_rfl_nxny:Array<Dynamic>; public var grdat_rfl_nxpy:Array<Dynamic>; public var grdat_rfl_pxny:Array<Dynamic>; public var grdat_rfl_pxpy:Array<Dynamic>;
public var grdat_rot_nxny:Array<Dynamic>; public var grdat_rot_nxpy:Array<Dynamic>; public var grdat_rot_pxny:Array<Dynamic>; public var grdat_rot_pxpy:Array<Dynamic>;
public var grdat_actors:Array<Dynamic>; //actors cannot be saved. so does not need
//diagnosis data. For diagnosis only. not to be used in real game.
public var diag_create_x:Float; public var diag_create_y:Float; public var diag_noa:Int; public var diag_last_created_ids:String="";
public var camx:Float; public var camy:Float;
public var upd:Bool = false;
public function new(u0:Int, u1:Engine){super();}
override public function init()
{
this.texts[0] = new F(); this.texts[0].c = 15243112; this.texts[0].f_cu = Script.getFont(19);
this.texts[1] = new F(); this.texts[0].c = 16412414; this.texts[1].f_cu = Script.getFont(19);
this.add_def(def);
this.add_dra(diag_drawing);
this.sceh = Engine.sceneHeight; this.scew = Engine.sceneWidth;
this.scrh = Engine.screenHeight; this.scrw = Engine.screenWidth;
this.half_sceh = Engine.sceneHeight/2; this.half_scew = Engine.sceneWidth/2;
Script.createRecycledActorOnLayer(Conte.player_part("legs"),this.scew*0.5-32,this.sceh*0.5-32, Engine.engine.getLayerById(2));
this.player = Script.lastCreatedActor;
this.load_sce();
}
public function add_def(a:Dynamic):Void{Engine.engine.whenUpdatedListeners.push(a);}
public function add_dra(a:Dynamic):Void{Engine.engine.whenDrawingListeners.push(a);}
public function def():Void
{
this.cheklag += 1; if(this.cheklag > 2147400000){this.cheklag = -2147400000;}
Engine.engine.cameraFollow(this.player);
if(this.upd)
{
this.upd = false;
this.camx = Engine.cameraX; this.camy = Engine.cameraY;
this.marg_xmax = this.half_scew + this.initile_xmax*64 + this.offsx - this.camx - this.scrw;
this.marg_xmin = this.camx - this.half_scew - this.initile_xmin* 64 - this.offsx;
this.marg_ymax = this.half_sceh + this.initile_ymax*64 + this.offsy - this.camy - this.scrh;
this.marg_ymin = this.camy - this.half_sceh - this.initile_ymin* 64 - this.offsy;
if(!(this.shifting))
{
if(this.marg_xmax < 128){this.popu_grdat_vert(this.initile_xmax); this.initile_xmax +=1;}
else if(this.marg_xmax > 192){this.initile_xmax -=1; this.remo_grdat_vert(this.initile_xmax);}
if(this.marg_xmin < 128){this.initile_xmin -=1;this.popu_grdat_vert(this.initile_xmin); }
else if(this.marg_xmin > 192){this.remo_grdat_vert(this.initile_xmin); this.initile_xmin +=1;}
if(this.marg_ymax < 128){this.popu_grdat_horz(this.initile_ymax); this.initile_ymax +=1;}
else if(this.marg_ymax > 192){this.initile_ymax -=1; this.remo_grdat_horz(this.initile_ymax);}
if(this.marg_ymin < 128){this.initile_ymin -=1; this.popu_grdat_horz(this.initile_ymin);}
else if(this.marg_ymin > 192){this.remo_grdat_horz(this.initile_ymin); this.initile_ymin +=1;}
if(this.camx < 128){this.shift_xinc();}
else if(this.scew - this.camx - this.scrw < 128){this.shift_xdec();}
if(this.camy < 128){this.shift_yinc();}
else if(this.scew - this.camy - this.scrh < 128){this.shift_ydec();}
}
Script.runLater(125,update,null);
}
}
public function diag_drawing()
{
this.texts[0].ds("check lag: "+this.cheklag,5,0); this.texts[1].ds("number of actors: " + this.diag_noa,300,0);
this.texts[1].ds("camx: "+this.camx,5,20);
this.texts[1].ds("camy: "+this.camy,5,40);
this.texts[1].ds("initile_xmax: "+this.initile_xmax,5,70);
this.texts[1].ds("initile_xmin: "+this.initile_xmin,5,90);
this.texts[1].ds("initile_ymax: "+this.initile_ymax,5,110);
this.texts[1].ds("initile_ymin: "+this.initile_ymin,5,130);
this.texts[1].ds("marg_xmax: "+this.marg_xmax,5,160);
this.texts[1].ds("marg_xmin: "+this.marg_xmin,5,180);
this.texts[1].ds("marg_ymax: "+this.marg_ymax,5,200);
this.texts[1].ds("marg_ymin: "+this.marg_ymin,5,220);
this.texts[1].ds("offsx: "+this.offsx,5,240);
this.texts[1].ds("offsy: "+this.offsy,5,260);
this.texts[1].ds("player x: "+this.player.getX(),5,280);
this.texts[1].ds("player y: "+this.player.getY(),5,300);
}
public function init_data()
{
if(this.grdat_actors == null||""+this.grdat_actors =="undefined"){this.grdat_actors = [];}
if(this.grdat_ids_nxny == null||""+this.grdat_ids_nxny=="undefined"){this.grdat_ids_nxny = [];}
if(this.grdat_ids_nxpy == null||""+this.grdat_ids_nxpy=="undefined"){this.grdat_ids_nxpy = [];}
if(this.grdat_ids_pxny == null||""+this.grdat_ids_pxny=="undefined"){this.grdat_ids_pxny = [];}
if(this.grdat_ids_pxpy == null||""+this.grdat_ids_pxpy=="undefined"){this.grdat_ids_pxpy = [];}
if(this.grdat_rfl_nxny == null||""+this.grdat_rfl_nxny=="undefined"){this.grdat_rfl_nxny = [];}
if(this.grdat_rfl_nxpy == null||""+this.grdat_rfl_nxpy=="undefined"){this.grdat_rfl_nxpy = [];}
if(this.grdat_rfl_pxny == null||""+this.grdat_rfl_pxny=="undefined"){this.grdat_rfl_pxny = [];}
if(this.grdat_rfl_pxpy == null||""+this.grdat_rfl_pxpy=="undefined"){this.grdat_rfl_pxpy = [];}
if(this.grdat_rot_nxny == null||""+this.grdat_rot_nxny=="undefined"){this.grdat_rot_nxny = [];}
if(this.grdat_rot_nxpy == null||""+this.grdat_rot_nxpy=="undefined"){this.grdat_rot_nxpy = [];}
if(this.grdat_rot_pxny == null||""+this.grdat_rot_pxny=="undefined"){this.grdat_rot_pxny = [];}
if(this.grdat_rot_pxpy == null||""+this.grdat_rot_pxpy=="undefined"){this.grdat_rot_pxpy = [];}
this.init_sce();
}
public function init_sce()
{
this.initile_xmax = Std.int(Math.ceil(this.half_scrw/64)) +2; this.initile_xmin = Std.int(Math.floor(0-this.half_scrw/64)) -2;
this.initile_ymax = Std.int(Math.ceil(this.half_scrh/64)) +2; this.initile_ymin = Std.int(Math.floor(0-this.half_scrh/64)) -2;
var a:Int = this.initile_xmin; var b:Int = this.initile_xmax;
var c:Int = this.initile_ymin; var d:Int = this.initile_ymax;
Engine.engine.cameraFollow(this.player);
//horizontal populating for veritcal scrolling. .
while(c < d){this.popu_grdat_horz(c); c=c+1;}
//currently testing populate vertiucal.
//while(a < b){this.popu_grdat_vert(a); a = a+1; }
this.upd= true;
}
public function load_sce()
{
this.init_data();
}
//create the actors. in this case, ground "tiles".
public function popu_grdat_horz(y):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=0; var a:String =""; var f:Bool = false; var r:Float=0;
if(y < 0)
{
while(x < xmax)
{
if(this.grdat_actors[x]==null||""+this.grdat_actors[x]=="undefined"){this.grdat_actors[x] = [];}
if(x < 0)
{
if(this.grdat_ids_nxny[0-x]==null||""+this.grdat_ids_nxny[0-x]=="undefined"){this.grdat_ids_nxny[0-x]=[];}
if(this.grdat_rfl_nxny[0-x]==null||""+this.grdat_rfl_nxny[0-x]=="undefined"){this.grdat_rfl_nxny[0-x]=[];}
if(this.grdat_rot_nxny[0-x]==null||""+this.grdat_rot_nxny[0-x]=="undefined"){this.grdat_rot_nxny[0-x]=[];}
if(this.grdat_ids_nxny[0-x][0-y]==null||""+this.grdat_ids_nxny[0-x][0-y]=="undefined"){this.grdat_ids_nxny[0-x][0-y]=this.randgen_grdat_ids();}
if(this.grdat_rfl_nxny[0-x][0-y]==null||""+this.grdat_rfl_nxny[0-x][0-y]=="undefined"){this.grdat_rfl_nxny[0-x][0-y]=this.randgen_rfl();}
if(this.grdat_rot_nxny[0-x][0-y]==null||""+this.grdat_rot_nxny[0-x][0-y]=="undefined"){this.grdat_rot_nxny[0-x][0-y]=this.randgen_rot();}
a = this.grdat_ids_nxny[0-x][0-y]; f=this.grdat_rfl_nxny[0-x][0-y]; r= this.grdat_rot_nxny[0-x][0-y];
}
else
{
if(this.grdat_ids_pxny[x]==null||""+this.grdat_ids_pxny[x]=="undefined"){this.grdat_ids_pxny[x]=[];}
if(this.grdat_rfl_pxny[x]==null||""+this.grdat_rfl_pxny[x]=="undefined"){this.grdat_rfl_pxny[x]=[];}
if(this.grdat_rot_pxny[x]==null||""+this.grdat_rot_pxny[x]=="undefined"){this.grdat_rot_pxny[x]=[];}
if(this.grdat_ids_pxny[x][0-y]==null||""+this.grdat_ids_pxny[x][0-y]=="undefined"){this.grdat_ids_pxny[x][0-y]=this.randgen_grdat_ids();}
if(this.grdat_rfl_pxny[x][0-y]==null||""+this.grdat_rfl_pxny[x][0-y]=="undefined"){this.grdat_rfl_pxny[x][0-y]=this.randgen_rfl();}
if(this.grdat_rot_pxny[x][0-y]==null||""+this.grdat_rot_pxny[x][0-y]=="undefined"){this.grdat_rot_pxny[x][0-y]=this.randgen_rot();}
a = this.grdat_ids_pxny[x][0-y]; f=this.grdat_rfl_pxny[x][0-y]; r = this.grdat_rot_pxny[x][0-y];
}
create_x = this.half_scew + x*64 + this.offsx; create_y = this.half_sceh + y*64 + this.offsy;
this.diag_last_created_ids = a;
Script.createRecycledActorOnLayer(Conte.grdat_actorType(a),create_x,create_y,Engine.engine.getLayerById(0)); this.diag_noa += 1;
this.grdat_actors[x][y] = Script.lastCreatedActor;
if(r !=0){this.grdat_actors[x][y].spinTo(r,0,Easing.linear);}
x = x+1;
}
}
else
{
while(x < xmax)
{
if(this.grdat_actors[x]==null||""+this.grdat_actors[x]=="undefined"){this.grdat_actors[x] = [];}
if(x < 0)
{
if(this.grdat_ids_nxpy[0-x]==null||""+this.grdat_ids_nxpy[0-x]=="undefined"){this.grdat_ids_nxpy[0-x]=[];}
if(this.grdat_rfl_nxpy[0-x]==null||""+this.grdat_rfl_nxpy[0-x]=="undefined"){this.grdat_rfl_nxpy[0-x]=[];}
if(this.grdat_rot_nxpy[0-x]==null||""+this.grdat_rot_nxpy[0-x]=="undefined"){this.grdat_rot_nxpy[0-x]=[];}
if(this.grdat_ids_nxpy[0-x][y]==null||""+this.grdat_ids_nxpy[0-x][y]=="undefined"){this.grdat_ids_nxpy[0-x][y]=this.randgen_grdat_ids();}
if(this.grdat_rfl_nxpy[0-x][y]==null||""+this.grdat_rfl_nxpy[0-x][y]=="undefined"){this.grdat_rfl_nxpy[0-x][y]=this.randgen_rfl();}
if(this.grdat_rot_nxpy[0-x][y]==null||""+this.grdat_rot_nxpy[0-x][y]=="undefined"){this.grdat_rot_nxpy[0-x][y]=this.randgen_rot();}
a = this.grdat_ids_nxpy[0-x][y]; f=this.grdat_rfl_nxpy[0-x][y]; r = this.grdat_rot_nxpy[0-x][y];
}
else
{
if(this.grdat_ids_pxpy[x]==null||""+this.grdat_ids_pxpy[x]=="undefined"){this.grdat_ids_pxpy[x]=[];}
if(this.grdat_rfl_pxpy[x]==null||""+this.grdat_rfl_pxpy[x]=="undefined"){this.grdat_rfl_pxpy[x]=[];}
if(this.grdat_rot_pxpy[x]==null||""+this.grdat_rot_pxpy[x]=="undefined"){this.grdat_rot_pxpy[x]=[];}
if(this.grdat_ids_pxpy[x][y]==null||""+this.grdat_ids_pxpy[x][y]=="undefined"){this.grdat_ids_pxpy[x][y]=this.randgen_grdat_ids();}
if(this.grdat_rfl_pxpy[x][y]==null||""+this.grdat_rfl_pxpy[x][y]=="undefined"){this.grdat_rfl_pxpy[x][y]=this.randgen_rfl();}
if(this.grdat_rot_pxpy[x][y]==null||""+this.grdat_rot_pxpy[x][y]=="undefined"){this.grdat_rot_pxpy[x][y]=this.randgen_rot();}
a = this.grdat_ids_pxpy[x][y]; f=this.grdat_rfl_pxpy[x][y]; r = this.grdat_rot_pxpy[x][y];
}
create_x = this.half_scew + x*64 + this.offsx; create_y = this.half_sceh + y*64 + this.offsy;
this.diag_last_created_ids = a;
Script.createRecycledActorOnLayer(Conte.grdat_actorType(a),create_x,create_y,Engine.engine.getLayerById(0));this.diag_noa += 1;
this.grdat_actors[x][y] = Script.lastCreatedActor;
if(r !=0){this.grdat_actors[x][y].spinTo(r,0,Easing.linear);}
x = x+1;
}
}
}
public function popu_grdat_vert(x):Void
{
if(this.grdat_actors[x]==null ||""+this.grdat_actors[x] == "undefined"){this.grdat_actors[x] = [];}
var ymax:Int = this.initile_ymax; var ymin:Int = this.initile_ymin; var y:Int = ymin; var a:String=""; var f:Bool; var r:Float; var create_x:Float=0; var create_y:Float=0;
if(x < 0)
{
while (y < ymax)
{
if(y < 0)
{
if(this.grdat_ids_nxny[0-x]==null ||""+this.grdat_ids_nxny[0-x]=="undefined"){this.grdat_ids_nxny[0-x]=[];}
if(this.grdat_ids_nxny[0-x][0-y]==null ||""+this.grdat_ids_nxny[0-x][0-y]=="undefined"){this.grdat_ids_nxny[0-x][0-y] = this.randgen_grdat_ids();}
if(this.grdat_rfl_nxny[0-x]==null ||""+this.grdat_rfl_nxny[0-x]=="undefined"){this.grdat_rfl_nxny[0-x]=[];}
if(this.grdat_rfl_nxny[0-x][0-y]==null ||""+this.grdat_rfl_nxny[0-x][0-y]=="undefined"){this.grdat_rfl_nxny[0-x][0-y] = this.randgen_rfl();}
if(this.grdat_rot_nxny[0-x]==null ||""+this.grdat_rot_nxny[0-x]=="undefined"){this.grdat_rot_nxny[0-x]=[];}
if(this.grdat_rot_nxny[0-x][0-y]==null ||""+this.grdat_rot_nxny[0-x][0-y]=="undefined"){this.grdat_rot_nxny[0-x][0-y] = this.randgen_rot();}
a = this.grdat_ids_nxny[0-x][0-y]; f = this.grdat_rfl_nxny[0-x][0-y]; r = this.grdat_rot_nxny[0-x][0-y];
}
else
{
if(this.grdat_ids_nxpy[0-x]==null ||""+this.grdat_ids_nxpy[0-x]=="undefined"){this.grdat_ids_nxpy[0-x]=[];}
if(this.grdat_ids_nxpy[0-x][y]==null ||""+this.grdat_ids_nxpy[0-x][y]=="undefined"){this.grdat_ids_nxpy[0-x][y] = this.randgen_grdat_ids();}
if(this.grdat_rfl_nxpy[0-x]==null ||""+this.grdat_rfl_nxpy[0-x]=="undefined"){this.grdat_rfl_nxpy[0-x]=[];}
if(this.grdat_rfl_nxpy[0-x][y]==null ||""+this.grdat_rfl_nxpy[0-x][y]=="undefined"){this.grdat_rfl_nxpy[0-x][y] = this.randgen_rfl();}
if(this.grdat_rot_nxpy[0-x]==null ||""+this.grdat_rot_nxpy[0-x]=="undefined"){this.grdat_rot_nxpy[0-x]=[];}
if(this.grdat_rot_nxpy[0-x][y]==null ||""+this.grdat_rot_nxpy[0-x][y]=="undefined"){this.grdat_rot_nxpy[0-x][y] = this.randgen_rot();}
a = this.grdat_ids_nxpy[0-x][y]; f = this.grdat_rfl_nxpy[0-x][y]; r = this.grdat_rot_nxpy[0-x][y];
}
create_x = this.half_scew + x*64 + this.offsx; create_y = this.half_sceh + y*64 + this.offsy;
this.diag_create_x = create_x; this.diag_create_y = create_y;
Script.createRecycledActorOnLayer(Conte.grdat_actorType(a),create_x,create_y,Engine.engine.getLayerById(0));this.diag_noa += 1;
this.grdat_actors[x][y] = Script.lastCreatedActor;
if(r !=0){this.grdat_actors[x][y].spinTo(r,0,Easing.linear);}
y = y + 1;
}
}
else
{
while (y < ymax)
{
if(y < 0)
{
if(this.grdat_ids_pxny[x]==null ||""+this.grdat_ids_pxny[x]=="undefined"){this.grdat_ids_pxny[x]=[];}
if(this.grdat_ids_pxny[x][0-y]==null ||""+this.grdat_ids_pxny[x][0-y]=="undefined"){this.grdat_ids_pxny[x][0-y] = this.randgen_grdat_ids();}
if(this.grdat_rfl_pxny[x]==null ||""+this.grdat_rfl_pxny[x]=="undefined"){this.grdat_rfl_pxny[x]=[];}
if(this.grdat_rfl_pxny[x][0-y]==null ||""+this.grdat_rfl_pxny[x][0-y]=="undefined"){this.grdat_rfl_pxny[x][0-y] = this.randgen_rfl();}
if(this.grdat_rot_pxny[x]==null ||""+this.grdat_rot_pxny[x]=="undefined"){this.grdat_rot_pxny[x]=[];}
if(this.grdat_rot_pxny[x][0-y]==null ||""+this.grdat_rot_pxny[x][0-y]=="undefined"){this.grdat_rot_pxny[x][0-y] = this.randgen_rot();}
a = this.grdat_ids_pxny[x][0-y]; f = this.grdat_rfl_pxny[x][0-y]; r = this.grdat_rot_pxny[x][0-y];
}
else
{
if(this.grdat_ids_pxpy[x]==null ||""+this.grdat_ids_pxpy[x]=="undefined"){this.grdat_ids_pxpy[x]=[];}
if(this.grdat_ids_pxpy[x][y]==null ||""+this.grdat_ids_pxpy[x][y]=="undefined"){this.grdat_ids_pxpy[x][y] = this.randgen_grdat_ids();}
if(this.grdat_rfl_pxpy[x]==null ||""+this.grdat_rfl_pxpy[x]=="undefined"){this.grdat_rfl_pxpy[x]=[];}
if(this.grdat_rfl_pxpy[x][y]==null ||""+this.grdat_rfl_pxpy[x][y]=="undefined"){this.grdat_rfl_pxpy[x][y] = this.randgen_rfl();}
if(this.grdat_rot_pxpy[x]==null ||""+this.grdat_rot_pxpy[x]=="undefined"){this.grdat_rot_pxpy[x]=[];}
if(this.grdat_rot_pxpy[x][y]==null ||""+this.grdat_rot_pxpy[x][y]=="undefined"){this.grdat_rot_pxpy[x][y] = this.randgen_rot();}
a = this.grdat_ids_pxpy[x][y]; f = this.grdat_rfl_pxpy[x][y]; r = this.grdat_rot_pxpy[x][y];
}
create_x = this.half_scew + x*64 + this.offsx; create_y = this.half_sceh + y*64 + this.offsy;
this.diag_create_x = create_x; this.diag_create_y = create_y;
Script.createRecycledActorOnLayer(Conte.grdat_actorType(a),create_x,create_y,Engine.engine.getLayerById(0));this.diag_noa += 1;
this.grdat_actors[x][y] = Script.lastCreatedActor;
if(r !=0){this.grdat_actors[x][y].spinTo(r,0,Easing.linear);}
y = y + 1;
}
}
}
//randomly generates data. different algorithm may be used in the real game.
public function randgen_grdat_ids():String
{
var rand:Int = Std.int(Math.floor(Math.random() * 9.999));
if(rand == 0){return "grass_0";} else if(rand == 1){return "grass_1";}
else if(rand == 2){return "grass_2";} else if(rand == 3){return "grass_3";}
else if(rand == 4){return "grass_4";} else if(rand == 5){return "grass_5";}
else if(rand == 6){return "grass_6";} else if(rand == 7){return "grass_7";}
else if(rand == 8){return "grass_8";} else if(rand == 9){return "grass_9";}
return "grass_9";
}
public function randgen_rfl():Bool{if(Math.random() > 0.5) {return true;} return false;}
public function randgen_rot():Float{return Math.floor(Math.random() * 3.999) * 90;}
//killing the grdat_actors when they leave the boundary. same thing can be done on items, furnitures.
public function remo_grdat_horz(y):Void.
{
var xmax:Int = this.initile_xmax; var xmin = this.initile_xmin; var x=xmin;
while(x < xmax)
{
if(this.grdat_actors[x][y] !=null && ""+this.grdat_actors[x][y]!="undefined"){Script.recycleActor(this.grdat_actors[x][y]); this.grdat_actors[x][y]=null; this.diag_noa -=1;}
x+=1;
}
}
public function remo_grdat_vert(x):Void
{
var ymax:Int = this.initile_ymax; var ymin = this.initile_ymin; var y=ymin;
while(y < ymax)
{
if(this.grdat_actors[x][y] !=null && ""+this.grdat_actors[x][y]!="undefined"){Script.recycleActor(this.grdat_actors[x][y]); this.grdat_actors[x][y]=null; this.diag_noa -=1;}
y+=1;
}
}
//performs shifting when camera reaches the edge of the finite scene.
public function shift_xdec():Void
{
this.shifting = true; this.player.makeAlwaysSimulate();
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;
while(x < xmax)
{
y = ymin;
while(y < ymax)
{
if(this.grdat_actors[x][y]!=null&&""+this.grdat_actors[x][y]!="undefined"){this.grdat_actors[x][y].setX(this.grdat_actors[x][y].getX() - this.half_scew);}
y = y+1;
}
x = x+1;
}
this.offsx -= this.half_scew;
//indirect position setting for player. for we are using http://stencyl-nator.blogspot.com/p/keyboard-movements-code-mode.html for player
this.player.setValue("Player_leg_behav","x",this.player.getValue("Player_leg_behav","x")-this.half_scew);
Script.runLater(20,stop_shift,null);
}
public function shift_xinc():Void
{
this.shifting = true;this.player.makeAlwaysSimulate();
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;
while(x < xmax)
{
y = ymin;
while(y < ymax)
{
if(this.grdat_actors[x][y]!=null&&""+this.grdat_actors[x][y]!="undefined"){this.grdat_actors[x][y].setX(this.grdat_actors[x][y].getX() + this.half_scew);}
y = y+1;
}
x = x+1;
}
this.offsx += this.half_scew; this.player.setValue("Player_leg_behav","x",this.player.getValue("Player_leg_behav","x")+this.half_scew);
Script.runLater(200,stop_shift,null);
}
public function shift_ydec():Void
{
this.shifting = true;this.player.makeAlwaysSimulate();
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;
while(x < xmax)
{
y = ymin;
while(y < ymax)
{
if(this.grdat_actors[x][y]!=null&&""+this.grdat_actors[x][y]!="undefined"){this.grdat_actors[x][y].setY(this.grdat_actors[x][y].getY() - this.half_sceh);}
y = y+1;
}
x = x+1;
}
this.offsy -= this.half_sceh; this.player.setValue("Player_leg_behav","y",this.player.getValue("Player_leg_behav","y")-this.half_sceh);
Script.runLater(20,stop_shift,null);
}
public function shift_yinc():Void
{
this.shifting = true;this.player.makeAlwaysSimulate();
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;
while(x < xmax)
{
y = ymin;
while(y < ymax)
{
if(this.grdat_actors[x][y]!=null&&""+this.grdat_actors[x][y]!="undefined"){this.grdat_actors[x][y].setY(this.grdat_actors[x][y].getY() + this.half_sceh);}
y = y+1;
}
x = x+1;
}
this.offsy += this.half_sceh; this.player.setValue("Player_leg_behav","y",this.player.getValue("Player_leg_behav","y")+this.half_sceh);
Script.runLater(20,stop_shift,null);
}
public function stop_shift(t:TimedTask):Void{this.shifting = false; this.player.makeSometimesSimulate();}
public function update(t:TimedTask):Void {this.upd = true;} // allows scanning for update
}
No comments:
Post a Comment