Programming game, need help to be able to win/ lose the game.
in
Programming Questions
•
10 months ago
We are programming a basic "game" for our final in Cmps 10. The Object of the game is to hit the blue " Mother Ship" which is progressively moving to the left of the screen, with the single cannon shot you are given and allowed to move only left and right after shooting. The game is Won if you hit the Blue MotherShip before it leaves the screen and is lost if the cannon shot fails to hit the mother ship or if the cannon shot hits one of the several SubShips that are protecting the MotherShip ( The SubShips will be put into motion later to protect the MotherShip)
Some Help on a few things would be greatly appreciated:
1) How to Set up hit-detection to allow the players to win the game
Some Help on a few things would be greatly appreciated:
1) How to Set up hit-detection to allow the players to win the game
2) How to set up the lose function if the player fails to hit the MotherShip or hits a SubShip.
3) How to inform the player that they have lost or won the game
Help with any or all of the above requested ^ would be greatly appreciated
Here is the code of what we have so far, We thank you once again
Help with any or all of the above requested ^ would be greatly appreciated
Here is the code of what we have so far, We thank you once again
- int y; // The rising cannon integer
int rise; // Same^
// some things that the computer needs to remember
int x = 150; // the position of the critter
int dir = 1; // which way is it moving +1 = right, -1 = left
int z; // The Mother Ship's movement integer
int climb; // Same ^^
void setup() {
y=1;
rise=2;
climb= 2;
size(1000, 1000);
}
void draw() {
if (mousePressed){
background(150);
frameRate(1000);
// Blue MotherShip
fill(0,0,255); // Blue
noStroke();
rect( 750 - z, 60, 10, 10); // 1st line
rect( 760 - z, 50, 10, 20); // 2nd line
rect( 770 - z, 43, 10, 45); // 3rd line
rect( 780 - z, 34, 10, 64); // 4th line
rect( 790-z, 34, 10, 54);//5th line
rect( 800 - z, 20 , 10, 60); // 6th line
rect( 810 - z, 20 , 10, 60); // 7th line
rect( 820 - z, 20 , 10, 68); // 8th line
rect( 830 - z, 20 , 10, 68); // 9th line
rect(840 - z, 20, 10, 60);//10th line
rect(850-z, 20, 10, 60); //11th line
rect( 860 - z, 34, 10, 55); // 12th line
rect(870 -z, 34, 10, 65);//13th line
rect( 880 - z, 43, 10, 45); // 14th line
rect( 890 - z, 50, 10, 20); // 15th line
rect( 900 - z, 60, 10, 10); // 16th line
// Red SubShip
fill(255,0,0);
noStroke();
rect(740-0, 160, 10, 10); // 1st line
rect( 750 - 0, 150, 10, 20); // 1st line
rect( 760 - 0, 160, 10, 10); // 2nd line
rect( 770 - 0, 160, 10, 20); // 3rd line
rect( 780 - 0, 160, 10, 20); // 4th line
rect( 790-0, 160, 10, 10);//5th line
rect( 800 - 0, 150 , 10, 20); // 6th line
rect( 810 - 0, 160 , 10, 10); // 7th line
// Yellow-> Green Subship
fill(0,255,0);
rect(200-0, 160, 10, 10); // 1st line
rect( 210 - 0, 150, 10, 20); // 1st line
rect( 220 - 0, 160, 10, 10); // 2nd line
rect( 230 - 0, 160, 10, 20); // 3rd line
rect( 240 - 0, 160, 10, 20); // 4th line
rect( 250-0, 160, 10, 10);//5th line
rect( 260 - 0, 150 , 10, 20); // 6th line
rect( 270 - 0, 160 , 10, 10); // 7th line
// Camoflauged SubShip
fill (0);
rect(460, 300, 10, 10); // 1st line
rect( 470 - 0, 290, 10, 20); // 1st line
rect( 480 - 0, 300, 10, 10); // 2nd line
rect( 490 - 0, 300, 10, 20); // 3rd line
rect( 500 - 0, 300, 10, 20); // 4th line
rect( 510-0, 300, 10, 10);//5th line
rect( 520 - 0, 290 , 10, 20); // 6th line
rect( 530 - 0, 300 , 10, 10); // 7th line
// Purple SubShip
fill(237, 171, 29);
rect(50, 300, 10, 10); // 1st line
rect( 60 - 0, 290, 10, 20); // 1st line
rect( 70 - 0, 300, 10, 10); // 2nd line
rect( 80 - 0, 300, 10, 20); // 3rd line
rect( 90 - 0, 300, 10, 20); // 4th line
rect( 100-0, 300, 10, 10);//5th line
rect( 110 - 0, 290 , 10, 20); // 6th line
rect( 120 - 0, 300 , 10, 10); // 7th line
// Light Blue SubShip
fill(103, 224, 232);
rect(880, 300, 10, 10); // 1st line
rect( 890 - 0, 290, 10, 20); // 1st line
rect( 900 - 0, 300, 10, 10); // 2nd line
rect( 910 - 0, 300, 10, 20); // 3rd line
rect( 920 - 0, 300, 10, 20); // 4th line
rect( 930-0, 300, 10, 10);//5th line
rect( 940 - 0, 290 , 10, 20); // 6th line
rect( 950 - 0, 300 , 10, 10); // 7th line
if ( climb >1)// RULE FOR MOTHERSHIP
z= z+1;
if( rise >1)// RULE FOR CANNON
y= y+1;
// Hero Ship
fill(255,0,0); // Red
ellipse(x, 600, 60, 30);
fill(0);
ellipse(x, 550-y, 15,15);
}
else {
background (150);
frameRate(1000);
// Blue MotherShip
fill(0,0,255);
noStroke();
rect( 750 - 0, 60, 10, 10); // 1st line
rect( 760 - 0, 50, 10, 20); // 2nd line
rect( 770 - 0, 43, 10, 45); // 3rd line
rect( 780 - 0, 34, 10, 64); // 4th line
rect( 790-0, 34, 10, 54);//5th line
rect( 800 - 0, 20 , 10, 60); // 6th line
rect( 810 - 0, 20 , 10, 60); // 7th line
rect( 820 - 0, 20 , 10, 68); // 8th line
rect( 830 - 0, 20 , 10, 68); // 9th line
rect(840 - 0, 20, 10, 60);//10th line
rect(850-0, 20, 10, 60); //11th line
rect( 860 - 0, 34, 10, 55); // 12th line
rect(870 -0, 34, 10, 65);//13th line
rect( 880 - 0, 43, 10, 45); // 14th line
rect( 890 - 0, 50, 10, 20); // 15th line
rect( 900 - 0, 60, 10, 10); // 16th line
// Red SubShip
noStroke();
rect(740-0, 160, 10, 10); // 1st line
rect( 750 - 0, 150, 10, 20); // 1st line
rect( 760 - 0, 160, 10, 10); // 2nd line
rect( 770 - 0, 160, 10, 20); // 3rd line
rect( 780 - 0, 160, 10, 20); // 4th line
rect( 790-0, 160, 10, 10);//5th line
rect( 800 - 0, 150 , 10, 20); // 6th line
rect( 810 - 0, 160 , 10, 10); // 7th line
// Yellow Subship
noStroke();
fill(224,218,11);
rect(200-0, 160, 10, 10); // 1st line
rect( 210 - 0, 150, 10, 20); // 1st line
rect( 220 - 0, 160, 10, 10); // 2nd line
rect( 230 - 0, 160, 10, 20); // 3rd line
rect( 240 - 0, 160, 10, 20); // 4th line
rect( 250-0, 160, 10, 10);//5th line
rect( 260 - 0, 150 , 10, 20); // 6th line
rect( 270 - 0, 160 , 10, 10); // 7th line
// Purple SubShip
fill(123, 41, 142);
rect(50, 300, 10, 10); // 1st line
rect( 60 - 0, 290, 10, 20); // 1st line
rect( 70 - 0, 300, 10, 10); // 2nd line
rect( 80 - 0, 300, 10, 20); // 3rd line
rect( 90 - 0, 300, 10, 20); // 4th line
rect( 100-0, 300, 10, 10);//5th line
rect( 110 - 0, 290 , 10, 20); // 6th line
rect( 120 - 0, 300 , 10, 10); // 7th line
// Light Blue SubShip
fill(103, 224, 232);
rect(880, 300, 10, 10); // 1st line
rect( 890 - 0, 290, 10, 20); // 1st line
rect( 900 - 0, 300, 10, 10); // 2nd line
rect( 910 - 0, 300, 10, 20); // 3rd line
rect( 920 - 0, 300, 10, 20); // 4th line
rect( 930-0, 300, 10, 10);//5th line
rect( 940 - 0, 290 , 10, 20); // 6th line
rect( 950 - 0, 300 , 10, 10); // 7th line
// Start Line
fill( 237, 29, 199);
rect( 475, 545, 50, 10);
// Hero Ship
fill(0); //
fill(255,0,0);
ellipse(x, 600, 60, 30);
fill(0);
ellipse(x, 550, 15,15);
}
// adjust the position and direction
x = x + dir;
if (x < mouseX) {
dir = 1;
}
else if (x > mouseX) {
dir = -1;
}
else {
dir = 0;
}
}
1