0% found this document useful (0 votes)
112 views

Code

Uploaded by

api-747581968
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Code

Uploaded by

api-747581968
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

/******************************

*Title: Engineering Project


*Description: Present Drop Catch
*Inputs:
*Output:
*Author: Isabella Talmon
*Revision History:
1/21/24 - Added in code for pixel art
1/23/24 - Added in background lines
1/24/24 - Fixed colors and outlines
1/25/24 - Ran some tests for object drop code
1/26/24 - Implemented drop code
1/27/24 - Gameover screen and movement
1/29/24 - Fixed size for present, fixed hitbox for present, changed velocity for objects dropping
1/31/24 - Added in shapes, pop matrix, rotations, and translate
*Notes:
*******************************/
float objectVelocity = 7;
float objectX = 300;
float objectY = 30;
float playerX = 450;

//if key is pressed/not pressed


boolean leftArrow = false;
boolean rightArrow = false;
boolean spaceBar = false;

boolean dead = true; //gameover and start screen

void setup(){
size(1000,600);
}

void draw(){
if(dead == true){
background(0);
textAlign(CENTER);
fill(255);
textSize(50);
text("Press the space bar to begin!", width/2, height/2);
if(spaceBar){
dead = false;
}
}
if(dead == false){
background(#E575FC);

//Background Lines
int line=-15;
while(line<1000)
{
noStroke();
rect(line,-5,10,650);
line=line+60;
}
//star shape left
pushMatrix();
fill(#C027D8);
translate(width*0.1, height*0.5);
rotate(frameCount / 100.0);
star(0, 0, 30, 70, 5);
popMatrix();
//star shape right
pushMatrix();
translate(width*0.9, height*0.5);
rotate(frameCount / -100.0);
star(0, 0, 30, 70, 5);
popMatrix();

//pentagon left
pushMatrix();
translate(width*0.1, height*0.2);
rotate(frameCount / 100.0);
polygon(0, 0, 50, 5);
popMatrix();
//pentagon right
pushMatrix();
translate(width*0.9, height*0.2);
rotate(frameCount / -100.0);
polygon(0, 0, 50, 5);
popMatrix();

//octagon left
pushMatrix();
translate(width*0.1, height*0.8);
rotate(frameCount / 100.0);
polygon(0, 0, 50, 8);
popMatrix();
//octagon right
pushMatrix();
translate(width*0.9, height*0.8);
rotate(frameCount / -100.0);
polygon(0, 0, 50, 8);
popMatrix();

//coin
fill(#F7E40A);
ellipse(objectX,objectY,50,50);

//box outline
noStroke();
fill(#000000);
rect(playerX, 490, 200/2, 160/2);

//box color
noStroke();
fill(#6D55DE);
rect(playerX+5, 495, 180/2, 140/2);

//lid outline
noStroke();
fill(#000000);
rect(playerX-5, 470, 220/2, 50/2);

//lid color
noStroke();
fill(#6D55DE);
rect (playerX, 475, 200/2, 30/2);
rect(playerX+5,500,180/2,10/2);

//bow outline
noStroke();
fill(#000000);
rect(playerX+10, 455, 10/2,30/2);
rect(playerX+15, 450, 10/2,10/2);
rect(playerX+20, 445, 30/2,10/2);
rect(playerX+35, 450, 10/2,10/2);
rect(playerX+40, 455, 10/2,10/2);
rect(playerX+45, 460, 20/2,10/2);
rect(playerX+40, 465, 10/2,10/2);
rect(playerX+55, 465, 10/2,10/2);
rect(playerX+55, 455, 10/2,10/2);
rect(playerX+60, 450, 10/2,10/2);
rect(playerX+65, 445, 30/2,10/2);
rect(playerX+80, 450, 10/2,10/2);
rect(playerX+85, 455, 10/2,30/2);
rect(playerX+25, 475,30/2,10/2);
rect(playerX+60, 475,30/2,10/2);

//bow color
noStroke();
fill(#D14ACF);
rect(playerX+15,455,10/2,30/2);
rect(playerX+20,450,30/2,40/2);
rect(playerX+35,455,10/2,30/2);
rect(playerX+20,460,10/2,10/2);
rect(playerX+45,465,20/2,10/2);
rect(playerX+40,460,10/2,10/2);
rect(playerX+55,460,10/2,10/2);
rect(playerX+60,455,10/2,30/2);
rect(playerX+65,450,30/2,40/2);
rect(playerX+80,455,10/2,30/2);
rect(playerX+25,470,30/2,10/2);
rect(playerX+60,470,30/2,10/2);

//ribbon outline
noStroke();
fill(#000000);
rect(playerX+40,470,5,100);
rect(playerX+55,470,5,100);
rect(playerX+45,470,10,5);

//ribbon color
noStroke();
fill(#D14ACF);
rect(playerX+45,475,10,90);

PlayerPosition();
moveObject();
if(gameOver()){ //when game ends
resetObject();
dead = true;
}
if(objectIsTouchingPlayer()){
resetObject();
}
}
}

//movement
void PlayerPosition(){
if(leftArrow){
playerX -= 6; //move left
}
if(rightArrow){
playerX += 6; //move right
}
}

void resetObject(){
objectY = 30;
objectX = random(100,700);
}

//moves object down


void moveObject(){
objectY += objectVelocity;
}

boolean gameOver(){
if(objectY >= height){
return true;
}
return false;
}
//hitbox
boolean objectIsTouchingPlayer(){
if(objectX >= playerX && objectX <= playerX+80 && objectY >= 540 && objectY <= 590){
return true;
}
return false;
}

//starts movement when keys are pressed


void keyPressed(){
if(keyCode == LEFT){
leftArrow = true;
}
if(keyCode == RIGHT){
rightArrow = true;
}
if(key == ' '){
spaceBar = true;
}
}

//stops movement when keys are released


void keyReleased(){
if(keyCode == LEFT){
leftArrow = false;
}
if(keyCode == RIGHT){
rightArrow = false;
}
if(key == ' '){
spaceBar = false;
}
}
void star(float x, float y, float radius1, float radius2, int npoints) {
float angle = TWO_PI / npoints;
float halfAngle = angle/2.0;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius2;
float sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a+halfAngle) * radius1;
sy = y + sin(a+halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
void polygon(float x, float y, float radius, int npoints) {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}

You might also like