so-called unlimited scene with zoom - gameplay scene

code for the gameplay scene. 

package scripts;
import com.stencyl.Engine;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.Script; 
import com.stencyl.behavior.TimedTask;
import com.stencyl.models.Actor; 
class S_gameplay_behav extends SceneScript 
{
public var camx:Float; public var camy:Float; 
public var scew:Float; public var sceh:Float;
public var scrw:Float; public var scrh:Float; 
public var half_sceh:Float; public var half_scew:Float; 
public var half_scrh:Float; public var half_scrw:Float; 
public var diag_gate:Bool = false; 
public static var camcx: Float; public static var camcy: Float; 
public static var disp_xcen:Float=0; public static var disp_ycen:Float=0;
public static var disp_xmax:Int=0; public static var disp_xmin:Int=0; public static var disp_ymax:Int=0; public static var disp_ymin:Int=0; 
public static var offsx: Float=0; public static var offsy:Float=0; 
public static var setting_zoom:Bool = false; public static var shifting:Bool = false;
// map data
public static var tdat:Floor_data = new Floor_data();  public static var obdat:Object_data = new Object_data(); 
public static var zoom: Float = 1; public static var continued: Bool = false; public static var scene_name:String="";  public static var old_zoom:Float; 
public static var zoom_cx: Float; public static var zoom_cy:Float; 
public static var player_torso:Actor = null; 
public var dtext_s : Dtext = new Dtext(55); public var checklag:Int =0; public var diag_rf:RF = new RF(); 
public function new (){super();}
override public function init()
{
this.diag_rf.c =0; this.diag_rf.a =0.5; S_gameplay_behav.player_torso = null;  
this.sceh = Engine.sceneHeight; this.scew = Engine.sceneWidth; 
this.scrh = Engine.screenHeight; this.scrw = Engine.screenWidth; 
this.half_sceh = this.sceh/2; this.half_scew = this.scew/2;  
this.half_scrh = this.scrh/2; this.half_scrw = this.scrw/2;  
Script.createRecycledActor(Conte.atid("b_int"),0,0,Script.FRONT);
Script.createRecycledActor(Conte.atid("b_gameplay_menu"),0,170,Script.FRONT);
Script.createRecycledActor(Conte.atid("b_save_game"),0,233,Script.FRONT);
if(Player_ngs.unlock_zoom || Player_data.unlocked_zoom)
{
Script.createRecycledActor(Conte.atid("b_zoom_in"),0,135,Script.FRONT);
Script.createRecycledActor(Conte.atid("b_zoom_level"),37,135,Script.FRONT);
Script.createRecycledActor(Conte.atid("b_zoom_out"),140,135,Script.FRONT);
}
Engine.engine.whenDrawingListeners.push(dwg);
this.load_sce("","","player_room",0,0); 
}
public function init_sce()
{
S_gameplay_behav.tdat.init();  S_gameplay_behav.obdat.init(); 
Engine.cameraX = this.half_scew - this.half_scrw; Engine.cameraY = this.half_sceh - this.half_scrh;
S_gameplay_behav.camcx = Engine.cameraX + Engine.screenWidth/2; S_gameplay_behav.camcy = Engine.cameraY + Engine.screenHeight/2; 
this.camx = Engine.cameraX; this.camy = Engine.cameraY; 
S_gameplay_behav.disp_xcen = (this.camx + this.half_scrw - this.half_scew)/512/S_gameplay_behav.zoom + S_gameplay_behav.offsx/512; // checkm inconsistency
S_gameplay_behav.disp_ycen = (this.camy + this.half_scrh - this.half_sceh)/512/S_gameplay_behav.zoom + S_gameplay_behav.offsy/512;
S_gameplay_behav.disp_xmax = Std.int(Math.ceil(S_gameplay_behav.disp_xcen + this.half_scrw/512/S_gameplay_behav.zoom) + 2);
S_gameplay_behav.disp_xmin = Std.int(Math.floor(S_gameplay_behav.disp_xcen - this.half_scrw/512/S_gameplay_behav.zoom) - 1);
S_gameplay_behav.disp_ymax = Std.int(Math.ceil(S_gameplay_behav.disp_ycen + this.half_scrh/512/S_gameplay_behav.zoom) + 2);
S_gameplay_behav.disp_ymin = Std.int(Math.floor(S_gameplay_behav.disp_ycen - this.half_scrh/512/S_gameplay_behav.zoom) - 1);
S_gameplay_behav.camcx = Engine.cameraX + Engine.screenWidth/2; S_gameplay_behav.camcy = Engine.cameraY + Engine.screenHeight/2; 
var x:Int = S_gameplay_behav.disp_xmin; var y:Int = S_gameplay_behav.disp_ymin;
while (y < S_gameplay_behav.disp_ymax)
{
S_gameplay_behav.tdat.ren_horz(y, S_gameplay_behav.disp_xmin, S_gameplay_behav.disp_xmax); 
S_gameplay_behav.obdat.ren_horz(y, S_gameplay_behav.disp_xmin, S_gameplay_behav.disp_xmax); 
y = y +1;  
}
var init_player_x:Float = Engine.cameraX + Engine.screenWidth/2 -256; //fucus porblem here. 
var init_player_y:Float = Engine.cameraY + Engine.screenHeight/2 -256 ;
S_gameplay_behav.player_torso = Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_torso"),init_player_x,init_player_y,1);
S_gameplay_behav.player_torso.growTo(S_gameplay_behav.zoom*0.8,S_gameplay_behav.zoom*0.8,0,null);
this.def();
}
public function def() // we will try without using when Updated Listeners. 
{
this.checklag +=1;
if(!S_gameplay_behav.setting_zoom)
{
var old_xmax:Int = S_gameplay_behav.disp_xmax; var old_xmin:Int = S_gameplay_behav.disp_xmin; 
var old_ymax:Int = S_gameplay_behav.disp_ymax; var old_ymin:Int = S_gameplay_behav.disp_ymin; 
var x:Int; var y:Int; 
S_gameplay_behav.camcx = Engine.cameraX + Engine.screenWidth/2; S_gameplay_behav.camcy = Engine.cameraY + Engine.screenHeight/2; 
this.camx = Engine.cameraX; this.camy = Engine.cameraY; 
S_gameplay_behav.disp_xmax = Std.int(Math.ceil(S_gameplay_behav.disp_xcen + this.half_scrw/512/S_gameplay_behav.zoom) + 2);
S_gameplay_behav.disp_xmin = Std.int(Math.floor(S_gameplay_behav.disp_xcen - this.half_scrw/512/S_gameplay_behav.zoom) - 1);
S_gameplay_behav.disp_ymax = Std.int(Math.ceil(S_gameplay_behav.disp_ycen + this.half_scrh/512/S_gameplay_behav.zoom) + 2);
S_gameplay_behav.disp_ymin = Std.int(Math.floor(S_gameplay_behav.disp_ycen - this.half_scrh/512/S_gameplay_behav.zoom) - 1);
if(S_gameplay_behav.disp_xmin < old_xmin) // left side
{
var a:Int = old_xmin; while(a > S_gameplay_behav.disp_xmin)
{
a = a -1; 
S_gameplay_behav.tdat.ren_vert(a,old_ymin,old_ymax);
S_gameplay_behav.obdat.ren_vert(a,old_ymin,old_ymax);
}
}
else if(S_gameplay_behav.disp_xmin > old_xmin) // remove actor
{
var a:Int = old_xmin; while(a < S_gameplay_behav.disp_xmin)
{
S_gameplay_behav.tdat.remo_vert(a,old_ymin,old_ymax);
S_gameplay_behav.obdat.remo_vert(a,old_ymin,old_ymax);
a = a +1; 
}
}
if(S_gameplay_behav.disp_xmax > old_xmax) // right side
{
var a:Int = old_xmax; while(a < S_gameplay_behav.disp_xmax)
{
S_gameplay_behav.tdat.ren_vert(a,old_ymin,old_ymax);
S_gameplay_behav.obdat.ren_vert(a,old_ymin,old_ymax);
a = a +1; 
}
}
else if(S_gameplay_behav.disp_xmax < old_xmax)
{
var a:Int = old_xmax; while(a > S_gameplay_behav.disp_xmax)
{
a = a-1; 
S_gameplay_behav.tdat.remo_vert(a,old_ymin,old_ymax);
S_gameplay_behav.obdat.remo_vert(a,old_ymin,old_ymax);
}
}
if(S_gameplay_behav.disp_ymin < old_ymin)// upperside
{
var a:Int = old_ymin; while(a > S_gameplay_behav.disp_ymin)
{
a = a-1; 
S_gameplay_behav.tdat.ren_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
S_gameplay_behav.obdat.ren_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
}
}
else if(S_gameplay_behav.disp_ymin > old_ymin)
{
var a:Int = old_ymin; while(a < S_gameplay_behav.disp_ymin)
{
S_gameplay_behav.tdat.remo_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
S_gameplay_behav.obdat.remo_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
a = a+1; 
}
}
if(S_gameplay_behav.disp_ymax > old_ymax) // lower side
{
var a:Int = old_ymax; while(a < S_gameplay_behav.disp_ymax)
{
S_gameplay_behav.tdat.ren_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
S_gameplay_behav.obdat.ren_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
a = a+1; 
}
}
else if(S_gameplay_behav.disp_ymax < old_ymax)
{
var a:Int = old_ymax; while(a > S_gameplay_behav.disp_ymax)
{
a = a-1; 
S_gameplay_behav.tdat.remo_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
S_gameplay_behav.obdat.remo_horz(a,S_gameplay_behav.disp_xmin,S_gameplay_behav.disp_xmax);
}
}
// shifting -- did not happen
}
if(Engine.cameraX < 0){this.shift_px();} // did go through this gate. 
else if(Engine.cameraX > Engine.sceneWidth - Engine.screenWidth){this.shift_nx();}
if(Engine.cameraY < 0){this.shift_py();}
else if(Engine.cameraY > Engine.sceneHeight - Engine.screenHeight){this.shift_ny();}
var tt:TimedTask = new TimedTask(this.next_frame,15,false,null); 
Engine.engine.tasks.push(tt);
}
public function dwg() // draws diagnosis data
{
this.diag_rf.fill_rec(195,0,200,300);
this.dtext_s.drawString("check lag: "+this.checklag,200,0);
this.dtext_s.drawString("zoom_mult: "+S_gameplay_behav.zoom,200,15);
this.dtext_s.drawString("cam center x: "+S_gameplay_behav.camcx,200,30);
this.dtext_s.drawString("cam center y: "+S_gameplay_behav.camcy,200,45);
this.dtext_s.drawString("disp_xcen: "+S_gameplay_behav.disp_xcen,200,60);
this.dtext_s.drawString("disp_ycen: "+S_gameplay_behav.disp_ycen,200,75);
this.dtext_s.drawString("disp_xmax: "+S_gameplay_behav.disp_xmax,200,90);
this.dtext_s.drawString("disp_xmin: "+S_gameplay_behav.disp_xmin,200,105);
this.dtext_s.drawString("disp_ymax: "+S_gameplay_behav.disp_ymax,200,120);
this.dtext_s.drawString("disp_ymin: "+S_gameplay_behav.disp_ymin,200,135);
this.dtext_s.drawString("number of tiles: "+S_gameplay_behav.tdat.number_of_actors,200,150);
this.dtext_s.drawString("offsx: "+S_gameplay_behav.offsx,200,165);
this.dtext_s.drawString("offsy: "+S_gameplay_behav.offsy,200,180);
this.dtext_s.drawString("create_x"+ Floor_data.diag_create_x,200,195);
this.dtext_s.drawString("save name: "+ Save.name,200,210);
}
public function load_sce(savename:String, region:String, map:String, udg:Int, level:Int)
{
this.init_sce();
}
public function next_frame(t:TimedTask){this.def();}
public static function end_set_zoom(t:TimedTask){S_gameplay_behav.setting_zoom = false;}
public static function move_cam(x:Float,y:Float){}
public static function set_zoom()
{
S_gameplay_behav.setting_zoom = true; 
S_gameplay_behav.old_zoom = S_gameplay_behav.zoom; 
S_gameplay_behav.zoom = Math.pow(1.2,0-B_zoom_level_behav.zoom_level);
S_gameplay_behav.tdat.set_zoom();
S_gameplay_behav.obdat.set_zoom();
S_gameplay_behav.player_torso.say("Player_torso_behav","set_zoom");
var tt:TimedTask = new TimedTask(S_gameplay_behav.end_set_zoom,15,false,null); 
Engine.engine.tasks.push(tt);
}
public function shift_nx()
{
S_gameplay_behav.offsx += Engine.sceneWidth/2/S_gameplay_behav.zoom; 
S_gameplay_behav.tdat.shift_nx(); 
S_gameplay_behav.obdat.shift_nx();
S_gameplay_behav.player_torso.say("Player_torso_behav","shift_nx");
Engine.cameraX -= this.half_scew; 
}
public function shift_ny()
{
S_gameplay_behav.offsy += Engine.sceneWidth/2/S_gameplay_behav.zoom; 
S_gameplay_behav.tdat.shift_ny(); 
S_gameplay_behav.obdat.shift_ny(); 
S_gameplay_behav.player_torso.say("Player_torso_behav","shift_ny");
Engine.cameraY -= this.half_sceh; 
}
public function shift_px() 
{
this.diag_gate = true;
S_gameplay_behav.offsx -= Engine.sceneWidth/2/S_gameplay_behav.zoom;
S_gameplay_behav.tdat.shift_px(); 
S_gameplay_behav.obdat.shift_px(); 
S_gameplay_behav.player_torso.say("Player_torso_behav","shift_px");
Engine.cameraX += this.half_scew; 
}
public function shift_py()
{
S_gameplay_behav.offsy -= Engine.sceneWidth/2/S_gameplay_behav.zoom; 
S_gameplay_behav.tdat.shift_py(); 
S_gameplay_behav.obdat.shift_py(); 
S_gameplay_behav.player_torso.say("Player_torso_behav","shift_py");
Engine.cameraY += this.half_sceh; 
}
}


No comments:

Post a Comment