sc endless scene wz - player

code for so called endless scenes with zoom  - player
 
Here we make our own collision system without using colision events but rather making comparison with actors in the range.

package scripts;
import com.stencyl.Engine;
import com.stencyl.behavior.ActorScript; // all actor behaviors extends ActorScript
import com.stencyl.behavior.Script;
import com.stencyl.behavior.TimedTask;
import com.stencyl.models.Actor; 
import com.stencyl.models.actor.Collision;
import com.stencyl.utils.ColorMatrix;// recolor player body parts

class Player_torso_behav extends ActorScript
{
public var diag_text: Dtext = new Dtext(); var diag_rh:RH = new RH(); public var diag_col:String = ""; public var diag_0:Float=0; public var diag_1:Float=0; public var diag_2:Float=0; public var anim_cycle:Float =0; public var player_speed = 1; public var posx:Float; public var posy:Float; // player position anti-aliasing public var old_posx:Float; public var old_posy:Float; // for continious collision purpose. public var move_x: Float =0; public var move_y : Float =0; public var move_east:Bool = false; public var move_north:Bool = false; public var move_south = false; public var move_west = false; public var direction:Int =0; public var moving = false; // player body parts and joints public static var head_actor:Actor = null; public static var head_offx = 0; public static var head_offy = -10; public var head_adjx:Float =0; public var head_adjy:Float =0; public static var neck_actor:Actor = null; public static var neck_offx = 0; public static var neck_offy = -20; public var neck_adjx:Float =0; public var neck_adjy:Float =0; public static var arms_adjx:Array<Dynamic>=[]; public static var arms_adjy:Array<Dynamic>=[]; public static var tails_adjx:Array<Dynamic>=[]; public static var tails_adjy:Array<Dynamic>=[]; public static var arms_actors:Array<Dynamic>=[]; public static var arms_lencol: Array <Int>=[]; public static var arms_refl:Array<Dynamic>=[]; // curently unused public static var arms_offsx: Array<Dynamic>=[]; public static var arms_offsy:Array<Dynamic>=[]; public static var arms_rota:Array<Dynamic>=[]; public static var arms_redpwr:Array<Dynamic>=[]; public static var arms_grepwr:Array<Dynamic>=[]; public static var arms_blupwr:Array<Dynamic>=[]; public static var tails_actors:Array<Dynamic>=[]; public static var tails_lencol: Array <Int>=[]; public static var tails_refl:Array<Dynamic>=[]; // curently unused public static var tails_offsx: Array<Dynamic>=[]; public static var tails_offsy:Array<Dynamic>=[]; public static var tails_rota:Array<Dynamic>=[]; public static var tails_redpwr:Array<Dynamic>=[]; public static var tails_grepwr:Array<Dynamic>=[]; public static var tails_blupwr:Array<Dynamic>=[]; public static var number_of_arms:Int =0; public static var number_of_tails:Int = 0; public static var speed:Float = 1; public function new (a,b,c){super(b);} override public function init() // when created { this.diag_text.red_pwr =0; this.diag_text.gre_pwr =0; this.diag_text.blu_pwr =0; this.posx = actor.getX(); this.posy = actor.getY(); var center_x:Float = this.posx + 256; // in this case the player torso width 512 os its haldf width = 256 var center_y:Float = this.posy + 256; addKeyStateListener("a",press_west); addKeyStateListener("d",press_east); addKeyStateListener("w",press_north); addKeyStateListener("s",press_south); actor.whenDrawingListeners.push(diag_drawing); actor.bitmapFilters = []; var ckc:ColorMatrix = new ColorMatrix(); ckc.colorize(Player_data.torso_redpwr*65536 + Player_data.torso_grepwr * 256 + Player_data.torso_blupwr,1); actor.bitmapFilters[0] = ckc.getFilter(); actor.currAnimation.filter = actor.bitmapFilters; // direction and position for body parts - degree of roataion follows clocks exactly. 0 degrees at 00:00 this.head_adjx = Player_torso_behav.head_offy * Math.sin(this.direction * Math.PI/-180) * S_gameplay_behav.zoom; this.head_adjy = Player_torso_behav.head_offy * Math.cos(this.direction * Math.PI/180)* S_gameplay_behav.zoom; this.neck_adjx = Player_torso_behav.neck_offy * Math.sin(this.direction * Math.PI/-180)* S_gameplay_behav.zoom; this.neck_adjy = Player_torso_behav.neck_offy * Math.cos(this.direction * Math.PI/180)* S_gameplay_behav.zoom; Player_torso_behav.head_actor = Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_head"),center_x - 64 + this.head_adjx,center_y - 64 + this.head_adjy,3); Player_torso_behav.neck_actor = Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_neck"),center_x - 80 + this.neck_adjx,center_y - 80 + this.head_adjy,2); Player_torso_behav.head_actor.growTo(0.44 * S_gameplay_behav.zoom,0.44* S_gameplay_behav.zoom,0,null); Player_torso_behav.neck_actor.growTo(0.6* S_gameplay_behav.zoom,0.6* S_gameplay_behav.zoom,0,null); var cka:ColorMatrix = new ColorMatrix(); cka.colorize(Player_data.head_redpwr*65536 + Player_data.head_grepwr * 256 + Player_data.head_blupwr,1); var ckb:ColorMatrix = new ColorMatrix(); ckb.colorize(Player_data.neck_redpwr*65536 + Player_data.neck_grepwr * 256 + Player_data.neck_blupwr,1); Player_torso_behav.head_actor.bitmapFilters = []; Player_torso_behav.head_actor.bitmapFilters[0] = cka.getFilter(); Player_torso_behav.head_actor.currAnimation.filter = Player_torso_behav.head_actor.bitmapFilters; Player_torso_behav.neck_actor.bitmapFilters = []; Player_torso_behav.neck_actor.bitmapFilters[0] = ckb.getFilter(); Player_torso_behav.neck_actor.currAnimation.filter = Player_torso_behav.neck_actor.bitmapFilters; Player_torso_behav.head_actor.setX(center_x - 64 + this.head_adjx); Player_torso_behav.head_actor.setY(center_y - 64 + this.head_adjy); Player_torso_behav.neck_actor.setX(center_x - 80 + this.neck_adjx); Player_torso_behav.neck_actor.setY(center_y - 80 + this.neck_adjy); var a:Int =0; // arms var segm_center_x:Float; var segm_center_y:Float; var color:Int = 0; var delta_x:Float; var delta_y:Float; var create_x:Float; var create_y:Float; var bf: ColorMatrix = new ColorMatrix(); var act:Actor; while(a < Player_torso_behav.number_of_arms) { Player_torso_behav.arms_actors[a] = []; Player_torso_behav.arms_adjx[a] = []; Player_torso_behav.arms_adjy[a] = []; //initialisation // upper segment segm_center_x = (Player_torso_behav.arms_offsx[a][0] +98)* 0.8 * S_gameplay_behav.zoom - 98; // in this case, half wisth = 98 segm_center_y = (Player_torso_behav.arms_offsy[a][0] +67)* 0.8 * S_gameplay_behav.zoom - 67; // half height = 67 Player_torso_behav.arms_actors[a][0] =Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_arm_s0"),center_x+segm_center_x,center_y+segm_center_y,2); Player_torso_behav.arms_actors[a][0].growTo(Player_body_data.scal_upper_arm*0.8*S_gameplay_behav.zoom,Player_body_data.scal_upper_arm*0.8*S_gameplay_behav.zoom,0,null); Player_torso_behav.arms_actors[a][0].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[a],null,0); act = Player_torso_behav.arms_actors[a][0]; color = Std.int(Player_torso_behav.arms_redpwr[a][0]*65536+Player_torso_behav.arms_grepwr[a][0]*256 + Player_torso_behav.arms_blupwr[a][0]); // removed the red cpomponent to show effects. this.diag_0 = Player_torso_behav.arms_redpwr[a][0]; this.diag_1 = Player_torso_behav.arms_grepwr[a][0]; this.diag_2 = Player_torso_behav.arms_blupwr[a][0];// showing that color did transfer successfully act.bitmapFilters=[]; bf= new ColorMatrix(); // needs to be renewed everytime before recoloring actors. bf.colorize(color); act.bitmapFilters[0] = bf.getFilter(); act.currAnimation.filter = act.bitmapFilters;// it works only if the actor is not taken directly form list. // lower segment segm_center_x = (Player_torso_behav.arms_offsx[a][1] + 43.5)* 0.8 * S_gameplay_behav.zoom - 43.5; // in this case, half wisth = 43.5 segm_center_y = (Player_torso_behav.arms_offsy[a][1] + 69)* 0.8 * S_gameplay_behav.zoom - 69; Player_torso_behav.arms_actors[a][1] =Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_arm_s1"),center_x+segm_center_x,center_y+segm_center_y,2); Player_torso_behav.arms_actors[a][1].growTo(Player_body_data.scal_lower_arm*0.8*S_gameplay_behav.zoom,Player_body_data.scal_lower_arm*0.8*S_gameplay_behav.zoom,0,null); Player_torso_behav.arms_actors[a][1].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[a],null,0); act = Player_torso_behav.arms_actors[a][1]; color = Std.int(Player_torso_behav.arms_redpwr[a][1]*65536 + Player_torso_behav.arms_redpwr[a][1]*256 + Player_torso_behav.arms_blupwr[a][1]); act.bitmapFilters=[]; bf= new ColorMatrix(); // needs to be renewed everytime before recoloring actors. bf.colorize(color); act.bitmapFilters[0] = bf.getFilter(); act.currAnimation.filter = act.bitmapFilters; segm_center_x = (Player_torso_behav.arms_offsx[a][2] + 81.5)* 0.8 * S_gameplay_behav.zoom - 81.5; segm_center_y = (Player_torso_behav.arms_offsy[a][2] + 61.5)* 0.8 * S_gameplay_behav.zoom - 61.5; Player_torso_behav.arms_actors[a][2] =Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_tailpaw"),center_x+segm_center_x,center_y+segm_center_y,2); Player_torso_behav.arms_actors[a][2].growTo(0.4*S_gameplay_behav.zoom,0.4*S_gameplay_behav.zoom,0,null); Player_torso_behav.arms_actors[a][2].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[a],null,0); act = Player_torso_behav.arms_actors[a][2]; color = Std.int(Player_torso_behav.arms_redpwr[a][2]*65536 + Player_torso_behav.arms_redpwr[a][2]*256 + Player_torso_behav.arms_blupwr[a][2]); act.bitmapFilters=[]; bf= new ColorMatrix(); // needs to be renewed everytime before recoloring actors. bf.colorize(color); act.bitmapFilters[0] = bf.getFilter(); act.currAnimation.filter = act.bitmapFilters; a = a+1; } a = 0; // tails while(a < Player_torso_behav.number_of_tails) { Player_torso_behav.tails_actors[a] = []; Player_torso_behav.tails_adjx[a] = []; Player_torso_behav.tails_adjy[a] = []; // init segm_center_x = (Player_torso_behav.tails_offsx[a][0] +128)* 0.8 * S_gameplay_behav.zoom - 128; segm_center_y = (Player_torso_behav.tails_offsy[a][0] +110.5)* 0.8 * S_gameplay_behav.zoom - 110.5; Player_torso_behav.tails_actors[a][0] =Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_tail_s0"),center_x+segm_center_x,center_y+segm_center_y,2);// registered Player_torso_behav.tails_actors[a][0].growTo(0.8*S_gameplay_behav.zoom,0.8*S_gameplay_behav.zoom,0,null); Player_torso_behav.tails_actors[a][0].tweenProps.angle.tween(0,Player_torso_behav.tails_rota[a]+180,null,0); // direction problem. act = Player_torso_behav.tails_actors[a][0]; color = Std.int(Player_torso_behav.tails_redpwr[a][0]*65536+Player_torso_behav.tails_grepwr[a][0]*256 + Player_torso_behav.tails_blupwr[a][0]); // color component problems. - crash found this.diag_0 = Player_torso_behav.tails_redpwr[a][0]; this.diag_1 = Player_torso_behav.tails_grepwr[a][0]; this.diag_2 = Player_torso_behav.tails_blupwr[a][0];// showing that color did transfer successfully act.bitmapFilters=[]; bf= new ColorMatrix(); // needs to be renewed everytime before recoloring actors. bf.colorize(color); act.bitmapFilters[0] = bf.getFilter(); act.currAnimation.filter = act.bitmapFilters;// it works only if the actor is not taken directly form list. segm_center_x = (Player_torso_behav.tails_offsx[a][1] + 110.5)* 0.8 * S_gameplay_behav.zoom - 110.5; segm_center_y = (Player_torso_behav.tails_offsy[a][1] + 110.5)* 0.8 * S_gameplay_behav.zoom - 110.5; Player_torso_behav.tails_actors[a][1] =Engine.engine.getRecycledActorOfTypeOnLayer(Conte.player_atid("player_tail_s1"),center_x+segm_center_x,center_y+segm_center_y,2);// registered Player_torso_behav.tails_actors[a][1].growTo(0.8*S_gameplay_behav.zoom,0.8*S_gameplay_behav.zoom,0,null); Player_torso_behav.tails_actors[a][1].tweenProps.angle.tween(0,Player_torso_behav.tails_rota[a]+180,null,0); // direction problem. act = Player_torso_behav.tails_actors[a][1]; color = Std.int(Player_torso_behav.tails_redpwr[a][1]*65536+Player_torso_behav.tails_grepwr[a][1]*256 + Player_torso_behav.tails_blupwr[a][1]); // color component problems. - crash found this.diag_0 = Player_torso_behav.tails_redpwr[a][1]; this.diag_1 = Player_torso_behav.tails_grepwr[a][1]; this.diag_2 = Player_torso_behav.tails_blupwr[a][1];// showing that color did transfer successfully act.bitmapFilters=[]; bf= new ColorMatrix(); // needs to be renewed everytime before recoloring actors. bf.colorize(color); act.bitmapFilters[0] = bf.getFilter(); act.currAnimation.filter = act.bitmapFilters;// it works only if the actor is not taken directly form list. a = a+1; } this.def(); this.set_direction(Player_body_data.direction); } public function col(): Void // pairs with actors in list. { this.diag_col = "no collisions detected"; var pl_dimension:Float = 512 * 0.8 * S_gameplay_behav.zoom; var pl_left_bound:Float = this.posx + 256 - (pl_dimension * 0.5); var pl_right_bound:Float = this.posx + 256 + (pl_dimension * 0.5); var pl_upper_bound:Float = this.posy + 256 - (pl_dimension * 0.5); var pl_lower_bound:Float = this.posy + 256 + (pl_dimension * 0.5); var xmin:Int = Std.int(Math.floor(S_gameplay_behav.disp_xcen)) -1; var xmax:Int = Std.int(Math.ceil(S_gameplay_behav.disp_xcen)) +2; var ymin:Int = Std.int(Math.floor(S_gameplay_behav.disp_ycen)) -1; var ymax:Int = Std.int(Math.ceil(S_gameplay_behav.disp_ycen)) +2; var y:Int = ymin; var x:Int = xmin; while(x < xmax) { y = ymin; while(y < ymax) { if(Std.is(S_gameplay_behav.obdat.actors[x][y],Actor)) { var obj_left_bound:Float = S_gameplay_behav.obdat.actors[x][y].getX() + 256 - 256 * S_gameplay_behav.zoom; var obj_right_bound:Float = S_gameplay_behav.obdat.actors[x][y].getX() + 256 + 256 * S_gameplay_behav.zoom; var obj_upper_bound:Float = S_gameplay_behav.obdat.actors[x][y].getY() + 256 - 256 * S_gameplay_behav.zoom; var obj_lower_bound:Float = S_gameplay_behav.obdat.actors[x][y].getY() + 256 + 256 * S_gameplay_behav.zoom; if(pl_right_bound > obj_left_bound && pl_left_bound < obj_right_bound && pl_lower_bound > obj_upper_bound && pl_upper_bound < obj_lower_bound) { this.diag_col = "collision detected"; var dx:Float = this.posx - S_gameplay_behav.obdat.actors[x][y].getX(); var dy:Float = this.posy - S_gameplay_behav.obdat.actors[x][y].getY(); if(dx < 0) { if(dy < 0) // upper left corner { if(dx < dy) { this.diag_col = "left side"; this.posx = Math.min(this.posx,obj_left_bound - 256 - (pl_dimension * 0.5)); } else { this.diag_col = "upper side"; this.posy = Math.min(this.posy,obj_upper_bound - 256 - (pl_dimension * 0.5)); } } else // lower left corner, dx is negative, dy is positive. { if(dx + dy < 0) // remains left side { this.diag_col = "left side"; this.posx = Math.min(this.posx,obj_left_bound- 256 - (pl_dimension * 0.5)); } else { this.diag_col = "bottom side"; this.posy = Math.max(this.posy,obj_lower_bound - 256 + (pl_dimension * 0.5)); } } } else { if(dy < 0) // uppper right, dx is positive, { if(dx + dy < 0) // remains upper side { this.diag_col = "upper side"; this.posy = Math.min(this.posy,obj_upper_bound - 256 - (pl_dimension * 0.5)); } else { this.diag_col = "rignt side"; this.posx = Math.max(this.posx,obj_right_bound - 256 + (pl_dimension * 0.5)); } } else { if(dx < dy) { this.diag_col = "bottom side"; this.posy = Math.max(this.posy,obj_lower_bound - 256 + (pl_dimension * 0.5)); } else { this.diag_col = "right side"; this.posx = Math.max(this.posx,obj_right_bound - 256 + (pl_dimension * 0.5)); } } } } } y = y+1; } x = x+1; } } public function def():Void { var delta_x:Float; var delta_y:Float; var tt:TimedTask = new TimedTask(this.next_frame,20,false,null); if(this.moving) { . Player_torso_behav.head_actor.setX(this.posx + 256 - 64 + this.head_adjx); Player_torso_behav.head_actor.setY(this.posy + 256 - 64 + this.head_adjy); Player_torso_behav.neck_actor.setX(this.posx + 256 - 80 + this.neck_adjx); Player_torso_behav.neck_actor.setY(this.posy + 256 - 80 + this.neck_adjy); // arms var a=0; while (a < Player_torso_behav.number_of_arms) { Player_torso_behav.arms_actors[a][0].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][0] - 98); Player_torso_behav.arms_actors[a][0].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][0]- 67); Player_torso_behav.arms_actors[a][1].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][1] - 43.5); Player_torso_behav.arms_actors[a][1].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][1]- 69); Player_torso_behav.arms_actors[a][2].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][2] - 81.5); Player_torso_behav.arms_actors[a][2].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][2] - 61.5); a=a+1; } a=0; while (a < Player_torso_behav.number_of_tails) // tails { Player_torso_behav.tails_actors[a][0].setX(this.posx + 256 - Player_torso_behav.tails_adjx[a][0] - 128); Player_torso_behav.tails_actors[a][0].setY(this.posy + 256 - Player_torso_behav.tails_adjy[a][0] - 110.5); Player_torso_behav.tails_actors[a][1].setX(this.posx + 256 - Player_torso_behav.tails_adjx[a][1] - 110.5); // in this case the half width and half height if this actor is 110.5 Player_torso_behav.tails_actors[a][1].setY(this.posy + 256 - Player_torso_behav.tails_adjy[a][1] - 110.5); a=a+1; } this.anim_cycle += 0.05 * Player_data.speed; this.set_anim(); this.old_posx = this.posx; this.old_posy = this.posy; var dx:Float = move_x * Player_data.speed; // todo list. var dy:Float = move_y * Player_data.speed; this.posx += dx * S_gameplay_behav.zoom; this.posy += dy* S_gameplay_behav.zoom; this.col(); actor.setX(this.posx); actor.setY(this.posy); Engine.cameraX = actor.getX() - Engine.screenWidth/2 + actor.cacheWidth/2 ; Engine.cameraY = actor.getY() - Engine.screenHeight/2 + actor.cacheHeight/2 ; S_gameplay_behav.disp_xcen += (this.posx-this.old_posx) /512/ S_gameplay_behav.zoom; S_gameplay_behav.disp_ycen += (this.posy-this.old_posy) /512/ S_gameplay_behav.zoom; } Engine.engine.tasks.push(tt); } public function diag_drawing() { var dx:Float = actor.getX() - Engine.cameraX; var dy:Float = actor.getY() - Engine.cameraY; var pl_left_bound:Float = this.posx + 256 - (256 * 0.8 * S_gameplay_behav.zoom)- Engine.cameraX; var pl_right_bound:Float = this.posx + 256 + (256 * 0.8 * S_gameplay_behav.zoom)- Engine.cameraX; var pl_upper_bound:Float = this.posy + 256 - (256 * 0.8 * S_gameplay_behav.zoom)- Engine.cameraY; var pl_lower_bound:Float = this.posy + 256 + (256 * 0.8 * S_gameplay_behav.zoom)- Engine.cameraY; var rh_width = pl_right_bound - pl_left_bound; var rh_height = pl_lower_bound - pl_upper_bound; this.diag_rh.draw(pl_left_bound,pl_upper_bound,rh_width,rh_height); this.diag_text.drawString("movex: "+ this.move_x, dx,dy); this.diag_text.drawString("movey: "+ this.move_y, dx,dy+20); this.diag_text.drawString("moving:" + this.moving,dx,dy + 40); this.diag_text.drawString("col: " + this.diag_col,dx,dy + 60); this.diag_text.drawString("abri:: lastupper arm color"+ this.diag_0+","+this.diag_1+","+this.diag_2,dx,dy + 80); } public function get_anim(a:Float):String { var b:Int = Std.int(a); if(b == 0){return "neutral";} return "neutral"; } public function next_frame(a:TimedTask):Void{this.def();} public function press_east(p:Bool,r:Bool,u0) { if(p) { this.moving = true; this.move_east = true; if(this.move_west) { if(this.move_north && !(this.move_south)){this.direction =0; this.move_x =0; this.move_y = -1;} else if(!(this.move_north) && this.move_south){this.direction =180; this.move_x =0; this.move_y = 1;} else {this.direction = 90;} } else { if(this.move_north && !(this.move_south)){this.direction = 45;this.move_x =0.707; this.move_y = -0.707;} else if(!(this.move_north) && this.move_south){this.direction = 135;this.move_x =0.707; this.move_y = 0.707;} else {this.direction = 90; this.move_x = 1; this.move_y = 0;} } } else if(r) { this.move_east = false; if(this.move_west) { if(this.move_north && !(this.move_south)){this.direction = 315;this.move_x =-0.707; this.move_y = -0.707;} else if(!(this.move_north) && this.move_south){this.direction = 225;this.move_x =-0.707; this.move_y = 0.707;} else {this.direction = 270; this.move_x = -1; this.move_y = 0;} } else { if(this.move_north && !(this.move_south)){this.direction = 0; this.move_x = 0; this.move_y = -1;} else if(!(this.move_north) && this.move_south){this.direction = 180;this.move_x = 0; this.move_y = 1;} else this.stop_player_movement(); } } this.set_direction(this.direction); } public function press_north(p:Bool,r:Bool,u0) // showing that this is no typo { if(p) { this.moving = true; this.move_north = true; if(this.move_south) { if(this.move_east && !(this.move_west)){this.direction =90;this.move_x = 1; this.move_y = 0;} else if(!(this.move_east) && this.move_west){this.direction =270;this.move_x = -1; this.move_y = 0;} else {this.direction = 0;} } else { if(this.move_east && !(this.move_west)){this.direction = 45;this.move_x =0.707; this.move_y = -0.707;} else if(!(this.move_east) && this.move_west){this.direction = 315;this.move_x =-0.707; this.move_y = -0.707;} else {this.direction = 0; this.move_x =0; this.move_y =-1;} // direction work, but movement did not } } else if(r) { this.move_north = false; if(this.move_south) { if(this.move_east && !(this.move_west)){this.direction = 135;this.move_x =0.707; this.move_y = 0.707;} else if(!(this.move_east) && this.move_west){this.direction = 225;this.move_x =-0.707; this.move_y = 0.707;} else {this.direction = 180;this.move_x = 0; this.move_y = 1;} } else { if(this.move_east && !(this.move_west)){this.direction = 90;this.move_x = 1; this.move_y = 0;} else if(!(this.move_east) && this.move_west){this.direction = 270;this.move_x = -1; this.move_y = 0;} else this.stop_player_movement(); } } this.set_direction(this.direction); } public function press_west(p:Bool,r:Bool,u0) { if(p) { this.moving = true; this.move_west = true; if(this.move_east) { if(this.move_north && !(this.move_south)){this.direction = 0;this.move_x = 0; this.move_y = -1;} else if(!(this.move_north) && this.move_south){this.direction = 180;this.move_x = 0; this.move_y = 1;} else {this.direction = 270;} } else { if(this.move_north && !(this.move_south)){this.direction = 315;this.move_x =-0.707; this.move_y = -0.707;} else if(!(this.move_north) && this.move_south){this.direction = 225;this.move_x =-0.707; this.move_y = 0.707;} else {this.direction = 270;this.move_x = -1; this.move_y = 0;} } } else if(r) { this.move_west = false; if(this.move_east) { if(this.move_north && !(this.move_south)){this.direction = 45;this.move_x =-0.707; this.move_y = 0.707;} else if(!(this.move_north) && this.move_south){this.direction = 135;this.move_x =0.707; this.move_y = 0.707;} else {this.direction = 90;this.move_x = 1; this.move_y = 0;} } else { if(this.move_north && !(this.move_south)){this.direction = 0;this.move_x = 0; this.move_y = -1;} else if(!(this.move_north) && this.move_south){this.direction = 180;this.move_x = 0; this.move_y = 1;} else this.stop_player_movement(); } } this.set_direction(this.direction); } public function press_south(p:Bool,r:Bool,u0) { if(p) { this.moving = true; this.move_south = true; if(this.move_north) { if(this.move_east && !(this.move_west)){this.direction = 90;this.move_x = 1; this.move_y = 0;} else if(!(this.move_east) && this.move_west){this.direction = 270;this.move_x = -1; this.move_y = 0;} else {this.direction = 180;} } else { if(this.move_east && !(this.move_west)){this.direction = 135;this.move_x =0.707; this.move_y = 0.707;} else if(!(this.move_east) && this.move_west){this.direction = 225;this.move_x =-0.707; this.move_y = 0.707;} else {this.direction = 180;this.move_x = 0; this.move_y = 1;} } } else if(r) { this.move_south = false; if(this.move_north) { if(this.move_east && !(this.move_west)){this.direction = 45;this.move_x =0.707; this.move_y = -0.707;} else if(!(this.move_east) && this.move_west){this.direction = 315;this.move_x = -0.707; this.move_y = -0.707;} else {this.direction = 0;this.move_x = 0; this.move_y = -1;} } else { if(this.move_east && !(this.move_west)){this.direction = 90;this.move_x = 1; this.move_y = 0;} else if(!(this.move_east) && this.move_west){this.direction = 270;this.move_x = -1; this.move_y = 0;} else this.stop_player_movement(); } } this.set_direction(this.direction); } public function set_anim() // set anim differs from case to case, { if(this.anim_cycle > 42){this.anim_cycle -= 42;} var a:Int = Std.int(this.anim_cycle) % 43; var b:String = ""; if(a == 0 || a == 21){b = "neutral";} else if(a >= 1 && a <= 10){b="n"+ Std.int(a-1);} else if(a >= 11 && a <= 20){b = "n"+ Std.int(20-a);} else if(a >= 22 && a <= 31){b = "p"+ Std.int(a - 22);} else if(a >= 32 && a <= 42){b = "p"+ Std.int(42-a);} actor.setAnimation(b); } public function set_direction(a:Int) // uses for multi acror { if(a == null ||""+a == "undefined"){a=0;} actor.tweenProps.angle.tween(actor.getAngleInDegrees(),a,null,0); Player_torso_behav.head_actor.tweenProps.angle.tween(Player_torso_behav.head_actor.getAngleInDegrees(),a,null,0); Player_torso_behav.neck_actor.tweenProps.angle.tween(Player_torso_behav.neck_actor.getAngleInDegrees(),a,null,0); Player_body_data.direction = a; // save direction this.head_adjx = Player_torso_behav.head_offy * Math.sin(a * Math.PI/-180) * S_gameplay_behav.zoom; this.head_adjy = Player_torso_behav.head_offy * Math.cos(a * Math.PI/180) * S_gameplay_behav.zoom; this.neck_adjx = Player_torso_behav.neck_offy * Math.sin(a * Math.PI/-180) * S_gameplay_behav.zoom; this.neck_adjy = Player_torso_behav.neck_offy * Math.cos(a * Math.PI/180) * S_gameplay_behav.zoom; var b:Int =0; var pythom:Float =0; while(b < Player_torso_behav.number_of_arms) //body part rota is in degrees. and clock wise direction. { pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[b][0] +67,2)+Math.pow(Player_torso_behav.arms_offsx[b][0] +98,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[b][0] = pythom * Math.sin((Player_torso_behav.arms_rota[b]+a) * Math.PI/-180); Player_torso_behav.arms_adjy[b][0] = pythom * Math.cos((Player_torso_behav.arms_rota[b]+a) * Math.PI/180); Player_torso_behav.arms_actors[b][0].setX(this.posx + 256 - Player_torso_behav.arms_adjx[b][0] - 98); Player_torso_behav.arms_actors[b][0].setY(this.posy + 256 - Player_torso_behav.arms_adjy[b][0]- 67); Player_torso_behav.arms_actors[b][0].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[b]+ a,null,0); pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[b][1] +69,2)+Math.pow(Player_torso_behav.arms_offsx[b][1] + 43.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[b][1] = pythom * Math.sin((Player_torso_behav.arms_rota[b]+a) * Math.PI/-180); Player_torso_behav.arms_adjy[b][1] = pythom * Math.cos((Player_torso_behav.arms_rota[b]+a) * Math.PI/180); Player_torso_behav.arms_actors[b][1].setX(this.posx + 256 - Player_torso_behav.arms_adjx[b][1] - 43.5); Player_torso_behav.arms_actors[b][1].setY(this.posy + 256 - Player_torso_behav.arms_adjy[b][1]- 69); Player_torso_behav.arms_actors[b][1].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[b]+ a,null,0); pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[b][2] +61.5,2)+Math.pow(Player_torso_behav.arms_offsx[b][2] + 81.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[b][2] = pythom * Math.sin((Player_torso_behav.arms_rota[b]+a) * Math.PI/-180); Player_torso_behav.arms_adjy[b][2] = pythom * Math.cos((Player_torso_behav.arms_rota[b]+a) * Math.PI/180); Player_torso_behav.arms_actors[b][2].setX(this.posx + 256 - Player_torso_behav.arms_adjx[b][2] - 81.5); Player_torso_behav.arms_actors[b][2].setY(this.posy + 256 - Player_torso_behav.arms_adjy[b][2] - 61.5); Player_torso_behav.arms_actors[b][2].tweenProps.angle.tween(0,Player_torso_behav.arms_rota[b]+ a,null,0); b=b+1; } b=0; while(b < Player_torso_behav.number_of_tails) { pythom = Math.sqrt(Math.pow(Player_torso_behav.tails_offsx[b][0] + 128,2)+Math.pow(Player_torso_behav.tails_offsy[b][0] + 110.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.tails_adjx[b][0] = pythom * Math.sin((Player_torso_behav.tails_rota[b]+a) * Math.PI/-180); Player_torso_behav.tails_adjy[b][0] = pythom * Math.cos((Player_torso_behav.tails_rota[b]+a) * Math.PI/180); Player_torso_behav.tails_actors[b][0].setX(this.posx + 256 - Player_torso_behav.tails_adjx[b][0] - 128); Player_torso_behav.tails_actors[b][0].setY(this.posy + 256 - Player_torso_behav.tails_adjy[b][0] - 110.5); Player_torso_behav.tails_actors[b][0].tweenProps.angle.tween(0,Player_torso_behav.tails_rota[b]+ 180+ a,null,0); pythom = Math.sqrt(Math.pow(Player_torso_behav.tails_offsx[b][1] + 110.5,2)+Math.pow(Player_torso_behav.tails_offsy[b][1] + 110.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.tails_adjx[b][1] = pythom * Math.sin((Player_torso_behav.tails_rota[b]+a) * Math.PI/-180); Player_torso_behav.tails_adjy[b][1] = pythom * Math.cos((Player_torso_behav.tails_rota[b]+a) * Math.PI/180); Player_torso_behav.tails_actors[b][1].setX(this.posx + 256 - Player_torso_behav.tails_adjx[b][1] - 110.5); Player_torso_behav.tails_actors[b][1].setY(this.posy + 256 - Player_torso_behav.tails_adjy[b][1] - 110.5); Player_torso_behav.tails_actors[b][1].tweenProps.angle.tween(0,Player_torso_behav.tails_rota[b]+ 180+ a,null,0); b = b+1; } } public function set_zoom() { actor.growTo(S_gameplay_behav.zoom * 0.8,S_gameplay_behav.zoom*0.8,0,null); Player_torso_behav.head_actor.growTo(0.44 * S_gameplay_behav.zoom,0.44* S_gameplay_behav.zoom,0,null); Player_torso_behav.neck_actor.growTo(0.6* S_gameplay_behav.zoom,0.6* S_gameplay_behav.zoom,0,null); this.head_adjx = Player_torso_behav.head_offy * Math.sin(this.direction * Math.PI/-180) * S_gameplay_behav.zoom; this.head_adjy = Player_torso_behav.head_offy * Math.cos(this.direction * Math.PI/180)* S_gameplay_behav.zoom; this.neck_adjx = Player_torso_behav.neck_offy * Math.sin(this.direction * Math.PI/-180)* S_gameplay_behav.zoom; this.neck_adjy = Player_torso_behav.neck_offy * Math.cos(this.direction * Math.PI/180)* S_gameplay_behav.zoom; Player_torso_behav.head_actor.setX(this.posx + 256 - 64 + this.head_adjx); Player_torso_behav.head_actor.setY(this.posy + 256 - 64 + this.head_adjy); Player_torso_behav.neck_actor.setX(this.posx + 256 - 80 + this.neck_adjx); Player_torso_behav.neck_actor.setY(this.posy + 256 - 80 + this.neck_adjy); var a:Int =0; var pythom:Float =0; while(a < Player_torso_behav.number_of_arms) { pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[a][0] +67,2)+Math.pow(Player_torso_behav.arms_offsx[a][0] +98,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[a][0] = pythom * Math.sin((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/-180); Player_torso_behav.arms_adjy[a][0] = pythom * Math.cos((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/180); Player_torso_behav.arms_actors[a][0].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][0] - 98); Player_torso_behav.arms_actors[a][0].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][0]- 67); Player_torso_behav.arms_actors[a][0].growTo(Player_body_data.scal_upper_arm*0.8*S_gameplay_behav.zoom,Player_body_data.scal_upper_arm*0.8*S_gameplay_behav.zoom,0,null); pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[a][1] +69,2)+Math.pow(Player_torso_behav.arms_offsx[a][1] + 43.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[a][1] = pythom * Math.sin((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/-180); Player_torso_behav.arms_adjy[a][1] = pythom * Math.cos((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/180); Player_torso_behav.arms_actors[a][1].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][1] - 43.5); Player_torso_behav.arms_actors[a][1].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][1]- 69); Player_torso_behav.arms_actors[a][1].growTo(Player_body_data.scal_lower_arm*0.8*S_gameplay_behav.zoom,Player_body_data.scal_lower_arm*0.8*S_gameplay_behav.zoom,0,null); pythom = Math.sqrt(Math.pow(Player_torso_behav.arms_offsy[a][2] +61.5,2)+Math.pow(Player_torso_behav.arms_offsx[a][2] + 81.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.arms_adjx[a][2] = pythom * Math.sin((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/-180); Player_torso_behav.arms_adjy[a][2] = pythom * Math.cos((Player_torso_behav.arms_rota[a]+this.direction) * Math.PI/180); Player_torso_behav.arms_actors[a][2].setX(this.posx + 256 - Player_torso_behav.arms_adjx[a][2] - 81.5); Player_torso_behav.arms_actors[a][2].setY(this.posy + 256 - Player_torso_behav.arms_adjy[a][2] - 61.5); Player_torso_behav.arms_actors[a][2].growTo(0.4*S_gameplay_behav.zoom,0.4*S_gameplay_behav.zoom,0,null); a=a+1; } a=0; while(a < Player_torso_behav.number_of_tails) { pythom = Math.sqrt(Math.pow(Player_torso_behav.tails_offsx[a][0] + 128,2)+Math.pow(Player_torso_behav.tails_offsy[a][0] + 110.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.tails_adjx[a][0] = pythom * Math.sin((Player_torso_behav.tails_rota[a]+a) * Math.PI/-180); Player_torso_behav.tails_adjy[a][0] = pythom * Math.cos((Player_torso_behav.tails_rota[a]+a) * Math.PI/180); Player_torso_behav.tails_actors[a][0].setX(this.posx + 256 - Player_torso_behav.tails_adjx[a][0] - 128); Player_torso_behav.tails_actors[a][0].setY(this.posy + 256 - Player_torso_behav.tails_adjy[a][0] - 110.5); Player_torso_behav.tails_actors[a][0].growTo(0.8*S_gameplay_behav.zoom,0.8*S_gameplay_behav.zoom,0,null); pythom = Math.sqrt(Math.pow(Player_torso_behav.tails_offsx[a][1] + 110.5,2)+Math.pow(Player_torso_behav.tails_offsy[a][1] + 110.5,2)) * 0.8 * S_gameplay_behav.zoom; Player_torso_behav.tails_adjx[a][1] = pythom * Math.sin((Player_torso_behav.tails_rota[a]+a) * Math.PI/-180); Player_torso_behav.tails_adjy[a][1] = pythom * Math.cos((Player_torso_behav.tails_rota[a]+a) * Math.PI/180); Player_torso_behav.tails_actors[a][1].setX(this.posx + 256 - Player_torso_behav.tails_adjx[a][1] - 110.5); Player_torso_behav.tails_actors[a][1].setY(this.posy + 256 - Player_torso_behav.tails_adjy[a][1] - 110.5); Player_torso_behav.tails_actors[a][1].growTo(0.8*S_gameplay_behav.zoom,0.8*S_gameplay_behav.zoom,0,null); a=a+1; } }
public function stop_player_movement(){this.moving = false; this.move_east = false; this.move_north = false; this.move_south = false; this.move_west = false;} public function shift_nx(){this.posx -= Engine.sceneWidth/2;} public function shift_ny(){this.posy -= Engine.sceneHeight/2;} public function shift_px(){this.posx += Engine.sceneWidth/2;} public function shift_py(){this.posy += Engine.sceneHeight/2;}
}

No comments:

Post a Comment