diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2012-06-03 15:24:13 -0400 |
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2012-06-03 15:24:13 -0400 |
| commit | a87eb8f0548206c0c9a7ff180774d48b97447418 (patch) | |
| tree | aac57019771e61098a17c1019ab6e5d5e1d02709 /src/com | |
| parent | 4847dc7cafaeceeb73be22d2d4b37fa25a8d90fd (diff) | |
| download | frigidearth-a87eb8f0548206c0c9a7ff180774d48b97447418.tar.gz frigidearth-a87eb8f0548206c0c9a7ff180774d48b97447418.tar.bz2 frigidearth-a87eb8f0548206c0c9a7ff180774d48b97447418.zip | |
Added message window
Diffstat (limited to 'src/com')
| -rw-r--r-- | src/com/fourisland/frigidearth/MapViewGameState.java | 55 |
1 files changed, 54 insertions, 1 deletions
| diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index e038d41..3b2cce2 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java | |||
| @@ -22,8 +22,9 @@ public class MapViewGameState implements GameState | |||
| 22 | private final int TILE_HEIGHT = 16; | 22 | private final int TILE_HEIGHT = 16; |
| 23 | private final int GAME_WIDTH = 100; | 23 | private final int GAME_WIDTH = 100; |
| 24 | private final int GAME_HEIGHT = 100; | 24 | private final int GAME_HEIGHT = 100; |
| 25 | private final int MESSAGE_HEIGHT = 5; | ||
| 25 | private final int VIEWPORT_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; | 26 | private final int VIEWPORT_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; |
| 26 | private final int VIEWPORT_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT; | 27 | private final int VIEWPORT_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT - MESSAGE_HEIGHT; |
| 27 | private final int MAX_ROOM_WIDTH = 13; | 28 | private final int MAX_ROOM_WIDTH = 13; |
| 28 | private final int MIN_ROOM_WIDTH = 7; | 29 | private final int MIN_ROOM_WIDTH = 7; |
| 29 | private final int MAX_ROOM_HEIGHT = 13; | 30 | private final int MAX_ROOM_HEIGHT = 13; |
| @@ -33,6 +34,7 @@ public class MapViewGameState implements GameState | |||
| 33 | private final int[][] OCTET_MULTIPLIERS = new int[][] {new int[] {1,0,0,-1,-1,0,0,1}, new int[] {0,1,-1,0,0,-1,1,0}, new int[] {0,1,1,0,0,-1,-1,0}, new int[] {1,0,0,1,-1,0,0,-1}}; | 34 | private final int[][] OCTET_MULTIPLIERS = new int[][] {new int[] {1,0,0,-1,-1,0,0,1}, new int[] {0,1,-1,0,0,-1,1,0}, new int[] {0,1,1,0,0,-1,-1,0}, new int[] {1,0,0,1,-1,0,0,-1}}; |
| 34 | private Tile[][] grid; | 35 | private Tile[][] grid; |
| 35 | private boolean[][] gridLighting; | 36 | private boolean[][] gridLighting; |
| 37 | private String[] messages = new String[MESSAGE_HEIGHT]; | ||
| 36 | private List<Room> rooms = new ArrayList<Room>(); | 38 | private List<Room> rooms = new ArrayList<Room>(); |
| 37 | private List<Mob> mobs = new ArrayList<Mob>(); | 39 | private List<Mob> mobs = new ArrayList<Mob>(); |
| 38 | private int playerx = 4; | 40 | private int playerx = 4; |
| @@ -525,6 +527,21 @@ public class MapViewGameState implements GameState | |||
| 525 | 527 | ||
| 526 | // Render player | 528 | // Render player |
| 527 | g.drawImage(SystemFont.getCharacter('@'), (playerx-viewportx)*TILE_WIDTH, (playery-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | 529 | g.drawImage(SystemFont.getCharacter('@'), (playerx-viewportx)*TILE_WIDTH, (playery-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); |
| 530 | |||
| 531 | // Render messages | ||
| 532 | g.setColor(new Color(53, 63, 62)); | ||
| 533 | g.fillRect(0, VIEWPORT_HEIGHT*TILE_HEIGHT, Main.GAME_WIDTH, TILE_HEIGHT*MESSAGE_HEIGHT); | ||
| 534 | |||
| 535 | for (int i=0; i<MESSAGE_HEIGHT; i++) | ||
| 536 | { | ||
| 537 | if (messages[i] != null) | ||
| 538 | { | ||
| 539 | for (int j=0; j<messages[i].length(); j++) | ||
| 540 | { | ||
| 541 | g.drawImage(SystemFont.getCharacter(messages[i].charAt(j)), j*TILE_WIDTH, (VIEWPORT_HEIGHT+i)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | ||
| 542 | } | ||
| 543 | } | ||
| 544 | } | ||
| 528 | } | 545 | } |
| 529 | 546 | ||
| 530 | public void processInput(KeyEvent e) | 547 | public void processInput(KeyEvent e) |
| @@ -543,12 +560,16 @@ public class MapViewGameState implements GameState | |||
| 543 | playerx = to.x; | 560 | playerx = to.x; |
| 544 | playery = to.y; | 561 | playery = to.y; |
| 545 | } else { | 562 | } else { |
| 563 | printMessage("Blocked: " + dir.name()); | ||
| 564 | |||
| 546 | return; | 565 | return; |
| 547 | } | 566 | } |
| 548 | 567 | ||
| 549 | break; | 568 | break; |
| 550 | 569 | ||
| 551 | default: | 570 | default: |
| 571 | printMessage("The sky is the limit! You can also place items in the same manner, but we'll get to that later."); | ||
| 572 | |||
| 552 | return; | 573 | return; |
| 553 | } | 574 | } |
| 554 | 575 | ||
| @@ -609,4 +630,36 @@ public class MapViewGameState implements GameState | |||
| 609 | 630 | ||
| 610 | return true; | 631 | return true; |
| 611 | } | 632 | } |
| 633 | |||
| 634 | private void printMessage(String message) | ||
| 635 | { | ||
| 636 | String temp = message; | ||
| 637 | |||
| 638 | while (temp.length() > VIEWPORT_WIDTH) | ||
| 639 | { | ||
| 640 | String shortm = temp.substring(0, VIEWPORT_WIDTH); | ||
| 641 | |||
| 642 | if ((temp.charAt(VIEWPORT_WIDTH) == ' ') || (shortm.endsWith(" "))) | ||
| 643 | { | ||
| 644 | pushUpMessages(shortm); | ||
| 645 | temp = temp.substring(VIEWPORT_WIDTH); | ||
| 646 | } else { | ||
| 647 | int lastSpace = shortm.lastIndexOf(" "); | ||
| 648 | pushUpMessages(shortm.substring(0, lastSpace)); | ||
| 649 | temp = temp.substring(lastSpace); | ||
| 650 | } | ||
| 651 | } | ||
| 652 | |||
| 653 | pushUpMessages(temp); | ||
| 654 | } | ||
| 655 | |||
| 656 | private void pushUpMessages(String message) | ||
| 657 | { | ||
| 658 | for (int i=1; i<MESSAGE_HEIGHT; i++) | ||
| 659 | { | ||
| 660 | messages[i-1] = messages[i]; | ||
| 661 | } | ||
| 662 | |||
| 663 | messages[MESSAGE_HEIGHT-1] = message; | ||
| 664 | } | ||
| 612 | } | 665 | } |
