Advertisement
Nojus_Globys

mar07

Mar 7th, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | Software | 0 0
  1.  
  2. PImage
  3.     player,
  4.     donut;
  5.  
  6. float
  7.     playerX,
  8.     playerY,
  9.     playerSize,
  10.     step,
  11.    
  12.     donutX,
  13.     donutY,
  14.     donutSize;
  15.  
  16. int score = 0;
  17.  
  18. boolean
  19.   left, // false
  20.   right, // false
  21.   up, // false
  22.   down; // false
  23.  
  24. void setup () {
  25.     size(1200, 800);
  26.     imageMode (CENTER);
  27.  
  28.     player = loadImage("data/player.png");
  29.     donut = loadImage("data/donut.png");
  30.    
  31.     playerX = width * 0.5;
  32.     playerY = height * 0.5;
  33.     playerSize = height * 0.15;
  34.     step = height * 0.02;
  35.  
  36.     donutX = donutY = donutSize = height * 0.1;
  37. }
  38.  
  39. void player () {
  40.     image (player, playerX, playerY, playerSize, playerSize);
  41.    
  42.     if (left) // if (left == true)
  43.       playerX -= step;
  44.     if (right)
  45.       playerX += step;
  46.     if (up)
  47.       playerY -= step;
  48.     if (down)
  49.       playerY += step;
  50.    
  51.     //if (keyPressed){
  52.     //  if (key == 'a')
  53.     //    playerX -= step;
  54.     //  if (key == 'd')
  55.     //    playerX += step;
  56.     //  if (key == 'w')
  57.     //    playerY -= step;
  58.     //  if (key == 's')
  59.     //    playerY += step;
  60.     //}
  61. }
  62.  
  63. void keyPressed () {
  64.   if (key == 'a')
  65.    left = true;
  66.   if (key == 'd')
  67.     right = true;
  68.   if (key == 'w')
  69.     up = true;
  70.   if (key == 's')
  71.     down = true;
  72. }
  73.  
  74. void keyReleased () {
  75.   left = right = up = down = false;
  76. }
  77.  
  78. void score () {
  79.   fill (0); // tekstas bus juodas
  80.   textSize (donutSize); // teksto dydis bus lygus spurgos dydžiui
  81.   text (score, width - donutSize * 1.5, donutSize);
  82. }
  83.  
  84. void draw () {
  85.   background (255);
  86.   player ();
  87.   image (donut, donutX, donutY, donutSize, donutSize);
  88.   score ();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement