From df65f21501cf8e3de51d01fee4eab1d488bd568c Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 2 Jun 2012 19:37:27 -0400 Subject: Added basic random dungeon generator and moving viewport --- src/com/fourisland/frigidearth/Main.java | 4 +- .../fourisland/frigidearth/MapViewGameState.java | 168 ++++++++++++++++++--- 2 files changed, 147 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/frigidearth/Main.java b/src/com/fourisland/frigidearth/Main.java index ed35f9c..40a10f7 100644 --- a/src/com/fourisland/frigidearth/Main.java +++ b/src/com/fourisland/frigidearth/Main.java @@ -28,8 +28,8 @@ import javax.swing.JFrame; */ public class Main { - public static final int GAME_WIDTH = 320; - public static final int GAME_HEIGHT = 240; + public static final int GAME_WIDTH = 640; + public static final int GAME_HEIGHT = 480; public static final int FPS = (1000 / 60); // 60 fps private static JFrame mainWindow; diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 2ecaeb1..e8da885 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -5,8 +5,8 @@ package com.fourisland.frigidearth; import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.util.Random; @@ -18,65 +18,171 @@ public class MapViewGameState implements GameState { private final int TILE_WIDTH = 16; private final int TILE_HEIGHT = 16; - private final int GAME_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; - private final int GAME_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT; - private Color[][] grid; + private final int GAME_WIDTH = 100; + private final int GAME_HEIGHT = 100; + private final int VIEWPORT_WIDTH = Main.GAME_WIDTH / TILE_WIDTH; + private final int VIEWPORT_HEIGHT = Main.GAME_HEIGHT / TILE_HEIGHT; + private final int ROOM_MAX_SIZE = 10; + private final int ROOM_MIN_SIZE = 6; + private final int MAX_ROOMS = 30; + private boolean[][] grid; private int playerx = 4; private int playery = 4; + private int viewportx = 0; + private int viewporty = 0; public MapViewGameState() { - Random r = new Random(); - grid = new Color[GAME_WIDTH][GAME_HEIGHT]; + grid = new boolean[GAME_WIDTH][GAME_HEIGHT]; for (int x=0; x 0) + if ((playerx > 0) && (!grid[playerx-1][playery])) { playerx--; } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - if (playerx < GAME_WIDTH - 1) + if ((playerx < GAME_WIDTH - 1) && (!grid[playerx+1][playery])) { playerx++; } } else if (e.getKeyCode() == KeyEvent.VK_UP) { - if (playery > 0) + if ((playery > 0) && (!grid[playerx][playery-1])) { playery--; } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { - if (playery < GAME_HEIGHT - 1) + if ((playery < GAME_HEIGHT - 1) && (!grid[playerx][playery+1])) { playery++; } @@ -84,17 +190,33 @@ public class MapViewGameState implements GameState return; } - Random r = new Random(); + adjustViewport(); + } + + private void adjustViewport() + { + if (playerx > (VIEWPORT_WIDTH/2)) + { + if (playerx < (GAME_WIDTH - (VIEWPORT_WIDTH/2-1))) + { + viewportx = playerx - (VIEWPORT_WIDTH/2); + } else { + viewportx = GAME_WIDTH - VIEWPORT_WIDTH; + } + } else { + viewportx = 0; + } - if (r.nextBoolean()) + if (playery > (VIEWPORT_HEIGHT/2)) { - for (int x=0; x