Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage
- tiles,
- tile;
- int
- tileSize = 32,
- mapSize = 20,
- tilesX = tileSize * (mapSize + 2),
- tilesWidth = 9, // kiek telpa tile'ų į tile'ų rinkinio plotį
- chosen = -1;
- int column = -1, row = -1;
- void setup () {
- size (992, 640);
- noFill ();
- stroke (255, 50);
- textSize (tileSize);
- tiles = loadImage ("data/tileset2.png");
- }
- void grid () {
- noFill();
- for (int y = 0; y < mapSize; ++y) {
- for (int x = 0; x < mapSize; ++x)
- square (x * tileSize, y * tileSize, tileSize);
- }
- }
- void choose () {
- // gaunam pasirinkto tile'o numerį
- if (mouseX > tilesX && mouseX < tilesX + tiles.width && mousePressed) {
- column = (mouseX - tilesX) / tileSize;
- row = mouseY / tileSize; // 4.9 -> 4
- //println (mouseY, row);
- chosen = column + (row * tilesWidth);
- //chosen = row * tilesWidth;
- }
- // atvaizduojam pasirinkto tile'o numerį
- fill (0);
- //text (chosen, width * 0.9, height * 0.95);
- text (str(mouseY) + "; " + str (row) + "; " + str (chosen), width * 0.7, height * 0.95);
- // išsikerpam tile'ą iš viso rinkinio
- int x = column * tileSize,
- y = row * tileSize;
- tile = tiles.get(x, y, tileSize, tileSize);
- image (tile, mouseX - tileSize / 2, mouseY - tileSize / 2);
- }
- void draw () {
- background (85, 180, 255);
- image (tiles, tilesX, 0);
- grid ();
- choose ();
- }
Advertisement
Advertisement