diff options
Diffstat (limited to 'src/com/fourisland')
| -rw-r--r-- | src/com/fourisland/frigidearth/MapViewGameState.java | 45 | ||||
| -rw-r--r-- | src/com/fourisland/frigidearth/Mob.java | 16 | ||||
| -rw-r--r-- | src/com/fourisland/frigidearth/mobs/Mouse.java | 8 |
3 files changed, 49 insertions, 20 deletions
| diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index c1caab0..86fe437 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java | |||
| @@ -519,9 +519,9 @@ public class MapViewGameState implements GameState | |||
| 519 | // Render mobs | 519 | // Render mobs |
| 520 | for (Mob mob : mobs) | 520 | for (Mob mob : mobs) |
| 521 | { | 521 | { |
| 522 | if ((gridLighting[mob.getX()][mob.getY()]) && (mob.getX() > viewportx) && (mob.getX() < viewportx+VIEWPORT_WIDTH) && (mob.getY() > viewporty) && (mob.getY() < viewporty+VIEWPORT_HEIGHT)) | 522 | if ((gridLighting[mob.x][mob.y]) && (isInViewport(mob.x, mob.y))) |
| 523 | { | 523 | { |
| 524 | g.drawImage(SystemFont.getCharacter(mob.getDisplayCharacter()), (mob.getX()-viewportx)*TILE_WIDTH, (mob.getY()-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | 524 | g.drawImage(SystemFont.getCharacter(mob.getDisplayCharacter()), (mob.x-viewportx)*TILE_WIDTH, (mob.y-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); |
| 525 | } | 525 | } |
| 526 | } | 526 | } |
| 527 | 527 | ||
| @@ -557,8 +557,31 @@ public class MapViewGameState implements GameState | |||
| 557 | 557 | ||
| 558 | if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked())) | 558 | if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked())) |
| 559 | { | 559 | { |
| 560 | playerx = to.x; | 560 | // Check for mobs |
| 561 | playery = to.y; | 561 | boolean foundMob = false; |
| 562 | for (Mob mob : mobs) | ||
| 563 | { | ||
| 564 | if (mob.getPosition().equals(to)) | ||
| 565 | { | ||
| 566 | printMessage("You hit the " + mob.getName().toLowerCase()); | ||
| 567 | mob.health--; | ||
| 568 | |||
| 569 | if (mob.health <= 0) | ||
| 570 | { | ||
| 571 | printMessage("You killed the " + mob.getName().toLowerCase() + "!"); | ||
| 572 | mobs.remove(mob); | ||
| 573 | } | ||
| 574 | |||
| 575 | foundMob = true; | ||
| 576 | break; | ||
| 577 | } | ||
| 578 | } | ||
| 579 | |||
| 580 | if (!foundMob) | ||
| 581 | { | ||
| 582 | playerx = to.x; | ||
| 583 | playery = to.y; | ||
| 584 | } | ||
| 562 | } else { | 585 | } else { |
| 563 | printMessage("Blocked: " + dir.name()); | 586 | printMessage("Blocked: " + dir.name()); |
| 564 | 587 | ||
| @@ -568,8 +591,6 @@ public class MapViewGameState implements GameState | |||
| 568 | break; | 591 | break; |
| 569 | 592 | ||
| 570 | default: | 593 | 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 | |||
| 573 | return; | 594 | return; |
| 574 | } | 595 | } |
| 575 | 596 | ||
| @@ -582,7 +603,7 @@ public class MapViewGameState implements GameState | |||
| 582 | { | 603 | { |
| 583 | toDir = Direction.getRandomDirection(); | 604 | toDir = Direction.getRandomDirection(); |
| 584 | Point to = toDir.to(mob.getPosition()); | 605 | Point to = toDir.to(mob.getPosition()); |
| 585 | if ((isValidPosition(to.x,to.y)) &&(!grid[to.x][to.y].isBlocked())) | 606 | if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked()) && (!to.equals(new Point(playerx, playery)))) |
| 586 | { | 607 | { |
| 587 | mob.moveInDirection(toDir); | 608 | mob.moveInDirection(toDir); |
| 588 | break; | 609 | break; |
| @@ -631,6 +652,16 @@ public class MapViewGameState implements GameState | |||
| 631 | return true; | 652 | return true; |
| 632 | } | 653 | } |
| 633 | 654 | ||
| 655 | private boolean isInViewport(int x, int y) | ||
| 656 | { | ||
| 657 | if (x < viewportx) return false; | ||
| 658 | if (x > viewportx+VIEWPORT_WIDTH) return false; | ||
| 659 | if (y < viewporty) return false; | ||
| 660 | if (y > viewporty+VIEWPORT_HEIGHT) return false; | ||
| 661 | |||
| 662 | return true; | ||
| 663 | } | ||
| 664 | |||
| 634 | private void printMessage(String message) | 665 | private void printMessage(String message) |
| 635 | { | 666 | { |
| 636 | String temp = message; | 667 | String temp = message; |
| diff --git a/src/com/fourisland/frigidearth/Mob.java b/src/com/fourisland/frigidearth/Mob.java index c07e039..fdc7a8a 100644 --- a/src/com/fourisland/frigidearth/Mob.java +++ b/src/com/fourisland/frigidearth/Mob.java | |||
| @@ -12,8 +12,9 @@ import java.awt.Point; | |||
| 12 | */ | 12 | */ |
| 13 | public abstract class Mob | 13 | public abstract class Mob |
| 14 | { | 14 | { |
| 15 | private int x; | 15 | public int x; |
| 16 | private int y; | 16 | public int y; |
| 17 | public int health; | ||
| 17 | 18 | ||
| 18 | public Mob(int x, int y) | 19 | public Mob(int x, int y) |
| 19 | { | 20 | { |
| @@ -21,16 +22,6 @@ public abstract class Mob | |||
| 21 | this.y = y; | 22 | this.y = y; |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | public int getX() | ||
| 25 | { | ||
| 26 | return x; | ||
| 27 | } | ||
| 28 | |||
| 29 | public int getY() | ||
| 30 | { | ||
| 31 | return y; | ||
| 32 | } | ||
| 33 | |||
| 34 | public Point getPosition() | 25 | public Point getPosition() |
| 35 | { | 26 | { |
| 36 | return new Point(x,y); | 27 | return new Point(x,y); |
| @@ -44,4 +35,5 @@ public abstract class Mob | |||
| 44 | } | 35 | } |
| 45 | 36 | ||
| 46 | public abstract char getDisplayCharacter(); | 37 | public abstract char getDisplayCharacter(); |
| 38 | public abstract String getName(); | ||
| 47 | } | 39 | } |
| diff --git a/src/com/fourisland/frigidearth/mobs/Mouse.java b/src/com/fourisland/frigidearth/mobs/Mouse.java index ad5aa60..5fdf7cd 100644 --- a/src/com/fourisland/frigidearth/mobs/Mouse.java +++ b/src/com/fourisland/frigidearth/mobs/Mouse.java | |||
| @@ -15,11 +15,17 @@ public class Mouse extends Mob | |||
| 15 | public Mouse(int x, int y) | 15 | public Mouse(int x, int y) |
| 16 | { | 16 | { |
| 17 | super(x, y); | 17 | super(x, y); |
| 18 | |||
| 19 | health = 1; | ||
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | |||
| 21 | public char getDisplayCharacter() | 22 | public char getDisplayCharacter() |
| 22 | { | 23 | { |
| 23 | return 'm'; | 24 | return 'm'; |
| 24 | } | 25 | } |
| 26 | |||
| 27 | public String getName() | ||
| 28 | { | ||
| 29 | return "Mouse"; | ||
| 30 | } | ||
| 25 | } | 31 | } |
