about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/fourisland/frigidearth/Main.java2
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java98
2 files changed, 77 insertions, 23 deletions
diff --git a/src/com/fourisland/frigidearth/Main.java b/src/com/fourisland/frigidearth/Main.java index 09c0b28..ff81aad 100644 --- a/src/com/fourisland/frigidearth/Main.java +++ b/src/com/fourisland/frigidearth/Main.java
@@ -75,7 +75,7 @@ public class Main extends Canvas
75 75
76 gameCanvas.createBufferStrategy(2); 76 gameCanvas.createBufferStrategy(2);
77 77
78 setGameState(new MapViewGameState()); 78 setGameState(new MapViewGameState(1));
79 } 79 }
80 80
81 public static void setGameState(GameState m_gameState) 81 public static void setGameState(GameState m_gameState)
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 5d21a99..9bee398 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java
@@ -52,9 +52,13 @@ public class MapViewGameState implements GameState
52 private boolean haveKey = false; 52 private boolean haveKey = false;
53 private boolean snowGrow = false; 53 private boolean snowGrow = false;
54 private int heartbeat = 0; 54 private int heartbeat = 0;
55 private int floor;
56 private int spawnTimer = 0;
55 57
56 public MapViewGameState() 58 public MapViewGameState(int floor)
57 { 59 {
60 this.floor = floor;
61
58 grid = new Tile[MAP_WIDTH][MAP_HEIGHT]; 62 grid = new Tile[MAP_WIDTH][MAP_HEIGHT];
59 gridLighting = new boolean[MAP_WIDTH][MAP_HEIGHT]; 63 gridLighting = new boolean[MAP_WIDTH][MAP_HEIGHT];
60 64
@@ -352,8 +356,6 @@ public class MapViewGameState implements GameState
352 { 356 {
353 int width = Functions.random(MIN_ROOM_WIDTH, MAX_ROOM_WIDTH); 357 int width = Functions.random(MIN_ROOM_WIDTH, MAX_ROOM_WIDTH);
354 int height = Functions.random(MIN_ROOM_HEIGHT, MAX_ROOM_HEIGHT); 358 int height = Functions.random(MIN_ROOM_HEIGHT, MAX_ROOM_HEIGHT);
355 Tile floor = Tile.DirtFloor;
356 Tile wall = Tile.DirtWall;
357 Room room = null; 359 Room room = null;
358 Rectangle bounds = null; 360 Rectangle bounds = null;
359 361
@@ -414,34 +416,35 @@ public class MapViewGameState implements GameState
414 { 416 {
415 if (xtemp == room.getX()) 417 if (xtemp == room.getX())
416 { 418 {
417 grid[xtemp][ytemp] = wall; 419 grid[xtemp][ytemp] = Tile.DirtWall;
418 } else if (xtemp == room.getX()+room.getWidth()-1) 420 } else if (xtemp == room.getX()+room.getWidth()-1)
419 { 421 {
420 grid[xtemp][ytemp] = wall; 422 grid[xtemp][ytemp] = Tile.DirtWall;
421 } else if (ytemp == room.getY()) 423 } else if (ytemp == room.getY())
422 { 424 {
423 grid[xtemp][ytemp] = wall; 425 grid[xtemp][ytemp] = Tile.DirtWall;
424 } else if (ytemp == room.getY()+room.getHeight()-1) 426 } else if (ytemp == room.getY()+room.getHeight()-1)
425 { 427 {
426 grid[xtemp][ytemp] = wall; 428 grid[xtemp][ytemp] = Tile.DirtWall;
427 } else { 429 } else {
428 grid[xtemp][ytemp] = floor; 430 grid[xtemp][ytemp] = Tile.DirtFloor;
429 } 431 }
430 } 432 }
431 } 433 }
432 434
433 rooms.add(room); 435 rooms.add(room);
434 436
435 // Place mice in random rooms because yolo 437 // Spawn some random monsters
436 int random = Functions.random(0,100); 438 int perf = 60;
437 if (random < 25) 439 for (;;)
438 { 440 {
439 Mob mob = new Mouse(Functions.random(room.getX()+1, room.getX()+room.getWidth()-2), Functions.random(room.getY()+1, room.getY()+room.getHeight()-2)); 441 if (Functions.random(0, 100) < perf)
440 mobs.add(mob); 442 {
441 } else if (random < 50) 443 perf /= 2;
442 { 444 mobs.add(createInDepthMonster(room));
443 Mob mob = new Rat(Functions.random(room.getX()+1, room.getX()+room.getWidth()-2), Functions.random(room.getY()+1, room.getY()+room.getHeight()-2)); 445 } else {
444 mobs.add(mob); 446 break;
447 }
445 } 448 }
446 449
447 return true; 450 return true;
@@ -450,7 +453,6 @@ public class MapViewGameState implements GameState
450 private boolean makeCorridor(int x, int y, Direction direction) 453 private boolean makeCorridor(int x, int y, Direction direction)
451 { 454 {
452 int length = Functions.random(MIN_CORRIDOR_LENGTH, MAX_CORRIDOR_LENGTH); 455 int length = Functions.random(MIN_CORRIDOR_LENGTH, MAX_CORRIDOR_LENGTH);
453 Tile floor = Tile.Corridor;
454 456
455 int xtemp = 0; 457 int xtemp = 0;
456 int ytemp = 0; 458 int ytemp = 0;
@@ -480,7 +482,7 @@ public class MapViewGameState implements GameState
480 482
481 for (ytemp = y; ytemp > (y-length); ytemp--) 483 for (ytemp = y; ytemp > (y-length); ytemp--)
482 { 484 {
483 grid[xtemp][ytemp] = floor; 485 grid[xtemp][ytemp] = Tile.Corridor;
484 } 486 }
485 487
486 break; 488 break;
@@ -508,7 +510,7 @@ public class MapViewGameState implements GameState
508 510
509 for (xtemp = x; xtemp < (x+length); xtemp++) 511 for (xtemp = x; xtemp < (x+length); xtemp++)
510 { 512 {
511 grid[xtemp][ytemp] = floor; 513 grid[xtemp][ytemp] = Tile.Corridor;
512 } 514 }
513 515
514 break; 516 break;
@@ -536,7 +538,7 @@ public class MapViewGameState implements GameState
536 538
537 for (ytemp = y; ytemp < (y+length); ytemp++) 539 for (ytemp = y; ytemp < (y+length); ytemp++)
538 { 540 {
539 grid[xtemp][ytemp] = floor; 541 grid[xtemp][ytemp] = Tile.Corridor;
540 } 542 }
541 543
542 break; 544 break;
@@ -564,7 +566,7 @@ public class MapViewGameState implements GameState
564 566
565 for (xtemp = x; xtemp > (x-length); xtemp--) 567 for (xtemp = x; xtemp > (x-length); xtemp--)
566 { 568 {
567 grid[xtemp][ytemp] = floor; 569 grid[xtemp][ytemp] = Tile.Corridor;
568 } 570 }
569 571
570 break; 572 break;
@@ -744,6 +746,7 @@ public class MapViewGameState implements GameState
744 746
745 public void processInput(KeyEvent e) 747 public void processInput(KeyEvent e)
746 { 748 {
749 // Handle input
747 switch (e.getKeyCode()) 750 switch (e.getKeyCode())
748 { 751 {
749 case KeyEvent.VK_LEFT: 752 case KeyEvent.VK_LEFT:
@@ -916,9 +919,29 @@ public class MapViewGameState implements GameState
916 heartbeat++; 919 heartbeat++;
917 if (heartbeat == 4) heartbeat = 0; 920 if (heartbeat == 4) heartbeat = 0;
918 921
922 // Spawn mobs
923 if (spawnTimer == 10)
924 {
925 spawnTimer = 0;
926
927 Room r = rooms.get(Functions.random(0, rooms.size()-1));
928 if (r.canGenerateMonsters())
929 {
930 Mob m = createInDepthMonster(r);
931 if (!gridLighting[m.x][m.y])
932 {
933 mobs.add(m);
934 }
935 }
936 } else {
937 spawnTimer++;
938 }
939
940 // Do viewport stuff
919 adjustViewport(); 941 adjustViewport();
920 calculateFieldOfView(); 942 calculateFieldOfView();
921 943
944 // Handle death
922 if (health <= 0) 945 if (health <= 0)
923 { 946 {
924 printMessage("You have died! Press [ENTER] to quit."); 947 printMessage("You have died! Press [ENTER] to quit.");
@@ -1184,4 +1207,35 @@ public class MapViewGameState implements GameState
1184 1207
1185 return null; 1208 return null;
1186 } 1209 }
1210
1211 private Mob createInDepthMonster(Room r)
1212 {
1213 int x = Functions.random(r.getX()+1, r.getX()+r.getWidth()-2);
1214 int y = Functions.random(r.getY()+1, r.getY()+r.getHeight()-2);
1215
1216 List<Class> mobTypes = new ArrayList<Class>();
1217 switch (floor)
1218 {
1219 case 10:
1220 case 9:
1221 case 8:
1222 case 7:
1223 case 6:
1224 case 5:
1225 case 4:
1226 case 3:
1227 case 2:
1228 case 1:
1229 mobTypes.add(Mouse.class);
1230 mobTypes.add(Rat.class);
1231 }
1232
1233 try
1234 {
1235 return (Mob) mobTypes.get(Functions.random(0, mobTypes.size()-1)).getConstructor(int.class, int.class).newInstance(x, y);
1236 } catch (Exception ex)
1237 {
1238 return null;
1239 }
1240 }
1187} 1241}