about summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2012-06-03 15:44:51 -0400
committerStarla Insigna <hatkirby@fourisland.com>2012-06-03 15:44:51 -0400
commitd40dec9d9916e97ffdc2cf58c2f937c958b409f6 (patch)
tree528b883c424eade291625f63090353cc1c0fdeb7 /src/com/fourisland
parent2cbe14faf609baee282f3fe82d4d841a24ff7e51 (diff)
downloadfrigidearth-d40dec9d9916e97ffdc2cf58c2f937c958b409f6.tar.gz
frigidearth-d40dec9d9916e97ffdc2cf58c2f937c958b409f6.tar.bz2
frigidearth-d40dec9d9916e97ffdc2cf58c2f937c958b409f6.zip
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.
Diffstat (limited to 'src/com/fourisland')
-rw-r--r--src/com/fourisland/frigidearth/Main.java19
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java66
2 files changed, 42 insertions, 43 deletions
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;
28 */ 28 */
29public class Main extends Canvas 29public class Main extends Canvas
30{ 30{
31 public static final int GAME_WIDTH = 636; 31 public static final int CANVAS_WIDTH = 636;
32 public static final int GAME_HEIGHT = 480; 32 public static final int CANVAS_HEIGHT = 480;
33 public static final int FPS = (1000 / 60); // 60 fps
34 33
35 private static JFrame mainWindow; 34 private static JFrame mainWindow;
36 private static Color[][] grid; 35 private static Color[][] grid;
@@ -47,8 +46,8 @@ public class Main extends Canvas
47 46
48 mainWindow = new JFrame(); 47 mainWindow = new JFrame();
49 mainWindow.setTitle("Frigid Earth"); 48 mainWindow.setTitle("Frigid Earth");
50 mainWindow.setSize(GAME_WIDTH*2, GAME_HEIGHT*2); 49 mainWindow.setSize(CANVAS_WIDTH*2, CANVAS_HEIGHT*2);
51 mainWindow.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-GAME_WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-GAME_HEIGHT); 50 mainWindow.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-CANVAS_WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-CANVAS_HEIGHT);
52 mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 51 mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53 mainWindow.addKeyListener(new KeyListener() { 52 mainWindow.addKeyListener(new KeyListener() {
54 @Override 53 @Override
@@ -121,7 +120,7 @@ public class Main extends Canvas
121 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 120 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
122 GraphicsDevice device = env.getDefaultScreenDevice(); 121 GraphicsDevice device = env.getDefaultScreenDevice();
123 GraphicsConfiguration config = device.getDefaultConfiguration(); 122 GraphicsConfiguration config = device.getDefaultConfiguration();
124 BufferedImage vImg = config.createCompatibleImage(GAME_WIDTH, GAME_HEIGHT, Transparency.TRANSLUCENT); 123 BufferedImage vImg = config.createCompatibleImage(CANVAS_WIDTH, CANVAS_HEIGHT, Transparency.TRANSLUCENT);
125 Graphics2D g = vImg.createGraphics(); 124 Graphics2D g = vImg.createGraphics();
126 125
127 for (Renderable renderable : renderables) 126 for (Renderable renderable : renderables)
@@ -131,10 +130,10 @@ public class Main extends Canvas
131 130
132 do { 131 do {
133 do { 132 do {
134 float wt = mainWindow.getWidth() / (float) GAME_WIDTH; 133 float wt = mainWindow.getWidth() / (float) CANVAS_WIDTH;
135 float ht = (mainWindow.getHeight() - mainWindow.getInsets().top) / (float) GAME_HEIGHT; 134 float ht = (mainWindow.getHeight() - mainWindow.getInsets().top) / (float) CANVAS_HEIGHT;
136 int renderWidth = Math.round(Math.min(wt, ht) * GAME_WIDTH); 135 int renderWidth = Math.round(Math.min(wt, ht) * CANVAS_WIDTH);
137 int renderHeight = Math.round(Math.min(wt, ht) * GAME_HEIGHT); 136 int renderHeight = Math.round(Math.min(wt, ht) * CANVAS_HEIGHT);
138 int renderX = (mainWindow.getWidth()/2)-(renderWidth/2); 137 int renderX = (mainWindow.getWidth()/2)-(renderWidth/2);
139 int renderY = ((mainWindow.getHeight()-mainWindow.getInsets().top)/2)-(renderHeight/2); 138 int renderY = ((mainWindow.getHeight()-mainWindow.getInsets().top)/2)-(renderHeight/2);
140 139
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
20{ 20{
21 private final int TILE_WIDTH = 12; 21 private final int TILE_WIDTH = 12;
22 private final int TILE_HEIGHT = 12; 22 private final int TILE_HEIGHT = 12;
23 private final int GAME_WIDTH = 100; 23 private final int MAP_WIDTH = 100;
24 private final int GAME_HEIGHT = 100; 24 private final int MAP_HEIGHT = 100;
25 private final int MESSAGE_HEIGHT = 5; 25 private final int MESSAGE_HEIGHT = 5;
26 private final int VIEWPORT_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; 26 private final int VIEWPORT_WIDTH = Main.CANVAS_WIDTH / TILE_WIDTH;
27 private final int VIEWPORT_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT - MESSAGE_HEIGHT; 27 private final int VIEWPORT_HEIGHT = Main.CANVAS_HEIGHT / TILE_HEIGHT - MESSAGE_HEIGHT;
28 private final int MAX_ROOM_WIDTH = 13; 28 private final int MAX_ROOM_WIDTH = 13;
29 private final int MIN_ROOM_WIDTH = 7; 29 private final int MIN_ROOM_WIDTH = 7;
30 private final int MAX_ROOM_HEIGHT = 13; 30 private final int MAX_ROOM_HEIGHT = 13;
@@ -44,14 +44,14 @@ public class MapViewGameState implements GameState
44 44
45 public MapViewGameState() 45 public MapViewGameState()
46 { 46 {
47 grid = new Tile[GAME_WIDTH][GAME_HEIGHT]; 47 grid = new Tile[MAP_WIDTH][MAP_HEIGHT];
48 gridLighting = new boolean[GAME_WIDTH][GAME_HEIGHT]; 48 gridLighting = new boolean[MAP_WIDTH][MAP_HEIGHT];
49 49
50 for (int x=0; x<GAME_WIDTH; x++) 50 for (int x=0; x<MAP_WIDTH; x++)
51 { 51 {
52 for (int y=0; y<GAME_HEIGHT; y++) 52 for (int y=0; y<MAP_HEIGHT; y++)
53 { 53 {
54 if ((x == 0) || (x == GAME_WIDTH-1) || (y == 0) || (y == GAME_HEIGHT-1)) 54 if ((x == 0) || (x == MAP_WIDTH-1) || (y == 0) || (y == MAP_HEIGHT-1))
55 { 55 {
56 grid[x][y] = Tile.StoneWall; 56 grid[x][y] = Tile.StoneWall;
57 } else { 57 } else {
@@ -60,7 +60,7 @@ public class MapViewGameState implements GameState
60 } 60 }
61 } 61 }
62 62
63 makeRoom(GAME_WIDTH/2, GAME_HEIGHT/2, Direction.getRandomDirection()); 63 makeRoom(MAP_WIDTH/2, MAP_HEIGHT/2, Direction.getRandomDirection());
64 64
65 int currentFeatures = 1; 65 int currentFeatures = 1;
66 int objects = 300; 66 int objects = 300;
@@ -79,8 +79,8 @@ public class MapViewGameState implements GameState
79 Direction validTile = null; 79 Direction validTile = null;
80 for (int testing = 0; testing < 1000; testing++) 80 for (int testing = 0; testing < 1000; testing++)
81 { 81 {
82 newx = Functions.random(1, GAME_WIDTH-1); 82 newx = Functions.random(1, MAP_WIDTH-1);
83 newy = Functions.random(1, GAME_HEIGHT-1); 83 newy = Functions.random(1, MAP_HEIGHT-1);
84 validTile = null; 84 validTile = null;
85 85
86 if ((grid[newx][newy] == Tile.DirtWall) || (grid[newx][newy] == Tile.Corridor)) 86 if ((grid[newx][newy] == Tile.DirtWall) || (grid[newx][newy] == Tile.Corridor))
@@ -159,8 +159,8 @@ public class MapViewGameState implements GameState
159 { 159 {
160 for (int testing = 0; testing < 1000; testing++) 160 for (int testing = 0; testing < 1000; testing++)
161 { 161 {
162 newx = Functions.random(1, GAME_WIDTH-1); 162 newx = Functions.random(1, MAP_WIDTH-1);
163 newy = Functions.random(1, GAME_HEIGHT-2); 163 newy = Functions.random(1, MAP_HEIGHT-2);
164 ways = 4; 164 ways = 4;
165 165
166 for (Direction dir : Direction.values()) 166 for (Direction dir : Direction.values())
@@ -231,14 +231,14 @@ public class MapViewGameState implements GameState
231 231
232 for (int ytemp=room.getY(); ytemp < room.getY()+room.getHeight(); ytemp++) 232 for (int ytemp=room.getY(); ytemp < room.getY()+room.getHeight(); ytemp++)
233 { 233 {
234 if ((ytemp < 0) || (ytemp > GAME_HEIGHT)) 234 if ((ytemp < 0) || (ytemp > MAP_HEIGHT))
235 { 235 {
236 return false; 236 return false;
237 } 237 }
238 238
239 for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++) 239 for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++)
240 { 240 {
241 if ((xtemp < 0) || (xtemp > GAME_WIDTH)) 241 if ((xtemp < 0) || (xtemp > MAP_WIDTH))
242 { 242 {
243 return false; 243 return false;
244 } 244 }
@@ -295,7 +295,7 @@ public class MapViewGameState implements GameState
295 switch (direction) 295 switch (direction)
296 { 296 {
297 case North: 297 case North:
298 if ((x < 0) || (x > GAME_WIDTH)) 298 if ((x < 0) || (x > MAP_WIDTH))
299 { 299 {
300 return false; 300 return false;
301 } else { 301 } else {
@@ -304,7 +304,7 @@ public class MapViewGameState implements GameState
304 304
305 for (ytemp = y; ytemp > (y-length); ytemp--) 305 for (ytemp = y; ytemp > (y-length); ytemp--)
306 { 306 {
307 if ((ytemp < 0) || (ytemp > GAME_HEIGHT)) 307 if ((ytemp < 0) || (ytemp > MAP_HEIGHT))
308 { 308 {
309 return false; 309 return false;
310 } 310 }
@@ -323,7 +323,7 @@ public class MapViewGameState implements GameState
323 break; 323 break;
324 324
325 case East: 325 case East:
326 if ((y < 0) || (y > GAME_HEIGHT)) 326 if ((y < 0) || (y > MAP_HEIGHT))
327 { 327 {
328 return false; 328 return false;
329 } else { 329 } else {
@@ -332,7 +332,7 @@ public class MapViewGameState implements GameState
332 332
333 for (xtemp = x; xtemp < (x+length); xtemp++) 333 for (xtemp = x; xtemp < (x+length); xtemp++)
334 { 334 {
335 if ((xtemp < 0) || (xtemp > GAME_WIDTH)) 335 if ((xtemp < 0) || (xtemp > MAP_WIDTH))
336 { 336 {
337 return false; 337 return false;
338 } 338 }
@@ -351,7 +351,7 @@ public class MapViewGameState implements GameState
351 break; 351 break;
352 352
353 case South: 353 case South:
354 if ((x < 0) || (x > GAME_WIDTH)) 354 if ((x < 0) || (x > MAP_WIDTH))
355 { 355 {
356 return false; 356 return false;
357 } else { 357 } else {
@@ -360,7 +360,7 @@ public class MapViewGameState implements GameState
360 360
361 for (ytemp = y; ytemp < (y+length); ytemp++) 361 for (ytemp = y; ytemp < (y+length); ytemp++)
362 { 362 {
363 if ((ytemp < 0) || (ytemp > GAME_HEIGHT)) 363 if ((ytemp < 0) || (ytemp > MAP_HEIGHT))
364 { 364 {
365 return false; 365 return false;
366 } 366 }
@@ -379,7 +379,7 @@ public class MapViewGameState implements GameState
379 break; 379 break;
380 380
381 case West: 381 case West:
382 if ((y < 0) || (y > GAME_HEIGHT)) 382 if ((y < 0) || (y > MAP_HEIGHT))
383 { 383 {
384 return false; 384 return false;
385 } else { 385 } else {
@@ -388,7 +388,7 @@ public class MapViewGameState implements GameState
388 388
389 for (xtemp = x; xtemp > (x-length); xtemp--) 389 for (xtemp = x; xtemp > (x-length); xtemp--)
390 { 390 {
391 if ((xtemp < 0) || (xtemp > GAME_WIDTH)) 391 if ((xtemp < 0) || (xtemp > MAP_WIDTH))
392 { 392 {
393 return false; 393 return false;
394 } 394 }
@@ -412,9 +412,9 @@ public class MapViewGameState implements GameState
412 412
413 private void calculateFieldOfView() 413 private void calculateFieldOfView()
414 { 414 {
415 for (int x=0; x<GAME_WIDTH; x++) 415 for (int x=0; x<MAP_WIDTH; x++)
416 { 416 {
417 for (int y=0; y<GAME_HEIGHT; y++) 417 for (int y=0; y<MAP_HEIGHT; y++)
418 { 418 {
419 gridLighting[x][y] = false; 419 gridLighting[x][y] = false;
420 } 420 }
@@ -530,7 +530,7 @@ public class MapViewGameState implements GameState
530 530
531 // Render messages 531 // Render messages
532 g.setColor(new Color(53, 63, 62)); 532 g.setColor(new Color(53, 63, 62));
533 g.fillRect(0, VIEWPORT_HEIGHT*TILE_HEIGHT, Main.GAME_WIDTH, TILE_HEIGHT*MESSAGE_HEIGHT); 533 g.fillRect(0, VIEWPORT_HEIGHT*TILE_HEIGHT, Main.CANVAS_WIDTH, TILE_HEIGHT*MESSAGE_HEIGHT);
534 534
535 for (int i=0; i<MESSAGE_HEIGHT; i++) 535 for (int i=0; i<MESSAGE_HEIGHT; i++)
536 { 536 {
@@ -598,11 +598,11 @@ public class MapViewGameState implements GameState
598 { 598 {
599 if (playerx > (VIEWPORT_WIDTH/2)) 599 if (playerx > (VIEWPORT_WIDTH/2))
600 { 600 {
601 if (playerx < (GAME_WIDTH - (VIEWPORT_WIDTH/2-1))) 601 if (playerx < (MAP_WIDTH - (VIEWPORT_WIDTH/2-1)))
602 { 602 {
603 viewportx = playerx - (VIEWPORT_WIDTH/2); 603 viewportx = playerx - (VIEWPORT_WIDTH/2);
604 } else { 604 } else {
605 viewportx = GAME_WIDTH - VIEWPORT_WIDTH; 605 viewportx = MAP_WIDTH - VIEWPORT_WIDTH;
606 } 606 }
607 } else { 607 } else {
608 viewportx = 0; 608 viewportx = 0;
@@ -610,11 +610,11 @@ public class MapViewGameState implements GameState
610 610
611 if (playery > (VIEWPORT_HEIGHT/2)) 611 if (playery > (VIEWPORT_HEIGHT/2))
612 { 612 {
613 if (playery < (GAME_HEIGHT - (VIEWPORT_HEIGHT/2-1))) 613 if (playery < (MAP_HEIGHT - (VIEWPORT_HEIGHT/2-1)))
614 { 614 {
615 viewporty = playery - (VIEWPORT_HEIGHT/2); 615 viewporty = playery - (VIEWPORT_HEIGHT/2);
616 } else { 616 } else {
617 viewporty = GAME_HEIGHT - VIEWPORT_HEIGHT; 617 viewporty = MAP_HEIGHT - VIEWPORT_HEIGHT;
618 } 618 }
619 } else { 619 } else {
620 viewporty = 0; 620 viewporty = 0;
@@ -624,9 +624,9 @@ public class MapViewGameState implements GameState
624 private boolean isValidPosition(int x, int y) 624 private boolean isValidPosition(int x, int y)
625 { 625 {
626 if (x < 0) return false; 626 if (x < 0) return false;
627 if (x > GAME_WIDTH) return false; 627 if (x > MAP_WIDTH) return false;
628 if (y < 0) return false; 628 if (y < 0) return false;
629 if (y > GAME_HEIGHT) return false; 629 if (y > MAP_HEIGHT) return false;
630 630
631 return true; 631 return true;
632 } 632 }