Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.neet.MapViewer.TileMap;
- import javafx.scene.canvas.Canvas;
- import com.neet.MapViewer.Helper.*;
- public class TileMap {
- private int[][] tileType;
- public Canvas mapCanvas = new Canvas(640,640); //640 because there are 40 tile with tile size 16;
- /**
- * initialise canvas for the tile map.
- */
- public void render(){
- drawMap();
- }
- public void drawMap() {
- tileType = new int[Map.getNumRows()][Map.getNumCols()];
- for(int row = 0; row < Map.getNumRows(); row++) {
- for(int col = 0; col < Map.getNumCols(); col++) {
- if(Map.getTile(row, col) == 0) continue;
- /* Variable r is for any tile that is not dividable by 20 is a non blocked tile
- Variable c is for the column of source. If the tile mob 20 is 0 thn it its at first row of source
- and if mob 20 is 1 than it is at the second row of source.
- */
- int r = Map.getTile(row, col) / Img.getNumTilesAcross();
- int c = Map.getTile(row, col) % Img.getNumTilesAcross();
- if (r == 0) {
- mapCanvas.getGraphicsContext2D().drawImage(
- Img.tileSet, c * Img.TILESIZE, 0, Img.TILESIZE, Img.TILESIZE,
- col * Img.TILESIZE, row * Img.TILESIZE, Img.TILESIZE, Img.TILESIZE);
- tileType[row][col] = 0;
- }
- else {
- mapCanvas.getGraphicsContext2D().drawImage(
- Img.tileSet, c * Img.TILESIZE, Img.TILESIZE, Img.TILESIZE, Img.TILESIZE,
- col * Img.TILESIZE, row * Img.TILESIZE, Img.TILESIZE, Img.TILESIZE);
- tileType[row][col] = 1;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement