about summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2012-06-04 07:32:00 -0400
committerStarla Insigna <hatkirby@fourisland.com>2012-06-04 07:32:00 -0400
commit48525fb8610a197f7cd479848b6a6abb72bfcf82 (patch)
tree196f9171b85c2771a41a53968a7ba01e1ffee418 /src/com
parente68193a5bacb0f668f09d4a399fbc9c3418d2fa8 (diff)
downloadfrigidearth-48525fb8610a197f7cd479848b6a6abb72bfcf82.tar.gz
frigidearth-48525fb8610a197f7cd479848b6a6abb72bfcf82.tar.bz2
frigidearth-48525fb8610a197f7cd479848b6a6abb72bfcf82.zip
Created key rooms
There are not yet keys in the key rooms, but the rooms are generated in a random extreme of the map and are bordered with windows.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java147
1 files changed, 142 insertions, 5 deletions
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index e0cc8cb..bcac17d 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java
@@ -9,6 +9,7 @@ import com.fourisland.frigidearth.mobs.Rat;
9import java.awt.Color; 9import java.awt.Color;
10import java.awt.Graphics2D; 10import java.awt.Graphics2D;
11import java.awt.Point; 11import java.awt.Point;
12import java.awt.Rectangle;
12import java.awt.event.KeyEvent; 13import java.awt.event.KeyEvent;
13import java.util.ArrayList; 14import java.util.ArrayList;
14import java.util.Collections; 15import java.util.Collections;
@@ -65,7 +66,28 @@ public class MapViewGameState implements GameState
65 } 66 }
66 } 67 }
67 68
68 makeRoom(MAP_WIDTH/2, MAP_HEIGHT/2, Direction.getRandomDirection()); 69 Direction keyRoomDirection = Direction.getRandomDirection();
70 Rectangle legalBounds = null;
71 switch (keyRoomDirection)
72 {
73 case North:
74 legalBounds = new Rectangle(0, 14, MAP_WIDTH, MAP_HEIGHT-14);
75 break;
76
77 case East:
78 legalBounds = new Rectangle(0, 0, MAP_WIDTH-14, MAP_HEIGHT);
79 break;
80
81 case South:
82 legalBounds = new Rectangle(0, 0, MAP_WIDTH, MAP_HEIGHT-14);
83 break;
84
85 case West:
86 legalBounds = new Rectangle(14, 0, MAP_WIDTH-14, MAP_HEIGHT);
87 break;
88 }
89
90 makeRoom(MAP_WIDTH/2, MAP_HEIGHT/2, Direction.getRandomDirection(), legalBounds);
69 91
70 int currentFeatures = 1; 92 int currentFeatures = 1;
71 int objects = 300; 93 int objects = 300;
@@ -140,7 +162,7 @@ public class MapViewGameState implements GameState
140 { 162 {
141 if (Functions.random(0, 100) <= 75) 163 if (Functions.random(0, 100) <= 75)
142 { 164 {
143 if (makeRoom(newx+xmod, newy+ymod, validTile)) 165 if (makeRoom(newx+xmod, newy+ymod, validTile, legalBounds))
144 { 166 {
145 currentFeatures++; 167 currentFeatures++;
146 grid[newx][newy] = Tile.Door; 168 grid[newx][newy] = Tile.Door;
@@ -200,17 +222,132 @@ public class MapViewGameState implements GameState
200 } 222 }
201 } 223 }
202 224
225 // Create key room
226 Room oRoom = null;
227 for (Room r : rooms)
228 {
229 if (oRoom == null)
230 {
231 oRoom = r;
232 } else if ((keyRoomDirection == Direction.North) && (r.getY() < oRoom.getY()))
233 {
234 oRoom = r;
235 } else if ((keyRoomDirection == Direction.East) && (r.getX() > oRoom.getX()))
236 {
237 oRoom = r;
238 } else if ((keyRoomDirection == Direction.South) && (r.getY() > oRoom.getY()))
239 {
240 oRoom = r;
241 } else if ((keyRoomDirection == Direction.West) && (r.getX() < oRoom.getX()))
242 {
243 oRoom = r;
244 }
245 }
246
247 Room room = null;
248 switch (keyRoomDirection)
249 {
250 case North:
251 room = new Room(oRoom.getX()+oRoom.getWidth()/2-3, oRoom.getY()-13, 7, 13, false);
252 break;
253
254 case East:
255 room = new Room(oRoom.getX()+oRoom.getWidth(), oRoom.getY()+oRoom.getHeight()/2-3, 13, 7, false);
256 break;
257
258 case South:
259 room = new Room(oRoom.getX()+oRoom.getWidth()/2-3, oRoom.getY()+oRoom.getHeight(), 7, 13, false);
260 break;
261
262 case West:
263 room = new Room(oRoom.getX()-13, oRoom.getY()+oRoom.getHeight()/2-3, 13, 7, false);
264 break;
265 }
266
267 for (int ytemp=room.getY(); ytemp < room.getY()+room.getHeight(); ytemp++)
268 {
269 for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++)
270 {
271 if (xtemp == room.getX())
272 {
273 if (((keyRoomDirection == Direction.North) || (keyRoomDirection == Direction.South)) && (ytemp % 2 == 0) && (ytemp != room.getY()))
274 {
275 grid[xtemp][ytemp] = Tile.Window;
276 } else {
277 grid[xtemp][ytemp] = Tile.DirtWall;
278 }
279 } else if (xtemp == room.getX()+room.getWidth()-1)
280 {
281 if (((keyRoomDirection == Direction.North) || (keyRoomDirection == Direction.South)) && (ytemp % 2 == 0) && (ytemp != (room.getY()+room.getHeight())))
282 {
283 grid[xtemp][ytemp] = Tile.Window;
284 } else {
285 grid[xtemp][ytemp] = Tile.DirtWall;
286 }
287 } else if (ytemp == room.getY())
288 {
289 if (((keyRoomDirection == Direction.West) || (keyRoomDirection == Direction.East)) && (xtemp % 2 == 0) && (xtemp != room.getX()))
290 {
291 grid[xtemp][ytemp] = Tile.Window;
292 } else {
293 grid[xtemp][ytemp] = Tile.DirtWall;
294 }
295 } else if (ytemp == room.getY()+room.getHeight()-1)
296 {
297 if (((keyRoomDirection == Direction.West) || (keyRoomDirection == Direction.East)) && (xtemp % 2 == 0) && (xtemp != (room.getX()+room.getWidth())))
298 {
299 grid[xtemp][ytemp] = Tile.Window;
300 } else {
301 grid[xtemp][ytemp] = Tile.DirtWall;
302 }
303 } else {
304 grid[xtemp][ytemp] = Tile.DirtFloor;
305 }
306 }
307 }
308
309 switch (keyRoomDirection)
310 {
311 case North:
312 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()] = Tile.Door;
313 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()-1] = Tile.DirtFloor;
314 break;
315
316 case East:
317 grid[room.getX()-1][room.getY()+room.getHeight()/2] = Tile.Door;
318 grid[room.getX()][room.getY()+room.getHeight()/2] = Tile.DirtFloor;
319 break;
320
321 case South:
322 grid[room.getX()+room.getWidth()/2][room.getY()-1] = Tile.Door;
323 grid[room.getX()+room.getWidth()/2][room.getY()] = Tile.DirtFloor;
324 break;
325
326 case West:
327 grid[room.getX()+room.getWidth()][room.getY()+room.getHeight()/2] = Tile.Door;
328 grid[room.getX()+room.getWidth()-1][room.getY()+room.getHeight()/2] = Tile.DirtFloor;
329 break;
330 }
331
203 adjustViewport(); 332 adjustViewport();
204 calculateFieldOfView(); 333 calculateFieldOfView();
205 } 334 }
206 335
207 private boolean makeRoom(int x, int y, Direction direction) 336 private boolean makeRoom(int x, int y, Direction direction, Rectangle legalBounds)
208 { 337 {
209 int width = Functions.random(MIN_ROOM_WIDTH, MAX_ROOM_WIDTH); 338 int width = Functions.random(MIN_ROOM_WIDTH, MAX_ROOM_WIDTH);
210 int height = Functions.random(MIN_ROOM_HEIGHT, MAX_ROOM_HEIGHT); 339 int height = Functions.random(MIN_ROOM_HEIGHT, MAX_ROOM_HEIGHT);
211 Tile floor = Tile.DirtFloor; 340 Tile floor = Tile.DirtFloor;
212 Tile wall = Tile.DirtWall; 341 Tile wall = Tile.DirtWall;
213 Room room = null; 342 Room room = null;
343 Rectangle bounds = null;
344
345 if (legalBounds == null)
346 {
347 bounds = new Rectangle(0, 0, MAP_WIDTH, MAP_HEIGHT);
348 } else {
349 bounds = legalBounds;
350 }
214 351
215 switch (direction) 352 switch (direction)
216 { 353 {
@@ -237,14 +374,14 @@ public class MapViewGameState implements GameState
237 374
238 for (int ytemp=room.getY(); ytemp < room.getY()+room.getHeight(); ytemp++) 375 for (int ytemp=room.getY(); ytemp < room.getY()+room.getHeight(); ytemp++)
239 { 376 {
240 if ((ytemp < 0) || (ytemp > MAP_HEIGHT)) 377 if ((ytemp < bounds.y) || (ytemp > bounds.y+bounds.height ))
241 { 378 {
242 return false; 379 return false;
243 } 380 }
244 381
245 for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++) 382 for (int xtemp=room.getX(); xtemp < room.getX()+room.getWidth(); xtemp++)
246 { 383 {
247 if ((xtemp < 0) || (xtemp > MAP_WIDTH)) 384 if ((xtemp < bounds.x) || (xtemp > bounds.x+bounds.width))
248 { 385 {
249 return false; 386 return false;
250 } 387 }