// Cloned by Yiming Fu on 1 Dec 2022 from World "Red vs Blue" by Octavian
// Please leave this clone trail here.
AB.clockTick = 100;
// Speed of run: Step every n milliseconds. Default 100.
AB.maxSteps = 100000;
// Length of run: Maximum length of run in steps. Default 1000.
AB.screenshotStep = 100;
// Take screenshot on this step. (All resources should have finished loading.) Default 50.
const OBJ_MONSTER = 'uploads/octa1936/knight.obj';
const OBJ_HUMAN = 'uploads/octa1936/Human.obj';
const HUMAN_SCALE = 70;
const MONSTER_SCALE = 70;
const MONSTER_TEXTURE = "uploads/octa1936/Red_Color.jpg";
const FILE_ARRAY = [
"/uploads/octa1936/Blue_Color.jpg",
"/uploads/octa1936/Red_Color.jpg"
];
const SKYCOLOR = 0xccffcc;
const ARMYSIZE = 100;
const objectsize = 500 ;
const MAXPOS = 4000 ;
const startRadiusConst = MAXPOS * 1.5 ;
const maxRadiusConst = MAXPOS * 5 ;
ABHandler.MAXCAMERAPOS = MAXPOS * 10 ;
ABWorld.drawCameraControls = false;
AB.drawRunControls = false;
var THEARMY1 = new Array( ARMYSIZE );
var THEARMY2 = new Array( ARMYSIZE );
var textureArray = new Array ( FILE_ARRAY.length );
var humanswin = false;
var monsterswin = false;
function loadResources()
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
startFileLoad ( i );
}
function startFileLoad ( n )
{
var loader = new THREE.TextureLoader();
loader.load ( FILE_ARRAY[n], function ( thetexture )
{
thetexture.minFilter = THREE.LinearFilter;
textureArray[n] = thetexture;
if ( asynchFinished() ) initArmy1(); initArmy2();
});
}
function asynchFinished()
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
if ( ! textureArray[i] )
return false;
return true;
}
function initArmy1()
{
var t = 0;
var r = 0;
for ( var c=1 ; c <= ARMYSIZE / 10 ; c++ )
{
var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
var theobject = new THREE.Mesh( shape );
var posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -2;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -3;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -4;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -5;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -6;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -7;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -8;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -9;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -10;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * -11;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY1[t] = theobject;
t++;
}
}
function initArmy2()
{
var t = 0;
var r = 1;
for ( var c=1 ; c <= ARMYSIZE / 10 ; c++ )
{
var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
var theobject = new THREE.Mesh( shape );
var posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 2;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 3;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 4;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 5;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 6;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 7;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 8;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 9;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 10;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
for (c=1 ; c <= ARMYSIZE / 10; c++ )
{
shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
theobject = new THREE.Mesh( shape );
posx = ((objectsize * 5) - (c * objectsize));
theobject.position.x = posx;
theobject.position.z = objectsize * 11;
theobject.position.y = 0;
if (c > 10) theobject.position.z -= objectsize;
theobject.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
THEARMY2[t] = theobject;
t++;
}
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
AB.msg ( ` <hr> <p> Multi-user game. Pick a side. Click on the buttons to summon units for the sides. First one to reach 100 wins! <p>
<button onclick='baby();' class=ab-largenormbutton > Humans </button>
<button onclick='skull();' class=ab-largenormbutton > Monsters </button> <p> ` );
}
AB.world.newRun = function()
{
AB.loadingScreen();
AB.runReady = false;
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
loadResources();
};
AB.world.nextStep = function()
{
};
AB.world.endRun = function()
{
if(AB.abortRun && humanswin) AB.msg ("<br><font color=blue> <B> GAME OVER: HUMANS WIN! </B></font>", 2);
else if(AB.abortRun && monsterswin) AB.msg ("<br><font color=red> <B> GAME OVER: MONSTERS WIN! </B></font>", 2);
};
AB.socketStart();
function baby() { changeBaby(); AB.socketOut (); }
function skull() { changeSkull(); AB.socketOut (); }
var h = 0;
function changeBaby() // change a random box to texture n (5 or 6)
{
ABWorld.scene.add(THEARMY1[h]);
h ++;
if (h > THEARMY1.length)
{
humanswin = true;
AB.abortRun = true;
}
}
var m = 0;
function changeSkull() // change a random box to texture n (5 or 6)
{
ABWorld.scene.add(THEARMY2[m]);
m ++;
if (m > THEARMY2.length)
{
monsterswin = true;
AB.abortRun = true;
}
}
AB.socketIn = function() // incoming data on socket, i.e. clicks of other player
{
if ( ! AB.runReady ) return;
changeBaby();
};
AB.socketIn = function()
{
if (! AB.runReady ) return;
changeSkull();
};