Advertisement
Nojus_Globys

mar21

Mar 21st, 2023 (edited)
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | Software | 0 0
  1. float
  2. // paddle
  3.   paddleX,
  4.   paddleY,
  5.   paddleW, // plotis
  6.   paddleH, // aukštis
  7.   paddleStep,
  8. // ball
  9.   ballX = 0,
  10.   ballY = 0,
  11.   ballSize,
  12.   ballStep;
  13.  
  14. void setup () {
  15.   size (1280, 700);
  16.   rectMode (CENTER);
  17.  
  18.   paddleX = width * 0.5; // per vidurį
  19.   paddleY = height * 0.95; // apačioje
  20.  
  21.   paddleW = width * 0.125;
  22.   paddleH = height * 0.03;
  23.    
  24.   ballSize = height * 0.1;
  25.   paddleStep = ballStep = width * 0.01;
  26. }
  27.  
  28. void paddle () {
  29.   fill (255, 0, 0);
  30.   rect (paddleX, paddleY, paddleW, paddleH);
  31.  
  32.   if (keyPressed) {
  33.     //if (key == 'a')
  34.     if (keyCode == LEFT && paddleX > 0)
  35.       paddleX -= paddleStep;
  36.     if (keyCode == RIGHT && paddleX < width)
  37.       paddleX += paddleStep;
  38.   }
  39. }
  40.  
  41. void ball () {
  42.   fill (255);
  43.   circle (ballX, ballY, ballSize);
  44.  
  45.   ballX += ballStep;
  46.   ballY += ballStep;
  47.  
  48.   if (ballY > height)
  49.     stop ();
  50. }
  51.  
  52. void draw () {
  53.   background (0);
  54.   paddle ();
  55.   ball ();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement