Part 1,Part 2。
Combat
Combat occurs between the player and a monster. If the player tries to move, and the destination coordinate is within 50 pixels of a monster, the player will be able to then attack. The player continues moving as normal, but if the user presses A the player attacks all monsters within range. The same applies for aggressive monsters attacking players.
To make things more interesting, attacks do a random amount of damage. On each attack, the attacker randomly generates an integer between 0 and the attacker’s Max-Damage stat, inclusive, which is the amount of damage the attack will do. This integer is subtracted from the target’s HP.
If units could attack every frame, battles would be over very quickly. To slow things down, units have a “cooldown timer”. The cooldown timer is measured in milliseconds, and begins at 0ms. Units can only attack when the cooldown timer is 0ms. When a unit makes an attack, the cooldown timer is set to the unit’s Cooldown stat. Every frame, the cooldown timer is lowered by the number of milliseconds since the last frame, during this time the unit may not attack. When the “cooldown timer” reaches 0ms, the unit may attack again. This means the unit can only attack once every Cooldown milliseconds.
If a unit’s HP reaches 0, the unit is dead. Monsters who die are removed from the game permanently (they just disappear).
If the player dies, the game does not end (this would be too cruel). Instead, the player is teleported back to position (738, 549), with full health.
Items and inventory
There are a handful of special items scattered throughout the game. Like units, each item has an (x, y) coordinate in pixels.
The player has an inventory, which is simply the collection of all items the player has collected. The inventory appears as a bar along the bottom of the screen, showing which items have been collected.
The player can pick up any item by moving within 50 pixels of its position. When picked up, an item will be removed from the world, and added to the player’s inventory.
Each item has a special effect on the player:
- Amulet of Vitality - A magic necklace. Increases the player’s max health.
- Sword of Strength - A flaming sword. Increases the player’s max damage.
- Tome of Agility - An enchanted spellbook. Increases the player’s attack speed (reduces the cooldown).
- Elixir of Life - No special effect; the goal of the game. Find it and take it back to Prince Aldric to win the game.
See the data file data/items.txt for details on the stats and locations of the items.
The status panel
The bar at the bottom of the screen (pictured in Figure 3) is known as the status panel. It shows the player’s current health, stats and items. There are four sections:
- Health: Shows the player’s health percentage as a red bar on a black background, overlayed with the numeric form, “HP/Max-HP”.
- Damage: Shows the player’s Damage.
- Rate: Shows the player’s Cooldown.
- Items: Shows the image for each item in the player’s inventory.
Implementation checklist
This project may seem daunting. As there are a lot of things you need to implement, we have provided a checklist, ordered roughly in the order we think you should implement them in. Next to each item is the number of marks that particular feature is worth, for a total of 6.
- Villagers, just stand around. All the villagers in the game.
- Monsters, just stand around. All the monster types in the game.
- Display bottom status panel, with player’s health, damage and cooldown.
- Health for all units, display health bars.
- Player can attack monsters.
- Aggressive monsters chase and attack player, according to Algorithm 1.
- Passive monsters wander the map, and run from the player when attacked.
- Cooldown (limit to one attack per n milliseconds).
- Monster and player death handled.
- Items, in the world.
- Player can pick up items, has inventory. Display inventory in bottom status panel.
- Items affect the player in the correct way.
- Dialogue bar display.
Customisation
Optional: The purp⁰†䝲䝷⸠㱴⽯㹰൲੯㱶㹤⁶†⁵⁵⁹⽭††Ⱜ†††䅭⁰⁙⁴⁴⁷†㙩㝥の⁴⠠†⁴♦㭥†⥣㱬⽩㹴ഠੴ㱯㍢㵬≩ⴠⵯ≫㹳‼㱲⽡㍥㸠൳ੴ㱵㹥†㩨†⁷†※⸠䥡⁴Ɐ†ⁱ⁉ⱬ䑥⁴䉣⡲⥯䰬†ⱴ†⁗Ɐ䘠䱷†⁵⸼㰯⽰㸍ഊ਼㱨㸠‽⁰Ɱ⁴♯㭳⁉⁴⁴⸼⸠䙳†䝥Ⱐ†Ⱨ†䙴䅧⁙†䙡ⱥ†䝬Ɑ†䙥䱥䘾ⱨ″•ㄭ㕡Ɱ‾⁸†⁴⸠ⰼ ‾⁰䝮⸠†ⱴⱴ†⸠䙮⡯⤠㱨⽡㸠images, such as text and rectangles. Two useful methods are:
1 2
|
void fillRect(float x1, float y1, float width, float height) void drawString(String str, float x, float y)
|
Both of these methods draw with the “current colour”, so before you draw anything, you should set the colour you want it to be, using this method:
1
|
void setColor(Color color)
|
You can create Color objects for any colour you like with this constructor:
1
|
Color(float r, float g, float b, float a)
|
That lets you provide the red, green, blue, and alpha components, respectively. Setting alpha to less than 1.0 causes partial transparency, which is nice for health bar backgrounds.
See renderpanel.txt in the supplied package for examples of drawing text and rectangles, as well as some sample colours.
Health bars and the status panel
We’ve given you most of the code for rendering the status panel (see renderpanel.txt in the supplied package), since it’s pretty tricky to get right. You may simply take that code and use it in your Player.java (it is incomplete - note the comments there). After adding the status panel, the player won’t be centered in the playable area (which will be 70 pixels shorter). To fix this, c