Advertisement
Nojus_Globys

feb28-donuts

Feb 28th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | Software | 0 0
  1.  
  2. PImage // processing image
  3.   player, // žaidėjas
  4.   donut; // spurga
  5.  
  6. int
  7.   playerX,
  8.   playerY,
  9.   playerSize,
  10.   playerStep,
  11.  
  12.   donutX,
  13.   donutY,
  14.   donutSize,
  15.  
  16.   score = 0;
  17.  
  18. void setup () {
  19.   size (1200, 800);
  20.   player = loadImage ("data/player.png");
  21.   donut = loadImage ("data/donut.png");
  22.  
  23.   // imageMode (CORNER); - standartiškai
  24.   // imageMode (CENTER); - galima pasidaryti ir taip
  25.  
  26.   // pasistatau žaidėją maždaug per vidurį
  27.   playerX = width / 2;
  28.   playerY = height / 2;
  29.   playerSize = height / 5; // height * 0.2 - 160
  30.   playerStep = height / 50; // 800 / 50 = 16
  31.  
  32.   donutX = donutY = donutSize = height / 7;
  33. }
  34.  
  35. void player () {
  36.   // jeigu paspaustas 'a' klavišas IR ...
  37.     // judėti į kairę
  38.   // jeigu paspaustas 'd' klavišas IR ...
  39.     // judėti į dešinę
  40.   // jeigu paspaustas 'w' klavišas IR ...
  41.     // judėti į viršų
  42.   // jeigu paspaustas 's' klavišas IR ...
  43.     // judėti į apačią
  44.    
  45.     if (keyPressed && key == 'a')
  46.       playerX -= playerStep;
  47.       //playerX = playerX - playerStep;
  48.     else if (keyPressed && key == 'd')
  49.       playerX += playerStep;
  50.     else if (keyPressed && key == 'w')
  51.       playerY -= playerStep;
  52.     else if (keyPressed && key == 's')
  53.       playerY += playerStep;
  54.      
  55.   image (player, playerX, playerY, playerSize, playerSize);
  56. }
  57.  
  58. void draw () {
  59.   background (255);
  60.   player ();
  61.   image (donut, donutX, donutY, donutSize, donutSize);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement