i have a project in Processing. i am trying to create basic platform game but i could not do it. Can someone help? In this code, I am trying to create a player and this player should go left and right and can jump with space. The blocks I call “stages” should move up and down along the y-axis. The player object I created should also jump on these blocks. If the player touches Lava, the game should stop and “You Failed” should be displayed on the screen. If he successfully passes all 5 blocks and touches the last platform, “Congratulations, You Win!!” should write. Thank you for your help in advance.
PImage imgLava,imgGrass, imgStone, imgP1;
boolean isJumping = false;
void setup()
{
fullScreen(P3D);
camZ = (height/2) / tan((PI*60.0)/360.0);
noStroke();
textureMode(NORMAL);
imgLava = loadImage("lava.jpeg");
imgGrass = loadImage("grass.jpg");
imgStone= loadImage("stone.png");
imgP1= loadImage("p1.png");
}
float camZ = 0;
void draw()
{
background(0);
/*camera(width/2, height/2, camZ, //camx, camy, camz
width/2, height/2, 0, //lookx, looky, lookz
0, 1, 0 //eyex, eyey, eyez
);*/
camera(0, 0, camZ,
0, 0, 0,
0, 1, 0);
rotateX(rotX + distY);
rotateY(rotY + distX);
scale(20);
drawLava();
drawPlatform();
drawStage();
drawEndPlatform();
drawPlayer();
if(keyPressed)
{
if(keyCode == UP)
camZ -= 5;
if(keyCode == DOWN)
camZ += 5;
}
}
void drawLava()
{
int w = 1;
int h = 1;
beginShape(QUAD);
texture(imgLava);
vertex(-5, 1.0000, -54, 0, 0);
vertex(5, 1.0000, -54, w, 0);
vertex(5, 1.0000, 0, w, h);
vertex(-5, 1.0000, 0, 0, h);
endShape();
}
void drawPlatform()
{
int w = 1;
int h = 1;
beginShape(QUAD);
texture(imgGrass);
vertex(-2, 0.999, 0, 0, 0);
vertex(2, 0.999, 0, w, 0);
vertex(2, 0.999, -5, w, h);
vertex(-2, 0.999, -5, 0, h);
endShape();
}
int w=1,h=1;
void drawStage()
{
beginShape(QUADS);
texture(imgStone);
//+Z face
vertex(-1, -1, -10, 0, 0); //upper left corner
vertex(1, -1, -10, w, 0); //upper right corner
vertex(1, 1, -10, w, h); //bottom right corner
vertex(-1, 1, -10, 0, h); //bottom left corner
//-Z face
vertex(-1, -1, -15, 0, 0); //upper left corner
vertex(1, -1, -15, w, 0); //upper right corner
vertex(1, 1, -15, w, h); //bottom right corner
vertex(-1, 1, -15, 0, h); //bottom left corner
//+X face
vertex(1, -1, -10, 0, 0); //upper left corner
vertex(1, -1, -15, w, 0);
vertex(1, 1, -15, w, h);
vertex(1, 1, -10, 0, h);
//-X face
vertex(-1, -1, -10, 0, 0); //upper left corner
vertex(-1, -1, -15, w, 0);
vertex(-1, 1, -15, w, h);
vertex(-1, 1, -10, 0, h);
//-Y face
vertex(-1, -1, -10, 0, 0);
vertex(1, -1, -10, w, 0);
vertex(1, -1, -15, w, h);
vertex(-1, -1, -15, 0, h);
//+Y face
vertex(-1, 1, -10, 0, 0);
vertex(1, 1, -10, w, 0);
vertex(1, 1, -15, w, h);
vertex(-1, 1, -15, 0, h);
endShape();
beginShape(QUADS);
texture(imgStone);
//+Z face
vertex(-1, -1, -20, 0, 0); //upper left corner
vertex(1, -1, -20 ,w, 0); //upper right corner
vertex(1, 1, -20, w, h); //bottom right corner
vertex(-1, 1, -20, 0, h); //bottom left corner
//-Z face
vertex(-1, -1, -25, 0, 0); //upper left corner
vertex(1, -1, -25, w, 0); //upper right corner
vertex(1, 1, -25, w, h); //bottom right corner
vertex(-1, 1, -25, 0, h); //bottom left corner
//+X face
vertex(1, -1, -20, 0, 0); //upper left corner
vertex(1, -1, -25, w, 0);
vertex(1, 1, -25, w, h);
vertex(1, 1, -20, 0, h);
//-X face
vertex(-1, -1, -20, 0, 0); //upper left corner
vertex(-1, -1, -25, w, 0);
vertex(-1, 1, -25, w, h);
vertex(-1, 1, -20, 0, h);
//-Y face
vertex(-1, -1, -20, 0, 0);
vertex(1, -1, -20, w, 0);
vertex(1, -1, -25, w, h);
vertex(-1, -1, -25, 0, h);
//+Y face
vertex(-1, 1, -20, 0, 0);
vertex(1, 1, -20, w, 0);
vertex(1, 1, -25, w, h);
vertex(-1, 1, -25, 0, h);
endShape();
beginShape(QUADS);
texture(imgStone);
//+Z face
vertex(-1, -1, -30, 0, 0); //upper left corner
vertex(1, -1, -30 ,w, 0); //upper right corner
vertex(1, 1, -30, w, h); //bottom right corner
vertex(-1, 1, -30, 0, h); //bottom left corner
//-Z face
vertex(-1, -1, -35, 0, 0); //upper left corner
vertex(1, -1, -35, w, 0); //upper right corner
vertex(1, 1, -35, w, h); //bottom right corner
vertex(-1, 1, -35, 0, h); //bottom left corner
//+X face
vertex(1, -1, -30, 0, 0); //upper left corner
vertex(1, -1, -35, w, 0);
vertex(1, 1, -35, w, h);
vertex(1, 1, -30, 0, h);
//-X face
vertex(-1, -1, -30, 0, 0); //upper left corner
vertex(-1, -1, -35, w, 0);
vertex(-1, 1, -35, w, h);
vertex(-1, 1, -30, 0, h);
//-Y face
vertex(-1, -1, -30, 0, 0);
vertex(1, -1, -30, w, 0);
vertex(1, -1, -35, w, h);
vertex(-1, -1, -35, 0, h);
//+Y face
vertex(-1, 1, -30, 0, 0);
vertex(1, 1, -30, w, 0);
vertex(1, 1, -35, w, h);
vertex(-1, 1, -35, 0, h);
endShape();
beginShape(QUADS);
texture(imgStone);
//+Z face
vertex(-1, -1, -40, 0, 0); //upper left corner
vertex(1, -1, -40 ,w, 0); //upper right corner
vertex(1, 1, -40, w, h); //bottom right corner
vertex(-1, 1, -40, 0, h); //bottom left corner
//-Z face
vertex(-1, -1, -45, 0, 0); //upper left corner
vertex(1, -1, -45, w, 0); //upper right corner
vertex(1, 1, -45, w, h); //bottom right corner
vertex(-1, 1, -45, 0, h); //bottom left corner
//+X face
vertex(1, -1, -40, 0, 0); //upper left corner
vertex(1, -1, -45, w, 0);
vertex(1, 1, -45, w, h);
vertex(1, 1, -40, 0, h);
//-X face
vertex(-1, -1, -40, 0, 0); //upper left corner
vertex(-1, -1, -45, w, 0);
vertex(-1, 1, -45, w, h);
vertex(-1, 1, -40, 0, h);
//-Y face
vertex(-1, -1, -40, 0, 0);
vertex(1, -1, -40, w, 0);
vertex(1, -1, -45, w, h);
vertex(-1, -1, -45, 0, h);
//+Y face
vertex(-1, 1, -40, 0, 0);
vertex(1, 1, -40, w, 0);
vertex(1, 1, -45, w, h);
vertex(-1, 1, -45, 0, h);
endShape();
}
void drawEndPlatform()
{
int w = 1;
int h = 1;
beginShape(QUAD);
texture(imgGrass);
vertex(-2, 0.999, -49, 0, 0);
vertex(2, 0.999, -49, w, 0);
vertex(2, 0.999, -54, w, h);
vertex(-2, 0.999, -54, 0, h);
endShape();
}
void drawPlayer()
{
beginShape(QUADS);
texture(imgP1);
//+Z face
vertex(-0.25, 0.75, -1, 0, 0); //upper left corner
vertex(0.25, 0.75, -1, w, 0); //upper right corner
vertex(0.25, 0.998, -1, w, h); //bottom right corner
vertex(-0.25, 0.998, -1, 0, h); //bottom left corner
//-Z face
vertex(-0.25, 0.75, -1.5, 0, 0); //upper left corner
vertex(0.25, 0.75, -1.5, w, 0); //upper right corner
vertex(0.25, 0.998, -1.5, w, h); //bottom right corner
vertex(-0.25, 0.998, -1.5, 0, h); //bottom left corner
//+X face
vertex(0.25, 0.75, -1.0, 0, 0); //upper left corner
vertex(0.25, 0.75, -1.5, w, 0);
vertex(0.25, 0.998, -1.5, w, h);
vertex(0.25, 0.998, -1.0, 0, h);
//-X face
vertex(-0.25, 0.75, -1.0, 0, 0); //upper left corner
vertex(-0.25, 0.75, -1.5, w, 0);
vertex(-0.25, 0.998, -1.5, w, h);
vertex(-0.25, 0.998, -1.0, 0, h);
//-Y face
vertex(-0.25, 0.75, -1.0, 0, 0);
vertex(0.25, 0.75, -1.0, w, 0);
vertex(0.25, 0.75, -1.5, w, h);
vertex(-0.25, 0.75, -1.5, 0, h);
//+Y face
vertex(-0.25, 0.998, -1.0, 0, 0);
vertex(0.25, 0.998, -1.0, w, 0);
vertex(0.25, 0.998, -1.5, w, h);
vertex(-0.25, 0.998, -1.5, 0, h);
endShape();
}
float rotX = 0, rotY = 0;
float lastX, lastY;
float distX, distY;
void mousePressed()
{
lastX = mouseX;
lastY = mouseY;
}
void mouseDragged()
{
distX = radians(mouseX - lastX);
distY = radians(lastY - mouseY);
}
void mouseReleased()
{
rotX += distY;
rotY += distX;
distX = distY = 0;
}
>