Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float spieler_x = 20; //balken startpos y
- float spieler_y = 60; //balken startpos y
- float ball_x = 450; //position (x) kugel
- float ball_y = 350; //position (y) kugel
- float ball_speed_x = -3; //erhöhende ball geschwindigkeit
- float ball_speed_y = 0; //erhöhende ball geschwindigkeit
- float player_speed_y = 12; //max balken geschwindigkeit
- int runde; //runden counter
- int up = 'w';// standard = UP
- boolean upstate;
- int down = 's';// standard = DOWN
- boolean downstate;
- boolean autoplay = true;
- void setup () {
- size(900, 700);
- rectMode(CENTER);
- }
- void draw() {
- background(0);
- rect(spieler_x, spieler_y, 20, 100);
- ellipse(ball_x, ball_y, 10, 10);
- ball_x = ball_x + ball_speed_x;
- ball_y = ball_y + ball_speed_y;
- if (autoplay) spieler_y = ball_y;
- if (upstate && spieler_y > 50) spieler_y = spieler_y - player_speed_y;
- if (downstate && spieler_y < 650) spieler_y = spieler_y + player_speed_y;
- if (ball_x < 30) {
- if (ball_y < (spieler_y + 55) && ball_y > (spieler_y - 55)) {
- ball_speed_x = (-ball_speed_x) + 1;
- ball_speed_y = ball_speed_y - (spieler_y - ball_y) * 0.1;
- runde = runde + 1;
- println(runde);
- } else {
- ball_x = 450;
- ball_y = 350;
- ball_speed_x = -3;
- ball_speed_y = 0;
- runde = 0;
- print("Neue Runde");
- println(runde);
- }
- }
- if (ball_y > 695 || ball_y < 5) {
- ball_speed_y = -ball_speed_y;
- }
- if (ball_x > 895) {
- ball_speed_x = -ball_speed_x;
- }
- text("Runde: " + runde, 810, 20);
- }
- void keyPressed()
- {
- int pressedKey = key;
- print("down ");
- println(pressedKey);
- if (pressedKey == up) upstate = true;
- else if (pressedKey == down) downstate = true;
- else ;
- }
- void keyReleased() {
- int releasedKey = key;
- print("up ");
- println(releasedKey);
- if (releasedKey == up) upstate = false;
- else if (releasedKey == down) downstate = false;
- else ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement