Advertisement
Nojus_Globys

mar24

Mar 24th, 2023
1,175
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | Software | 0 0
  1.  
  2. PImage
  3.   tiles,
  4.   tile;
  5.  
  6. int
  7.   tileSize = 32,
  8.   mapSize = 20,
  9.   tilesX = tileSize * (mapSize + 2),
  10.   tilesWidth = 9, // kiek telpa tile'ų į tile'ų rinkinio plotį
  11.   chosen = -1;
  12.  
  13. int column = -1, row = -1;
  14.  
  15. void setup () {
  16.    size (992, 640);
  17.    noFill ();
  18.    stroke (255, 50);
  19.    textSize (tileSize);
  20.    
  21.    tiles = loadImage ("data/tileset2.png");
  22. }
  23.  
  24. void grid () {
  25.   noFill();
  26.   for (int y = 0; y < mapSize; ++y) {
  27.     for (int x = 0; x < mapSize; ++x)
  28.       square (x * tileSize, y * tileSize, tileSize);
  29.   }
  30. }
  31.  
  32. void choose () {
  33.   // gaunam pasirinkto tile'o numerį
  34.       if (mouseX > tilesX && mouseX < tilesX + tiles.width && mousePressed) {
  35.            column = (mouseX - tilesX) / tileSize;
  36.             row = mouseY / tileSize; // 4.9 -> 4
  37.             //println (mouseY, row);
  38.         chosen = column + (row * tilesWidth);
  39.         //chosen = row * tilesWidth;
  40.       }
  41.     // atvaizduojam pasirinkto tile'o numerį
  42.       fill (0);
  43.       //text (chosen, width * 0.9, height * 0.95);
  44.       text (str(mouseY) + "; " + str (row) + "; " + str (chosen), width * 0.7, height * 0.95);
  45.    // išsikerpam tile'ą iš viso rinkinio
  46.      int x = column * tileSize,
  47.          y = row * tileSize;
  48.      tile = tiles.get(x, y, tileSize, tileSize);
  49.       image (tile, mouseX - tileSize / 2, mouseY - tileSize / 2);
  50. }
  51.  
  52. void draw () {
  53.   background (85, 180, 255);
  54.   image (tiles, tilesX, 0);
  55.   grid ();
  56.   choose ();
  57. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement