xxxxxxxxxx
void setup()
{
size(500, 500, P3D);
background(50, 120, 230);
xPos = width / 2; yPos = height;
}
float xPos, yPos, zPos;
void draw()
{
noStroke();
lights();
pushMatrix();
translate(xPos + random(5), yPos + random(5), zPos + random(5));
fill(60, 40, 20);
box(15);
popMatrix();
if (keyPressed)
{
if (key == 'a')
{
xPos -= 5;
}
if (key == 's')
{
yPos += 5;
}
if (key == 'w')
{
yPos -= 5;
}
if (key == 'd')
{
xPos += 5;
}
if (key == 'q')
{
zPos += 5;
}
if (key == 'e')
{
zPos -= 5;
}
if (key == ' ')
{
pushMatrix();
translate(xPos + random(-20, 20), yPos + random(-20, 20), zPos + random(-20, 20));
fill(70, 120, 40);
sphere(15);
popMatrix();
}
}
}