Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.AI.Map;
- import java.awt.image.BufferedImage;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import com.AI.main.Main;
- public class PixelMap {
- private int mapWidth, mapHeight;
- private BufferedImage image;
- private int w, h, type;
- public static int Environment = 1, Terrain = 0;
- private boolean firstTimeLoad = true;
- private HashMap<Vector2, Tile> TilesInMap = new HashMap<Vector2, Tile>();
- public List<Vector2> vList = new ArrayList<Vector2>();
- public PixelMap(int mapWidth, int mapHeight, int type, BufferedImage image){
- System.out.println("PixelMap Converted, from pixelImage: " + image);
- this.mapWidth = mapWidth;
- this.mapHeight = mapHeight;
- this.type = type;
- this.image = image;
- w = image.getWidth();
- h = image.getHeight();
- }
- public void RenderPixelMap(){
- for(int xx = 0; xx < h; xx++){
- for(int yy = 0; yy < w; yy++){
- int pixel = image.getRGB(xx, yy);
- int red = (pixel >> 16) & 0xff;
- int green = (pixel >> 8) & 0xff;
- int blue = (pixel) & 0xff;
- if(type == 0){
- if(red == 25 && green == 255 & blue == 29){
- renderTile(Tiles.grassTile, new Vector2(xx, yy));
- }
- if(red == 0 && green == 155 & blue == 255){
- renderTile(Tiles.waterTile, new Vector2(xx, yy));
- }
- if(red == 255 && green == 187 & blue == 127){
- renderTile(Tiles.sandTile, new Vector2(xx, yy));
- }
- if(red == 128 && green == 128 & blue == 128){
- renderTile(Tiles.rockTile, new Vector2(xx, yy));
- }
- }
- if(type == 1){
- if(red == 107 && green == 255 & blue == 107){
- renderTile(Tiles.treeTile, new Vector2(xx, yy));
- }
- }
- }
- }
- if(type == 0)
- if(firstTimeLoad)
- System.out.println("Terrain|| PixelsRendered: " + (TilesInMap.size() * (32*32)) + " TilesRendered: " + TilesInMap.size());
- if(type == 1)
- if(firstTimeLoad)
- System.out.println("Environment|| PixelsRendered: " + (TilesInMap.size() * (32*32)) + " TilesRendered: " + TilesInMap.size());
- firstTimeLoad = false;
- }
- public void renderTile(Tile t, Vector2 V2){
- if(V2.getX() <= mapWidth){
- if(V2.getY() <= mapHeight){
- Main.getGfx().drawImage(t.getImage(), V2.getX() * 32, V2.getY() * 32, 32, 32, null);
- if(firstTimeLoad){
- Vector2 ve2 = new Vector2((V2.getX() * 32), (V2.getY() * 32));
- TilesInMap.put(ve2, t);
- vList.add(vList.size(), ve2);
- }
- }else{
- System.out.println("Map out of Height bounds!!!");
- }
- }else{
- System.out.println("Map out of Width bounds!!!");
- }
- }
- public Tile getTileAt(int xPos, int yPos){
- int numberToShift;
- if(xPos == 0)
- numberToShift = 0;
- else
- numberToShift = -1;
- int startingBlocks = (xPos - numberToShift) * mapHeight;
- return TilesInMap.get(vList.get(startingBlocks + yPos));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement