For some reason when I compile my program it does not draw the map layers, however it does draw them if I debug or run from eclipse. However after it when I run it as a independent jar file it does draw the player, just not the maps.
Can anyone take a look and tell me what on earth is going on?
for those who have problems downloading
Here is my ground.java
package com.ChimpyGames.Tile;
import java.awt.Color;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
public class Ground {
private int x;
private int y;
private int tileSize;
private int[][] map;
public int mapWidth;
public int mapHeight;
public Ground(String s, int tileSize) {
this.tileSize = tileSize;
try {
BufferedReader br = new BufferedReader(new FileReader("src/maps/" + s
+ "/Ground.map"));
mapWidth = Integer.parseInt(br.readLine());
mapHeight = Integer.parseInt(br.readLine());
map = new int[mapHeight][mapWidth];
String delimiters = " ";
for (int row = 0; row < mapHeight; row++) {
String line = br.readLine();
String[] tokens = line.split(delimiters);
for (int col = 0; col < mapWidth; col++) {
map[row][col] = Integer.parseInt(tokens[col]);
}
}
} catch (Exception e) {
}
}
public static void update() {
}
public static void draw(Graphics g) {
for (int row = 0; row < mapHeight; row++) {
for (int col = 0; col < mapWidth; col++) {
int rc = map[row][col];
if (rc == 0) {
}
if (rc == 1) {
g.setColor(Color.WHITE);
g.fillRect(x + col * tileSize, y + row * tileSize,
tileSize, tileSize);
}
}
}
}
}
Here is my Play.java
package com.ChimpyGames.Menus;
import java.awt.Color;
import java.awt.Graphics2D;
import com.ChimpyGames.GamePanel;
import com.ChimpyGames.Entities.Player;
import com.ChimpyGames.Handlers.Keys;
import com.ChimpyGames.Tile.Ground;
import com.ChimpyGames.Tile.Mask1;
import com.ChimpyGames.Tile.Mask2;
import com.ChimpyGames.Tile.Overlay1;
import com.ChimpyGames.Tile.Overlay2;
import com.ChimpyGames.Tile.Scripts;
public class Play extends Menu {
Player player;
private String map;
public int tileSize;
public Ground ground;
public Mask1 mask1;
public Mask2 mask2;
public OVerlay1 overlay1;
public Overlay2 overlay2;
public Scripts scripts;
public Play(MenuManager gsm) {
super(gsm);
init();
}
@Override
public void init() {
// load the map by it's folder not by the .map
map = "DefaultMap";
tileSize = 32;
// Load Individual layers
ground = new Ground(map, tileSize);
mask1 = new Mask1(map, tileSize);
mask2 = new Mask2(map, tileSize);
overlay1 = new Overlay1(map, tileSize);
overlay2 = new Overlay2(map, tileSize);
scripts = new Scripts(map, tileSize);
player = new Player();
}
@Override
public void update() {
Ground.update();
Mask1.update();
Mask2.update();
player.update();
Overlay1.update();
Overlay2.update();
Scripts.update();
}
@Override
public void draw(Graphics2D g) {
handleInput();
g.setColor(Color.BLACK);
g.fillRect(0, 0, GamePanel.width, GamePanel.height);
Ground.draw(g);
Mask1.draw(g);
Mask2.draw(g);
// Keep above code at top
player.draw(g);
// Keep below code at bottom
Overlay1.draw(g);
Overlay2.draw(g);
Scripts.draw(g);
}
@Override
public void handleInput() {
player.up(Keys.keyState\[Keys.UP\]);
player.down(Keys.keyState\[Keys.DOWN\]);
player.left(Keys.keyState\[Keys.LEFT\]);
player.right(Keys.keyState\[Keys.RIGHT\]);
if (Keys.keyState\[Keys.ENTER\]) {
}
}
}
Ran as executable
Ran from eclipse