
//////////////////////
// 3D Landscape    //
//Code By Ayoros  //
///////////////////
function part7() {

    this.initdone = 0 ;
    this.canvaspart ;
    this.vbl = 0;

    this.text = new text_cursor() ;

var angle_land = 0;
var step = 1.5;
var a_data;
var fractal_zoom=0;
var vbl_land=0;
var test_landscape=1;

var water ;
var sand ;
var grass ;
var mountain ;

function NodeObj() {
	this.height = 0;
	//this.colour = "rgb(0,0,0)"
    this.water = 0;
    this.grass = 0;
    this.sand = 0;
    this.mountain = 0;
    this.value = 0 ;
}

function Coord() {
    this.x1 ;
    this.y1 ;
    this.x2 ;
    this.y2 ;
    this.x3 ;
    this.y3 ;
    this.x4 ;
    this.y4 ;
}

  this.init=function(){generateLandscape();this.text.init(choix_text[0],10,8,font_key);this.initdone=1};
function generateLandscape(){a_data=Array(33);for(var f=0;34>f;f++){a_data[f]=Array(33);for(var d=0;34>d;d++)a_data[f][d]=new NodeObj}a_data[0][0].height=0;a_data[0][32].height=0;a_data[32][32].height=0;a_data[32][0].height=0;for(f=16;0<f;f=Math.floor(f/2))for(var d=2*f,a=0;32>a;a+=d)for(var b=0;32>b;b+=d)s1=a_data[a+f][b].height=(a_data[a][b].height+a_data[a+d][b].height)/2+Math.random()*d*1.1-f,s2=a_data[a+d][b+f].height=(a_data[a+d][b].height+a_data[a+d][b+d].height)/2+Math.random()*d*1.1-f,s3=
a_data[a+f][b+d].height=(a_data[a+d][b+d].height+a_data[a][b+d].height)/2+Math.random()*d*1.1-f,s4=a_data[a][b+f].height=(a_data[a][b+d].height+a_data[a][b].height)/2+Math.random()*d*1.1-f,a_data[a+f][b+f].height=(s1+s2+s3+s4)/4+Math.random()*d*1.1-f;colourLandscape(step)}
function colourLandscape(f){function d(a,b){return a-b}f=Math.round(f);1>f&&(f=1);a_temp=Array(4);for(var a=0;32>a;a+=f)for(var b=0;32>b;b+=f)a_temp[0]=a_data[a][b].height,a_temp[1]=a_data[a][b+1].height,a_temp[2]=a_data[a+1][b+1].height,a_temp[3]=a_data[a+1][b].height,a_temp.sort(d),0>a_temp[3]?(temp=Math.floor(192+8*a_temp[3]),temp=~~(temp/10),a_data[a][b].water=1,a_data[a][b].grass=0,a_data[a][b].sand=0,a_data[a][b].mountain=0,a_data[a][b].value=temp):0>a_temp[2]?(a_data[a][b].water=0,a_data[a][b].grass=
0,a_data[a][b].sand=1,a_data[a][b].mountain=0,a_data[a][b].value=1):(14<a_temp[3]/f?(temp=Math.min(Math.floor(8*a_temp[0])+130,255),temp=~~(temp/10),a_data[a][b].water=0,a_data[a][b].grass=0,a_data[a][b].sand=0,a_data[a][b].mountain=1):(verdure=(a_temp[3]-a_temp[0])/f,temp=Math.min(Math.floor(16*verdure+4*a_temp[0]),155),temp=~~(temp/10),a_data[a][b].water=0,a_data[a][b].grass=1,a_data[a][b].sand=0,a_data[a][b].mountain=0),a_data[a][b].value=temp)}
function draw(f){width=600;height=400;fractal_zoom++;298<fractal_zoom&&(fractal_zoom=0);step=Math.round(step);1>step&&(step=1);centreX=~~(width/2);centreY=~~(height/2);scaleX=centreX/23;scaleY=centreY/23;elevationY=scaleY/2;s=Math.sin(angle_land)*fractal_zoom/256;c=Math.cos(angle_land)*fractal_zoom/256;deltaIX=-s*scaleX;deltaIY=c*scaleY;deltaJX=c*scaleX;deltaJY=s*scaleY;stepIX=deltaIX*step;stepIY=deltaIY*step;stepJX=deltaJX*step;stepJY=deltaJY*step;0<c?(startI=-16,stepI=step,endI=16):(startI=16-step,
stepI=-step,endI=-16);0<s?(startJ=-16,stepJ=step):(startJ=16-step,stepJ=-step);var d=[];water=[];sand=[];grass=[];mountain=[];for(var a=0,b=startI;-17<b&&16>b;b+=stepI){var e=0;d[a]=[];for(var g=startJ;-17<g&&16>g;g+=stepJ){d[a][e]=new Coord;d[a][e].x1=deltaIX*b+deltaJX*g+centreX;d[a][e].y1=deltaIY*b+deltaJY*g+centreY;d[a][e].x2=d[a][e].x1+stepJX;d[a][e].y2=d[a][e].y1+stepJY;d[a][e].x3=d[a][e].x2+stepIX;d[a][e].y3=d[a][e].y2+stepIY;d[a][e].x4=d[a][e].x1+stepIX;d[a][e].y4=d[a][e].y1+stepIY;d[a][e].y1-=
Math.max(a_data[b+16][g+16].height,0)*elevationY;d[a][e].y2-=Math.max(a_data[b+16][g+16+step].height,0)*elevationY;d[a][e].y3-=Math.max(a_data[b+16+step][g+16+step].height,0)*elevationY;d[a][e].y4-=Math.max(a_data[b+16+step][g+16].height,0)*elevationY;var h=a_data[b+16+step][g+16];0!=h.water&&(void 0===water[h.value]&&(water[h.value]=[]),water[h.value].push({i:a,j:e}));0!=h.sand&&(void 0===sand[h.value]&&(sand[h.value]=[]),sand[h.value].push({i:a,j:e}));0!=h.grass&&(void 0===grass[h.value]&&(grass[h.value]=
[]),grass[h.value].push({i:a,j:e}));0!=h.mountain&&(void 0===mountain[h.value]&&(mountain[h.value]=[]),mountain[h.value].push({i:a,j:e}));e++}a++}if(1==test_landscape){ctx=f.contex;ctx.beginPath();ctx.lineWidth=1;ctx.strokeStyle="#e65ed4";for(b=0;b<d.length;b++)for(g=0;g<d[b].length;g++)ctx.moveTo(d[b][g].x1,d[b][g].y1),ctx.lineTo(d[b][g].x2,d[b][g].y2);ctx.closePath();ctx.stroke();ctx.beginPath();ctx.lineWidth=1;ctx.strokeStyle="#e6615e";for(b=0;b<d.length;b++)for(g=0;g<d[b].length;g++)ctx.moveTo(d[b][g].x1,
d[b][g].y1),ctx.lineTo(d[b][g].x3,d[b][g].y3);ctx.closePath();ctx.stroke();ctx.beginPath();ctx.lineWidth=1;ctx.strokeStyle="#e68e5e";for(b=0;b<d.length;b++)for(g=0;g<d[b].length;g++)ctx.moveTo(d[b][g].x1,d[b][g].y1),ctx.lineTo(d[b][g].x4,d[b][g].y4);ctx.closePath();ctx.stroke()}else{for(b=0;b<water.length;b++)if(void 0!==water[b]){ctx.beginPath();for(g=0;g<water[b].length;g++)if(a=water[b][g].i,e=water[b][g].j,33>a&&33>e){f=d[a][e].x1;0>f&&(f=0);639<f&&(f=639);h=d[a][e].x2;0>h&&(h=0);639<h&&(h=639);
var k=d[a][e].x3;0>k&&(k=0);639<k&&(k=639);var l=d[a][e].x4;0>l&&(l=0);639<l&&(l=639);var m=d[a][e].y1;0>m&&(m=0);399<m&&(m=399);var n=d[a][e].y2;0>n&&(n=0);399<n&&(n=399);var p=d[a][e].y3;0>p&&(p=0);399<p&&(p=399);a=d[a][e].y4;0>a&&(a=0);399<a&&(a=399);ctx.moveTo(f,m);ctx.lineTo(h,n);ctx.lineTo(k,p);ctx.lineTo(l,a)}ctx.closePath();ctx.fillStyle="rgb(0,0,"+10*b+")";ctx.fill()}for(b=0;b<grass.length;b++)if(void 0!==grass[b]){ctx.beginPath();for(g=0;g<grass[b].length;g++)a=grass[b][g].i,e=grass[b][g].j,
33>a&&33>e&&(f=d[a][e].x1,0>f&&(f=0),639<f&&(f=639),h=d[a][e].x2,0>h&&(h=0),639<h&&(h=639),k=d[a][e].x3,0>k&&(k=0),639<k&&(k=639),l=d[a][e].x4,0>l&&(l=0),639<l&&(l=639),m=d[a][e].y1,0>m&&(m=0),399<m&&(m=399),n=d[a][e].y2,0>n&&(n=0),399<n&&(n=399),p=d[a][e].y3,0>p&&(p=0),399<p&&(p=399),a=d[a][e].y4,0>a&&(a=0),399<a&&(a=399),ctx.moveTo(f,m),ctx.lineTo(h,n),ctx.lineTo(k,p),ctx.lineTo(l,a));ctx.closePath();ctx.fillStyle="rgb("+10*b+","+(10*b+100)+","+10*b+")";ctx.fill()}for(b=0;b<sand.length;b++)if(void 0!==
sand[b]){ctx.beginPath();for(g=0;g<sand[b].length;g++)a=sand[b][g].i,e=sand[b][g].j,33>a&&33>e&&(f=d[a][e].x1,0>f&&(f=0),639<f&&(f=639),h=d[a][e].x2,0>h&&(h=0),639<h&&(h=639),k=d[a][e].x3,0>k&&(k=0),639<k&&(k=639),l=d[a][e].x4,0>l&&(l=0),639<l&&(l=639),m=d[a][e].y1,0>m&&(m=0),399<m&&(m=399),n=d[a][e].y2,0>n&&(n=0),399<n&&(n=399),p=d[a][e].y3,0>p&&(p=0),399<p&&(p=399),a=d[a][e].y4,0>a&&(a=0),399<a&&(a=399),ctx.moveTo(f,m),ctx.lineTo(h,n),ctx.lineTo(k,p),ctx.lineTo(l,a));ctx.closePath();ctx.fillStyle=
"rgb(232,232,84)";ctx.fill()}for(b=0;b<mountain.length;b++)if(void 0!==mountain[b]){ctx.beginPath();for(g=0;g<mountain[b].length;g++)a=mountain[b][g].i,e=mountain[b][g].j,33>a&&33>e&&(f=d[a][e].x1,0>f&&(f=0),639<f&&(f=639),h=d[a][e].x2,0>h&&(h=0),639<h&&(h=639),k=d[a][e].x3,0>k&&(k=0),639<k&&(k=639),l=d[a][e].x4,0>l&&(l=0),639<l&&(l=639),m=d[a][e].y1,0>m&&(m=0),399<m&&(m=399),n=d[a][e].y2,0>n&&(n=0),399<n&&(n=399),p=d[a][e].y3,0>p&&(p=0),399<p&&(p=399),a=d[a][e].y4,0>a&&(a=0),399<a&&(a=399),ctx.moveTo(f,
m),ctx.lineTo(h,n),ctx.lineTo(k,p),ctx.lineTo(l,a));ctx.closePath();ctx.fillStyle="rgb("+10*b+","+10*b+","+10*b+")";ctx.fill()}}angle_land+=0.02}
this.render=function(f){0==this.initdone&&(this.canvaspart=new canvas(600,400),this.init(),this.canvaspart.contex.globalCompositeOperation="lighter");0==this.vbl&&(test_landscape=1,step=1.5,generateLandscape());601==this.vbl&&(test_landscape=0,step=1,generateLandscape());this.canvaspart.clear();0<vbl_land&&300>vbl_land&&draw(this.canvaspart);300<=vbl_land&&301>vbl_land&&(generateLandscape(),vbl_land=0);this.text.render(this.canvaspart,choix_pos[0].x,choix_pos[0].y);this.canvaspart.draw(f,60,88);vbl_land++;
100>this.vbl&&mycanvasblack.draw(f,60,88,1-this.vbl/100);this.vbl>intro_parts[part_running].part_duration-100&&mycanvasblack.draw(f,60,88,1-(intro_parts[part_running].part_duration-this.vbl)/100);this.vbl++};

return this ;
}
//////////////
//END PART7//
////////////
