Changeset 8edd04e in lost-haven for main


Ignore:
Timestamp:
Jun 7, 2020, 3:04:32 PM (4 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
master
Children:
a49176d
Parents:
155577b
Message:

Make the decompiled game code compile successfully

Location:
main
Files:
31 added
17 edited

Legend:

Unmodified
Added
Removed
  • main/AuxState.java

    r155577b r8edd04e  
    22
    33public enum AuxState {
    4     None,
    5     MsgBox
     4  None,
     5  MsgBox
    66}
  • main/Creature.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.awt.image.*;
    4 
    5 public class Creature {
    6         private String name;
    7         private CreatureType type;
    8         private BufferedImage img;
    9         private Gender gender;
    10         private int level;
    11         private Point loc;
    12         private int speed;
    13         private long lastMoved;
    14         private int attackSpeed;
    15         private int damage;
    16         private long lastAttacked;
    17         private int strength;
    18         private int dexterity;
    19         private int constitution;
    20         private int charisma;
    21         private int wisdom;
    22         private int intelligence;
    23         private int hitpoints;
    24         private int manapoints;
    25         private int maxHitpoints;
    26         private int maxManapoints;
    27        
    28         public Creature() {
    29                 name = "";
    30                 gender = Gender.None;
    31                 loc = new Point(0, 0);
    32         }
    33 
    34         public Creature(String name) {
    35                 this.name = name;
    36                 loc = new Point(0, 0);
    37         }
    38        
    39         public Creature(String name, Gender gender) {
    40                 this.name = name;
    41                 this.gender = gender;
    42                 loc = new Point(0, 0);
    43         }
    44        
    45         public int getAttackSpeed() {
    46                 return attackSpeed;
    47         }
    48 
    49         public int getCharisma() {
    50                 return charisma;
    51         }
    52 
    53         public int getConstitution() {
    54                 return constitution;
    55         }
    56 
    57         public int getDamage() {
    58                 return damage;
    59         }
    60 
    61         public int getDexterity() {
    62                 return dexterity;
    63         }
    64 
    65         public Gender getGender() {
    66                 return gender;
    67         }
    68 
    69         public int getHitpoints() {
    70                 return hitpoints;
    71         }
    72        
    73         public BufferedImage getImg() {
    74                 return img;
    75         }
    76 
    77         public int getIntelligence() {
    78                 return intelligence;
    79         }
    80 
    81         public long getLastAttacked() {
    82                 return lastAttacked;
    83         }
    84 
    85         public long getLastMoved() {
    86                 return lastMoved;
    87         }
    88 
    89         public int getLevel() {
    90                 return level;
    91         }
    92 
    93         public Point getLoc() {
    94                 return loc;
    95         }
    96 
    97         public int getManapoints() {
    98                 return manapoints;
    99         }
    100 
    101         public int getMaxHitpoints() {
    102                 return maxHitpoints;
    103         }
    104 
    105         public int getMaxManapoints() {
    106                 return maxManapoints;
    107         }
    108 
    109         public String getName() {
    110                 return name;
    111         }
    112 
    113         public int getSpeed() {
    114                 return speed;
    115         }
    116 
    117         public int getStrength() {
    118                 return strength;
    119         }
    120        
    121         public CreatureType getType() {
    122                 return type;
    123         }
    124 
    125         public int getWisdom() {
    126                 return wisdom;
    127         }
    128 
    129         public void setAttackSpeed(int attackSpeed) {
    130                 this.attackSpeed = attackSpeed;
    131         }
    132 
    133         public void setCharisma(int charisma) {
    134                 this.charisma = charisma;
    135         }
    136 
    137         public void setConstitution(int constitution) {
    138                 this.constitution = constitution;
    139         }
    140 
    141         public void setDamage(int damage) {
    142                 this.damage = damage;
    143         }
    144 
    145         public void setDexterity(int dexterity) {
    146                 this.dexterity = dexterity;
    147         }
    148 
    149         public void setGender(Gender gender) {
    150                 this.gender = gender;
    151         }
    152 
    153         public void setHitpoints(int hitpoints) {
    154                 this.hitpoints = hitpoints;
    155         }
    156        
    157         public void setImg(BufferedImage img) {
    158                 this.img = img;
    159         }
    160  
    161         public void setIntelligence(int intelligence) {
    162                 this.intelligence = intelligence;
    163         }
    164 
    165         public void setLastAttacked(long lastAttacked) {
    166                 this.lastAttacked = lastAttacked;
    167         }
    168 
    169         public void setLastMoved(long lastMoved) {
    170                 this.lastMoved = lastMoved;
    171         }
    172 
    173         public void setLevel(int level) {
    174                 this.level = level;
    175         }
    176 
    177         public void setLoc(Point loc) {
    178                 this.loc = loc;
    179         }
    180 
    181         public void setManapoints(int manapoints) {
    182                 this.manapoints = manapoints;
    183         }
    184 
    185         public void setMaxHitpoints(int maxHitpoints) {
    186                 this.maxHitpoints = maxHitpoints;
    187         }
    188 
    189         public void setMaxManapoints(int maxManapoints) {
    190                 this.maxManapoints = maxManapoints;
    191         }
    192 
    193         public void setName(String name) {
    194                 this.name = name;
    195         }
    196 
    197         public void setSpeed(int speed) {
    198                 this.speed = speed;
    199         }
    200 
    201         public void setStrength(int strength) {
    202                 this.strength = strength;
    203         }
    204        
    205         public void setType(CreatureType type) {
    206                 this.type = type;
    207         }
    208 
    209         public void setWisdom(int wisdom) {
    210                 this.wisdom = wisdom;
    211         }
    212        
    213         public String toString() {
    214                 return name;
    215         }
    216        
    217         public boolean equals(Object c) {
    218                 return name.trim().equals(((Creature)c).name.trim());
    219         }
     3import java.awt.*;
     4import java.awt.image.BufferedImage;
     5import java.io.*;
     6import java.util.*;
     7import javax.imageio.ImageIO;
     8
     9import gamegui.Animation;
     10
     11public class Creature implements Comparable<Creature> {
     12
     13  public int passive;
     14  public int thorns;
     15  public int confused;
     16  public int sand;
     17
     18  protected String name;
     19  protected CreatureType type;
     20  protected Model model;
     21  protected int level;
     22  protected Point loc;
     23  protected int[] attributes; 
     24  protected int hitpoints;
     25  protected int manapoints;
     26  protected int maxHitpoints;
     27  protected int maxManapoints;
     28  protected int experience;
     29  protected EquippedWeapon weapon;
     30  protected EquippedWeapon spell;
     31
     32  private Point target;
     33  private Creature enemyTarget;
     34  private int speed;
     35  private long lastMoved;
     36  private long lastAttacked;
     37  private LinkedList<ItemDrop> drops;
     38  private LinkedList<EffectTimer> effectTimers;
     39  private boolean disabled;
     40  private SpawnPoint spawnPoint;
     41  private boolean dying;
     42
     43  public Creature() {
     44    this.name = "";
     45    this.loc = new Point(0, 0);
     46    this.target = this.loc;
     47    this.attributes = new int[4];
     48    this.experience = 0;
     49    this.weapon = null;
     50    this.spell = null;
     51    this.drops = new LinkedList<ItemDrop>();
     52    this.effectTimers = new LinkedList<EffectTimer>();
     53    this.disabled = false;
     54    this.spawnPoint = null;
     55    this.passive = 0;
     56    this.thorns = 0;
     57    this.confused = 0;
     58    this.sand = 0;
     59    this.dying = false;
     60  }
     61
     62  public Creature(String name, CreatureType type) {
     63    this.name = name;
     64    this.type = type;
     65    this.loc = new Point(0, 0);
     66    this.target = this.loc;
     67    this.attributes = new int[4];
     68    this.experience = 0;
     69    this.weapon = null;
     70    this.spell = null;
     71    this.drops = new LinkedList<ItemDrop>();
     72    this.effectTimers = new LinkedList<EffectTimer>();
     73    this.disabled = false;
     74    this.spawnPoint = null;
     75    this.passive = 0;
     76    this.thorns = 0;
     77    this.confused = 0;
     78    this.sand = 0;
     79    this.dying = false;
     80  }
     81
     82  public Creature(Creature cr) {
     83    this.name = cr.name;
     84    this.type = cr.type;
     85    this.model = new Model(cr.model);
     86    this.level = cr.level;
     87    this.loc = new Point(cr.loc);
     88    this.target = cr.target;
     89    this.speed = cr.speed;
     90    this.lastMoved = cr.lastMoved;
     91    this.lastAttacked = cr.lastAttacked;
     92    this.attributes = (int[])cr.attributes.clone();
     93    this.hitpoints = cr.hitpoints;
     94    this.manapoints = cr.manapoints;
     95    this.maxHitpoints = cr.maxHitpoints;
     96    this.maxManapoints = cr.maxManapoints;
     97    this.experience = cr.experience;
     98    this.weapon = cr.weapon.copy((Point)null);
     99    if (cr.spell != null)
     100      this.spell = cr.spell.copy((Point)null);
     101    this.drops = cr.drops;
     102    this.effectTimers = new LinkedList<EffectTimer>(cr.effectTimers);
     103    this.disabled = cr.disabled;
     104    this.spawnPoint = null;
     105    this.passive = cr.passive;
     106    this.thorns = cr.thorns;
     107    this.confused = cr.confused;
     108    this.sand = cr.sand;
     109    this.dying = cr.dying;
     110  }
     111
     112  public Creature copy() {
     113    return new Creature(this);
     114  }
     115
     116  public void setDying(boolean dying) {
     117    if (!this.model.hasDeath())
     118      return;
     119    if (dying) {
     120      this.model.setAction(Action.Dying);
     121    } else {
     122      this.model.getAnimation(Direction.West, Action.Dying).reset();
     123    }
     124    this.dying = dying;
     125  }
     126
     127  public boolean isDying() {
     128    return this.dying;
     129  }
     130
     131  public void checkTimedEffects() {
     132    Iterator<EffectTimer> iter = this.effectTimers.iterator();
     133    while (iter.hasNext()) {
     134      EffectTimer cur = iter.next();
     135      if (cur.expired()) {
     136        cur.getEffect().cancelEffect(this);
     137        iter.remove();
     138      }
     139    }
     140  }
     141
     142  public void addEffect(TimedEffect e) {
     143    this.effectTimers.add(new EffectTimer(e, e.getDuration()));
     144  }
     145
     146  public Point move() {
     147    Point newLoc;
     148    double dist = (this.speed * (System.currentTimeMillis() - this.lastMoved) / 1000L);
     149    if (this.lastMoved == 0L) {
     150      dist = 0.0D;
     151    }
     152    if (this.enemyTarget != null) {
     153      this.target = this.enemyTarget.loc;
     154    }
     155    this.lastMoved = System.currentTimeMillis();
     156    if (Point.dist(this.loc, this.target) <= dist) {
     157      newLoc = this.target;
     158      if (this.model.getAction() != Action.Attacking) {
     159        this.model.setAction(Action.Standing);
     160      }
     161    } else {
     162      if (this.model.getAction() != Action.Attacking) {
     163        this.model.setAction(Action.Walking);
     164      }
     165      int xDif = (int)(Point.xDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target));
     166      int yDif = (int)(Point.yDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target));
     167      newLoc = new Point(this.loc.getX(), this.loc.getXMin() + xDif, this.loc.getY(), this.loc.getYMin() + yDif);
     168      newLoc.setX(newLoc.getX() + newLoc.getXMin() / 100);
     169      newLoc.setXMin(newLoc.getXMin() % 100);
     170      newLoc.setY(newLoc.getY() + newLoc.getYMin() / 100);
     171      newLoc.setYMin(newLoc.getYMin() % 100);
     172      if (newLoc.getXMin() < 0) {
     173        newLoc.setX(newLoc.getX() - 1);
     174        newLoc.setXMin(newLoc.getXMin() + 100);
     175      } else if (newLoc.getYMin() < 0) {
     176        newLoc.setY(newLoc.getY() - 1);
     177        newLoc.setYMin(newLoc.getYMin() + 100);
     178      }
     179      this.model.setDirection(calcDirection());
     180    }
     181    return newLoc;
     182  }
     183
     184  private Direction calcDirection() {
     185    Direction dir;
     186    int xDif2 = Point.xDif(this.loc, this.target);
     187    int yDif2 = Point.yDif(this.target, this.loc);
     188    double angle = 1.5707963267948966D;
     189    if (xDif2 == 0) {
     190      if (yDif2 != 0) {
     191        angle *= Math.abs(yDif2 / yDif2);
     192      }
     193    } else {
     194      angle = Math.atan(yDif2 / xDif2);
     195    }
     196    if (angle >= 0.7853981633974483D) {
     197      dir = Direction.North;
     198    } else if (-0.7853981633974483D <= angle && angle <= 0.7853981633974483D) {
     199      dir = Direction.East;
     200    } else {
     201      dir = Direction.South;
     202    }
     203    if (xDif2 < 0)
     204      switch (dir) {
     205        case North:
     206          dir = Direction.South;
     207          break;
     208        case South:
     209          dir = Direction.North;
     210          break;
     211        case East:
     212          dir = Direction.West;
     213          break;
     214      }
     215    return dir;
     216  }
     217
     218  public Projectile attack(Creature enemy, AttackType attType) {
     219    Weapon weap = selectWeapon(attType);
     220    if (System.currentTimeMillis() - this.lastAttacked >= (weap.getAttackSpeed() * 100) && !this.disabled) {
     221      this.lastAttacked = System.currentTimeMillis();
     222      Point oldTarget = this.target;
     223      this.target = enemy.getLoc();
     224      this.model.setDirection(calcDirection());
     225      this.target = oldTarget;
     226      if (attType != AttackType.Spell) {
     227        this.model.setAction(Action.Attacking);
     228        this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset();
     229      }
     230      if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) {
     231        Point loc = new Point(this.loc);
     232        loc.setY(loc.getY() - 55);
     233        return weap.spawnProjectile(loc, enemy.getLoc());
     234      }
     235      weap.applyContactEffects(enemy);
     236    }
     237    return null;
     238  }
     239
     240  public Projectile attack(Point targ, AttackType attType) {
     241    Weapon weap = selectWeapon(attType);
     242    if ((System.currentTimeMillis() - this.lastAttacked) / 100L >= weap.getAttackSpeed() && !this.disabled) {
     243      this.lastAttacked = System.currentTimeMillis();
     244      Point oldTarget = this.target;
     245      this.target = targ;
     246      this.model.setDirection(calcDirection());
     247      this.target = oldTarget;
     248      if (attType != AttackType.Spell) {
     249        this.model.setAction(Action.Attacking);
     250        this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset();
     251      }
     252      if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) {
     253        Point loc = new Point(this.loc);
     254        loc.setY(loc.getY() - 30);
     255        return weap.spawnProjectile(loc, targ);
     256      }
     257    }
     258    return null;
     259  }
     260
     261  private Weapon selectWeapon(AttackType attType) {
     262    switch (attType) {
     263      case Weapon:
     264        return this.weapon;
     265      case Spell:
     266        return this.spell;
     267    }
     268    return this.weapon;
     269  }
     270
     271  public void addDrop(ItemDrop item) {
     272    this.drops.add(item);
     273  }
     274
     275  public LinkedList<ItemDrop> getDrops() {
     276    return this.drops;
     277  }
     278
     279  public LinkedList<Item> spawnDrops() {
     280    LinkedList<Item> newDrops = new LinkedList<Item>();
     281    Iterator<ItemDrop> iter = this.drops.iterator();
     282    Random gen = new Random();
     283    while (iter.hasNext()) {
     284      ItemDrop cur = iter.next();
     285      if (gen.nextDouble() <= cur.getDropChance()) {
     286        newDrops.add(cur.getItem());
     287      }
     288    }
     289    return newDrops;
     290  }
     291
     292  public void draw(Graphics g, int playerX, int playerY) {
     293    if (this.passive > 0) {
     294      g.drawImage(LostHavenRPG.passiveAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
     295    }
     296    if (this.thorns > 0) {
     297      g.drawImage(LostHavenRPG.thornsAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
     298    }
     299    this.model.draw(g, 400 + this.loc.getX() - playerX, 300 + this.loc.getY() - playerY);
     300    if (this.confused > 0) {
     301      g.drawImage(LostHavenRPG.confuseAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
     302    }
     303    if (this.sand > 0) {
     304      g.drawImage(LostHavenRPG.sandAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
     305    }
     306    g.setColor(Color.red);
     307    g.fillRect(360 + this.loc.getX() - playerX, 290 - this.model.getHeight() + this.loc.getY() - playerY, 80 * this.hitpoints / this.maxHitpoints, 10);
     308    g.setColor(Color.black);
     309    Font font12 = new Font("Arial", 0, 12);
     310    FontMetrics metrics = g.getFontMetrics(font12);
     311    g.setFont(font12);
     312    g.drawString(this.name, 400 + this.loc.getX() - playerX - metrics.stringWidth(this.name) / 2, 300 - this.model.getHeight() + this.loc.getY() - playerY);
     313  }
     314
     315  public void save(PrintWriter out) {
     316    out.println(this.type);
     317    if (this.spawnPoint == null) {
     318      out.println(-1);
     319    } else {
     320      out.println(this.spawnPoint.idNum);
     321    }
     322    out.println(String.valueOf(this.loc.getX()) + "," + this.loc.getY());
     323    out.println(this.model.getDirection());
     324    out.println(this.model.getAction());
     325    out.println(this.hitpoints);
     326    out.println(this.manapoints);
     327    out.println(this.passive);
     328    out.println(this.thorns);
     329    out.println(this.confused);
     330    out.println(this.sand);
     331    if (this.weapon == null) {
     332      out.println("None");
     333    } else {
     334      out.println(this.weapon.getName());
     335    }
     336  }
     337
     338  public static Creature loadTemplate(BufferedReader in) {
     339    Creature cr = new Creature();
     340    BufferedImage[] imgProj = new BufferedImage[8];
     341    try {
     342      cr.name = in.readLine();
     343      cr.type = CreatureType.valueOf(cr.name);
     344      if (cr.type == CreatureType.Player) {
     345        cr = Player.loadTemplate(in);
     346      }
     347      cr.setSpeed(Integer.parseInt(in.readLine()));
     348      cr.setAttribute(Attribute.Strength, Integer.parseInt(in.readLine()));
     349      cr.setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine()));
     350      cr.setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine()));
     351      cr.setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine()));
     352      ItemType wType = ItemType.valueOf(in.readLine());
     353      if (wType == ItemType.RangedWeapon) {
     354        imgProj = LostHavenRPG.imgBow;
     355      } else if (wType == ItemType.Spell) {
     356        imgProj[0] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     357        imgProj[1] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     358        imgProj[2] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     359        imgProj[3] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     360        imgProj[4] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     361        imgProj[5] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     362        imgProj[6] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     363        imgProj[7] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
     364      }
     365      cr.model = cr.loadModel(cr.type.toString());
     366      cr.setWeapon(new Weapon("None", wType, "Dagger.png", imgProj, 10, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine())));
     367      cr.setExperience(Integer.parseInt(in.readLine()));
     368    } catch (IOException ioe) {
     369      ioe.printStackTrace();
     370    }
     371    return cr;
     372  }
     373
     374  public Model loadModel(String folder) {
     375    boolean noAnims = false;
     376    Animation anmStandN = new Animation("north", 0, 0, 40, 60, 300, true);
     377    Animation anmStandS = new Animation("south", 0, 0, 40, 60, 300, true);
     378    Animation anmStandE = new Animation("east", 0, 0, 40, 60, 300, true);
     379    Animation anmStandW = new Animation("west", 0, 0, 40, 60, 300, true);
     380    Animation anmWalkN = new Animation("north", 0, 0, 40, 60, 300, true);
     381    Animation anmWalkS = new Animation("south", 0, 0, 40, 60, 300, true);
     382    Animation anmWalkE = new Animation("east", 0, 0, 40, 60, 300, true);
     383    Animation anmWalkW = new Animation("west", 0, 0, 40, 60, 300, true);
     384    Animation anmAttackN = new Animation("north", 0, 0, 40, 60, 500, false);
     385    Animation anmAttackS = new Animation("south", 0, 0, 40, 60, 500, false);
     386    Animation anmAttackE = new Animation("east", 0, 0, 40, 60, 500, false);
     387    Animation anmAttackW = new Animation("west", 0, 0, 40, 60, 500, false);
     388    Animation anmDeath = new Animation("west", 0, 0, 40, 60, 1000, false);
     389    BufferedImage walkN = null;
     390    BufferedImage walkS = null;
     391    BufferedImage walkE = null;
     392    BufferedImage walkW = null;
     393    boolean hasDeathAnim = (getClass().getResource("../images/" + folder + "/Death1.png") != null);
     394    try {
     395      if (getClass().getResource("../images/" + folder + "/WalkN.png") != null) {
     396        walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN.png"));
     397        anmWalkN.addFrame(walkN);
     398        walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS.png"));
     399        anmWalkS.addFrame(walkS);
     400        walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE.png"));
     401        anmWalkE.addFrame(walkE);
     402        walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW.png"));
     403        anmWalkW.addFrame(walkW);
     404      } else if (getClass().getResource("../images/" + folder + "/WalkN1.png") != null) {
     405        walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN1.png"));
     406        anmWalkN.addFrame(walkN);
     407        anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png")));
     408        walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS1.png"));
     409        anmWalkS.addFrame(walkS);
     410        anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png")));
     411        walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE1.png"));
     412        anmWalkE.addFrame(walkE);
     413        anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png")));
     414        walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW1.png"));
     415        anmWalkW.addFrame(walkW);
     416        anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png")));
     417      } else {
     418        noAnims = true;
     419        anmStandN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     420        anmStandS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     421        anmStandE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     422        anmStandW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     423        anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     424        anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     425        anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     426        anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     427        anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     428        anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     429        anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     430        anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     431        anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     432        anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     433        anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     434        anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
     435      }
     436      if (!noAnims) {
     437        BufferedImage standN, standS, standE, standW;
     438        if (getClass().getResource("../images/" + folder + "/StandN.png") == null) {
     439          standN = walkN;
     440          standS = walkS;
     441          standE = walkE;
     442          standW = walkW;
     443        } else {
     444          standN = ImageIO.read(getClass().getResource("../images/" + folder + "/StandN.png"));
     445          standS = ImageIO.read(getClass().getResource("../images/" + folder + "/StandS.png"));
     446          standE = ImageIO.read(getClass().getResource("../images/" + folder + "/StandE.png"));
     447          standW = ImageIO.read(getClass().getResource("../images/" + folder + "/StandW.png"));
     448          anmWalkN = new Animation("north", 0, 0, 40, 60, 150, true);
     449          anmWalkS = new Animation("south", 0, 0, 40, 60, 150, true);
     450          anmWalkE = new Animation("east", 0, 0, 40, 60, 150, true);
     451          anmWalkW = new Animation("west", 0, 0, 40, 60, 150, true);
     452          anmWalkN.addFrame(walkN);
     453          anmWalkN.addFrame(standN);
     454          anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png")));
     455          anmWalkN.addFrame(standN);
     456          anmWalkS.addFrame(walkS);
     457          anmWalkS.addFrame(standS);
     458          anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png")));
     459          anmWalkS.addFrame(standS);
     460          anmWalkE.addFrame(walkE);
     461          anmWalkE.addFrame(standE);
     462          anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png")));
     463          anmWalkE.addFrame(standE);
     464          anmWalkW.addFrame(walkW);
     465          anmWalkW.addFrame(standW);
     466          anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png")));
     467          anmWalkW.addFrame(standW);
     468        }
     469        anmStandN.addFrame(standN);
     470        anmStandS.addFrame(standS);
     471        anmStandE.addFrame(standE);
     472        anmStandW.addFrame(standW);
     473        if (getClass().getResource("../images/" + folder + "/AttackN.png") != null) {
     474          anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN.png")));
     475          anmAttackN.addFrame(standN);
     476          anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS.png")));
     477          anmAttackS.addFrame(standS);
     478          anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE.png")));
     479          anmAttackE.addFrame(standE);
     480          anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW.png")));
     481          anmAttackW.addFrame(standW);
     482        } else if (getClass().getResource("../images/" + folder + "/AttackN1.png") != null) {
     483          anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN1.png")));
     484          anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN2.png")));
     485          anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS1.png")));
     486          anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS2.png")));
     487          anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE1.png")));
     488          anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE2.png")));
     489          anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW1.png")));
     490          anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW2.png")));
     491        } else {
     492          anmAttackN.addFrame(standN);
     493          anmAttackS.addFrame(standS);
     494          anmAttackE.addFrame(standE);
     495          anmAttackW.addFrame(standW);
     496        }
     497        if (hasDeathAnim) {
     498          anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death1.png")));
     499          anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death2.png")));
     500        }
     501      }
     502    } catch (IOException ioe) {
     503      ioe.printStackTrace();
     504    }
     505    Model model = new Model(hasDeathAnim);
     506    model.addAnimation(Direction.North, Action.Standing, anmStandN);
     507    model.addAnimation(Direction.South, Action.Standing, anmStandS);
     508    model.addAnimation(Direction.East, Action.Standing, anmStandE);
     509    model.addAnimation(Direction.West, Action.Standing, anmStandW);
     510    model.addAnimation(Direction.North, Action.Walking, anmWalkN);
     511    model.addAnimation(Direction.South, Action.Walking, anmWalkS);
     512    model.addAnimation(Direction.East, Action.Walking, anmWalkE);
     513    model.addAnimation(Direction.West, Action.Walking, anmWalkW);
     514    model.addAnimation(Direction.North, Action.Attacking, anmAttackN);
     515    model.addAnimation(Direction.South, Action.Attacking, anmAttackS);
     516    model.addAnimation(Direction.East, Action.Attacking, anmAttackE);
     517    model.addAnimation(Direction.West, Action.Attacking, anmAttackW);
     518    if (hasDeathAnim) {
     519      model.addAnimation(Direction.West, Action.Dying, anmDeath);
     520    }
     521    return model;
     522  }
     523
     524  public void load(BufferedReader in) {
     525    try {
     526      this.spawnPoint = LostHavenRPG.getSpawnPoint(Integer.parseInt(in.readLine()));
     527      if (this.spawnPoint != null) {
     528        this.spawnPoint.numSpawns++;
     529      }
     530      String strLoc = in.readLine();
     531      getLoc().setX(Integer.valueOf(strLoc.substring(0, strLoc.indexOf(","))).intValue());
     532      getLoc().setY(Integer.valueOf(strLoc.substring(strLoc.indexOf(",") + 1)).intValue());
     533      getModel().setDirection(Direction.valueOf(in.readLine()));
     534      getModel().setAction(Action.valueOf(in.readLine()));
     535      setHitpoints(Integer.valueOf(in.readLine()).intValue());
     536      setManapoints(Integer.valueOf(in.readLine()).intValue());
     537      this.passive = Integer.valueOf(in.readLine()).intValue();
     538      this.thorns = Integer.valueOf(in.readLine()).intValue();
     539      this.confused = Integer.valueOf(in.readLine()).intValue();
     540      this.sand = Integer.valueOf(in.readLine()).intValue();
     541      String strWeapon = in.readLine();
     542      if (!strWeapon.equals("None")) {
     543        setWeapon((Weapon)LostHavenRPG.items.get(strWeapon));
     544      }
     545    } catch (IOException ioe) {
     546      ioe.printStackTrace();
     547    }
     548  }
     549
     550  protected int attributeIndex(Attribute attribute) {
     551    switch (attribute) {
     552      case Strength:
     553        return 0;
     554      case Dexterity:
     555        return 1;
     556      case Constitution:
     557        return 2;
     558      case Wisdom:
     559        return 3;
     560    }
     561    return -1;
     562  }
     563
     564  public int getAttribute(Attribute attribute) {
     565    return this.attributes[attributeIndex(attribute)];
     566  }
     567
     568  public void setAttribute(Attribute attribute, int num) {
     569    this.attributes[attributeIndex(attribute)] = num;
     570    updateStats();
     571  }
     572
     573  private void updateStats() {
     574    this.hitpoints = 2 * this.attributes[2];
     575    this.maxHitpoints = 2 * this.attributes[2];
     576    this.manapoints = 2 * this.attributes[3];
     577    this.maxManapoints = 2 * this.attributes[3];
     578  }
     579
     580  public Creature getEnemyTarget() {
     581    return this.enemyTarget;
     582  }
     583
     584  public int getExperience() {
     585    return this.experience;
     586  }
     587
     588  public int getHitpoints() {
     589    return this.hitpoints;
     590  }
     591
     592  public Model getModel() {
     593    return this.model;
     594  }
     595
     596  public long getLastAttacked() {
     597    return this.lastAttacked;
     598  }
     599
     600  public long getLastMoved() {
     601    return this.lastMoved;
     602  }
     603
     604  public int getLevel() {
     605    return this.level;
     606  }
     607
     608  public Point getLoc() {
     609    return this.loc;
     610  }
     611
     612  public int getManapoints() {
     613    return this.manapoints;
     614  }
     615
     616  public int getMaxHitpoints() {
     617    return this.maxHitpoints;
     618  }
     619
     620  public int getMaxManapoints() {
     621    return this.maxManapoints;
     622  }
     623
     624  public String getName() {
     625    return this.name;
     626  }
     627
     628  public int getSpeed() {
     629    return this.speed;
     630  }
     631
     632  public Point getTarget() {
     633    return this.target;
     634  }
     635
     636  public CreatureType getType() {
     637    return this.type;
     638  }
     639
     640  public EquippedWeapon getWeapon() {
     641    return this.weapon;
     642  }
     643
     644  public EquippedWeapon getSpell() {
     645    return this.spell;
     646  }
     647
     648  public void setEnemyTarget(Creature enemyTarget) {
     649    this.enemyTarget = enemyTarget;
     650  }
     651
     652  public void setExperience(int experience) {
     653    this.experience = experience;
     654  }
     655
     656  public void setHitpoints(int hitpoints) {
     657    if (hitpoints > 0) {
     658      this.hitpoints = hitpoints;
     659    } else {
     660      this.hitpoints = 0;
     661    }
     662  }
     663
     664  public void setModel(Model model) {
     665    this.model = model;
     666  }
     667
     668  public void setLastAttacked(long lastAttacked) {
     669    this.lastAttacked = lastAttacked;
     670  }
     671
     672  public void setLastMoved(long lastMoved) {
     673    this.lastMoved = lastMoved;
     674  }
     675
     676  public void setLevel(int level) {
     677    this.level = level;
     678  }
     679
     680  public void setLoc(Point loc) {
     681    this.loc = loc;
     682  }
     683
     684  public void setManapoints(int manapoints) {
     685    if (manapoints > 0) {
     686      this.manapoints = manapoints;
     687    } else {
     688      this.manapoints = 0;
     689    }
     690  }
     691
     692  public void setMaxHitpoints(int maxHitpoints) {
     693    this.maxHitpoints = maxHitpoints;
     694  }
     695
     696  public void setMaxManapoints(int maxManapoints) {
     697    this.maxManapoints = maxManapoints;
     698  }
     699
     700  public void setName(String name) {
     701    this.name = name;
     702  }
     703
     704  public void setSpeed(int speed) {
     705    this.speed = speed;
     706  }
     707
     708  public void setTarget(Point target) {
     709    this.target = target;
     710  }
     711
     712  public void setType(CreatureType type) {
     713    this.type = type;
     714  }
     715
     716  public void setWeapon(Weapon weapon) {
     717    this.weapon = new EquippedWeapon(this, weapon);
     718    this.weapon.update();
     719    (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size());
     720    (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size());
     721    (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size());
     722    (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size());
     723  }
     724
     725  public void setSpell(Weapon spell) {
     726    this.spell = new EquippedWeapon(this, spell);
     727    this.spell.update();
     728  }
     729
     730  public SpawnPoint getSpawnPoint() {
     731    return this.spawnPoint;
     732  }
     733
     734  public void setSpawnPoint(SpawnPoint sp) {
     735    this.spawnPoint = sp;
     736  }
     737
     738  public boolean farFromSpawnPoint() {
     739    if (this.spawnPoint == null)
     740      return false;
     741    return (Point.dist(this.spawnPoint.getLoc(), this.loc) > 800.0D);
     742  }
     743
     744  public boolean closerToSpawnPoint(Point newLoc) {
     745    if (this.spawnPoint == null)
     746      return false;
     747    return (Point.dist(this.spawnPoint.getLoc(), this.loc) >= Point.dist(this.spawnPoint.getLoc(), newLoc));
     748  }
     749
     750  public void disable() {
     751    this.disabled = true;
     752  }
     753
     754  public void enable() {
     755    this.disabled = false;
     756  }
     757
     758  public String toString() {
     759    return this.name;
     760  }
     761
     762  public int compareTo(Creature c) {
     763    return 0;
     764  }
    220765}
  • main/CreatureType.java

    r155577b r8edd04e  
    22
    33public enum CreatureType {
    4 
     4  Archer,
     5  Bandit,
     6  Blob,
     7  BlueBlob,
     8  Specter,
     9  CrystalGuard,
     10  DesertAmbusher,
     11  Ghost,
     12  Goblin,
     13  Golem,
     14  Guardian,
     15  Player,
     16  Pyromancer,
     17  RustedArmor,
     18  BurningCorpse,
     19  Wight,
     20  Zombie
    521}
  • main/GameState.java

    r155577b r8edd04e  
    22
    33public enum GameState {
    4     Main,
    5     CreateAccount,
    6     CreateClass,
    7     LoadGame,
    8     Info,
    9     Credits,
    10     Game,
    11     GameMenu,
    12     GameInventory,
    13     GameStats
     4  Main,
     5  CreateAccount,
     6  LoadGame,
     7  Info,
     8  Credits,
     9  Game,
     10  GameIntro,
     11  GameInfo,
     12  GameMenu,
     13  GameStats,
     14  GameGems,
     15  GameInventory,
     16  GameMap,
     17  Victory
    1418}
  • main/Gender.java

    r155577b r8edd04e  
    22
    33public enum Gender {
    4     None,
    5     Male,
    6     Female
     4  None,
     5  Male,
     6  Female
    77}
  • main/Job.java

    r155577b r8edd04e  
    22
    33public enum Job {
    4     None,
    5     Fighter,
    6     Ranger,
    7     Barbarian,
    8     Sorceror,
    9     Druid,
    10     Wizard
     4  None,
     5  Fighter,
     6  Ranger,
     7  Barbarian,
     8  Sorceror,
     9  Druid,
     10  Wizard
    1111}
  • main/Land.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.awt.image.*;
     3import java.awt.image.BufferedImage;
    44
    55public class Land extends MapElement {
    6         private LandType type;
    7        
    8         public Land(LandType type, BufferedImage img, boolean passable) {
    9                 super(img, passable);
    106
    11                 this.type = type;
    12         }
    13        
    14         public Land(LandType type, String imgFile, boolean passable) {
    15                 super(imgFile, passable);
    16                
    17                 this.type = type;
    18         }
    19        
    20         public LandType getType() {
    21                 return type;
    22         }
     7  private LandType type;
     8
     9  public Land(LandType type, BufferedImage img, boolean passable) {
     10    super(img, passable);
     11    this.type = type;
     12  }
     13
     14  public Land(LandType type, String imgFile, boolean passable) {
     15    super(imgFile, passable);
     16    this.type = type;
     17  }
     18
     19  public Land(Land copy) {
     20    super(copy);
     21    this.type = copy.type;
     22  }
     23
     24  public LandType getType() {
     25    return this.type;
     26  }
    2327}
  • main/LandType.java

    r155577b r8edd04e  
    22
    33public enum LandType {
    4         Grass,
    5         Ocean
     4  Lava,
     5  Metal,
     6  Charred,
     7  Swamp,
     8  Vines,
     9  Crystal,
     10  CrystalFormation,
     11  Water,
     12  Forest,
     13  Tree,
     14  Plains,
     15  Desert,
     16  Mountains,
     17  Cave,
     18  Ocean,
     19  Snow,
     20  Steam;
    621}
  • main/Location.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.util.*;
     3import java.util.PriorityQueue;
    44
    55public class Location {
    6         private Land land;
    7         private Structure structure;
    8         private PriorityQueue<Creature> creatures;
    9        
    10         public Location(Land land, Structure structure) {
    11                 this.land = land;
    12                 this.structure = structure;
    13                 this.creatures = new PriorityQueue<Creature>();
    14         }
    156
    16         public void addCreature(Creature creature) {
    17                 creatures.add(creature);
    18         }
    19        
    20         public Land getLand() {
    21                 return land;
    22         }
     7  private Land land;
     8  private Structure structure;
     9  private PriorityQueue<Creature> creatures;
    2310
    24         public Structure getStruct() {
    25                 return structure;
    26         }
    27        
    28         public void setLand(Land type) {
    29                 land = type;
    30         }
    31        
    32         public void setStruct(Structure type) {
    33                 structure = type;
    34         }
    35        
    36         public boolean isPassable() {
    37                 return land.isPassable() && structure.isPassable();
    38         }
     11  public Location(Land land, Structure structure) {
     12    this.land = land;
     13    this.structure = structure;
     14    this.creatures = new PriorityQueue<Creature>();
     15  }
     16
     17  public void addCreature(Creature creature) {
     18    this.creatures.add(creature);
     19  }
     20
     21  public void spawnCreature(Creature creature, Point loc) {
     22    Creature newC = creature.copy();
     23    newC.setLoc(loc);
     24    this.creatures.add(newC);
     25  }
     26
     27  public Land getLand() {
     28    return this.land;
     29  }
     30
     31  public Structure getStruct() {
     32    return this.structure;
     33  }
     34
     35  public PriorityQueue<Creature> getCreatures() {
     36    return this.creatures;
     37  }
     38
     39  public void setLand(Land type) {
     40    this.land = type;
     41  }
     42
     43  public void setStruct(Structure type) {
     44    this.structure = type;
     45  }
     46
     47  public boolean isPassable() {
     48    return (this.land.isPassable() && this.structure.isPassable());
     49  }
    3950}
  • main/LostHavenRPG.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.awt.*;
     3import java.awt.Color;
     4import java.awt.DisplayMode;
     5import java.awt.Font;
     6import java.awt.FontMetrics;
     7import java.awt.Frame;
     8import java.awt.Graphics;
     9import java.awt.GraphicsConfiguration;
     10import java.awt.GraphicsDevice;
     11import java.awt.GraphicsEnvironment;
     12import java.awt.MouseInfo;
     13import java.awt.event.*;
    414import java.awt.image.*;
    5 import java.awt.event.*;
    615import java.io.*;
    7 import java.util.*;
    8 import javax.imageio.*;
    9 import java.text.*;
     16import java.text.SimpleDateFormat;
     17import java.util.Date;
     18import java.util.HashMap;
     19import java.util.Iterator;
     20import java.util.LinkedList;
     21
     22import javax.imageio.ImageIO;
    1023
    1124import gamegui.*;
    1225
    13 /*
    14  * This is the main class in the project. It initializes wide-screen mode and is responsible for drawing to the screen and handling
    15  * input.
    16  *
    17  * The classes in the gamegui folder are similar to the Swing classes in that they help in building a gui. They are all extended from
    18  * the Member class and instances of each of them can be added to a Window class. They also have input-handling functionality.
    19  */
     26public class LostHavenRPG implements KeyListener, MouseListener {
    2027
    21 public class LostHavenRPG implements KeyListener, MouseListener {
    22         private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] {
    23         new DisplayMode(800, 600, 32, 0),
    24         new DisplayMode(800, 600, 16, 0),
    25         new DisplayMode(800, 600, 8, 0)
     28  private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] {
     29      new DisplayMode(800, 600, 32, 0),
     30      new DisplayMode(800, 600, 16, 0),
     31      new DisplayMode(800, 600, 8, 0)
    2632    };
    27        
    28         boolean done;
    29         boolean changePending;
    30        
    31         Player player;
    32         Map map;
    33        
    34         //all "types" should be enums so it's easier to see all possible values while programming
    35         HashMap<LandType, Land> landMap;
    36         HashMap<StructureType, Structure> structMap;
    37         HashMap<CreatureType, Creature> creatureMap;
    38        
    39         BufferedImage girl;
    40         BufferedImage guy;
    41    
    42     public GameState gameState;
    43     public AuxState auxState;
    44    
    45     //GUI elements
    46     Frame frmMain;
    47    
    48     gamegui.Window wndMain;
    49     gamegui.Window wndCreateAccount;
    50     gamegui.Window wndChooseClass;
    51     gamegui.Window wndGameInfo;
    52     gamegui.Window wndCredits;
    53    
    54     RadioGroup rdgGenderSelection;
    55     RadioGroup rdgClassSelection;
    56    
    57     gamegui.Window wndMessage;
    58     gamegui.Window wndProgress;
    59     gamegui.Window wndConnecting;
    60    
    61     Textbox selectedText;
    6233
    63     public LostHavenRPG(GraphicsDevice device) {
    64         try {
    65             GraphicsConfiguration gc = device.getDefaultConfiguration();
    66             frmMain = new Frame(gc);
    67             frmMain.setUndecorated(true);
    68             frmMain.setIgnoreRepaint(true);
    69             device.setFullScreenWindow(frmMain);
    70            
    71             if (device.isDisplayChangeSupported()) {
    72                 chooseBestDisplayMode(device);
    73             }
    74            
    75             frmMain.addMouseListener(this);
    76             frmMain.addKeyListener(this);
    77             frmMain.createBufferStrategy(2);
    78             BufferStrategy bufferStrategy = frmMain.getBufferStrategy();
     34  public static Map map;
     35  public static HashMap<LandType, Land> landMap;
     36  public static HashMap<StructureType, Structure> structMap;
     37  public static HashMap<CreatureType, Creature> creatureMap;
     38  public static HashMap<String, Item> items;
     39  public static LinkedList<RespawnPoint> respawnPoints;
     40  public static LinkedList<SpawnPoint> spawnPoints;
    7941
    80             player = new Player();
    81             done = false;
    82             changePending = false;
    83            
    84             gameState = GameState.Main;
    85             auxState = AuxState.None;
    86            
    87             loadMap();
    88                 map = new Map("mapInfo.txt", "structInfo.txt", landMap, structMap);
    89                 map.getLoc(10, 10).addCreature(new Creature());
    90             initGUIElements();
    91            
    92             while (!done) {
    93                 Graphics g = bufferStrategy.getDrawGraphics();
    94                 move();
    95                 render(g);
    96                 g.dispose();
    97                 bufferStrategy.show();
    98             }
    99         }
    100         catch (Exception e) {
    101             e.printStackTrace();
    102         }
    103         finally {
    104             device.setFullScreenWindow(null);
    105         }
     42  public static BufferedImage[] airSprites;
     43  public static BufferedImage[] earthSprites;
     44  public static BufferedImage[] fireSprites;
     45  public static BufferedImage[] waterSprites;
     46  public static BufferedImage[] imgBow;
     47  public static BufferedImage passiveAura;
     48  public static BufferedImage thornsAura;
     49  public static BufferedImage confuseAura;
     50  public static BufferedImage sandAura;
     51  public static Model rangedModel;
     52  public static Model meleeModel;
     53  public static ScrollList lstInventory;
     54  public static ScrollList lstGems;
     55  public static Frame frmMain;
     56
     57  public GameState gameState;
     58  public AuxState auxState;
     59
     60  boolean done;
     61  boolean changePending;
     62  Player player;
     63
     64  LinkedList<Gem> gems;
     65  LinkedList<Item> drops;
     66  LinkedList<Projectile> projectiles;
     67 
     68  BufferedImage imgMap;
     69 
     70  Window wndMain;
     71  Window wndCreateAccount;
     72  Window wndGameIntro;
     73  Window wndGameInfo;
     74  Window wndCredits;
     75  Window wndStatDisplay;
     76  Window wndGameInventory;
     77  Window wndGameGems;
     78  Window wndGameStats;
     79  Window wndGameMap;
     80  Window wndVictory;
     81  Window[] wndTutorials;
     82  Window wndTutOptions;
     83  Window wndMessage;
     84
     85  int wndTutCur; 
     86  boolean infoStart;
     87 
     88  Button btnMenu;
     89  Button btnStats;
     90  Button btnGems;
     91  Button btnInventory;
     92  Button btnMap;
     93 
     94  Label lblGemVal;
     95  Label lblSpellCost;
     96 
     97  Graphics g;
     98 
     99  Point startPoint;
     100 
     101  Textbox selectedText;
     102 
     103  boolean started = false;
     104 
     105  public LostHavenRPG(GraphicsDevice device) {
     106    try {
     107      GraphicsConfiguration gc = device.getDefaultConfiguration();
     108      frmMain = new Frame(gc);
     109      frmMain.setUndecorated(true);
     110      frmMain.setIgnoreRepaint(true);
     111      device.setFullScreenWindow(frmMain);
     112      if (device.isDisplayChangeSupported())
     113        chooseBestDisplayMode(device);
     114      frmMain.addMouseListener(this);
     115      frmMain.addKeyListener(this);
     116      frmMain.createBufferStrategy(2);
     117      BufferStrategy bufferStrategy = frmMain.getBufferStrategy();
     118      this.g = bufferStrategy.getDrawGraphics();
     119      this.done = false;
     120      this.changePending = false;
     121      this.gameState = GameState.Main;
     122      this.auxState = AuxState.None;
     123      loadMapElements();
     124      this.imgMap = ImageIO.read(getClass().getResource("../images/mapLarge.png"));
     125      map = new Map("map.png", "structInfo2.txt", landMap, structMap, true);
     126      this.startPoint = new Point(7050, 6150);
     127      loadItems();
     128      loadCreatures();
     129      loadSpawnPoints();
     130      loadSpellSprites();
     131      initGUIElements();
     132      this.started = true;
     133      while (!this.done) {
     134        this.g = bufferStrategy.getDrawGraphics();
     135        handleEvents();
     136        render(this.g);
     137        this.g.dispose();
     138        bufferStrategy.show();
     139      }
     140    } catch (Exception e) {
     141      e.printStackTrace();
     142    } finally {
     143      device.setFullScreenWindow(null);
     144    }
     145  }
     146 
     147  private void initGUIElements() {
     148    Font font11 = new Font("Arial", 0, 11);
     149    Font font12 = new Font("Arial", 0, 12);
     150    Font font14 = new Font("Arial", 0, 14);
     151    Font font24 = new Font("Arial", 0, 24);
     152    BufferedImage imgSub = null;
     153    BufferedImage imgAdd = null;
     154    BufferedImage imgSkillSub = null;
     155    BufferedImage imgSkillAdd = null;
     156    String strengthDesc = "Raises damage inflicted by melee weapons.";
     157    String dexterityDesc = "Lowers cooldown of all weapons.";
     158    String constitutionDesc = "Raises starting hitpoints and hitpoints gained per level.";
     159    String wisdomDesc = "Raises starting manapoints and manapoints gained per level.";
     160    String lightWeaponDesc = "Raises damage inflicted by light weapons.";
     161    String heavyWeaponDesc = "Raises damage inflicted by heavy weapons.";
     162    String rangedWeaponDesc = "Raises damage inflicted by ranged weapons.";
     163    String evocationDesc = "Raises the possible number of activated gems.";
     164    this.wndMain = new Window("main", 0, 0, 800, 600, true);
     165    Animation anmTitle = new Animation("title", 144, 0, 512, 95, 83, true);
     166    try {
     167      anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame1.png")));
     168      anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame2.png")));
     169      anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame3.png")));
     170      anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame4.png")));
     171      anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame5.png")));
     172      imgSub = ImageIO.read(getClass().getResource("../images/imgSub.png"));
     173      imgAdd = ImageIO.read(getClass().getResource("../images/imgAdd.png"));
     174      imgSkillSub = ImageIO.read(getClass().getResource("../images/imgSkillSub.png"));
     175      imgSkillAdd = ImageIO.read(getClass().getResource("../images/imgSkillAdd.png"));
     176    } catch (IOException ioe) {
     177      ioe.printStackTrace();
     178    }
     179    this.wndMain.add(anmTitle);
     180    this.wndMain.add(new Button("new game", 500, 140, 200, 40, "New Game", font12));
     181    this.wndMain.add(new Button("load game", 500, 230, 200, 40, "Load Game", font12));
     182    this.wndMain.add(new Button("game info", 500, 320, 200, 40, "Game Information", font12));
     183    this.wndMain.add(new Button("credits", 500, 410, 200, 40, "Credits", font12));
     184    this.wndMain.add(new Button("quit", 500, 500, 200, 40, "Quit", font12));
     185    this.wndStatDisplay = new Window("stat display", 0, 550, 799, 49, false);
     186    this.wndGameStats = new Window("game stats", 0, 125, 320, 425);
     187    this.wndGameGems = new Window("inventory", 359, 299, 220, 251);
     188    lstGems = new ScrollList("gem list", 0, 0, 200, 251, null, null);
     189    lstGems.addScrollBar(new ScrollBar("scrollgem", 200, 0, 20, 251, 3));
     190    this.wndGameGems.add(lstGems);
     191    this.wndGameInventory = new Window("inventory", 579, 299, 220, 251);
     192    lstInventory = new ScrollList("inventory list", 0, 0, 200, 251, null, null);
     193    lstInventory.addScrollBar(new ScrollBar("scrollinv", 200, 0, 20, 251, 3));
     194    this.wndGameInventory.add(lstInventory);
     195    this.wndGameMap = new Window("inventory", 443, 357, 356, 193);
     196    this.btnMenu = new Button("main menu", 360, 10, 80, 20, "Main Menu", font12);
     197    this.btnStats = new Button("stats", 600, 5, 80, 16, "Character", font12);
     198    this.btnInventory = new Button("inventory", 700, 5, 80, 16, "Inventory", font12);
     199    this.btnGems = new Button("gems", 600, 29, 80, 16, "Gems", font12);
     200    this.btnMap = new Button("map", 700, 29, 80, 16, "Map", font12);
     201    this.lblGemVal = new Label("gemVal", 515, 5, 67, 20, "Gem Value: 0", font12, Align.Right);
     202    this.lblSpellCost = new Label("spellCost", 515, 24, 67, 20, "Spell Cost: 0", font12, Align.Right);
     203    this.wndStatDisplay.add(this.btnMenu);
     204    this.wndStatDisplay.add(this.btnStats);
     205    this.wndStatDisplay.add(this.btnGems);
     206    this.wndStatDisplay.add(this.btnInventory);
     207    this.wndStatDisplay.add(this.btnMap);
     208    this.wndStatDisplay.add(this.lblGemVal);
     209    this.wndStatDisplay.add(this.lblSpellCost);
     210    this.wndGameStats.add(new Label("strength", 10, 20, 70, 30, "Strength", font12, Align.Left));
     211    this.wndGameStats.add(new Label("strengthDesc", 20, 45, 70, 15, strengthDesc, font11, Align.Left));
     212    this.wndGameStats.add(new Label("dexterity", 10, 65, 70, 30, "Dexterity", font12, Align.Left));
     213    this.wndGameStats.add(new Label("dexterityDesc", 20, 90, 70, 15, dexterityDesc, font11, Align.Left));
     214    this.wndGameStats.add(new Label("constitution", 10, 110, 70, 30, "Constitution", font12, Align.Left));
     215    this.wndGameStats.add(new Label("constitutionDesc", 20, 135, 70, 15, constitutionDesc, font11, Align.Left));
     216    this.wndGameStats.add(new Label("wisdom", 10, 155, 70, 30, "Wisdom", font12, Align.Left));
     217    this.wndGameStats.add(new Label("wisdomDesc", 20, 180, 70, 15, wisdomDesc, font11, Align.Left));
     218    this.wndGameStats.add(new Label("strVal", 220, 20, 70, 30, "0", font12, Align.Left));
     219    this.wndGameStats.add(new Label("dexVal", 220, 65, 70, 30, "0", font12, Align.Left));
     220    this.wndGameStats.add(new Label("conVal", 220, 110, 70, 30, "0", font12, Align.Left));
     221    this.wndGameStats.add(new Label("wisVal", 220, 155, 70, 30, "0", font12, Align.Left));
     222    this.wndGameStats.add(new Label("light weapons", 10, 220, 70, 30, "Light Weapons", font12, Align.Left));
     223    this.wndGameStats.add(new Label("lightWeaponDesc", 20, 245, 70, 15, lightWeaponDesc, font11, Align.Left));
     224    this.wndGameStats.add(new Label("heavy weapons", 10, 265, 70, 30, "Heavy Weapons", font12, Align.Left));
     225    this.wndGameStats.add(new Label("heavyWeaponDesc", 20, 290, 70, 15, heavyWeaponDesc, font11, Align.Left));
     226    this.wndGameStats.add(new Label("ranged weapons", 10, 310, 70, 30, "Ranged Weapons", font12, Align.Left));
     227    this.wndGameStats.add(new Label("rangedWeaponDesc", 20, 335, 70, 15, rangedWeaponDesc, font11, Align.Left));
     228    this.wndGameStats.add(new Label("evocation", 10, 355, 70, 30, "Evocation", font12, Align.Left));
     229    this.wndGameStats.add(new Label("evocationDesc", 20, 380, 70, 15, evocationDesc, font11, Align.Left));
     230    this.wndGameStats.add(new Label("lightWeaponVal", 220, 220, 70, 30, "0", font12, Align.Left));
     231    this.wndGameStats.add(new Label("heavyWeaponVal", 220, 265, 70, 30, "0", font12, Align.Left));
     232    this.wndGameStats.add(new Label("rangedWeaponVal", 220, 310, 70, 30, "0", font12, Align.Left));
     233    this.wndGameStats.add(new Label("evocationVal", 220, 355, 70, 30, "0", font12, Align.Left));
     234    this.wndGameStats.add(new Label("skillVal", 130, 395, 70, 30, "0", font12, Align.Left));
     235    this.wndGameStats.add(new Button("lightWeapon+", 265, 230, 20, 20, imgSkillAdd));
     236    this.wndGameStats.add(new Button("heavyWeapon+", 265, 275, 20, 20, imgSkillAdd));
     237    this.wndGameStats.add(new Button("rangedWeapon+", 265, 320, 20, 20, imgSkillAdd));
     238    this.wndGameStats.add(new Button("evocation+", 265, 365, 20, 20, imgSkillAdd));
     239    this.wndGameStats.add(new Label("skilllPoints", 50, 395, 70, 30, "Remaining Points:", font12, Align.Right));
     240    this.wndCreateAccount = new Window("create account", 0, 0, 800, 600, true);
     241    this.wndCreateAccount.add(new Label("title", 250, 15, 300, 20, "Create an Account", font24));
     242    this.wndCreateAccount.add(new Textbox("user", 340, 100, 190, 30, "Username:", font12, false));
     243    this.wndCreateAccount.add(new Label("strength", 90, 190, 70, 30, "Strength", font12, Align.Left));
     244    this.wndCreateAccount.add(new Label("strengthDesc", 115, 220, 70, 15, strengthDesc, font11, Align.Left));
     245    this.wndCreateAccount.add(new Label("dexterity", 90, 250, 70, 30, "Dexterity", font12, Align.Left));
     246    this.wndCreateAccount.add(new Label("dexterityDesc", 115, 280, 70, 15, dexterityDesc, font11, Align.Left));
     247    this.wndCreateAccount.add(new Label("constitution", 90, 310, 70, 30, "Constitution", font12, Align.Left));
     248    this.wndCreateAccount.add(new Label("constitutionDesc", 115, 340, 70, 15, constitutionDesc, font11, Align.Left));
     249    this.wndCreateAccount.add(new Label("wisdom", 90, 370, 70, 30, "Wisdom", font12, Align.Left));
     250    this.wndCreateAccount.add(new Label("wisdomDesc", 115, 400, 70, 15, wisdomDesc, font11, Align.Left));
     251    this.wndCreateAccount.add(new Label("attPoints", 110, 430, 70, 30, "Remaining Points:", font12, Align.Right));
     252    this.wndCreateAccount.add(new Label("strVal", 264, 190, 70, 30, "0", font12, Align.Left));
     253    this.wndCreateAccount.add(new Label("dexVal", 264, 250, 70, 30, "0", font12, Align.Left));
     254    this.wndCreateAccount.add(new Label("conVal", 264, 310, 70, 30, "0", font12, Align.Left));
     255    this.wndCreateAccount.add(new Label("wisVal", 264, 370, 70, 30, "0", font12, Align.Left));
     256    this.wndCreateAccount.add(new Label("attVal", 215, 430, 70, 30, "0", font12, Align.Left));
     257    this.wndCreateAccount.add(new Button("strength-", 205, 198, 20, 20, imgSub));
     258    this.wndCreateAccount.add(new Button("strength+", 315, 198, 20, 20, imgAdd));
     259    this.wndCreateAccount.add(new Button("dexterity-", 205, 258, 20, 20, imgSub));
     260    this.wndCreateAccount.add(new Button("dexterity+", 315, 258, 20, 20, imgAdd));
     261    this.wndCreateAccount.add(new Button("constitution-", 205, 318, 20, 20, imgSub));
     262    this.wndCreateAccount.add(new Button("constitution+", 315, 318, 20, 20, imgAdd));
     263    this.wndCreateAccount.add(new Button("wisdom-", 205, 378, 20, 20, imgSub));
     264    this.wndCreateAccount.add(new Button("wisdom+", 315, 378, 20, 20, imgAdd));
     265    this.wndCreateAccount.add(new Label("light weapons", 450, 190, 70, 30, "Light Weapons", font12, Align.Left));
     266    this.wndCreateAccount.add(new Label("lightWeaponDesc", 475, 220, 70, 15, lightWeaponDesc, font11, Align.Left));
     267    this.wndCreateAccount.add(new Label("heavy weapons", 450, 250, 70, 30, "Heavy Weapons", font12, Align.Left));
     268    this.wndCreateAccount.add(new Label("heavyWeaponDesc", 475, 280, 70, 15, heavyWeaponDesc, font11, Align.Left));
     269    this.wndCreateAccount.add(new Label("ranged weapons", 450, 310, 70, 30, "Ranged Weapons", font12, Align.Left));
     270    this.wndCreateAccount.add(new Label("rangedWeaponDesc", 475, 340, 70, 15, rangedWeaponDesc, font11, Align.Left));
     271    this.wndCreateAccount.add(new Label("evocation", 450, 370, 70, 30, "Evocation", font12, Align.Left));
     272    this.wndCreateAccount.add(new Label("evocationDesc", 475, 400, 70, 15, evocationDesc, font11, Align.Left));
     273    this.wndCreateAccount.add(new Label("skilllPoints", 475, 430, 70, 30, "Remaining Points:", font12, Align.Right));
     274    this.wndCreateAccount.add(new Label("lightWeaponVal", 620, 190, 70, 30, "0", font12, Align.Left));
     275    this.wndCreateAccount.add(new Label("heavyWeaponVal", 620, 250, 70, 30, "0", font12, Align.Left));
     276    this.wndCreateAccount.add(new Label("rangedWeaponVal", 620, 310, 70, 30, "0", font12, Align.Left));
     277    this.wndCreateAccount.add(new Label("evocationVal", 620, 370, 70, 30, "0", font12, Align.Left));
     278    this.wndCreateAccount.add(new Label("skillVal", 575, 430, 70, 30, "0", font12, Align.Left));
     279    this.wndCreateAccount.add(new Button("lightWeapon-", 565, 198, 20, 20, imgSkillSub));
     280    this.wndCreateAccount.add(new Button("lightWeapon+", 675, 198, 20, 20, imgSkillAdd));
     281    this.wndCreateAccount.add(new Button("heavyWeapon-", 565, 258, 20, 20, imgSkillSub));
     282    this.wndCreateAccount.add(new Button("heavyWeapon+", 675, 258, 20, 20, imgSkillAdd));
     283    this.wndCreateAccount.add(new Button("rangedWeapon-", 565, 318, 20, 20, imgSkillSub));
     284    this.wndCreateAccount.add(new Button("rangedWeapon+", 675, 318, 20, 20, imgSkillAdd));
     285    this.wndCreateAccount.add(new Button("evocation-", 565, 378, 20, 20, imgSkillSub));
     286    this.wndCreateAccount.add(new Button("evocation+", 675, 378, 20, 20, imgSkillAdd));
     287    this.wndCreateAccount.add(new Button("create", 245, 520, 140, 30, "Create", font12));
     288    this.wndCreateAccount.add(new Button("cancel", 415, 520, 140, 30, "Cancel", font12));
     289    this.wndCredits = new Window("main", 0, 0, 800, 600, true);
     290    this.wndCredits.add(new Label("title", 250, 15, 300, 20, "Credits", font24));
     291    this.wndCredits.add(new Label("1", 250, 160, 300, 20, "Dmitry Portnoy", font14));
     292    this.wndCredits.add(new Label("2", 250, 180, 300, 20, "Team Leader", font12));
     293    this.wndCredits.add(new Label("3", 250, 195, 300, 20, "Programmer", font12));
     294    this.wndCredits.add(new Label("4", 250, 235, 300, 20, "Daniel Vu", font14));
     295    this.wndCredits.add(new Label("5", 250, 255, 300, 20, "Graphic Artist", font12));
     296    this.wndCredits.add(new Label("6", 250, 295, 300, 20, "Jason Cooper", font14));
     297    this.wndCredits.add(new Label("7", 250, 315, 300, 20, "Designer", font12));
     298    this.wndCredits.add(new Label("8", 250, 355, 300, 20, "Special thanks to", font14));
     299    this.wndCredits.add(new Label("9", 250, 375, 300, 20, "The Game Creation Society", font12));
     300    this.wndTutorials = new Window[13];
     301    String[] text = new String[13];
     302    this.wndTutOptions = new Window("tut", 300, 0, 499, 140, false);
     303    this.wndTutOptions.add(new Button("previous", 260, 110, 60, 20, "Previous", font12, Align.Center));
     304    this.wndTutOptions.add(new Button("next", 340, 110, 60, 20, "Next", font12, Align.Center));
     305    this.wndTutOptions.add(new Button("skip", 420, 110, 60, 20, "Skip", font12, Align.Center));
     306    this.wndTutOptions.add(new Label("num", 200, 110, 60, 20, "1 / 13", font12, Align.Center));
     307    text[0] = "When you die, you will be resurrected with no penalty at the closest purple pedestal you have activated. To activate a pedestal, you must walk over it. If you have not activated any purple pedestals, you will resurrect where you started the game. It is important to activate any purple pedestals you see to save you time when you die. You can also use purple pedestals to replenish all of your HP and MP by stepping on them.";
     308    text[1] = "When you kill enemies, they sometimes drop items. Left-click on an item to pick it up and place it in your inventory. Be careful when picking up items while there are many enemies around because they might kill you.";
     309    text[2] = "You can open your inventory from the bar at the bottom of the screen. You can mouse over any item in your inventory and see a description and relevant stats. Left-clicking any weapon in your inventory will equip it and unequip your previously equiped weapon. Left-clicking a gem will activate it provided you have enough evocation skill to do so. ";
     310    text[3] = "You can equip both melee and ranged weapons. If you have a ranged weapon, like this bow, you can fire at enemies from a safe distance. Ranged weapons never run out of ammunition. However, they cannot shoot through most obstacles.";
     311    text[4] = "Melee weapons are divided into light and heavy weapons. Heavy weapons are slower, but deal much more damage when they hit. Anyone can equip light weapons, but only players with at least 12 Strenth can use heavy weapons. The damage bonus from Strength is also greater for heavy weapons. The heavy weapon skill also adds more damage per hit than the light weapon skill.";
     312    text[5] = "You can open the Character window from the bottom bar. The character window shows the levels of all your skills and attributes. When you level up, you get two extra skill points and you can spend them here. Choose your skills carefully since you can't repick your skills later. You also get HP equal to your constitution and MP equal to your wisdom when you level up.";
     313    text[6] = "Assuming you have at least one gem activated and enough mana, you can cast spells by right-clicking anywhere on the map.  The total mana cost of your spell is half of the value of all the gems used to cast it.Any enemies that your spell collides with will be affected. However, you use MP every time you cast a spell, so you have to be careful not run out of MP in a battle. There are many gems with different effects and you should carefully choose which gems you want to use for your spell.";
     314    text[7] = "The Gems window is accessible from the bottom bar. Activated gems will appear in this window and will contribute their effects to any spells you cast. Each gem has a set amount of energy that is displayed if you mouse over it. Your evocation skill limits the amount of gems you can activate at once, so you should raise it to increase the power of your spells. You can left-click on any gem in the Gems window to place it back in your inventory if you want to activate a different gem.";
     315    text[8] = "The images under the Blob indicate that it is afflicted with some status effects. Status effects caused by spells usually last a few seconds, but it varies depending on the gem.";
     316    text[9] = "You can activate mutliple gems of the same type to get increased effects. Gems that have one-time effects, like dealing damage, will simply do more of that. Gems that cause the target to gain a temporary status effect will make that effect last longer if multiple gems are used.";
     317    text[10] = "These red portals will open your way out of this world. However, they have been protected by the magic of powerful artifacts. These artifacts are scattered throughout the land and you will need at least four to break the enchantment and activate these portals.";
     318    text[11] = "Yellow pedestals are portals to the aforementioned artifacts. Be warned that these artifacts are well-guarded and capturing them could prove deadly. To view this tutorial again, click on Game Information from the main menu. Good luck!";
     319    text[12] = "You can access the world map from the bottom bar. However, it does not show the locations of respawn or teleportation points. The Rectangular areas on top of the screen are the locations of the relics, but you must use teleportation points to get to them.";
     320    FontMetrics metrics = this.g.getFontMetrics(font12);
     321    try {
     322      for (int x = 0; x < this.wndTutorials.length; x++) {
     323        this.wndTutorials[x] = new Window("tut" + x, 0, 0, 800, 600, true);
     324        this.wndTutorials[x].add(new Button("screen", 0, 0, 800, 600, ImageIO.read(getClass().getResource("../images/Tutorial/ss" + (x + 1) + ".png"))));
     325        this.wndTutorials[x].add(this.wndTutOptions);
     326        MultiTextbox multiTextbox = new MultiTextbox("text", 305, 5, 490, 100, "", false, font12, metrics);
     327        multiTextbox.setBorder(false);
     328        multiTextbox.setText(text[x]);
     329        this.wndTutorials[x].add(multiTextbox);
     330      }
     331      this.wndTutCur = 0;
     332      this.wndGameIntro = new Window("intro", 0, 0, 800, 600, true);
     333      this.wndGameIntro.add(new Label("intro", 250, 15, 300, 20, "Introduction", font24));
     334      MultiTextbox txt = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics);
     335      txt.setBorder(false);
     336      txt.setText("You suddenly wake up in a strange place you do not recognize. You must find some weapons and some way to get out.\n\nKill creatures to get gems to power your spells and weapons to defend yourself with.\n\nTo get out of this world, you must unlock a portal that is protected by powerful artifacts. Each artifact can be accessed by a yellow portal somewhere in the world. You must collect at least four artifacts to unlock the portal.");
     337      this.wndGameIntro.add(txt);
     338      this.wndVictory = new Window("victory", 0, 0, 800, 600, true);
     339      this.wndVictory.add(new Label("victory", 250, 15, 300, 20, "Victory", font24));
     340      MultiTextbox txtV = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics);
     341      txtV.setBorder(false);
     342      txtV.setText("As you strike the final blow, the specter's body evaporates, leaving behind a pile of torn clothing. In the last seconds of its existance, you manage to peer under its hood and catch a glimpse of your own face. Was that simply proof of your failing psyche or does some darker secret lie behind that horrible monster? When you once again become aware of your surroundings, you find yourself alone in a forest clearing. There is no sign of hostile monsters and the only indications of your ordeal are your incredible fatigue and a pile of rags a few feet away from you. Was the world you were trapped in merely an illusion or is there some other explanation? You cannot be sure, but you hope to never have to remember that place again.");
     343      this.wndVictory.add(txtV);
     344    } catch (IOException ioe) {
     345      ioe.printStackTrace();
     346    }
     347    this.wndMessage = new Window("message", 290, 135, 220, 160);
     348    this.wndMessage.add(new Label("label", 20, 15, 180, 12, "none", font12));
     349    this.wndMessage.add(new Button("button", 70, 115, 80, 30, "OK", font12));
     350  }
     351 
     352  private void loadMapElements() {
     353    landMap = new HashMap<LandType, Land>();
     354    structMap = new HashMap<StructureType, Structure>();
     355    respawnPoints = new LinkedList<RespawnPoint>();
     356    BufferedImage nullImg = null;
     357    landMap.put(LandType.Lava, new Land(LandType.Lava, "Terrain/orange.png", true));
     358    landMap.put(LandType.Metal, new Land(LandType.Metal, "Terrain/darkRed.png", true));
     359    landMap.put(LandType.Charred, new Land(LandType.Charred, "Terrain/red.png", true));
     360    landMap.put(LandType.Swamp, new Land(LandType.Swamp, "Terrain/lightBrown.png", true));
     361    landMap.put(LandType.Vines, new Land(LandType.Vines, "Terrain/darkBrown.png", true));
     362    landMap.put(LandType.Crystal, new Land(LandType.Crystal, "Terrain/purple.png", true));
     363    landMap.put(LandType.CrystalFormation, new Land(LandType.CrystalFormation, "Terrain/darkPurple.png", false));
     364    landMap.put(LandType.Water, new Land(LandType.Water, "Terrain/blue.png", true));
     365    landMap.put(LandType.Forest, new Land(LandType.Forest, "Terrain/darkGreen.png", true));
     366    landMap.put(LandType.Tree, new Land(LandType.Tree, "Terrain/brown.png", false));
     367    landMap.put(LandType.Plains, new Land(LandType.Plains, "Terrain/lightGreen.png", true));
     368    landMap.put(LandType.Desert, new Land(LandType.Desert, "Terrain/yellow.png", true));
     369    landMap.put(LandType.Mountains, new Land(LandType.Mountains, "Terrain/mountain.png", false));
     370    landMap.put(LandType.Cave, new Land(LandType.Cave, "Terrain/mountain.png", false));
     371    landMap.put(LandType.Ocean, new Land(LandType.Ocean, "Terrain/darkBlue.png", false));
     372    landMap.put(LandType.Snow, new Land(LandType.Snow, "Terrain/lightBlue.png", true));
     373    landMap.put(LandType.Steam, new Land(LandType.Steam, "Terrain/lightGray.png", true));
     374    structMap.put(StructureType.None, new Structure(StructureType.None, nullImg, true));
     375    structMap.put(StructureType.LoginPedestal, new Structure(StructureType.LoginPedestal, "YellowPedestal.png", true));
     376    structMap.put(StructureType.RejuvenationPedestal, new Structure(StructureType.RejuvenationPedestal, "PurplePedestal.png", true));
     377    structMap.put(StructureType.LifePedestal, new Structure(StructureType.LifePedestal, "RedPedestal.png", true));
     378    structMap.put(StructureType.ManaPedestal, new Structure(StructureType.ManaPedestal, "BluePedestal.png", true));
     379    structMap.put(StructureType.RespawnPoint, new RespawnPoint(StructureType.RespawnPoint, "PurplePedestal.png", true));
     380    structMap.put(StructureType.ArtifactPoint, new ArtifactPoint(StructureType.ArtifactPoint, "YellowPedestal.png", true));
     381    structMap.put(StructureType.BossPoint, new ArtifactPoint(StructureType.BossPoint, "RedPedestal.png", true));
     382  }
     383 
     384  private void loadCreatures() {
     385    creatureMap = new HashMap<CreatureType, Creature>();
     386    try {
     387      BufferedReader in = new BufferedReader(new FileReader("creatures.txt"));
     388      while (in.ready()) {
     389        Creature cr = Creature.loadTemplate(in);
     390        String strItem;
     391        while (!(strItem = in.readLine()).equals("---"))
     392          cr.addDrop(new ItemDrop(items.get(strItem.substring(0, strItem.indexOf(","))), Integer.valueOf(strItem.substring(strItem.indexOf(",") + 2)).intValue()));
     393        creatureMap.put(cr.getType(), cr);
     394      }
     395      in.close();
     396    } catch (IOException ioe) {
     397      ioe.printStackTrace();
     398    }
     399    ((Player)creatureMap.get(CreatureType.Player)).initGems(this.gems);
     400    meleeModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player");
     401    rangedModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player/ranged");
     402  }
     403 
     404  private void loadSpawnPoints() {
     405    spawnPoints = new LinkedList<SpawnPoint>();
     406    try {
     407      BufferedReader in = new BufferedReader(new FileReader("spawnPoints.txt"));
     408      while (in.ready()) {
     409        Creature type = creatureMap.get(CreatureType.valueOf(in.readLine()));
     410        String strLoc = in.readLine();
     411        int x = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
     412        strLoc = strLoc.substring(strLoc.indexOf(",") + 1);
     413        int y = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
     414        strLoc = strLoc.substring(strLoc.indexOf(",") + 1);
     415        int xMin = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
     416        int yMin = Integer.parseInt(strLoc.substring(strLoc.indexOf(",") + 1));
     417        Point loc = new Point(x * 100 + xMin, y * 100 + yMin);
     418        SpawnPoint sp = new SpawnPoint(type, loc, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine()));
     419        spawnPoints.add(sp);
     420      }
     421      in.close();
     422    } catch (IOException ioe) {
     423      ioe.printStackTrace();
     424    }
     425  }
     426 
     427  private void loadItems() {
     428    items = new HashMap<String, Item>();
     429    this.drops = new LinkedList<Item>();
     430    this.projectiles = new LinkedList<Projectile>();
     431    this.gems = new LinkedList<Gem>();
     432    try {
     433      imgBow = new BufferedImage[8];
     434      imgBow[0] = ImageIO.read(getClass().getResource("../images/projectiles/bowNN.png"));
     435      imgBow[1] = ImageIO.read(getClass().getResource("../images/projectiles/bowNE.png"));
     436      imgBow[2] = ImageIO.read(getClass().getResource("../images/projectiles/bowEE.png"));
     437      imgBow[3] = ImageIO.read(getClass().getResource("../images/projectiles/bowSE.png"));
     438      imgBow[4] = ImageIO.read(getClass().getResource("../images/projectiles/bowSS.png"));
     439      imgBow[5] = ImageIO.read(getClass().getResource("../images/projectiles/bowSW.png"));
     440      imgBow[6] = ImageIO.read(getClass().getResource("../images/projectiles/bowWW.png"));
     441      imgBow[7] = ImageIO.read(getClass().getResource("../images/projectiles/bowNW.png"));
     442      BufferedReader in = new BufferedReader(new FileReader("items.txt"));
     443      while (in.ready()) {
     444        Item item;
     445        int attackSpeed, range, damage, value;
     446        String name = in.readLine();
     447        String img = String.valueOf(in.readLine()) + ".png";
     448        ItemType type = ItemType.valueOf(in.readLine());
     449        String desc = in.readLine();
     450        BufferedImage[] imgProj = new BufferedImage[8];
     451        switch (type) {
     452          case LightWeapon:
     453          case HeavyWeapon:
     454            attackSpeed = Integer.valueOf(in.readLine()).intValue();
     455            damage = Integer.valueOf(in.readLine()).intValue();
     456            item = new Weapon(name, type, img, null, attackSpeed, 55, damage);
     457            break;
     458          case RangedWeapon:
     459            attackSpeed = Integer.valueOf(in.readLine()).intValue();
     460            range = Integer.valueOf(in.readLine()).intValue();
     461            damage = Integer.valueOf(in.readLine()).intValue();
     462            imgProj = imgBow;
     463            item = new Weapon(name, type, img, imgProj, attackSpeed, range, damage);
     464            break;
     465          case Gem:
     466            value = Integer.valueOf(in.readLine()).intValue();
     467            item = new Gem(name, img, value, null);
     468            this.gems.add((Gem)item);
     469            break;
     470          default:
     471            item = new Item(name, type, img);
     472            break;
     473        }
     474        item.setDescription(desc);
     475        items.put(name, item);
     476      }
     477      in.close();
     478    } catch (IOException ioe) {
     479      ioe.printStackTrace();
     480    }
     481  }
     482 
     483  private void loadSpellSprites() {
     484    airSprites = loadSprites("air");
     485    earthSprites = loadSprites("earth");
     486    fireSprites = loadSprites("fire");
     487    waterSprites = loadSprites("water");
     488    try {
     489      passiveAura = ImageIO.read(getClass().getResource("../images/spells/auras/passiveAura.png"));
     490      thornsAura = ImageIO.read(getClass().getResource("../images/spells/auras/thornsAura.png"));
     491      confuseAura = ImageIO.read(getClass().getResource("../images/spells/auras/confuseAura.png"));
     492      sandAura = ImageIO.read(getClass().getResource("../images/spells/auras/sandAura.png"));
     493    } catch (IOException ioe) {
     494      ioe.printStackTrace();
     495    }
     496  }
     497 
     498  private BufferedImage[] loadSprites(String name) {
     499    BufferedImage[] sprites = new BufferedImage[8];
     500    try {
     501      sprites[0] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNN.png"));
     502      sprites[1] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNE.png"));
     503      sprites[2] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellEE.png"));
     504      sprites[3] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSE.png"));
     505      sprites[4] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSS.png"));
     506      sprites[5] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSW.png"));
     507      sprites[6] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellWW.png"));
     508      sprites[7] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNW.png"));
     509    } catch (IOException ioe) {
     510      ioe.printStackTrace();
     511    }
     512    return sprites;
     513  }
     514 
     515  public static SpawnPoint getSpawnPoint(int idNum) {
     516    if (idNum == -1)
     517      return null;
     518    Iterator<SpawnPoint> iter = spawnPoints.iterator();
     519    while (iter.hasNext()) {
     520      SpawnPoint sp;
     521      if ((sp = iter.next()).idNum == idNum)
     522        return sp;
     523    }
     524    return null;
     525  }
     526 
     527  private void spawnCreatures() {
     528    Iterator<SpawnPoint> iter = spawnPoints.iterator();
     529    while (iter.hasNext()) {
     530      SpawnPoint sp = iter.next();
     531      if (Point.dist(this.player.getLoc(), sp.getLoc()) >= 600.0D) {
     532        Creature cr = sp.spawn();
     533        if (cr != null)
     534          map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
     535      }
     536    }
     537  }
     538 
     539  private void moveCreatures() {
     540    int xLow = this.player.getLoc().getX() / 100 - 8;
     541    int xHigh = xLow + 17;
     542    int yLow = this.player.getLoc().getY() / 100 - 6;
     543    int yHigh = yLow + 13;
     544    if (xLow < 0)
     545      xLow = 0;
     546    if (xHigh > map.getLength())
     547      xHigh = map.getLength();
     548    if (yLow < 0)
     549      yLow = 0;
     550    if (yHigh > map.getHeight())
     551      yHigh = map.getHeight();
     552    for (int x = 0; x < map.getLength(); x++) {
     553      for (int y = 0; y < map.getHeight(); y++) {
     554        Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     555        while (iter.hasNext()) {
     556          Creature cr = iter.next();
     557          if (cr != this.player)
     558            if (cr.confused > 0) {
     559              cr.setEnemyTarget(findClosestTarget(cr));
     560            } else {
     561              cr.setEnemyTarget(this.player);
     562            } 
     563          if (cr.isDying() && cr.getModel().getAnimation(Direction.West, Action.Dying).reachedEnd()) {
     564            cr.setDying(false);
     565            if (cr == this.player) {
     566              respawnPlayer();
     567              continue;
     568            }
     569            if (cr.getType() == CreatureType.Specter)
     570              this.gameState = GameState.Victory;
     571            continue;
     572          }
     573          if (!cr.getModel().hasDeath() && cr.getHitpoints() <= 0) {
     574            iter.remove();
     575            continue;
     576          }
     577          move(cr);
     578          if (cr.getLoc().getX() / 100 != x || cr.getLoc().getY() / 100 != y) {
     579            iter.remove();
     580            map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
     581          }
     582        }
     583      }
     584    }
     585  }
     586 
     587  private void move(Creature cr) {
     588    if (cr.isDying())
     589      return;
     590    Point newLoc = cr.move();
     591    int minDist = 50;
     592    boolean creatureBlocking = false;
     593    cr.checkTimedEffects();
     594    Iterator<Item> itemIter = this.drops.iterator();
     595    while (itemIter.hasNext()) {
     596      Item item = itemIter.next();
     597      if (item.getLoc().equals(this.player.getLoc())) {
     598        this.player.pickUp(item);
     599        itemIter.remove();
     600      }
     601    }
     602    int xLow = newLoc.getX() / 100 - 2;
     603    int xHigh = xLow + 5;
     604    int yLow = newLoc.getY() / 100 - 2;
     605    int yHigh = yLow + 5;
     606    if (xLow < 0)
     607      xLow = 0;
     608    if (xHigh > map.getLength())
     609      xHigh = map.getLength();
     610    if (yLow < 0)
     611      yLow = 0;
     612    if (yHigh > map.getHeight())
     613      yHigh = map.getHeight();
     614    for (int x = xLow; x < xHigh; x++) {
     615      for (int y = yLow; y < yHigh; y++) {
     616        Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     617        while (iter.hasNext()) {
     618          Creature temp = iter.next();
     619          if (cr.getEnemyTarget() == temp && Point.dist(temp.getLoc(), newLoc) <= cr.getWeapon().getRange()) {
     620            creatureBlocking = true;
     621            if (temp != this.player || !temp.isDying()) {
     622              Projectile proj = cr.attack(temp, AttackType.Weapon);
     623              if (proj != null) {
     624                proj.setCreator(cr);
     625                proj.applySpawnEffects();
     626                addProjectile(proj);
     627                continue;
     628              }
     629              if (temp.getHitpoints() <= 0) {
     630                temp.setDying(true);
     631                if (temp != this.player) {
     632                  killCreature(temp);
     633                  this.player.setEnemyTarget(null);
     634                  this.player.setTarget(this.player.getLoc());
     635                }
     636              }
     637            }
     638            continue;
     639          }
     640          if (temp != cr && Point.dist(temp.getLoc(), newLoc) < minDist)
     641            creatureBlocking = true;
     642        }
     643      }
     644    }
     645    if (map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && !creatureBlocking && (!cr.farFromSpawnPoint() || cr.closerToSpawnPoint(newLoc))) {
     646      Location oldLoc = map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100);
     647      cr.setLoc(newLoc);
     648      if (cr == this.player)
     649        switch (map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct().getType()) {
     650          case RespawnPoint:
     651            ((RespawnPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).mark();
     652          case RejuvenationPedestal:
     653            this.player.setManapoints(this.player.getMaxManapoints());
     654          case LifePedestal:
     655            this.player.setHitpoints(this.player.getMaxHitpoints());
     656            break;
     657          case ManaPedestal:
     658            this.player.setManapoints(this.player.getMaxManapoints());
     659            break;
     660          case BossPoint:
     661            if (!this.player.readyForBoss())
     662              break;
     663          case ArtifactPoint:
     664            if (oldLoc != map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100)) {
     665              this.player.setLoc(((ArtifactPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).getTarget());
     666              this.player.setTarget(this.player.getLoc());
     667            }
     668            break;
     669        } 
     670    } else {
     671      cr.setTarget(cr.getLoc());
     672      if (cr.getModel().getAction() != Action.Attacking)
     673        cr.getModel().setAction(Action.Standing);
     674    }
     675  }
     676 
     677  private Creature findClosestTarget(Creature cr) {
     678    int xLow = cr.getLoc().getX() / 100 - 5;
     679    int xHigh = xLow + 11;
     680    int yLow = cr.getLoc().getY() / 100 - 5;
     681    int yHigh = yLow + 11;
     682    Creature closestCr = this.player;
     683    double minDist = Point.dist(cr.getLoc(), this.player.getLoc());
     684    if (xLow < 0)
     685      xLow = 0;
     686    if (xHigh > map.getLength())
     687      xHigh = map.getLength();
     688    if (yLow < 0)
     689      yLow = 0;
     690    if (yHigh > map.getHeight())
     691      yHigh = map.getHeight();
     692    for (int x = xLow; x < xHigh; x++) {
     693      for (int y = yLow; y < yHigh; y++) {
     694        Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     695        while (iter.hasNext()) {
     696          Creature cur = iter.next();
     697          if (cr != cur && minDist > Point.dist(cr.getLoc(), cur.getLoc())) {
     698            minDist = Point.dist(cr.getLoc(), cur.getLoc());
     699            closestCr = cur;
     700          }
     701        }
     702      }
     703    }
     704    return closestCr;
     705  }
     706 
     707  private synchronized void addProjectile(Projectile proj) {
     708    this.projectiles.add(proj);
     709  }
     710 
     711  private synchronized void moveProjectiles() {
     712    Iterator<Projectile> iter = this.projectiles.iterator();
     713    while (iter.hasNext()) {
     714      Projectile proj = iter.next();
     715      move(proj);
     716      if (proj.isDone())
     717        iter.remove();
     718    }
     719  }
     720 
     721  private void move(Projectile proj) {
     722    Point newLoc = proj.move();
     723    int minDist = 50;
     724    for (int x = 0; x < map.getLength(); x++) {
     725      for (int y = 0; y < map.getHeight(); y++) {
     726        Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     727        while (iter.hasNext()) {
     728          Creature cr = iter.next();
     729          if (Point.dist(cr.getLoc(), newLoc) < minDist && ((cr == this.player && !proj.isPlayerOwned()) || (cr != this.player && proj.isPlayerOwned()))) {
     730            if (!proj.penetrates())
     731              proj.setDone(true);
     732            if (!proj.creatureIsEffected(cr)) {
     733              proj.applyContactEffects(cr);
     734              proj.effectCreature(cr);
     735            }
     736            if (cr.getHitpoints() <= 0) {
     737              cr.setDying(true);
     738              if (cr != this.player) {
     739                killCreature(cr);
     740                this.player.setEnemyTarget(null);
     741                this.player.setTarget(this.player.getLoc());
     742              }
     743            }
     744          }
     745        }
     746      }
     747    }
     748    Location curLoc = map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100);
     749    if (proj.getTarget().equals(newLoc) || (!curLoc.isPassable() && curLoc.getLand().getType() != LandType.Ocean)) {
     750      proj.setDone(true);
     751    } else {
     752      proj.setLoc(newLoc);
     753    }
     754  }
     755 
     756  private void killCreature(Creature cr) {
     757    Iterator<Item> itemIter = cr.spawnDrops().iterator();
     758    while (itemIter.hasNext())
     759      this.drops.add(((Item)itemIter.next()).copy(cr.getLoc()));
     760    if (cr.getSpawnPoint() != null)
     761      cr.getSpawnPoint().removeCreature();
     762    this.player.setExperience(this.player.getExperience() + cr.getExperience());
     763    if (this.player.getExperience() >= (Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D) {
     764      this.player.setExperience(this.player.getExperience() - (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D));
     765      this.player.increaseLevel();
     766    }
     767  }
     768 
     769  public void respawnPlayer() {
     770    Iterator<RespawnPoint> iter = respawnPoints.iterator();
     771    RespawnPoint closest = null;
     772    double dist = 0.0D;
     773    this.player.setHitpoints(this.player.getMaxHitpoints());
     774    this.player.setManapoints(this.player.getMaxManapoints());
     775    while (iter.hasNext()) {
     776      RespawnPoint cur = iter.next();
     777      if (cur.isMarked() && (closest == null || dist > Point.dist(cur.getLoc(), this.player.getLoc()))) {
     778        closest = cur;
     779        dist = Point.dist(cur.getLoc(), this.player.getLoc());
     780      }
     781    }
     782    if (closest == null) {
     783      this.player.setLoc(this.startPoint);
     784    } else {
     785      this.player.setLoc(closest.getLoc());
     786    }
     787    this.player.setEnemyTarget(null);
     788    this.player.setTarget(this.player.getLoc());
     789  }
     790 
     791  private void handleEvents() {
     792    switch (this.gameState) {
     793      case Game:
     794      case GameMenu:
     795      case GameStats:
     796      case GameGems:
     797      case GameInventory:
     798      case GameMap:
     799        spawnCreatures();
     800        moveCreatures();
     801        moveProjectiles();
     802        break;
     803    }
     804  }
     805 
     806  private void render(Graphics g) {
     807    g.setColor(Color.black);
     808    g.fillRect(0, 0, 800, 600);
     809    switch (this.gameState) {
     810      case Main:
     811        drawMain(g);
     812        break;
     813      case CreateAccount:
     814        drawCreateAccount(g);
     815        break;
     816      case LoadGame:
     817        drawLoadGame(g);
     818        break;
     819      case Info:
     820        drawInfo(g);
     821        break;
     822      case Credits:
     823        drawCredits(g);
     824        break;
     825      case Victory:
     826        this.wndVictory.draw(g);
     827        break;
     828      case GameIntro:
     829        this.wndGameIntro.draw(g);
     830        break;
     831      case GameInfo:
     832        this.wndTutorials[this.wndTutCur].draw(g);
     833        break;
     834      case Game:
     835        drawMap(g);
     836        drawItems(g);
     837        drawCreatures(g);
     838        drawProjectiles(g);
     839        drawStatDisplay(g);
     840        break;
     841      case GameMenu:
     842        drawMap(g);
     843        drawItems(g);
     844        drawCreatures(g);
     845        drawProjectiles(g);
     846        drawStatDisplay(g);
     847        drawGameMenu(g);
     848        break;
     849      case GameStats:
     850        drawMap(g);
     851        drawItems(g);
     852        drawCreatures(g);
     853        drawProjectiles(g);
     854        drawStatDisplay(g);
     855        drawGameStats(g);
     856        break;
     857      case GameGems:
     858        drawMap(g);
     859        drawItems(g);
     860        drawCreatures(g);
     861        drawProjectiles(g);
     862        drawStatDisplay(g);
     863        drawGameGems(g);
     864        break;
     865      case GameInventory:
     866        drawMap(g);
     867        drawItems(g);
     868        drawCreatures(g);
     869        drawProjectiles(g);
     870        drawStatDisplay(g);
     871        drawGameInventory(g);
     872        break;
     873      case GameMap:
     874        drawMap(g);
     875        drawItems(g);
     876        drawCreatures(g);
     877        drawProjectiles(g);
     878        drawStatDisplay(g);
     879        drawGameMap(g);
     880        break;
     881    }
     882    switch (this.auxState) {
     883      case MsgBox:
     884        this.wndMessage.draw(g);
     885        break;
     886    }
     887  }
     888 
     889  public void save() {
     890    PrintWriter out = null;
     891    try {
     892      out = new PrintWriter(new FileWriter("save.txt"));
     893      for (int x = 0; x < map.getLength(); x++) {
     894        for (int y = 0; y < map.getHeight(); y++) {
     895          Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     896          while (iter.hasNext()) {
     897            Creature cr = iter.next();
     898            cr.save(out);
     899          }
     900        }
     901      }
     902      out.close();
     903      out = new PrintWriter(new FileWriter("savedItems.txt"));
     904      Iterator<Item> itrItem = this.drops.iterator();
     905      while (itrItem.hasNext()) {
     906        Item cur = itrItem.next();
     907        out.println(cur.getName());
     908        out.println(String.valueOf(cur.getLoc().getX()) + "," + cur.getLoc().getY());
     909      }
     910      out.close();
     911    } catch (IOException ioe) {
     912      ioe.printStackTrace();
     913    }
     914  }
     915 
     916  public void reset() {
     917    this.drops.clear();
     918    this.projectiles.clear();
     919    map.clearCreatures();
     920    lstInventory.clear();
     921    Iterator<SpawnPoint> iter = spawnPoints.iterator();
     922    while (iter.hasNext())
     923      ((SpawnPoint)iter.next()).clear();
     924    SpawnPoint.numSpawnPoints = 0;
     925    Iterator<RespawnPoint> rpIter = respawnPoints.iterator();
     926    while (rpIter.hasNext())
     927      ((RespawnPoint)rpIter.next()).unmark();
     928  }
     929 
     930  public void placeQuestObjects() {
     931    this.drops.add(((Item)items.get("Power Sword")).copy(new Point(1650, 150)));
     932    this.drops.add(((Item)items.get("Ice Scroll")).copy(new Point(3250, 150)));
     933    this.drops.add(((Item)items.get("BNW Shirt")).copy(new Point(4950, 250)));
     934    this.drops.add(((Item)items.get("Studded Leather Armor")).copy(new Point(6750, 150)));
     935    this.drops.add(((Item)items.get("Patched Leather")).copy(new Point(8450, 150)));
     936    this.drops.add(((Item)items.get("Fire Scroll")).copy(new Point(1650, 1450)));
     937    Creature cr = ((Creature)creatureMap.get(CreatureType.Specter)).copy();
     938    cr.setLoc(new Point(15850, 350));
     939    map.getLoc(158, 3).addCreature(cr);
     940  }
     941 
     942  public boolean load() {
     943    reset();
     944    try {
     945      BufferedReader in = new BufferedReader(new FileReader("save.txt"));
     946      while (in.ready()) {
     947        CreatureType type = CreatureType.valueOf(in.readLine());
     948        Creature cr = ((Creature)creatureMap.get(type)).copy();
     949        cr.load(in);
     950        if (cr.getType() == CreatureType.Player)
     951          this.player = (Player)cr;
     952        map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
     953      }
     954      Iterator<Creature> iter = map.getLoc(this.player.getTarget().getX() / 100, this.player.getTarget().getY() / 100).getCreatures().iterator();
     955      while (iter.hasNext()) {
     956        Creature cr2 = iter.next();
     957        if (cr2.getLoc().equals(this.player.getTarget()) && cr2 != this.player)
     958          this.player.setEnemyTarget(cr2);
     959      }
     960      in.close();
     961      in = new BufferedReader(new FileReader("savedItems.txt"));
     962      while (in.ready()) {
     963        Item cur = items.get(in.readLine());
     964        String loc = in.readLine();
     965        int x = Integer.parseInt(loc.substring(0, loc.indexOf(",")));
     966        int y = Integer.parseInt(loc.substring(loc.indexOf(",") + 1));
     967        this.drops.add(cur.copy(new Point(x, y)));
     968      }
     969      in.close();
     970    } catch (FileNotFoundException fnfe) {
     971      showMessage("There is no saved game to load");
     972      return false;
     973    } catch (IOException ioe) {
     974      ioe.printStackTrace();
     975      return false;
     976    }
     977    return true;
     978  }
     979 
     980  public static String dateString() {
     981    return (new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")).format(new Date());
     982  }
     983 
     984  public void showMessage(String text) {
     985    this.auxState = AuxState.MsgBox;
     986    ((Label)this.wndMessage.getMember("label")).setText(text);
     987  }
     988 
     989  private void drawMain(Graphics g) {
     990    this.wndMain.draw(g);
     991    g.setColor(Color.red);
     992    g.drawRect(10, 100, 380, 490);
     993    g.drawRect(410, 100, 380, 490);
     994  }
     995 
     996  private void drawCreateAccount(Graphics g) {
     997    ((Label)this.wndCreateAccount.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength)));
     998    ((Label)this.wndCreateAccount.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity)));
     999    ((Label)this.wndCreateAccount.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution)));
     1000    ((Label)this.wndCreateAccount.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom)));
     1001    ((Label)this.wndCreateAccount.getMember("attVal")).setText(Integer.toString(this.player.getAttributePoints()));
     1002    ((Label)this.wndCreateAccount.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons)));
     1003    ((Label)this.wndCreateAccount.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons)));
     1004    ((Label)this.wndCreateAccount.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons)));
     1005    ((Label)this.wndCreateAccount.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation)));
     1006    ((Label)this.wndCreateAccount.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints()));
     1007    this.wndCreateAccount.draw(g);
     1008  }
     1009 
     1010  private void drawLoadGame(Graphics g) {
     1011    Font tempFont = new Font("Arial", 0, 12);
     1012    FontMetrics metrics = g.getFontMetrics(tempFont);
     1013    g.setFont(tempFont);
     1014    g.setColor(Color.green);
     1015    g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
     1016  }
     1017 
     1018  private void drawInfo(Graphics g) {
     1019    if (this.infoStart) {
     1020      this.wndGameIntro.draw(g);
     1021    } else {
     1022      this.wndTutorials[this.wndTutCur].draw(g);
     1023    }
     1024  }
     1025 
     1026  private void drawCredits(Graphics g) {
     1027    this.wndCredits.draw(g);
     1028  }
     1029 
     1030  private void drawMap(Graphics g) {
     1031    int locX = this.player.getLoc().getX();
     1032    int locY = this.player.getLoc().getY();
     1033    int xLow = locX / 100 - 5;
     1034    int xHigh = xLow + 11;
     1035    int yLow = locY / 100 - 4;
     1036    int yHigh = yLow + 9;
     1037    if (xLow < 0)
     1038      xLow = 0;
     1039    if (xHigh > map.getLength())
     1040      xHigh = map.getLength();
     1041    if (yLow < 0)
     1042      yLow = 0;
     1043    if (yHigh > map.getHeight())
     1044      yHigh = map.getHeight();
     1045    int x;
     1046    for (x = xLow; x < xHigh; x++) {
     1047      for (int y = yLow; y < yHigh; y++) {
     1048        if (map.getLoc(x, y).getLand().getType() != LandType.Mountains && map.getLoc(x, y).getLand().getType() != LandType.Cave) {
     1049          g.drawImage(map.getLoc(x, y).getLand().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
     1050          g.drawImage(map.getLoc(x, y).getStruct().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
     1051        } else {
     1052          g.drawImage(((Land)landMap.get(LandType.Metal)).getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
     1053        }
     1054      }
     1055    }
     1056    for (x = xLow; x < xHigh; x++) {
     1057      for (int y = yLow; y < yHigh; y++) {
     1058        if (map.getLoc(x, y).getLand().getType() == LandType.Mountains || map.getLoc(x, y).getLand().getType() == LandType.Cave)
     1059          g.drawImage(map.getLoc(x, y).getLand().getImg(), 390 + x * 100 - locX, 290 + y * 100 - locY, null);
     1060      }
     1061    }
     1062  }
     1063 
     1064  private void drawItems(Graphics g) {
     1065    Iterator<Item> iter = this.drops.iterator();
     1066    while (iter.hasNext())
     1067      ((Item)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
     1068  }
     1069 
     1070  private synchronized void drawProjectiles(Graphics g) {
     1071    Iterator<Projectile> iter = this.projectiles.iterator();
     1072    while (iter.hasNext())
     1073      ((Projectile)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
     1074  }
     1075 
     1076  private void drawCreatures(Graphics g) {
     1077    int xLow = this.player.getLoc().getX() / 100 - 5;
     1078    int xHigh = xLow + 11;
     1079    int yLow = this.player.getLoc().getY() / 100 - 4;
     1080    int yHigh = yLow + 9;
     1081    if (xLow < 0)
     1082      xLow = 0;
     1083    if (xHigh > map.getLength())
     1084      xHigh = map.getLength();
     1085    if (yLow < 0)
     1086      yLow = 0;
     1087    if (yHigh > map.getHeight())
     1088      yHigh = map.getHeight();
     1089    for (int x = xLow; x < xHigh; x++) {
     1090      for (int y = yLow; y < yHigh; y++) {
     1091        Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
     1092        while (iter.hasNext())
     1093          ((Creature)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
     1094      }
     1095    }
     1096  }
     1097 
     1098  private void drawStatDisplay(Graphics g) {
     1099    this.lblGemVal.setText("Gem Value: " + this.player.getGemValue());
     1100    this.lblSpellCost.setText("Spell Cost: " + ((this.player.getGemValue() + 1) / 2));
     1101    this.wndStatDisplay.draw(g);
     1102    g.drawString(this.player.getName(), 20, 562);
     1103    g.drawString("Level " + this.player.getLevel(), 20, 574);
     1104    g.drawString("Relics Acquired: " + this.player.getRelicCount() + "/4", 20, 591);
     1105    g.setColor(Color.yellow);
     1106    g.drawRect(240, 578, 80, 15);
     1107    g.fillRect(240, 578, 80 * this.player.getExperience() / (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D), 15);
     1108    g.setColor(Color.green);
     1109    g.drawRect(125, 557, 80, 15);
     1110    g.fillRect(125, 557, 80 * this.player.getHitpoints() / this.player.getMaxHitpoints(), 15);
     1111    g.setColor(Color.blue);
     1112    g.drawRect(240, 557, 80, 15);
     1113    g.fillRect(240, 557, 80 * this.player.getManapoints() / this.player.getMaxManapoints(), 15);
     1114    g.setColor(Color.red);
     1115    g.drawString("HP:", 100, 569);
     1116    g.drawString("MP:", 215, 569);
     1117    g.drawString("Experience:", 170, 591);
     1118    g.drawString(String.valueOf(this.player.getExperience()) + "/" + ((int)(Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500), 245, 590);
     1119    g.drawString(String.valueOf(this.player.getHitpoints()) + "/" + this.player.getMaxHitpoints(), 130, 569);
     1120    g.drawString(String.valueOf(this.player.getManapoints()) + "/" + this.player.getMaxManapoints(), 245, 569);
     1121    this.player.getWeapon().drawStatic(g, 450 + this.wndStatDisplay.getX(), this.wndStatDisplay.getY());
     1122    int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
     1123    int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
     1124    if (450 + this.wndStatDisplay.getX() <= mouseX && mouseX < 500 + this.wndStatDisplay.getX() && this.wndStatDisplay.getY() <= mouseY && mouseY < 50 + this.wndStatDisplay.getY()) {
     1125      String itemType;
     1126      Item i = (this.player.getWeapon()).baseWeapon;
     1127      Window popup = new Window("popup", mouseX - 126, mouseY - 100, 126, 100, false);
     1128      Font font12 = new Font("Arial", 0, 12);
     1129      switch (i.getType()) {
     1130        case LightWeapon:
     1131          itemType = "Light Weapon";
     1132          break;
     1133        case HeavyWeapon:
     1134          itemType = "Heavy Weapon";
     1135          break;
     1136        case RangedWeapon:
     1137          itemType = "Ranged Weapon";
     1138          break;
     1139        default:
     1140          itemType = i.getType().toString();
     1141          break;
     1142      }
     1143      popup.add(new Label("info", 8, 5, 110, 15, "Equipped Weapon", font12));
     1144      popup.add(new Label("name", 8, 20, 110, 15, i.getName(), font12));
     1145      popup.add(new Label("type", 8, 50, 110, 15, itemType, font12));
     1146      popup.add(new Label("damage", 8, 65, 110, 15, "Damage: " + ((Weapon)i).getDamage() + "(" + this.player.getWeapon().getDamage() + ")", font12));
     1147      popup.add(new Label("damage", 8, 80, 110, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + "(" + (this.player.getWeapon().getAttackSpeed() / 10.0D) + ")" + " s", font12));
     1148      popup.draw(g);
     1149    }
     1150  }
     1151 
     1152  private void drawGameMenu(Graphics g) {}
     1153 
     1154  private void drawGameStats(Graphics g) {
     1155    ((Label)this.wndGameStats.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength)));
     1156    ((Label)this.wndGameStats.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity)));
     1157    ((Label)this.wndGameStats.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution)));
     1158    ((Label)this.wndGameStats.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom)));
     1159    ((Label)this.wndGameStats.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons)));
     1160    ((Label)this.wndGameStats.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons)));
     1161    ((Label)this.wndGameStats.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons)));
     1162    ((Label)this.wndGameStats.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation)));
     1163    ((Label)this.wndGameStats.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints()));
     1164    this.wndGameStats.draw(g);
     1165  }
     1166 
     1167  private void drawGameGems(Graphics g) {
     1168    this.wndGameGems.draw(g);
     1169    int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
     1170    int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
     1171    Window w = this.wndGameGems;
     1172    if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight())
     1173      this.player.drawInventory(g, lstGems, this.wndGameGems.getX() + 1, this.wndGameGems.getY() + 1);
     1174  }
     1175 
     1176  private void drawGameInventory(Graphics g) {
     1177    this.wndGameInventory.draw(g);
     1178    int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
     1179    int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
     1180    Window w = this.wndGameInventory;
     1181    if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight())
     1182      this.player.drawInventory(g, lstInventory, this.wndGameInventory.getX() + 1, this.wndGameInventory.getY() + 1);
     1183  }
     1184 
     1185  private void drawGameMap(Graphics g) {
     1186    this.wndGameMap.draw(g);
     1187    g.drawImage(this.imgMap, this.wndGameMap.getX() + 10, this.wndGameMap.getY() + 10, null);
     1188  }
     1189 
     1190  private void selectText(Textbox text) {
     1191    if (this.selectedText != null)
     1192      this.selectedText.setSelected(false);
     1193    this.selectedText = text;
     1194    if (text != null)
     1195      text.setSelected(true);
     1196  }
     1197 
     1198  private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
     1199    for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) {
     1200      DisplayMode[] modes = device.getDisplayModes();
     1201      for (int i = 0; i < modes.length; i++) {
     1202        if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth() && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight() && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth())
     1203          return BEST_DISPLAY_MODES[x];
     1204      }
     1205    }
     1206    return null;
     1207  }
     1208 
     1209  public static void chooseBestDisplayMode(GraphicsDevice device) {
     1210    DisplayMode best = getBestDisplayMode(device);
     1211    if (best != null)
     1212      device.setDisplayMode(best);
     1213  }
     1214 
     1215  public void mousePressed(MouseEvent e) {
     1216    boolean targetSet;
     1217    if (!this.started)
     1218      return;
     1219    switch (this.auxState) {
     1220      case None:
     1221        switch (this.gameState) {
     1222          case Main:
     1223            if (this.wndMain.getMember("new game").isClicked(e.getX(), e.getY())) {
     1224              this.player = (Player)((Creature)creatureMap.get(CreatureType.Player)).copy();
     1225              this.gameState = GameState.CreateAccount;
     1226              break;
     1227            }
     1228            if (this.wndMain.getMember("load game").isClicked(e.getX(), e.getY())) {
     1229              if (load()) {
     1230                this.player.setTimeLoggedOn(System.currentTimeMillis());
     1231                this.gameState = GameState.Game;
     1232              }
     1233              break;
     1234            }
     1235            if (this.wndMain.getMember("game info").isClicked(e.getX(), e.getY())) {
     1236              this.infoStart = true;
     1237              this.gameState = GameState.Info;
     1238              break;
     1239            }
     1240            if (this.wndMain.getMember("credits").isClicked(e.getX(), e.getY())) {
     1241              this.gameState = GameState.Credits;
     1242              break;
     1243            }
     1244            if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY()))
     1245              this.done = true;
     1246            break;
     1247          case CreateAccount:
     1248            if (this.wndCreateAccount.getMember("user").isClicked(e.getX(), e.getY())) {
     1249              selectText((Textbox)this.wndCreateAccount.getMember("user"));
     1250              break;
     1251            }
     1252            if (this.wndCreateAccount.getMember("create").isClicked(e.getX(), e.getY())) {
     1253              String user = ((Textbox)this.wndCreateAccount.getMember("user")).getText();
     1254              if (user.equals("")) {
     1255                showMessage("The username is empty");
     1256                break;
     1257              }
     1258              if (this.player.getAttributePoints() > 0) {
     1259                showMessage("You still have attribute points remaining");
     1260                break;
     1261              }
     1262              if (this.player.getSkillPoints() > 0) {
     1263                showMessage("You still have skill points remaining");
     1264                break;
     1265              }
     1266              this.wndCreateAccount.clear();
     1267              reset();
     1268              placeQuestObjects();
     1269              this.player.setName(user);
     1270              this.player.setLoc(this.startPoint);
     1271              this.player.setTarget(this.player.getLoc());
     1272              this.player.setWeapon((Weapon)items.get("Branch"));
     1273              this.player.pickUp((this.player.getWeapon()).baseWeapon);
     1274              map.getLoc(this.startPoint.getX() / 100, this.startPoint.getY() / 100).addCreature(this.player);
     1275              this.gameState = GameState.GameIntro;
     1276              break;
     1277            }
     1278            if (this.wndCreateAccount.getMember("cancel").isClicked(e.getX(), e.getY())) {
     1279              selectText(null);
     1280              this.wndCreateAccount.clear();
     1281              this.gameState = GameState.Main;
     1282              break;
     1283            }
     1284            if (this.wndCreateAccount.getMember("strength-").isClicked(e.getX(), e.getY())) {
     1285              this.player.repickAttribute(Attribute.Strength);
     1286              break;
     1287            }
     1288            if (this.wndCreateAccount.getMember("strength+").isClicked(e.getX(), e.getY())) {
     1289              this.player.allocateAttribute(Attribute.Strength);
     1290              break;
     1291            }
     1292            if (this.wndCreateAccount.getMember("dexterity-").isClicked(e.getX(), e.getY())) {
     1293              this.player.repickAttribute(Attribute.Dexterity);
     1294              break;
     1295            }
     1296            if (this.wndCreateAccount.getMember("dexterity+").isClicked(e.getX(), e.getY())) {
     1297              this.player.allocateAttribute(Attribute.Dexterity);
     1298              break;
     1299            }
     1300            if (this.wndCreateAccount.getMember("constitution-").isClicked(e.getX(), e.getY())) {
     1301              this.player.repickAttribute(Attribute.Constitution);
     1302              break;
     1303            }
     1304            if (this.wndCreateAccount.getMember("constitution+").isClicked(e.getX(), e.getY())) {
     1305              this.player.allocateAttribute(Attribute.Constitution);
     1306              break;
     1307            }
     1308            if (this.wndCreateAccount.getMember("wisdom-").isClicked(e.getX(), e.getY())) {
     1309              this.player.repickAttribute(Attribute.Wisdom);
     1310              break;
     1311            }
     1312            if (this.wndCreateAccount.getMember("wisdom+").isClicked(e.getX(), e.getY())) {
     1313              this.player.allocateAttribute(Attribute.Wisdom);
     1314              break;
     1315            }
     1316            if (this.wndCreateAccount.getMember("lightWeapon-").isClicked(e.getX(), e.getY())) {
     1317              this.player.repickSkill(Skill.LightWeapons);
     1318              break;
     1319            }
     1320            if (this.wndCreateAccount.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) {
     1321              this.player.allocateSkill(Skill.LightWeapons);
     1322              break;
     1323            }
     1324            if (this.wndCreateAccount.getMember("heavyWeapon-").isClicked(e.getX(), e.getY())) {
     1325              this.player.repickSkill(Skill.HeavyWeapons);
     1326              break;
     1327            }
     1328            if (this.wndCreateAccount.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) {
     1329              this.player.allocateSkill(Skill.HeavyWeapons);
     1330              break;
     1331            }
     1332            if (this.wndCreateAccount.getMember("rangedWeapon-").isClicked(e.getX(), e.getY())) {
     1333              this.player.repickSkill(Skill.RangedWeapons);
     1334              break;
     1335            }
     1336            if (this.wndCreateAccount.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) {
     1337              this.player.allocateSkill(Skill.RangedWeapons);
     1338              break;
     1339            }
     1340            if (this.wndCreateAccount.getMember("evocation-").isClicked(e.getX(), e.getY())) {
     1341              this.player.repickSkill(Skill.Evocation);
     1342              break;
     1343            }
     1344            if (this.wndCreateAccount.getMember("evocation+").isClicked(e.getX(), e.getY())) {
     1345              this.player.allocateSkill(Skill.Evocation);
     1346              break;
     1347            }
     1348            this.wndCreateAccount.handleEvent(e);
     1349            break;
     1350          case Info:
     1351            if (this.infoStart) {
     1352              this.infoStart = false;
     1353              break;
     1354            }
     1355            if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) {
     1356              if (this.wndTutCur != 0)
     1357                this.wndTutCur--;
     1358            } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) {
     1359              this.wndTutCur++;
     1360              if (this.wndTutCur > 12) {
     1361                this.gameState = GameState.Main;
     1362                this.wndTutCur = 0;
     1363              }
     1364            } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) {
     1365              this.gameState = GameState.Main;
     1366              this.wndTutCur = 0;
     1367            }
     1368            ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13");
     1369            break;
     1370          case Credits:
     1371            this.gameState = GameState.Main;
     1372            break;
     1373          case Victory:
     1374            this.gameState = GameState.Credits;
     1375            break;
     1376          case GameIntro:
     1377            this.gameState = GameState.GameInfo;
     1378            break;
     1379          case GameInfo:
     1380            if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) {
     1381              if (this.wndTutCur != 0)
     1382                this.wndTutCur--;
     1383            } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) {
     1384              this.wndTutCur++;
     1385              if (this.wndTutCur > 12) {
     1386                this.gameState = GameState.Game;
     1387                this.player.setTimeLoggedOn(System.currentTimeMillis());
     1388                this.wndTutCur = 0;
     1389              }
     1390            } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) {
     1391              this.gameState = GameState.Game;
     1392              this.player.setTimeLoggedOn(System.currentTimeMillis());
     1393              this.wndTutCur = 0;
     1394            }
     1395            ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13");
     1396            break;
     1397          case Game:
     1398            targetSet = false;
     1399            if (e.getY() < 550) {
     1400              if (this.player.isDying())
     1401                return;
     1402              int newX = this.player.getLoc().getX() + e.getX() - 400;
     1403              int newY = this.player.getLoc().getY() + e.getY() - 300;
     1404              if (e.getButton() == 1) {
     1405                Iterator<Item> itemIter = this.drops.iterator();
     1406                while (itemIter.hasNext()) {
     1407                  Item item = itemIter.next();
     1408                  if (item.getLoc().getX() - 25 <= newX && newX <= item.getLoc().getX() + 25 &&
     1409                    item.getLoc().getY() - 25 <= newY && newY <= item.getLoc().getY() + 25) {
     1410                    this.player.setTarget(item.getLoc());
     1411                    targetSet = true;
     1412                  }
     1413                }
     1414                for (int x = 0; x < map.getLength(); x++) {
     1415                  for (int y = 0; y < map.getHeight(); y++) {
     1416                    Iterator<Creature> crIter = map.getLoc(x, y).getCreatures().iterator();
     1417                    while (crIter.hasNext()) {
     1418                      Creature cr = crIter.next();
     1419                      if (cr.getLoc().getX() - cr.getModel().getWidth() / 2 <= newX && newX <= cr.getLoc().getX() + cr.getModel().getWidth() / 2 && cr != this.player &&
     1420                        cr.getLoc().getY() - cr.getModel().getHeight() <= newY && newY <= cr.getLoc().getY()) {
     1421                        this.player.setEnemyTarget(cr);
     1422                        targetSet = true;
     1423                      }
     1424                    }
     1425                  }
     1426                }
     1427                if (map.getLoc((int)Math.floor((newX / 100)), (int)Math.floor((newY / 100))).isPassable() && !targetSet) {
     1428                  this.player.setTarget(new Point(newX, newY));
     1429                  this.player.setEnemyTarget(null);
     1430                }
     1431                if (this.player.getEnemyTarget() != null && this.player.getWeapon().getType() == ItemType.RangedWeapon) {
     1432                  Projectile proj = this.player.attack(this.player.getEnemyTarget(), AttackType.Weapon);
     1433                  if (proj != null) {
     1434                    proj.setCreator(this.player);
     1435                    proj.applySpawnEffects();
     1436                    addProjectile(proj);
     1437                  }
     1438                  this.player.setTarget(this.player.getLoc());
     1439                  this.player.setEnemyTarget(null);
     1440                }
     1441                break;
     1442              }
     1443              if (e.getButton() == 3 &&
     1444                this.player.getSpell() != null && this.player.getManapoints() >= ((ManaDrain)this.player.getSpell().getSpawnEffect(EffectType.ManaDrain)).getMana()) {
     1445                Point loc = new Point(this.player.getLoc());
     1446                loc.setY(loc.getY() - 55);
     1447                Projectile proj = this.player.attack(new Point(newX, newY), AttackType.Spell);
     1448                if (proj != null) {
     1449                  proj.setCreator(this.player);
     1450                  proj.applySpawnEffects();
     1451                  addProjectile(proj);
     1452                }
     1453              }
     1454              break;
     1455            }
     1456            if (this.btnMenu.isClicked(e.getX(), e.getY())) {
     1457              this.gameState = GameState.Main;
     1458              this.player.updateTimePlayed();
     1459              save();
     1460              break;
     1461            }
     1462            if (this.btnStats.isClicked(e.getX(), e.getY())) {
     1463              this.gameState = GameState.GameStats;
     1464              break;
     1465            }
     1466            if (this.btnGems.isClicked(e.getX(), e.getY())) {
     1467              this.gameState = GameState.GameGems;
     1468              break;
     1469            }
     1470            if (this.btnInventory.isClicked(e.getX(), e.getY())) {
     1471              this.gameState = GameState.GameInventory;
     1472              break;
     1473            }
     1474            if (this.btnMap.isClicked(e.getX(), e.getY()))
     1475              this.gameState = GameState.GameMap;
     1476            break;
     1477          case GameStats:
     1478            if (this.wndGameStats.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) {
     1479              this.player.allocateSkill(Skill.LightWeapons);
     1480              break;
     1481            }
     1482            if (this.wndGameStats.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) {
     1483              this.player.allocateSkill(Skill.HeavyWeapons);
     1484              break;
     1485            }
     1486            if (this.wndGameStats.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) {
     1487              this.player.allocateSkill(Skill.RangedWeapons);
     1488              break;
     1489            }
     1490            if (this.wndGameStats.getMember("evocation+").isClicked(e.getX(), e.getY())) {
     1491              this.player.allocateSkill(Skill.Evocation);
     1492              break;
     1493            }
     1494            this.gameState = GameState.Game;
     1495            break;
     1496          case GameGems:
     1497            if (this.wndGameGems.isClicked(e.getX(), e.getY())) {
     1498              if (e.getX() < this.wndGameGems.getX() + this.wndGameGems.getWidth() - 20) {
     1499                int x = (e.getX() - this.wndGameGems.getX() - 1) / 50;
     1500                int y = (e.getY() - this.wndGameGems.getY() - 1 + lstGems.getTextStart()) / 50;
     1501                if (x + 4 * y >= 0 && x + 4 * y < lstGems.getList().size()) {
     1502                  Item i = this.player.getGems().get(x + y * 4);
     1503                  switch (i.getType()) {
     1504                    case Gem:
     1505                      this.player.deactivateGem((Gem)i);
     1506                      break;
     1507                  }
     1508                }
     1509              }
     1510              this.wndGameGems.handleEvent(e);
     1511              break;
     1512            }
     1513            this.gameState = GameState.Game;
     1514            break;
     1515          case GameInventory:
     1516            if (this.wndGameInventory.isClicked(e.getX(), e.getY())) {
     1517              if (e.getX() < this.wndGameInventory.getX() + this.wndGameInventory.getWidth() - 20) {
     1518                int x = (e.getX() - this.wndGameInventory.getX() - 1) / 50;
     1519                int y = (e.getY() - this.wndGameInventory.getY() - 1 + lstInventory.getTextStart()) / 50;
     1520                if (x + 4 * y >= 0 && x + 4 * y < this.player.getInventory().size()) {
     1521                  Item i = this.player.getInventory().get(x + y * 4);
     1522                  switch (i.getType()) {
     1523                    case HeavyWeapon:
     1524                      if (this.player.getAttribute(Attribute.Strength) < 12) {
     1525                        showMessage("You must have at least 12 Strength");
     1526                        break;
     1527                      }
     1528                    case LightWeapon:
     1529                    case RangedWeapon:
     1530                      this.player.setWeapon((Weapon)i);
     1531                      break;
     1532                    case Gem:
     1533                      if (!this.player.activateGem((Gem)i))
     1534                        showMessage("You must have a higher Evocation skill");
     1535                      break;
     1536                  }
     1537                }
     1538              }
     1539              this.wndGameInventory.handleEvent(e);
     1540              break;
     1541            }
     1542            this.gameState = GameState.Game;
     1543            break;
     1544          case GameMap:
     1545            this.gameState = GameState.Game;
     1546            break;
     1547        }
     1548        break;
     1549      case MsgBox:
     1550        if (this.wndMessage.getMember("button").isClicked(e.getX(), e.getY()))
     1551          this.auxState = AuxState.None;
     1552        break;
     1553    }
     1554  }
     1555 
     1556  public void mouseReleased(MouseEvent e) {
     1557  }
     1558 
     1559  public void mouseEntered(MouseEvent e) {
     1560  }
     1561 
     1562  public void mouseExited(MouseEvent e) {
     1563  }
     1564 
     1565  public void mouseClicked(MouseEvent e) {
     1566  }
     1567 
     1568  public void keyTyped(KeyEvent e) {
     1569  }
     1570 
     1571  public void keyPressed(KeyEvent e) {
     1572    if (this.selectedText != null)
     1573      this.selectedText.handleEvent(e);
     1574    if (e.getKeyCode() == 27)
     1575      if (this.gameState == GameState.Game) {
     1576        this.gameState = GameState.Main;
     1577        save();
     1578      } else {
     1579        this.done = true;
     1580      } 
     1581  }
     1582
     1583  public void keyReleased(KeyEvent e) {
     1584  }
     1585
     1586  public static void main(String[] args) {
     1587    try {
     1588      PrintStream st = new PrintStream(new FileOutputStream("err.txt", true));
     1589      System.setErr(st);
     1590      System.setOut(st);
     1591      System.out.println("-----[ Session started on " + dateString() + " ]-----");
     1592      GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
     1593      GraphicsDevice device = env.getDefaultScreenDevice();
     1594      new LostHavenRPG(device);
     1595    } catch (Exception e) {
     1596      e.printStackTrace();
    1061597    }
    107    
    108     private void initGUIElements() {           
    109         Font font10 = new Font("Arial", Font.PLAIN, 10);
    110         Font font11 = new Font("Arial", Font.PLAIN, 11);
    111         Font font12 = new Font("Arial", Font.PLAIN, 12);
    112         Font font14 = new Font("Arial", Font.PLAIN, 14);
    113         Font font24 = new Font("Arial", Font.PLAIN, 24);
    114        
    115         wndMain = new gamegui.Window("main", 0, 0, 800, 600, true);
    116        
    117         Animation anmTitle = new Animation("title", 144, 0, 512, 95, 1000/12);
    118        
    119         try {
    120                 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame1.png")));
    121                 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame2.png")));
    122                 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame3.png")));
    123                 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame4.png")));
    124                 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame5.png")));
    125         }catch(IOException ioe) {
    126                 ioe.printStackTrace();
    127         }
    128         wndMain.add(anmTitle);
    129        
    130         wndMain.add(new gamegui.Button("new game", 500, 140, 200, 40, "New Game", font12));
    131         wndMain.add(new gamegui.Button("load game", 500, 230, 200, 40, "Load Game", font12));
    132         wndMain.add(new gamegui.Button("game info", 500, 320, 200, 40, "Game Information", font12));
    133         wndMain.add(new gamegui.Button("credits", 500, 410, 200, 40, "Credits", font12));
    134         wndMain.add(new gamegui.Button("quit", 500, 500, 200, 40, "Quit", font12));
    135        
    136         wndCreateAccount = new gamegui.Window("create account", 0, 0, 800, 600, true);
    137        
    138         rdgGenderSelection = new RadioGroup("gender selection", 400, 315, 190, 30, "Gender:", font12);
    139        
    140         rdgGenderSelection.add(new RadioButton("male", 438, 318, 24, 24, "Male", font11, false));
    141         rdgGenderSelection.add(new RadioButton("female", 528, 318, 24, 24, "Female", font11, false));
    142        
    143         wndCreateAccount.add(new gamegui.Label("title", 250, 15, 300, 20, "Create an Account", font24, true));
    144         wndCreateAccount.add(new Textbox("user", 400, 150, 190, 30, "Username:", font12, false));
    145         wndCreateAccount.add(rdgGenderSelection);
    146         wndCreateAccount.add(new gamegui.Label("show class", 330, 370, 70, 30, "None", font12, false));
    147         wndCreateAccount.add(new gamegui.Button("choose class", 400, 370, 190, 30, "Choose Your Class", font12));
    148         wndCreateAccount.add(new gamegui.Button("create", 245, 520, 140, 30, "Create", font12));
    149         wndCreateAccount.add(new gamegui.Button("cancel", 415, 520, 140, 30, "Cancel", font12));
    150    
    151         wndChooseClass = new gamegui.Window("choose class", 0, 0, 800, 600, true);
    152        
    153         rdgClassSelection = new RadioGroup("class selection", 0, 0, 0, 0, "", font12);
    154        
    155         rdgClassSelection.add(new RadioButton("fighter", 138, 88, 24, 24, "Fighter", font14, true));
    156         rdgClassSelection.add(new RadioButton("ranger", 138, 158, 24, 24, "Ranger", font14, true));
    157         rdgClassSelection.add(new RadioButton("barbarian", 138, 228, 24, 24, "Barbarian", font14, true));
    158         rdgClassSelection.add(new RadioButton("sorceror", 138, 298, 24, 24, "Sorceror", font14, true));
    159         rdgClassSelection.add(new RadioButton("druid", 138, 368, 24, 24, "Druid", font14, true));
    160         rdgClassSelection.add(new RadioButton("wizard", 138, 438, 24, 24, "Wizard", font14, true));
    161        
    162         wndChooseClass.add(new gamegui.Label("title", 250, 15, 300, 20, "Choose a Character", font24, true));
    163         wndChooseClass.add(rdgClassSelection);
    164         wndChooseClass.add(new gamegui.Label("fighter", 170, 114, 170, 0, "A resolute and steadfast champion who has perfected the art of battle and his skill in melee weapons", font10, false));
    165         wndChooseClass.add(new gamegui.Label("ranger", 170, 184, 170, 0, "A skilled combatant who sneaks up on his opponents or shoots them from afar before they know it", font10, false));
    166         wndChooseClass.add(new gamegui.Label("barbarian", 170, 254, 170, 0, "A wild warrior who is unstoppable in battle and uses his own fury to strengthen his attacks", font10, false));
    167         wndChooseClass.add(new gamegui.Label("sorceror", 170, 324, 170, 0, "A chaotic spellcaster who uses his charisma and force of will to power his spells", font10, false));
    168         wndChooseClass.add(new gamegui.Label("druid", 170, 394, 170, 0, "A mystical enchanter who relies on the power of nature and his wisdom to work his magic", font10, false));
    169         wndChooseClass.add(new gamegui.Label("wizard", 170, 464, 170, 0, "A methodical and studious character who studies his opponents to know how to best attack them", font10, false));
    170         wndChooseClass.add(new gamegui.Button("select", 245, 520, 140, 30, "Select", font12));
    171         wndChooseClass.add(new gamegui.Button("cancel", 415, 520, 140, 30, "Cancel", font12));
    172        
    173         wndMessage = new gamegui.Window("message", 290, 135, 220, 160, false);
    174                 wndMessage.add(new gamegui.Label("label", 70, 15, 80, 12, "none", font12, true));
    175                 wndMessage.add(new gamegui.Button("button", 70, 115, 80, 30, "OK", font12));
    176     }
    177    
    178     private void loadMap() {
    179         landMap = new HashMap<LandType, Land>();
    180         structMap = new HashMap<StructureType, Structure>();
    181         BufferedImage nullImg = null;
    182        
    183         try {
    184                 girl = ImageIO.read(getClass().getResource("images/ArmoredGirl.png"));
    185                 guy = ImageIO.read(getClass().getResource("images/ArmoredGuy.png"));
    186         }catch(IOException ioe) {
    187                 ioe.printStackTrace();
    188         }
    189                
    190         landMap.put(LandType.Ocean, new Land(LandType.Ocean, "Ocean.png", false));
    191         landMap.put(LandType.Grass, new Land(LandType.Grass, "Grass.png", true));
    192        
    193         structMap.put(StructureType.None, new Structure(StructureType.None, nullImg, true));
    194         structMap.put(StructureType.BlueOrb, new Structure(StructureType.BlueOrb, "Blue Orb.png", false));
    195         structMap.put(StructureType.Cave, new Structure(StructureType.Cave, "Cave.png", false));
    196         structMap.put(StructureType.Gravestone, new Structure(StructureType.Gravestone, "Gravestone.png", false));
    197         structMap.put(StructureType.GraveyardFence1, new Structure(StructureType.GraveyardFence1, "HorGrave.png", false));
    198         structMap.put(StructureType.GraveyardFence2, new Structure(StructureType.GraveyardFence2, "VerGrave.png", false));
    199         structMap.put(StructureType.PicketFence1, new Structure(StructureType.PicketFence1, "HorPalisade.png", false));
    200         structMap.put(StructureType.PicketFence2, new Structure(StructureType.PicketFence2, "VerPalisade.png", false));
    201         structMap.put(StructureType.Hut, new Structure(StructureType.Hut, "Hut.png", false));
    202         structMap.put(StructureType.WitchHut, new Structure(StructureType.WitchHut, "Witch Hut.png", false));
    203         structMap.put(StructureType.Tent, new Structure(StructureType.Tent, "Tent.png", false));
    204         structMap.put(StructureType.LargeTent, new Structure(StructureType.LargeTent, "LargeTent.png", false));
    205         structMap.put(StructureType.House, new Structure(StructureType.House, "House.png", false));
    206         structMap.put(StructureType.Tree, new Structure(StructureType.Tree, "Trees.png", false));
    207         structMap.put(StructureType.BlueOrb, new Structure(StructureType.BlueOrb, "Blue Orb.png", false));
    208         structMap.put(StructureType.RedOrb, new Structure(StructureType.RedOrb, "Red Orb.png", false));
    209         structMap.put(StructureType.LoginPedestal, new Structure(StructureType.LoginPedestal, "YellowPedestal.png", true));
    210         structMap.put(StructureType.RejuvenationPedestal, new Structure(StructureType.RejuvenationPedestal, "PurplePedestal.png", true));
    211         structMap.put(StructureType.LifePedestal, new Structure(StructureType.LifePedestal, "RedPedestal.png", true));
    212         structMap.put(StructureType.ManaPedestal, new Structure(StructureType.ManaPedestal, "BluePedestal.png", true));
    213     }
    214    
    215     private void move() {
    216         double dist = player.getSpeed()*(System.currentTimeMillis()-player.getLastMoved())/1000;
    217         Point lastLoc = player.getLoc();
    218         Point target = player.getTarget();
    219         Point newLoc;
    220        
    221         player.setLastMoved(System.currentTimeMillis());
    222         if(Point.dist(lastLoc, player.getTarget()) <= dist)
    223                 player.setLoc(player.getTarget());
    224         else {
    225                 int xDif = (int)(Point.xDif(lastLoc, target)*dist/Point.dist(lastLoc, target));
    226                 int yDif = (int)(Point.yDif(lastLoc, target)*dist/Point.dist(lastLoc, target));
    227                 newLoc = new Point(lastLoc.getX(), lastLoc.getXMin()+xDif, lastLoc.getY(), lastLoc.getYMin()+yDif);
    228                 newLoc.setX(newLoc.getX()+newLoc.getXMin()/100);
    229                 newLoc.setXMin(newLoc.getXMin()%100);
    230                 newLoc.setY(newLoc.getY()+newLoc.getYMin()/100);
    231                 newLoc.setYMin(newLoc.getYMin()%100);
    232                 if(newLoc.getXMin()<0) {
    233                         newLoc.setX(newLoc.getX()-1);
    234                         newLoc.setXMin(newLoc.getXMin()+100);
    235                 }else if(newLoc.getYMin()<0) {
    236                         newLoc.setY(newLoc.getY()-1);
    237                         newLoc.setYMin(newLoc.getYMin()+100);
    238                 }
    239                 if(map.getLoc(newLoc.getX()/100, newLoc.getY()/100).isPassable())
    240                         player.setLoc(newLoc);
    241                 else
    242                         player.setTarget(player.getLoc());
    243         }
    244     }
    245    
    246     private void render(Graphics g) {
    247         g.setColor(Color.black);
    248         g.fillRect(0, 0, 800, 600);
    249        
    250         switch(gameState) {
    251                 case Main:
    252                         drawMain(g);
    253                         break;
    254                 case CreateAccount:
    255                         drawCreateAccount(g);
    256                         break;
    257                 case CreateClass:
    258                         drawCreateClass(g);
    259                         break;
    260                 case LoadGame:
    261                         drawLoadGame(g);
    262                         break;
    263                 case Info:
    264                         drawInfo(g);
    265                         break;
    266                 case Credits:
    267                         drawCredits(g);
    268                         break;
    269                 case Game:
    270                         calculateMapVertices();
    271             drawMap(g);
    272             drawItems(g);
    273             drawCreatures(g);
    274             drawChar(g);
    275             drawStatDisplay(g);
    276             drawChat(g);
    277                         break;
    278                 case GameMenu:
    279                         calculateMapVertices();
    280             drawMap(g);
    281             drawItems(g);
    282             drawCreatures(g);
    283             drawChar(g);
    284             drawStatDisplay(g);
    285             drawChat(g);
    286             drawGameMenu(g);
    287                         break;
    288                 case GameInventory:
    289                         calculateMapVertices();
    290             drawMap(g);
    291             drawItems(g);
    292             drawCreatures(g);
    293             drawChar(g);
    294             drawStatDisplay(g);
    295             drawChat(g);
    296             drawGameInventory(g);
    297                         break;
    298                 case GameStats:
    299                         calculateMapVertices();
    300             drawMap(g);
    301             drawItems(g);
    302             drawCreatures(g);
    303             drawChar(g);
    304             drawStatDisplay(g);
    305             drawChat(g);
    306             drawGameStats(g);
    307                         break;
    308                 }
    309        
    310         switch(auxState) {
    311                 case None:
    312                         break;
    313                 case MsgBox:
    314                         wndMessage.draw(g);
    315                         break;
    316                 }
    317     }
    318    
    319     public static String dateString() {
    320                 return new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date());
    321         }
    322    
    323     public void showMessage(String text) {
    324         auxState = AuxState.MsgBox;
    325         ((gamegui.Label)wndMessage.getMember("label")).setText(text);
    326     }
    327    
    328     private void calculateMapVertices() {
    329    
    330     }
    331    
    332     private void drawMain(Graphics g) {
    333         wndMain.draw(g);
    334        
    335         g.setColor(Color.red);
    336                 g.drawRect(10, 100, 380, 490);
    337                 g.drawRect(410, 100, 380, 490);
    338     }
    339    
    340     private void drawCreateAccount(Graphics g) {       
    341         wndCreateAccount.draw(g);
    342     }
    343    
    344     private void drawCreateClass(Graphics g) {
    345         wndChooseClass.draw(g);
    346     }
    347    
    348     private void drawLoadGame(Graphics g) {
    349         Font tempFont = new Font("Arial", Font.PLAIN, 12);
    350         FontMetrics metrics = g.getFontMetrics(tempFont);
    351        
    352         g.setFont(tempFont);
    353         g.setColor(Color.green);
    354         g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
    355     }
    356    
    357     private void drawInfo(Graphics g) {
    358         Font tempFont = new Font("Arial", Font.PLAIN, 12);
    359         FontMetrics metrics = g.getFontMetrics(tempFont);
    360        
    361         g.setFont(tempFont);
    362         g.setColor(Color.green);
    363         g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
    364     }
    365    
    366     private void drawCredits(Graphics g) {
    367         Font tempFont = new Font("Arial", Font.PLAIN, 12);
    368         FontMetrics metrics = g.getFontMetrics(tempFont);
    369        
    370         g.setFont(tempFont);
    371         g.setColor(Color.green);
    372         g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
    373     }
    374    
    375     private void drawMap(Graphics g) {
    376         int locX = player.getLoc().getX();
    377         int locY = player.getLoc().getY();
    378         int xLow = locX/100-4;
    379         int xHigh = xLow+9;
    380         int yLow = locY/100-3;
    381         int yHigh = yLow+7;
    382        
    383         if(xLow<0)
    384                 xLow = 0;
    385         if(xHigh>=map.getLength())
    386                 xHigh = map.getLength()-1;
    387         if(yLow<0)
    388                 yLow = 0;
    389         if(yHigh>=map.getHeight())
    390                 yHigh = map.getHeight()-1;
    391 
    392                 for(int x=xLow; x<xHigh; x++) {
    393                         for(int y=yLow; y<yHigh; y++) {
    394                                 g.drawImage(map.getLoc(x, y).getLand().getImg(), 400+x*100-locX, 300+y*100-locY, null);                         
    395                                 g.drawImage(map.getLoc(x, y).getStruct().getImg(), 400+x*100-locX, 300+y*100-locY, null);
    396                         }
    397                 }
    398     }
    399    
    400     private void drawItems(Graphics g) {
    401    
    402     }
    403    
    404     private void drawCreatures(Graphics g) {
    405    
    406     }
    407    
    408     private void drawChar(Graphics g) {
    409         switch(player.getGender()) {
    410                 case Female:
    411                         g.drawImage(girl, 375, 200, null);
    412                         break;
    413                 case Male:
    414                         g.drawImage(guy, 375, 200, null);
    415                         break;
    416                 }
    417     }
    418    
    419     private void drawStatDisplay(Graphics g) {
    420    
    421     }
    422    
    423     private void drawChat(Graphics g) {
    424    
    425     }
    426    
    427     private void drawGameMenu(Graphics g) {
    428    
    429     }
    430    
    431     private void drawGameInventory(Graphics g) {
    432    
    433     }
    434    
    435     private void drawGameStats(Graphics g) {
    436    
    437     }
    438    
    439     private void selectText(Textbox text) {
    440         if(selectedText != null)
    441                         selectedText.setSelected(false);
    442                 selectedText = text;
    443                
    444                 if(text != null)
    445                         text.setSelected(true);
    446     }
    447    
    448     private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
    449         for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) {
    450             DisplayMode[] modes = device.getDisplayModes();
    451             for (int i = 0; i < modes.length; i++) {
    452                 if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth()
    453                    && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight()
    454                    && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth())
    455                 {
    456                     return BEST_DISPLAY_MODES[x];
    457                 }
    458             }
    459         }
    460         return null;
    461     }
    462    
    463     public static void chooseBestDisplayMode(GraphicsDevice device) {
    464         DisplayMode best = getBestDisplayMode(device);
    465         if (best != null) {
    466             device.setDisplayMode(best);
    467         }
    468     }
    469    
    470     public void mousePressed(MouseEvent e) {
    471         switch(auxState) {
    472                 case None:
    473                         switch(gameState) {
    474                         case Main:                             
    475                                 if(wndMain.getMember("new game").isClicked(e.getX(),e.getY()))
    476                                         gameState = GameState.CreateAccount;
    477                                 else if(wndMain.getMember("load game").isClicked(e.getX(),e.getY()))
    478                                         gameState = GameState.LoadGame;
    479                                 else if(wndMain.getMember("game info").isClicked(e.getX(),e.getY()))
    480                                         gameState = GameState.Info;
    481                                 else if(wndMain.getMember("credits").isClicked(e.getX(),e.getY()))
    482                                         gameState = GameState.Credits;
    483                                 else if(wndMain.getMember("quit").isClicked(e.getX(),e.getY()))
    484                                         done = true;
    485                                 break;
    486                         case CreateAccount:
    487                                 if(wndCreateAccount.getMember("user").isClicked(e.getX(),e.getY()))
    488                                         selectText((Textbox)wndCreateAccount.getMember("user"));
    489                                 else if(wndCreateAccount.getMember("choose class").isClicked(e.getX(),e.getY())) {
    490                                         selectText(null);
    491                                         gameState = GameState.CreateClass;
    492                                 }else if(wndCreateAccount.getMember("create").isClicked(e.getX(),e.getY())) {
    493                                         String user = ((Textbox)wndCreateAccount.getMember("user")).getText();
    494                                         Gender gender = Gender.valueOf(rdgGenderSelection.getButton(rdgGenderSelection.getSelected()).getLabel());
    495                                        
    496                                         if(user.equals("")) {
    497                                                 showMessage("The username is empty");
    498                                         }else if(gender == Gender.None) {
    499                                                 showMessage("No gender has been selected");
    500                                         }else{
    501                                                 player = new Player(user, gender);
    502                                                 player.setSpeed(200);
    503                                                 player.setLoc(new Point(750, 860));
    504                                                 player.setTarget(player.getLoc());
    505                                                 gameState = GameState.Game;
    506                                         }
    507                                 }else if(wndCreateAccount.getMember("cancel").isClicked(e.getX(),e.getY())) {
    508                                         selectText(null);
    509                                         wndCreateAccount.clear();
    510                                         wndChooseClass.clear();
    511                                         gameState = GameState.Main;
    512                                 }else if(wndCreateAccount.handleEvent(e)) {
    513                                 }
    514                                 break;
    515                         case CreateClass:
    516                                 if(wndChooseClass.getMember("select").isClicked(e.getX(),e.getY())) {
    517                                         gameState = GameState.CreateAccount;
    518                                 }
    519                                 else if(wndChooseClass.getMember("cancel").isClicked(e.getX(),e.getY())) {
    520                                         gameState = GameState.CreateAccount;
    521                                 }else if(wndChooseClass.handleEvent(e)) {
    522                                 }
    523                                 break;
    524                         case LoadGame:
    525                                 gameState = GameState.Main;
    526                                 break;
    527                         case Info:
    528                                 gameState = GameState.Main;
    529                                 break;
    530                         case Credits:
    531                                 gameState = GameState.Main;
    532                                 break;
    533                         case Game:
    534                                 int newX = player.getLoc().getX()+e.getX()-400;
    535                                 int newY = player.getLoc().getY()+e.getY()-300;
    536                                 if(map.getLoc((int)(Math.floor(newX/100)), (int)(Math.floor(newY/100))).isPassable()) {
    537                                         player.setTarget(new Point(newX, newY));
    538                                         player.setLastMoved(System.currentTimeMillis());
    539                                 }
    540                                 break;
    541                         case GameMenu:
    542                                 break;
    543                         case GameInventory:
    544                                 break;
    545                         case GameStats:
    546                                 break;
    547                         }
    548                         break;
    549                 case MsgBox:
    550                         if(wndMessage.getMember("button").isClicked(e.getX(), e.getY())) {
    551                                 auxState = AuxState.None;
    552                         }
    553                         break;
    554                 }
    555         }
    556        
    557         public void mouseReleased(MouseEvent e) {
    558                
    559         }
    560        
    561         public void mouseEntered(MouseEvent e) {
    562 
    563         }
    564        
    565         public void mouseExited(MouseEvent e) {
    566            
    567         }
    568        
    569         public void mouseClicked(MouseEvent e) {
    570                
    571         }
    572  
    573         public void keyTyped(KeyEvent e) {
    574                
    575         }
    576        
    577         public void keyPressed(KeyEvent e) {
    578                 if(selectedText != null)
    579                         selectedText.handleEvent(e);
    580                
    581                 if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
    582                         if(gameState == GameState.Game)
    583                                 gameState = GameState.Main;
    584                         else
    585                                 done = true;
    586         }
    587        
    588         public void keyReleased(KeyEvent e) {
    589        
    590         }
    591    
    592         public static void main(String[] args) {
    593                 try {
    594                         PrintStream st = new PrintStream(new FileOutputStream("err.txt", true));
    595                         System.setErr(st);
    596                         System.setOut(st);
    597                         System.out.println("-----[ Session started on " + dateString() + " ]-----");
    598                        
    599                         GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    600                         GraphicsDevice device = env.getDefaultScreenDevice();
    601                         new LostHavenRPG(device);
    602         }
    603                 catch (Exception e) {
    604                         e.printStackTrace();
    605         }
    606                 System.exit(0);
    607         }
     1598    System.exit(0);
     1599  }
    6081600}
  • main/Map.java

    r155577b r8edd04e  
    11package main;
    22
     3import java.awt.Color;
     4import java.awt.image.BufferedImage;
    35import java.io.*;
    4 import java.util.*;
     6import java.util.HashMap;
     7
     8import javax.imageio.ImageIO;
    59
    610public class Map {
    7         private Location[][] grid;
    8        
    9         public Map(int x, int y) {
    10                 grid = new Location[x][y];
    11         }
    12        
    13         public Map(String landFile, String structFile, HashMap<LandType, Land> landMap, HashMap<StructureType, Structure> structMap) {
    14                 try {
    15                         int length, height, x, y;
    16                         String str, loc;
    17                         BufferedReader in = new BufferedReader(new FileReader(landFile));
    18                        
    19                         str = in.readLine();
    20                         length = Integer.parseInt(str.substring(0, str.indexOf("x")));
    21                         height = Integer.parseInt(str.substring(str.indexOf("x")+1));
    22                         grid = new Location[length][height];
    23                        
    24                         for(x=0; x<height; x++) {
    25                                 str = in.readLine();
    26                                 for(y=0; y<length; y++) {
    27                                         if(str.indexOf(",") == -1)
    28                                                 loc = str;
    29                                         else {
    30                                                 loc = str.substring(0, str.indexOf(","));
    31                                                 str = str.substring(str.indexOf(",")+1);
    32                                         }
    33                                        
    34                                         if(loc.equals("o")) {
    35                                                 loc = "Ocean";
    36                                         }else if(loc.equals("1")) {
    37                                                 loc = "Grass";
    38                                         }
    39                                        
    40                                         grid[y][x] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None));
    41                                 }
    42                         }
    43                        
    44                         in.close();
    45                        
    46                         in = new BufferedReader(new FileReader(structFile));
    47                        
    48                         while((loc = in.readLine()) != null) {
    49                                 str = in.readLine();
    50                                 x = Integer.valueOf(str.substring(0, str.indexOf(",")));
    51                                 y = Integer.valueOf(str.substring(str.indexOf(",")+1));
    52                                
    53                                 grid[x-1][y-1].setStruct(structMap.get(StructureType.valueOf(loc)));
    54                         }
    55                 } catch(IOException ioe) {
    56                         ioe.printStackTrace();
    57                 }
    58         }
    59        
    60         public Location getLoc(int x, int y) {
    61                 return grid[x][y];
    62         }
    63        
    64         public void setLoc(Location loc, int x, int y) {
    65                 grid[x][y] = loc;
    66         }
    67        
    68         public int getLength() {
    69                 return grid.length;
    70         }
    71        
    72         public int getHeight() {
    73                 if(grid.length>0)
    74                         return grid[0].length;
    75                 else
    76                         return 0;
    77         }
     11
     12  private Location[][] grid;
     13
     14  public Map(int x, int y) {
     15    this.grid = new Location[x][y];
     16  }
     17
     18  public Map(String mapFile, String structFile, HashMap<LandType, Land> landMap, HashMap<StructureType, Structure> structMap, boolean readMapFromImage) {
     19    if (readMapFromImage) {
     20      try {
     21        BufferedImage img = ImageIO.read(getClass().getResource("../images/" + mapFile));
     22        int length = img.getHeight();
     23        int height = img.getWidth();
     24        this.grid = new Location[height][length];
     25        int x;
     26        for (x = 0; x < height; x++) {
     27          for (int y = 0; y < length; y++) {
     28            String loc;
     29            Color clr = new Color(img.getRGB(x, y));
     30            if (clr.getRed() == 243 && clr.getGreen() == 119 && clr.getBlue() == 0) {
     31              loc = "Lava";
     32            } else if (clr.getRed() == 128 && clr.getGreen() == 0 && clr.getBlue() == 0) {
     33              loc = "Metal";
     34            } else if (clr.getRed() == 255 && clr.getGreen() == 0 && clr.getBlue() == 0) {
     35              loc = "Charred";
     36            } else if (clr.getRed() == 95 && clr.getGreen() == 155 && clr.getBlue() == 0) {
     37              loc = "Swamp";
     38            } else if (clr.getRed() == 0 && clr.getGreen() == 67 && clr.getBlue() == 0) {
     39              loc = "Vines";
     40            } else if (clr.getRed() == 255 && clr.getGreen() == 0 && clr.getBlue() == 255) {
     41              loc = "Crystal";
     42            } else if (clr.getRed() == 128 && clr.getGreen() == 0 && clr.getBlue() == 128) {
     43              loc = "CrystalFormation";
     44            } else if (clr.getRed() == 0 && clr.getGreen() == 0 && clr.getBlue() == 255) {
     45              loc = "Water";
     46            } else if (clr.getRed() == 0 && clr.getGreen() == 128 && clr.getBlue() == 0) {
     47              loc = "Forest";
     48            } else if (clr.getRed() == 139 && clr.getGreen() == 63 && clr.getBlue() == 43) {
     49              loc = "Tree";
     50            } else if (clr.getRed() == 179 && clr.getGreen() == 247 && clr.getBlue() == 207) {
     51              loc = "Plains";
     52            } else if (clr.getRed() == 255 && clr.getGreen() == 255 && clr.getBlue() == 0) {
     53              loc = "Desert";
     54            } else if (clr.getRed() == 83 && clr.getGreen() == 83 && clr.getBlue() == 83) {
     55              loc = "Mountains";
     56            } else if (clr.getRed() == 8 && clr.getGreen() == 0 && clr.getBlue() == 0) {
     57              loc = "Cave";
     58            } else if (clr.getRed() == 0 && clr.getGreen() == 0 && clr.getBlue() == 128) {
     59              loc = "Ocean";
     60            } else if (clr.getRed() == 0 && clr.getGreen() == 255 && clr.getBlue() == 255) {
     61              loc = "Snow";
     62            } else if (clr.getRed() == 160 && clr.getGreen() == 160 && clr.getBlue() == 164) {
     63              loc = "Steam";
     64            } else {
     65              loc = "Mountains";
     66            }
     67            this.grid[x][y] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None));
     68          }
     69        }
     70        BufferedReader in = new BufferedReader(new FileReader(structFile));
     71        String str;
     72        while ((str = in.readLine()) != null) {
     73          String loc = in.readLine();
     74          x = Integer.valueOf(loc.substring(0, loc.indexOf(","))).intValue();
     75          int y = Integer.valueOf(loc.substring(loc.indexOf(",") + 1)).intValue();
     76          Point loc1 = new Point((x - 1) * 100 + 50, (y - 1) * 100 + 50);
     77          if (str.equals("ArtifactPoint") || str.equals("BossPoint")) {
     78            String strTarg = in.readLine();
     79            int x2 = Integer.valueOf(strTarg.substring(0, strTarg.indexOf(","))).intValue();
     80            int y2 = Integer.valueOf(strTarg.substring(strTarg.indexOf(",") + 1)).intValue();
     81            Point loc2 = new Point((x2 - 1) * 100 + 50, (y2 - 1) * 100 + 50);
     82            ArtifactPoint struct = new ArtifactPoint((ArtifactPoint)structMap.get(StructureType.valueOf(str)), loc1);
     83            struct.setTarget(loc2);
     84            this.grid[x - 1][y - 1].setStruct(struct);
     85            ArtifactPoint struct2 = new ArtifactPoint((ArtifactPoint)structMap.get(StructureType.valueOf(str)), loc2);
     86            struct2.setTarget(loc1);
     87            this.grid[x2 - 1][y2 - 1].setStruct(struct2);
     88            continue;
     89          }
     90          if (str.equals("RespawnPoint")) {
     91            this.grid[x - 1][y - 1].setStruct(new RespawnPoint((RespawnPoint)structMap.get(StructureType.valueOf(str)), loc1));
     92            LostHavenRPG.respawnPoints.add((RespawnPoint)this.grid[x - 1][y - 1].getStruct());
     93            continue;
     94          }
     95          this.grid[x - 1][y - 1].setStruct(new Structure(structMap.get(StructureType.valueOf(str)), loc1));
     96        }
     97        in.close();
     98      } catch (IOException ioe) {
     99        ioe.printStackTrace();
     100      }
     101    } else {
     102      try {
     103        BufferedReader in = new BufferedReader(new FileReader("../" + mapFile));
     104        String str = in.readLine();
     105        int length = Integer.parseInt(str.substring(0, str.indexOf("x")));
     106        int height = Integer.parseInt(str.substring(str.indexOf("x") + 1));
     107        this.grid = new Location[length][height];
     108        int x;
     109        for (x = 0; x < height; x++) {
     110          str = in.readLine();
     111          for (int y = 0; y < length; y++) {
     112            String loc;
     113            if (str.indexOf(",") == -1) {
     114              loc = str;
     115            } else {
     116              loc = str.substring(0, str.indexOf(","));
     117              str = str.substring(str.indexOf(",") + 1);
     118            }
     119            if (loc.equals("o")) {
     120              loc = "OceanOld";
     121            } else if (loc.equals("1")) {
     122              loc = "GrassOld";
     123            }
     124            this.grid[y][x] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None));
     125          }
     126        }
     127        in.close();
     128        in = new BufferedReader(new FileReader(structFile));
     129        while ((str = in.readLine()) != null) {
     130          String loc = in.readLine();
     131          x = Integer.valueOf(loc.substring(0, loc.indexOf(","))).intValue();
     132          int y = Integer.valueOf(loc.substring(loc.indexOf(",") + 1)).intValue();
     133          this.grid[x - 1][y - 1].setStruct(structMap.get(StructureType.valueOf(str)));
     134        }
     135        in.close();
     136      } catch (IOException ioe) {
     137        ioe.printStackTrace();
     138      }
     139    }
     140  }
     141
     142  public void clearCreatures() {
     143    for (int x = 0; x < getLength(); x++) {
     144      for (int y = 0; y < getHeight(); y++) {
     145        getLoc(x, y).getCreatures().clear();
     146      }
     147    }
     148  }
     149
     150  public Location getLoc(int x, int y) {
     151    return this.grid[x][y];
     152  }
     153
     154  public void setLoc(Location loc, int x, int y) {
     155    this.grid[x][y] = loc;
     156  }
     157
     158  public int getLength() {
     159    return this.grid.length;
     160  }
     161
     162  public int getHeight() {
     163    if (this.grid.length > 0) {
     164      return (this.grid[0]).length;
     165    }
     166    return 0;
     167  }
    78168}
  • main/MapElement.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.awt.image.*;
     3import java.awt.image.BufferedImage;
    44import java.io.IOException;
    55
     
    77
    88public class MapElement {
    9         private BufferedImage img;
    10         private boolean passable;
    11        
    12         public MapElement(BufferedImage img, boolean passable) {
    13                 this.img = img;
    14                 this.passable = passable;
    15         }
    16        
    17         public MapElement(String imgFile, boolean passable) {
    18                 try {
    19                         img = ImageIO.read(getClass().getResource("images/"+imgFile));
    20                         this.passable = passable;
    21                 }catch(IOException ioe) {
    22                 ioe.printStackTrace();
    23         }
    24         }
    25        
    26         public BufferedImage getImg() {
    27                 return img;
    28         }
    29        
    30         public boolean isPassable() {
    31                 return passable;
    32         }
    33        
    34         public void setImg(BufferedImage img) {
    35                 this.img = img;
    36         }
    37        
    38         public void setPassable(boolean passable) {
    39                 this.passable = passable;
    40         }
     9
     10  private BufferedImage img;
     11  private boolean passable;
     12
     13  public MapElement(BufferedImage img, boolean passable) {
     14    this.img = img;
     15    this.passable = passable;
     16  }
     17
     18  public MapElement(String imgFile, boolean passable) {
     19    try {
     20      this.img = ImageIO.read(getClass().getResource("../images/" + imgFile));
     21      this.passable = passable;
     22    } catch (IOException ioe) {
     23      ioe.printStackTrace();
     24    }
     25  }
     26
     27  public MapElement(MapElement copy) {
     28    this.img = copy.img;
     29    this.passable = copy.passable;
     30  }
     31
     32  public BufferedImage getImg() {
     33    return this.img;
     34  }
     35
     36  public boolean isPassable() {
     37    return this.passable;
     38  }
     39
     40  public void setImg(BufferedImage img) {
     41    this.img = img;
     42  }
     43
     44  public void setPassable(boolean passable) {
     45    this.passable = passable;
     46  }
    4147}
  • main/Player.java

    r155577b r8edd04e  
    11package main;
    22
     3import java.awt.Font;
     4import java.awt.Graphics;
     5import java.awt.MouseInfo;
     6import java.io.*;
     7import java.util.*;
     8
     9import gamegui.*;
     10
    311public class Player extends Creature {
    4         private Point target;
    5         private int experience;
    6         private int gold;
    7        
    8         public Player() {
    9                 super();
    10                 target = new Point(0, 0);
    11         }
    12 
    13         public Player(String name) {
    14                 super(name);
    15                 target = new Point(0, 0);
    16         }
    17        
    18         public Player(String name, Gender gender) {
    19                 super(name, gender);
    20                 target = new Point(0, 0);
    21         }
    22        
    23         public int getExperience() {
    24                 return experience;
    25         }
    26        
    27         public int getGold() {
    28                 return gold;
    29         }
    30        
    31         public Point getTarget() {
    32                 return target;
    33         }
    34        
    35         public void setExperience(int experience) {
    36                 this.experience = experience;
    37         }
    38        
    39         public void setGold(int gold) {
    40                 this.gold = gold;
    41         }
    42        
    43         public void setTarget(Point target) {
    44                 this.target = target;
    45         }
     12
     13  private int gold;
     14  private int attributePoints;
     15  private int[] skills;
     16  private int skillPoints;
     17  private LinkedList<Item> inventory;
     18  private LinkedList<Item> gemsUsed;
     19  private HashMap<Gem, Integer> gems;
     20  private int relicCount;
     21  private int gemValue;
     22  private long timePlayed;
     23  private long timeLoggedOn;
     24
     25  public Player() {
     26    this.name = "Player";
     27    this.type = CreatureType.Player;
     28    this.skills = new int[9];
     29    this.inventory = new LinkedList<Item>();
     30    this.gemsUsed = new LinkedList<Item>();
     31    this.gems = new HashMap<Gem, Integer>();
     32    this.relicCount = 0;
     33    this.gemValue = 0;
     34    this.timePlayed = 0L;
     35    this.timeLoggedOn = 0L;
     36  }
     37
     38  public Player(Player p) {
     39    super(p);
     40    this.skills = (int[])p.skills.clone();
     41    this.attributePoints = p.attributePoints;
     42    this.skillPoints = p.skillPoints;
     43    this.inventory = new LinkedList<Item>(p.inventory);
     44    this.gemsUsed = new LinkedList<Item>(p.gemsUsed);
     45    this.gems = new HashMap<Gem, Integer>(p.gems);
     46    this.relicCount = p.relicCount;
     47    this.gemValue = p.gemValue;
     48    this.timePlayed = p.timePlayed;
     49    this.timeLoggedOn = p.timeLoggedOn;
     50  }
     51
     52  public Player copy() {
     53    return new Player(this);
     54  }
     55
     56  public boolean readyForBoss() {
     57    return (this.relicCount >= 4);
     58  }
     59
     60  public void setTimeLoggedOn(long time) {
     61    this.timeLoggedOn = time;
     62  }
     63
     64  public long getTimePlayed() {
     65    return this.timePlayed;
     66  }
     67
     68  public void updateTimePlayed() {
     69    this.timePlayed += System.currentTimeMillis() - this.timeLoggedOn;
     70  }
     71
     72  public void drawInventory(Graphics g, ScrollList inv, int x, int y) {
     73    int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
     74    int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
     75    int locX = (mouseX - x) / 50;
     76    int locY = (mouseY - y + inv.getTextStart()) / 50;
     77    if (locX + 4 * locY >= 0 && locX + 4 * locY < inv.getList().size()) {
     78      Window popup;
     79      String itemType;
     80      MultiTextbox desc;
     81      Item i = ((ItemImg)inv.getList().get(locX + locY * 4)).getItem();
     82      switch (i.getType()) {
     83        case Relic:
     84          popup = new Window("popup", mouseX - 100, mouseY - 150, 100, 165, false);
     85          break;
     86        default:
     87          popup = new Window("popup", mouseX - 100, mouseY - 100, 100, 100, false);
     88          break;
     89      }
     90      Font font12 = new Font("Arial", 0, 12);
     91      switch (i.getType()) {
     92        case LightWeapon:
     93          itemType = "Light Weapon";
     94          break;
     95        case HeavyWeapon:
     96          itemType = "Heavy Weapon";
     97          break;
     98        case RangedWeapon:
     99          itemType = "Ranged Weapon";
     100          break;
     101        default:
     102          itemType = i.getType().toString();
     103          break;
     104      }
     105      popup.add(new Label("name", 5, 5, 90, 15, i.getName(), font12));
     106      popup.add(new Label("type", 5, 35, 90, 15, itemType, font12));
     107      switch (i.getType()) {
     108        case LightWeapon:
     109        case HeavyWeapon:
     110        case RangedWeapon:
     111          popup.add(new Label("damage", 5, 50, 90, 15, "Damage: " + ((Weapon)i).getDamage(), font12));
     112          popup.add(new Label("damage", 5, 65, 90, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + " s", font12));
     113          break;
     114        case Spell:
     115          popup.add(new Label("energy", 5, 50, 90, 15, "Energy: " + ((Gem)i).getValue(), font12));
     116          desc = new MultiTextbox("description", 1, 80, 99, 84, "", false, font12, g.getFontMetrics(font12));
     117          desc.setText(i.getDescription());
     118          desc.setBorder(false);
     119          popup.add(desc);
     120          break;
     121      }
     122      popup.draw(g);
     123    }
     124  }
     125
     126  public void save(PrintWriter out) {
     127    super.save(out);
     128    out.println(this.name);
     129    out.println(this.level);
     130    out.println(this.timePlayed);
     131    out.println(this.experience);
     132    out.println(String.valueOf(getTarget().getX()) + "," + getTarget().getY());
     133    out.println(getAttribute(Attribute.Strength));
     134    out.println(getAttribute(Attribute.Dexterity));
     135    out.println(getAttribute(Attribute.Constitution));
     136    out.println(getAttribute(Attribute.Wisdom));
     137    out.println(getSkill(Skill.LightWeapons));
     138    out.println(getSkill(Skill.HeavyWeapons));
     139    out.println(getSkill(Skill.RangedWeapons));
     140    out.println(getSkill(Skill.Evocation));
     141    out.println(getSkill(Skill.Enchantment));
     142    out.println(this.attributePoints);
     143    out.println(this.skillPoints);
     144    out.println(getMaxHitpoints());
     145    out.println(getMaxManapoints());
     146    Object[] arr = LostHavenRPG.respawnPoints.toArray();
     147    for (int x = 0; x < arr.length; x++) {
     148      if (((RespawnPoint)arr[x]).isMarked())
     149        out.println(x);
     150    }
     151    out.println("---");
     152    Iterator<Item> iter = this.inventory.iterator();
     153    while (iter.hasNext())
     154      out.println(((Item)iter.next()).getName());
     155    out.println("---");
     156    iter = this.gemsUsed.iterator();
     157    while (iter.hasNext())
     158      out.println(((Item)iter.next()).getName());
     159    out.println("---");
     160  }
     161
     162  public static Player loadTemplate(BufferedReader in) {
     163    Player p = new Player();
     164    try {
     165      p.level = Integer.parseInt(in.readLine());
     166      p.setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine()));
     167      p.setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine()));
     168      p.setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine()));
     169      p.setSkill(Skill.Evocation, Integer.parseInt(in.readLine()));
     170      p.setSkill(Skill.Enchantment, Integer.parseInt(in.readLine()));
     171      p.attributePoints = Integer.parseInt(in.readLine());
     172      p.skillPoints = Integer.parseInt(in.readLine());
     173    } catch (IOException ioe) {
     174      ioe.printStackTrace();
     175    }
     176    return p;
     177  }
     178
     179  public void load(BufferedReader in) {
     180    try {
     181      super.load(in);
     182      int hp = getHitpoints();
     183      int mp = getManapoints();
     184      setName(in.readLine());
     185      this.level = Integer.valueOf(in.readLine()).intValue();
     186      this.timePlayed = Long.valueOf(in.readLine()).longValue();
     187      setExperience(Integer.valueOf(in.readLine()).intValue());
     188      String strTarget = in.readLine();
     189      getTarget().setX(Integer.valueOf(strTarget.substring(0, strTarget.indexOf(","))).intValue());
     190      getTarget().setY(Integer.valueOf(strTarget.substring(strTarget.indexOf(",") + 1)).intValue());
     191      setAttribute(Attribute.Strength, Integer.parseInt(in.readLine()));
     192      setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine()));
     193      setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine()));
     194      setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine()));
     195      setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine()));
     196      setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine()));
     197      setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine()));
     198      setSkill(Skill.Evocation, Integer.parseInt(in.readLine()));
     199      setSkill(Skill.Enchantment, Integer.parseInt(in.readLine()));
     200      this.attributePoints = Integer.parseInt(in.readLine());
     201      this.skillPoints = Integer.parseInt(in.readLine());
     202      setMaxHitpoints(Integer.parseInt(in.readLine()));
     203      setMaxManapoints(Integer.parseInt(in.readLine()));
     204      setHitpoints(hp);
     205      setManapoints(mp);
     206      setWeapon(this.weapon.baseWeapon);
     207      String strItem;
     208      while (!(strItem = in.readLine()).equals("---"))
     209        ((RespawnPoint)LostHavenRPG.respawnPoints.get(Integer.parseInt(strItem))).mark();
     210      this.weapon.update();
     211      while (!(strItem = in.readLine()).equals("---"))
     212        pickUp(LostHavenRPG.items.get(strItem));
     213      while (!(strItem = in.readLine()).equals("---")) {
     214        pickUp(LostHavenRPG.items.get(strItem));
     215        activateGem((Gem)LostHavenRPG.items.get(strItem));
     216      }
     217    } catch (IOException ioe) {
     218      ioe.printStackTrace();
     219    }
     220  }
     221
     222  public void pickUp(Item item) {
     223    this.inventory.add(item);
     224    LostHavenRPG.lstInventory.getList().add(new ItemImg(item));
     225    if (item.isRelic()) {
     226      this.relicCount++;
     227    }
     228  }
     229
     230  public boolean activateGem(Gem item) {
     231    if (this.gemValue + item.getValue() > getSkill(Skill.Evocation))
     232      return false;
     233    this.gemsUsed.add(item);
     234    LostHavenRPG.lstGems.getList().add(new ItemImg(item));
     235    this.inventory.remove(item);
     236    LostHavenRPG.lstInventory.getList().remove(new ItemImg(item));
     237    this.gemValue += item.getValue();
     238    addGem((Gem)LostHavenRPG.items.get(item.getName()));
     239    if (getSpell() == null) {
     240      setSpell(new Weapon("spell", ItemType.Spell, "Dagger.png", new java.awt.image.BufferedImage[8], 10, 250, 0));
     241    }
     242    getSpell().update();
     243    return true;
     244  }
     245
     246  public void deactivateGem(Gem item) {
     247    this.inventory.add(item);
     248    LostHavenRPG.lstInventory.getList().add(new ItemImg(item));
     249    this.gemsUsed.remove(item);
     250    LostHavenRPG.lstGems.getList().remove(new ItemImg(item));
     251    this.gemValue -= item.getValue();
     252    removeGem((Gem)LostHavenRPG.items.get(item.getName()));
     253    if (this.gemsUsed.size() == 0) {
     254      this.spell = null;
     255    } else {
     256      getSpell().update();
     257    }
     258  }
     259
     260  public LinkedList<Item> getInventory() {
     261    return this.inventory;
     262  }
     263
     264  public LinkedList<Item> getGems() {
     265    return this.gemsUsed;
     266  }
     267
     268  public void initGems(LinkedList<Gem> lstGems) {
     269    Iterator<Gem> iter = lstGems.iterator();
     270    while (iter.hasNext())
     271      this.gems.put(iter.next(), Integer.valueOf(0));
     272  }
     273
     274  public void addGem(Gem gem) {
     275    this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() + 1));
     276  }
     277
     278  public void removeGem(Gem gem) {
     279    this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() - 1));
     280  }
     281
     282  public int getGemNum(String name) {
     283    Iterator<Gem> iter = this.gems.keySet().iterator();
     284    while (iter.hasNext()) {
     285      Gem cur = iter.next();
     286      if (cur.getName().equals(name)) {
     287        return ((Integer)this.gems.get(cur)).intValue();
     288      }
     289    }
     290    return 0;
     291  }
     292
     293  public void increaseLevel() {
     294    this.skillPoints += 2;
     295    setHitpoints(getHitpoints() + getAttribute(Attribute.Constitution));
     296    setMaxHitpoints(getMaxHitpoints() + getAttribute(Attribute.Constitution));
     297    setManapoints(getManapoints() + getAttribute(Attribute.Wisdom));
     298    setMaxManapoints(getMaxManapoints() + getAttribute(Attribute.Wisdom));
     299    setLevel(getLevel() + 1);
     300  }
     301
     302  public void allocateAttribute(Attribute point) {
     303    if (this.attributePoints > 0) {
     304      setAttribute(point, getAttribute(point) + 1);
     305      this.attributePoints--;
     306    }
     307  }
     308
     309  public void repickAttribute(Attribute point) {
     310    if (getAttribute(point) > 6) {
     311      setAttribute(point, getAttribute(point) - 1);
     312      this.attributePoints++;
     313    }
     314  }
     315
     316  public void allocateSkill(Skill point) {
     317    if (this.skillPoints > 0) {
     318      setSkill(point, getSkill(point) + 1);
     319      this.skillPoints--;
     320      this.weapon.update();
     321    }
     322  }
     323
     324  public void repickSkill(Skill point) {
     325    if (getSkill(point) > 0) {
     326      setSkill(point, getSkill(point) - 1);
     327      this.skillPoints++;
     328      this.weapon.update();
     329    }
     330  }
     331
     332  private int skillIndex(Skill skill) {
     333    switch (skill) {
     334      case LightWeapons:
     335        return 0;
     336      case HeavyWeapons:
     337        return 1;
     338      case RangedWeapons:
     339        return 2;
     340      case Evocation:
     341        return 3;
     342      case Enchantment:
     343        return 4;
     344    }
     345    return -1;
     346  }
     347
     348  public int getSkill(Skill skill) {
     349    return this.skills[skillIndex(skill)];
     350  }
     351
     352  public void setSkill(Skill skill, int num) {
     353    this.skills[skillIndex(skill)] = num;
     354  }
     355
     356  public int getGold() {
     357    return this.gold;
     358  }
     359
     360  public int getAttributePoints() {
     361    return this.attributePoints;
     362  }
     363
     364  public int getSkillPoints() {
     365    return this.skillPoints;
     366  }
     367
     368  public int getGemValue() {
     369    return this.gemValue;
     370  }
     371
     372  public int getRelicCount() {
     373    return this.relicCount;
     374  }
     375
     376  public void setWeapon(Weapon weapon) {
     377    this.weapon = new EquippedWeapon(this, weapon);
     378    switch (weapon.getType()) {
     379      case LightWeapon:
     380      case HeavyWeapon:
     381        setModel(LostHavenRPG.meleeModel);
     382        break;
     383      case RangedWeapon:
     384        setModel(LostHavenRPG.rangedModel);
     385        break;
     386    }
     387    this.weapon.update();
     388    (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size());
     389    (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size());
     390    (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size());
     391    (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size());
     392  }
     393
     394  public void setGold(int gold) {
     395    this.gold = gold;
     396  }
     397
     398  public void setAttributePoints(int attributePoints) {
     399    this.attributePoints = attributePoints;
     400  }
     401
     402  public void setAttribute(Attribute attribute, int num) {
     403    this.attributes[attributeIndex(attribute)] = num;
     404    updateStats();
     405  }
     406
     407  private void updateStats() {
     408    this.hitpoints = 4 * this.attributes[2];
     409    this.maxHitpoints = 4 * this.attributes[2];
     410    this.manapoints = 2 * this.attributes[3];
     411    this.maxManapoints = 2 * this.attributes[3];
     412  }
     413
     414  public class ItemImg implements Listable {
     415    public Item i;
     416    public int xCoord;
     417    public int yCoord;
     418
     419    public ItemImg(Item i) {
     420      this.i = i;
     421    }
     422
     423    public void draw(int x, int y, Graphics g) {
     424      this.xCoord = x;
     425      this.yCoord = y;
     426      this.i.drawStatic(g, x, y);
     427    }
     428
     429    public Item getItem() {
     430      return this.i;
     431    }
     432
     433    public int getHeight() {
     434      return this.i.getImg().getHeight();
     435    }
     436
     437    public int getWidth() {
     438      return this.i.getImg().getWidth();
     439    }
     440
     441    public int getXOffset() {
     442      return 0;
     443    }
     444
     445    public int getYOffset() {
     446      return 0;
     447    }
     448
     449    public boolean equals(Object o) {
     450      return (((ItemImg)o).i == this.i);
     451    }
     452  }
    46453}
  • main/Point.java

    r155577b r8edd04e  
    22
    33public class Point {
    4         private int x;
    5         private int xMin;
    6         private int y;
    7         private int yMin;
    8        
    9         public Point() {
    10                 x = 0;
    11                 y = 0;
    12         }
    134
    14         public Point(int x, int y) {
    15                 this.x = x;
    16                 this.xMin = 0;
    17                 this.y = y;
    18                 this.yMin = 0;
    19         }
    20        
    21         public Point(int x, int xMin, int y, int yMin) {
    22                 this.x = x;
    23                 this.xMin = xMin;
    24                 this.y = y;
    25                 this.yMin = yMin;
    26         }
     5  private int x;
     6  private int xMin;
     7  private int y;
     8  private int yMin;
    279
    28         public int getX() {
    29                 return x;
    30         }
    31        
    32         public int getXMin() {
    33                 return xMin;
    34         }
     10  public Point() {
     11    this.x = 0;
     12    this.y = 0;
     13  }
    3514
    36         public int getY() {
    37                 return y;
    38         }
    39        
    40         public int getYMin() {
    41                 return yMin;
    42         }
     15  public Point(int x, int y) {
     16    this.x = x;
     17    this.xMin = 0;
     18    this.y = y;
     19    this.yMin = 0;
     20  }
    4321
    44         public void setX(int x) {
    45                 this.x = x;
    46         }
    47        
    48         public void setXMin(int xMin) {
    49                 this.xMin = xMin;
    50         }
     22  public Point(int x, int xMin, int y, int yMin) {
     23    this.x = x;
     24    this.xMin = xMin;
     25    this.y = y;
     26    this.yMin = yMin;
     27  }
    5128
    52         public void setY(int y) {
    53                 this.y = y;
    54         }
    55        
    56         public void setYMin(int yMin) {
    57                 this.yMin = yMin;
    58         }
    59        
    60         public String toString() {
    61                 return x+","+y;
    62         }
    63        
    64         public static int xDif(Point p1, Point p2) {
    65                 return 100*(p2.x-p1.x)+p2.xMin-p1.xMin;
    66         }
    67        
    68         public static int yDif(Point p1, Point p2) {
    69                 return 100*(p2.y-p1.y)+p2.yMin-p1.yMin;
    70         }
    71        
    72         public static double dist(Point p1, Point p2) {
    73                 return Math.sqrt(Math.pow(p1.x+p1.xMin/100-p2.x-p2.xMin/100, 2)+Math.pow(p1.y+p1.yMin/100-p2.y-p2.yMin/100, 2));
    74         }
     29  public Point(Point p) {
     30    this.x = p.x;
     31    this.xMin = p.xMin;
     32    this.y = p.y;
     33    this.yMin = p.yMin;
     34  }
     35
     36  public int getX() {
     37    return this.x;
     38  }
     39
     40  public int getXMin() {
     41    return this.xMin;
     42  }
     43
     44  public int getY() {
     45    return this.y;
     46  }
     47
     48  public int getYMin() {
     49    return this.yMin;
     50  }
     51
     52  public void setX(int x) {
     53    this.x = x;
     54  }
     55
     56  public void setXMin(int xMin) {
     57    this.xMin = xMin;
     58  }
     59
     60  public void setY(int y) {
     61    this.y = y;
     62  }
     63
     64  public void setYMin(int yMin) {
     65    this.yMin = yMin;
     66  }
     67
     68  public boolean equals(Point p) {
     69    return (this.x == p.x && this.y == p.y && this.xMin == p.xMin && this.yMin == p.yMin);
     70  }
     71
     72  public String toString() {
     73    return String.valueOf(this.x) + "," + this.y;
     74  }
     75
     76  public static int xDif(Point p1, Point p2) {
     77    return 100 * (p2.x - p1.x) + p2.xMin - p1.xMin;
     78  }
     79
     80  public static int yDif(Point p1, Point p2) {
     81    return 100 * (p2.y - p1.y) + p2.yMin - p1.yMin;
     82  }
     83
     84  public static double dist(Point p1, Point p2) {
     85    return Math.sqrt(Math.pow((p1.x + p1.xMin / 100 - p2.x - p2.xMin / 100), 2.0D) + Math.pow((p1.y + p1.yMin / 100 - p2.y - p2.yMin / 100), 2.0D));
     86  }
    7587}
  • main/SpawnPoint.java

    r155577b r8edd04e  
    11package main;
    22
     3import java.util.Iterator;
     4import java.util.Random;
     5
    36public class SpawnPoint {
    4         Point loc;
    5         long lastSpawned;
    6         long interval;
    7         Creature creature;
    8        
    9         public SpawnPoint(Point loc, long interval, Creature creature) {
    10                 this.loc = loc;
    11                 this.interval = interval;
    12                 this.creature = creature;
    13                 lastSpawned = 0;
    14         }
    15        
    16         //calling class handles the actual spawning of the creature if this method returns true
    17         public boolean spawn() {
    18                 if((System.currentTimeMillis()-lastSpawned) >= interval) {
    19                         lastSpawned = System.currentTimeMillis();
    20                         return true;
    21                 }else {
    22                         return false;
    23                 }
    24         }
     7
     8  static int numSpawnPoints = 0;
     9
     10  Point loc;
     11  long lastSpawned;
     12  long interval;
     13  Creature creature;
     14  int numSpawns;
     15  int maxSpawns;
     16  int idNum;
     17
     18  public SpawnPoint(Creature creature, Point loc, long interval, int maxSpawns) {
     19    this.creature = creature;
     20    this.loc = loc;
     21    this.interval = interval;
     22    this.maxSpawns = maxSpawns;
     23    this.lastSpawned = 0L;
     24    this.idNum = ++numSpawnPoints;
     25  }
     26
     27  public Creature spawn() {
     28    if (System.currentTimeMillis() - this.lastSpawned >= this.interval && this.numSpawns < this.maxSpawns) {
     29      this.lastSpawned = System.currentTimeMillis();
     30      Creature cr = this.creature.copy();
     31      Point newLoc = null;
     32      Random gen = new Random();
     33      boolean goodLoc = false, occupied = false;
     34      while (!goodLoc) {
     35        newLoc = new Point(this.loc.getX() - 400 + gen.nextInt(800), this.loc.getY() - 400 + gen.nextInt(800));
     36        if (newLoc.getX() >= 0 && newLoc.getY() >= 0 && LostHavenRPG.map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && Point.dist(newLoc, this.loc) <= 400.0D) {
     37          occupied = false;
     38          int xLow = newLoc.getX() / 100 - 2;
     39          int xHigh = xLow + 5;
     40          int yLow = newLoc.getY() / 100 - 2;
     41          int yHigh = yLow + 5;
     42          if (xLow < 0) {
     43            xLow = 0;
     44          }
     45          if (xHigh > LostHavenRPG.map.getLength()) {
     46            xHigh = LostHavenRPG.map.getLength();
     47          }
     48          if (yLow < 0) {
     49            yLow = 0;
     50          }
     51          if (yHigh > LostHavenRPG.map.getHeight()) {
     52            yHigh = LostHavenRPG.map.getHeight();
     53          }
     54          for (int x = xLow; x < xHigh; x++) {
     55            for (int y = yLow; y < yHigh; y++) {
     56              Iterator<Creature> iter = LostHavenRPG.map.getLoc(x, y).getCreatures().iterator();
     57              while (iter.hasNext() && !occupied) {
     58                Creature cur = iter.next();
     59                if (Point.dist(cur.getLoc(), newLoc) < 100.0D) {
     60                  occupied = true;
     61                }
     62              }
     63            }
     64          }
     65          if (!occupied) {
     66            goodLoc = true;
     67          }
     68        }
     69      }
     70      cr.setLoc(newLoc);
     71      cr.setSpawnPoint(this);
     72      this.numSpawns++;
     73      return cr;
     74    }
     75
     76    return null;
     77  }
     78
     79  public CreatureType getType() {
     80    return this.creature.getType();
     81  }
     82
     83  public Point getLoc() {
     84    return this.loc;
     85  }
     86
     87  public void removeCreature() {
     88    this.numSpawns--;
     89  }
     90
     91  public void clear() {
     92    this.numSpawns = 0;
     93    this.lastSpawned = 0L;
     94  }
    2595}
  • main/Structure.java

    r155577b r8edd04e  
    11package main;
    22
    3 import java.awt.image.*;
     3import java.awt.image.BufferedImage;
    44
    55public class Structure extends MapElement {
    6         private StructureType type;
    7        
    8         public Structure(StructureType type, BufferedImage img, boolean passable) {
    9                 super(img, passable);
    10                
    11                 this.type = type;
    12         }
    13        
    14         public Structure(StructureType type, String imgFile, boolean passable) {
    15                 super(imgFile, passable);
    16                
    17                 this.type = type;
    18         }
    19        
    20         public StructureType getType() {
    21                 return type;
    22         }
     6
     7  private StructureType type;
     8  private Point loc;
     9
     10  public Structure(StructureType type, BufferedImage img, boolean passable) {
     11    super(img, passable);
     12    this.type = type;
     13    this.loc = null;
     14  }
     15
     16  public Structure(StructureType type, String imgFile, boolean passable) {
     17    super(imgFile, passable);
     18    this.type = type;
     19    this.loc = null;
     20  }
     21
     22  public Structure(Structure copy, Point loc) {
     23    super(copy);
     24    this.type = copy.type;
     25    this.loc = loc;
     26  }
     27
     28  public StructureType getType() {
     29    return this.type;
     30  }
     31
     32  public Point getLoc() {
     33    return this.loc;
     34  }
    2335}
  • main/StructureType.java

    r155577b r8edd04e  
    22
    33public enum StructureType {
    4     None,
    5     Tent,
    6     LargeTent,
    7     House,
    8     Cave,
    9     Gravestone,
    10     GraveyardFence1,
    11     GraveyardFence2,
    12     PicketFence1,
    13     PicketFence2,
    14     Hut,
    15     WitchHut,
    16     Tree,
    17     BlueOrb,
    18     RedOrb,
    19     LoginPedestal,
    20     RejuvenationPedestal,
    21     LifePedestal,
    22     ManaPedestal
     4  None,
     5  Tent,
     6  LargeTent,
     7  House,
     8  Cave,
     9  Gravestone,
     10  GraveyardFence1,
     11  GraveyardFence2,
     12  PicketFence1,
     13  PicketFence2,
     14  Hut,
     15  WitchHut,
     16  Tree,
     17  BlueOrb,
     18  RedOrb,
     19  LoginPedestal,
     20  RejuvenationPedestal,
     21  LifePedestal,
     22  ManaPedestal,
     23  RespawnPoint,
     24  ArtifactPoint,
     25  BossPoint;
    2326}
Note: See TracChangeset for help on using the changeset viewer.