From d40dec9d9916e97ffdc2cf58c2f937c958b409f6 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 3 Jun 2012 15:44:51 -0400 Subject: Renamed GAME_WIDTH/GAME_HEIGHT constants Both Main and MapViewGameState had two constants called GAME_WIDTH and GAME_HEIGHT; however, in Main, they described the size in pixels of the canvas, and in MapViewGameState, the size, in tiles, of the map. They have now been renamed to avoid confusion. --- src/com/fourisland/frigidearth/Main.java | 19 +++---- .../fourisland/frigidearth/MapViewGameState.java | 66 +++++++++++----------- 2 files changed, 42 insertions(+), 43 deletions(-) (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/frigidearth/Main.java b/src/com/fourisland/frigidearth/Main.java index ca805df..89ed192 100644 --- a/src/com/fourisland/frigidearth/Main.java +++ b/src/com/fourisland/frigidearth/Main.java @@ -28,9 +28,8 @@ import javax.swing.JFrame; */ public class Main extends Canvas { - public static final int GAME_WIDTH = 636; - public static final int GAME_HEIGHT = 480; - public static final int FPS = (1000 / 60); // 60 fps + public static final int CANVAS_WIDTH = 636; + public static final int CANVAS_HEIGHT = 480; private static JFrame mainWindow; private static Color[][] grid; @@ -47,8 +46,8 @@ public class Main extends Canvas mainWindow = new JFrame(); mainWindow.setTitle("Frigid Earth"); - mainWindow.setSize(GAME_WIDTH*2, GAME_HEIGHT*2); - mainWindow.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-GAME_WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-GAME_HEIGHT); + mainWindow.setSize(CANVAS_WIDTH*2, CANVAS_HEIGHT*2); + mainWindow.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-CANVAS_WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-CANVAS_HEIGHT); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWindow.addKeyListener(new KeyListener() { @Override @@ -121,7 +120,7 @@ public class Main extends Canvas GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); - BufferedImage vImg = config.createCompatibleImage(GAME_WIDTH, GAME_HEIGHT, Transparency.TRANSLUCENT); + BufferedImage vImg = config.createCompatibleImage(CANVAS_WIDTH, CANVAS_HEIGHT, Transparency.TRANSLUCENT); Graphics2D g = vImg.createGraphics(); for (Renderable renderable : renderables) @@ -131,10 +130,10 @@ public class Main extends Canvas do { do { - float wt = mainWindow.getWidth() / (float) GAME_WIDTH; - float ht = (mainWindow.getHeight() - mainWindow.getInsets().top) / (float) GAME_HEIGHT; - int renderWidth = Math.round(Math.min(wt, ht) * GAME_WIDTH); - int renderHeight = Math.round(Math.min(wt, ht) * GAME_HEIGHT); + float wt = mainWindow.getWidth() / (float) CANVAS_WIDTH; + float ht = (mainWindow.getHeight() - mainWindow.getInsets().top) / (float) CANVAS_HEIGHT; + int renderWidth = Math.round(Math.min(wt, ht) * CANVAS_WIDTH); + int renderHeight = Math.round(Math.min(wt, ht) * CANVAS_HEIGHT); int renderX = (mainWindow.getWidth()/2)-(renderWidth/2); int renderY = ((mainWindow.getHeight()-mainWindow.getInsets().top)/2)-(renderHeight/2); diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index b425f2b..c1caab0 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -20,11 +20,11 @@ public class MapViewGameState implements GameState { private final int TILE_WIDTH = 12; private final int TILE_HEIGHT = 12; - private final int GAME_WIDTH = 100; - private final int GAME_HEIGHT = 100; + private final int MAP_WIDTH = 100; + private final int MAP_HEIGHT = 100; private final int MESSAGE_HEIGHT = 5; - private final int VIEWPORT_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; - private final int VIEWPORT_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT - MESSAGE_HEIGHT; + private final int VIEWPORT_WIDTH = Main.CANVAS_WIDTH / TILE_WIDTH; + private final int VIEWPORT_HEIGHT = Main.CANVAS_HEIGHT / TILE_HEIGHT - MESSAGE_HEIGHT; private final int MAX_ROOM_WIDTH = 13; private final int MIN_ROOM_WIDTH = 7; private final int MAX_ROOM_HEIGHT = 13; @@ -44,14 +44,14 @@ public class MapViewGameState implements GameState public MapViewGameState() { - grid = new Tile[GAME_WIDTH][GAME_HEIGHT]; - gridLighting = new boolean[GAME_WIDTH][GAME_HEIGHT]; + grid = new Tile[MAP_WIDTH][MAP_HEIGHT]; + gridLighting = new boolean[MAP_WIDTH][MAP_HEIGHT]; - for (int x=0; x GAME_HEIGHT)) + if ((ytemp < 0) || (ytemp > MAP_HEIGHT)) { return false; } for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++) { - if ((xtemp < 0) || (xtemp > GAME_WIDTH)) + if ((xtemp < 0) || (xtemp > MAP_WIDTH)) { return false; } @@ -295,7 +295,7 @@ public class MapViewGameState implements GameState switch (direction) { case North: - if ((x < 0) || (x > GAME_WIDTH)) + if ((x < 0) || (x > MAP_WIDTH)) { return false; } else { @@ -304,7 +304,7 @@ public class MapViewGameState implements GameState for (ytemp = y; ytemp > (y-length); ytemp--) { - if ((ytemp < 0) || (ytemp > GAME_HEIGHT)) + if ((ytemp < 0) || (ytemp > MAP_HEIGHT)) { return false; } @@ -323,7 +323,7 @@ public class MapViewGameState implements GameState break; case East: - if ((y < 0) || (y > GAME_HEIGHT)) + if ((y < 0) || (y > MAP_HEIGHT)) { return false; } else { @@ -332,7 +332,7 @@ public class MapViewGameState implements GameState for (xtemp = x; xtemp < (x+length); xtemp++) { - if ((xtemp < 0) || (xtemp > GAME_WIDTH)) + if ((xtemp < 0) || (xtemp > MAP_WIDTH)) { return false; } @@ -351,7 +351,7 @@ public class MapViewGameState implements GameState break; case South: - if ((x < 0) || (x > GAME_WIDTH)) + if ((x < 0) || (x > MAP_WIDTH)) { return false; } else { @@ -360,7 +360,7 @@ public class MapViewGameState implements GameState for (ytemp = y; ytemp < (y+length); ytemp++) { - if ((ytemp < 0) || (ytemp > GAME_HEIGHT)) + if ((ytemp < 0) || (ytemp > MAP_HEIGHT)) { return false; } @@ -379,7 +379,7 @@ public class MapViewGameState implements GameState break; case West: - if ((y < 0) || (y > GAME_HEIGHT)) + if ((y < 0) || (y > MAP_HEIGHT)) { return false; } else { @@ -388,7 +388,7 @@ public class MapViewGameState implements GameState for (xtemp = x; xtemp > (x-length); xtemp--) { - if ((xtemp < 0) || (xtemp > GAME_WIDTH)) + if ((xtemp < 0) || (xtemp > MAP_WIDTH)) { return false; } @@ -412,9 +412,9 @@ public class MapViewGameState implements GameState private void calculateFieldOfView() { - for (int x=0; x (VIEWPORT_WIDTH/2)) { - if (playerx < (GAME_WIDTH - (VIEWPORT_WIDTH/2-1))) + if (playerx < (MAP_WIDTH - (VIEWPORT_WIDTH/2-1))) { viewportx = playerx - (VIEWPORT_WIDTH/2); } else { - viewportx = GAME_WIDTH - VIEWPORT_WIDTH; + viewportx = MAP_WIDTH - VIEWPORT_WIDTH; } } else { viewportx = 0; @@ -610,11 +610,11 @@ public class MapViewGameState implements GameState if (playery > (VIEWPORT_HEIGHT/2)) { - if (playery < (GAME_HEIGHT - (VIEWPORT_HEIGHT/2-1))) + if (playery < (MAP_HEIGHT - (VIEWPORT_HEIGHT/2-1))) { viewporty = playery - (VIEWPORT_HEIGHT/2); } else { - viewporty = GAME_HEIGHT - VIEWPORT_HEIGHT; + viewporty = MAP_HEIGHT - VIEWPORT_HEIGHT; } } else { viewporty = 0; @@ -624,9 +624,9 @@ public class MapViewGameState implements GameState private boolean isValidPosition(int x, int y) { if (x < 0) return false; - if (x > GAME_WIDTH) return false; + if (x > MAP_WIDTH) return false; if (y < 0) return false; - if (y > GAME_HEIGHT) return false; + if (y > MAP_HEIGHT) return false; return true; } -- cgit 1.4.1