I am a noob in programming, so I am making a game in p5.js to learn, however, there is an issue…
let camX;
let camY;
let camZ;
let seed;
let objects = [];
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
camx = 0;
camy = 80;
camz = 0;
seed = 450
for(let i = 0; i < 606; i++)
{
randomSeed(seed);
objects.push([random(-400, 400), random(-400, 400), random(0, 2)]);
}
}
function moveCam()
{
if(keyIsPressed)
{
if(key == "a")
{
camx += 2;
}
if(key == "d")
{
camx -= 2;
}
if(key == "w")
{
camz -= 2;
}
if(key == "s")
{
camz += 2;
}
}
}
function drawObjects()
{
for(let i = 0; i < 606; i++)
{
if(objects[i][2] == 0)
{
translate(objects[i][0], -20, objects[i][1]);
box(20);
}
if(objects[i][2] == 1)
{
translate(objects[i][0], -40, objects[i][1]);
box(40);
}
if(objects[i][2] == 2)
{
translate(objects[i][0], -10, objects[i][1]);
sphere(40);
}
}
}
function draw() {
background(220);
push();
translate(camx, camy, camz);
box(8000, 20, 8000);
drawObjects();
pop();
}
when I run this code, it displays a white plane, however, none of the randomly generated objects seem to show up…
I have checked and there are elements in the array, so I am completely lost.
Please help me lol