Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I'm making a old-school Final Fantasy type game and I made a tile map class a while back and posted it on here (Is this a good way to implement a tile map from a text file? Is this a good way to implement a tile map from a text file?) But, when I got to collision, it was a nightmare. So I've updated it to make it more collision friendly and I was wondering what the community's thoughts were on this code.

I'm making a old-school Final Fantasy type game and I made a tile map class a while back and posted it on here (Is this a good way to implement a tile map from a text file?) But, when I got to collision, it was a nightmare. So I've updated it to make it more collision friendly and I was wondering what the community's thoughts were on this code.

I'm making a old-school Final Fantasy type game and I made a tile map class a while back and posted it on here (Is this a good way to implement a tile map from a text file?) But, when I got to collision, it was a nightmare. So I've updated it to make it more collision friendly and I was wondering what the community's thoughts were on this code.

Rollback to Revision 1
Source Link
tim
  • 25.3k
  • 3
  • 31
  • 76
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize; //sx and sy are the x and y sizes
 //of the map, posX and posY are
 //the position of the origin of
 //the map x and y are place holders
 //for iterators and mapSize is to make
 //sure sx, sy, and int[][] tilemap 
 //are correct. 
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize; //sx and sy are the x and y sizes
 //of the map, posX and posY are
 //the position of the origin of
 //the map x and y are place holders
 //for iterators and mapSize is to make
 //sure sx, sy, and int[][] tilemap 
 //are correct. 
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize;
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
added 513 characters in body
Source Link
Twiggy
  • 333
  • 2
  • 7
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize; //sx and sy are the x and y sizes
 //of the map, posX and posY are
 //the position of the origin of
 //the map x and y are place holders
 //for iterators and mapSize is to make
 //sure sx, sy, and int[][] tilemap 
 //are correct. 
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize;
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
import com.stardust.rpgtest2.Game;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TileMap 
{
 int posX, posY, x, y, sx, sy, mapSize; //sx and sy are the x and y sizes
 //of the map, posX and posY are
 //the position of the origin of
 //the map x and y are place holders
 //for iterators and mapSize is to make
 //sure sx, sy, and int[][] tilemap 
 //are correct. 
 public String filename;
 
 public int[][] tilemap;
 
 
 public TileMap(int posX, int posY, int mapSize, String filename)
 {
 this.mapSize = mapSize;
 tilemap = new int[mapSize][mapSize];
 this.posX = posX;
 this.posY = posY;
 this.sx = mapSize;
 this.sy = mapSize;
 this.filename = filename;
 }
 
 public void render(Graphics g)
 {
 for(int y = 0; y < tilemap.length; y++)
 { 
 for(int x = 0; x < tilemap.length; x++)
 {
 int textureType = tilemap[x][y];
 BufferedImage texture = Game.tileMaker.getTileArray()[textureType].texture; 
 g.drawImage(texture, posX, posY, null);
 posY += 32;
 }
 posX += 32;
 posY = Game.mapY;
 }
 posX = Game.mapX;
 posY = Game.mapY;
 }
 
 public void fileParser() throws IOException
 {
 BufferedReader in = new BufferedReader(new FileReader(filename));
 
 String line;
 
 while((line = in.readLine()) != null)
 {
 String[] values = line.split(",");
 
 for(String str : values)
 {
 int str_int = Integer.parseInt(str);
 tilemap[x][y] = str_int;
 ++y;
 }
 ++x;
 y = 0;
 }
 x = 0;
 
 in.close();
 }
}
Source Link
Twiggy
  • 333
  • 2
  • 7
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /