Mitt MazeMaker objekt.

Hej!
 
Nu har jag knåpat ihop koden för att visa en liten demo över labyrinten på film, enklast möjligt för att visa hur koden ter sig i verklighet.
 
För varje ny sektion spelaren kommer in i så tänds den sektionen upp och föregående släcks, som man kan se i filmen.
 
Här är filmen..
 
 
 
Här är den nya koden för MazeMaker objektet i Java..
 
public class MazeMaker
{
public static final int cSCALE = 150;
private MazeSection mMazeMapStart = null;

// Create the DEMO maze in the constructor.
public MazeMaker (float mazeStartPosX, float mazeStartPosY, float mazeStartPosZ)
{
// First create a demo maze.
// Start position in maze, the first section..
this.mMazeMapStart = new MazeSection();
this.mMazeMapStart.setPosX(mazeStartPosX);
this.mMazeMapStart.setPosY(mazeStartPosY);
this.mMazeMapStart.setPosZ(mazeStartPosZ);
this.mMazeMapStart.setScale(cSCALE * 2f);
this.mMazeMapStart.setType(0); // Forward.

// Set this first section as the parent.
MazeSection parent = this.mMazeMapStart;

// Create a corridor forward, 9 extra blocks..
for (int i=1;i<10;i++)
{
// Create a section..
// In front of the previous one.
MazeSection forward = new MazeSection();
forward.setPosX(mazeStartPosX);
forward.setPosY(mazeStartPosY);
forward.setPosZ(mazeStartPosZ + (cSCALE * 2 * i)); // Forward * a section size.
forward.setScale(cSCALE * 2f);
forward.setType(0); // Forward type.

// Set new section as forward for parent.
parent.setForwardSection(forward);

// Set the previous section
// as the backward section for the new one.
forward.setBackwardSection(parent);

// And the new forward section
// as the new parent before continue.
parent = forward; // parent.getForwardSection ();
}

// Now add a downturn section,
// before we start a downward corridor.
MazeSection dowTurn = new MazeSection();
dowTurn.setPosX(mazeStartPosX);
dowTurn.setPosY(mazeStartPosY);
dowTurn.setPosZ(mazeStartPosZ + (cSCALE * 2 * 10));
dowTurn.setScale(cSCALE * 2f);
dowTurn.setType(1); // Downturn from forward type.
dowTurn.setBackwardSection(parent); // Set the previous as backward section.
parent.setForwardSection(dowTurn);
parent = dowTurn; // This new section as parent.

// Create a downward corridor
// made of 9 sections..
for (int i=1;i<10;i++)
{
MazeSection down = new MazeSection();
down.setPosX(mazeStartPosX);
down.setPosY(mazeStartPosY - (cSCALE * 2 * i));
down.setPosZ(mazeStartPosZ + (cSCALE * 2 * 10));
down.setScale(cSCALE * 2f);
down.setType(2); // Down section, from forward downturn type.
down.setUpSection(parent); // Same again, make previous up.
parent.setDownSection(down);
parent = down; // New section as parent, before loop.
}
}
public MazeSection getStartSection ()
{
return this.mMazeMapStart;
}
public MazeSection getCurrentMazeSection
(MazeSection currentSection, Camera cam, float speed)
{
// The default test for everything/blocks..
if (cam.getPosition().x < currentSection.getPosX() + cSCALE &&
cam.getPosition().x > currentSection.getPosX() - cSCALE &&
cam.getPosition().y < currentSection.getPosY() + cSCALE &&
cam.getPosition().y > currentSection.getPosY() - cSCALE &&
cam.getPosition().z < currentSection.getPosZ() + cSCALE &&
cam.getPosition().z > currentSection.getPosZ() - cSCALE)
{
cam.moveCamera(Camera.CAMERA_MOVEIN, speed);
return currentSection;
}
// Test for entering new forward block..
else if (currentSection.getType() == 0 &&
currentSection.getForwardSection() != null &&
cam.getPosition().z >= currentSection.getPosZ() + cSCALE)
{
return currentSection.getForwardSection();
}
// Test for entering new backward block..
else if (currentSection.getType() == 0 &&
currentSection.getBackwardSection() != null &&
cam.getPosition().z <= currentSection.getPosZ() - cSCALE)
{
return currentSection.getBackwardSection();
}
// Test for entering new downward block..
else if (currentSection.getType() == 1 &&
currentSection.getDownSection() != null &&
cam.getPosition().y <= currentSection.getPosY() - cSCALE)
{
return currentSection.getDownSection();
}
// Test for entering new backward block.. (from forward to downturn)
else if (currentSection.getType() == 1 &&
currentSection.getBackwardSection() != null &&
cam.getPosition().z <= currentSection.getPosZ() - cSCALE)
{
return currentSection.getBackwardSection();
}
// Test for entering new downward block..
else if (currentSection.getType() == 2 &&
currentSection.getDownSection() != null &&
cam.getPosition().y <= currentSection.getPosY() - cSCALE)
{
return currentSection.getDownSection();
}
// Test for entering new upward block..
else if (currentSection.getType() == 2 &&
currentSection.getUpSection() != null &&
cam.getPosition().y >= currentSection.getPosY() + cSCALE)
{
return currentSection.getUpSection();
}
// We hit a wall..
else
{
cam.setPosition(currentSection.getPosX(),
currentSection.getPosY(),
currentSection.getPosZ());

return currentSection;
}
}
}

I botten av den nya koden har jag lagt till en begriplig IF-sats-smörja som jag kommer att förbättra sedan, här är den utformad för tydlighetens skull.
Den här delen bestämmer när det ska komma en ny sektion eller när spelaren träffar väggarna.
 
Ha det bra..

Kommentarer

Populära inlägg i den här bloggen

Lite ljud.

Monsterattack.

Skuggor.