Setting borders for paddle & switching between screens (layers of screens)
in
Programming Questions
•
1 year ago
I have 2 main bugs here mainly and the first one is:
1) When I move my paddle to the right side, it is supposed to have a limit and touch the border and stop there but when I past the border, I can see that it keeps jumping back. How do I solve this?
2) I have 3 screens and I want it that if I lose on Screen 2 (The actual game) I will move to Screen 3 (Game Over). Then I click "Menu" and can return to Screen 1 (main menu) and start the game again. Can someone help me with this. The screens seem to just be jumping around.
The Code:
- int ballx = 50;
- int bally = 50;
- int motionx = 6;
- int motiony = 5;
- int screendisplay = 1;
- PFont font;
- float ballx2 = random(50,900);
- int ballx1 = int(ballx2);
- float bally2 = random (300,400);
- int bally1 = int(bally2);
- void setup() {
- size(1000, 600);
- }
- void draw() {
- if (screendisplay == 1) {
- background (#AFE5EA);
- fill(255);
- rect(350, 300, 300, 100);
- font = loadFont ("SegoeUI-Light-48.vlw");
- textFont(font, 42);
- fill(0);
- text("Start", 450, 365);
- if (mouseX>350 && mouseX<650 && mouseY > 300 && mouseY < 400 && mousePressed == true && screendisplay == 1) {
- screendisplay = 2;
- }
- }
- if (screendisplay == 2) {
- background (#AFE5EA);
- fill(255);
- strokeWeight(6);
- ellipse(ballx, bally, 50, 50);
- ballx = ballx + motionx;
- bally = bally + motiony;
- if (ballx>970 || ballx<30) {
- motionx = motionx * -1;
- }
- if (bally <30) {
- motiony = motiony*-1;
- }
- rect(mouseX, 500, 150, 30);
- if (500-bally<40 && ballx >mouseX && ballx < mouseX+150) {
- motiony = motiony*-1;
- }
- if(mouseX + 150 > 1000){
- mouseX = 850;
- }
- if(mouseX < 2){
- mouseX = 3;
- }
- if (bally>570) {
- screendisplay = 3;
- bally = 500 - bally1;
- }
- }
- if (screendisplay == 3) {
- background(0);
- font = loadFont ("SegoeUI-Light-48.vlw");
- textFont(font, 42);
- fill(255);
- text("Menu", 450, 365);
- if (mouseX>400 && mouseX< 600 && mouseY > 340 && mouseY < 470 && mousePressed == true) {
- screendisplay = 2;
- }
- }
- }
1