Java代写:SWEN20003 Shadow Quest Part2

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 purpose of this project is to encourage creativity. While we have tried to provide every detail of the game design, if you wish, you may customise any part of the game (including the graphics, names of characters and items, map layout and game rules). You may also add any feature you can think of. However, you must implement all of the features in the above checklist to be eligible for full marks.

To encourage students with too much free time, we will hold a competition for “best game extension or modification”. It will be judged by the lecturer and tutors, based on the demonstrations, and three prizes will be offered. We look forward to seeing what you come up with!

Implementation tips

This section presents some tips on implementing the game engine described above. You may ignore the advice here, as long as your game exhibits the required features.

Text, rectangles and colours

In Slick, you use the provided Graphics object to draw things other than 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, calculate the camera position using RPG.screenheight-RPG.panelheight.

You may wish to re-use some of this code to render the health/name bars above all of the non-player characters, since it is quite similar. A nice algorithm for calculating the width of the bar is whichever is greater out of textwidth + 6 and 70 (but you don’t need to use this).

Using a nicer font

Optional feature: The default font that comes with Slick is pretty ugly. If you like, you can change to a nicer font, such as DejaVu Sans Bold (supplied). Loading fonts in Slick is difficult, so we have supplied a source file, FontLoader.java which loads fonts for you.

To use this, you’ll have to import org.newdawn.slick.Font in RPG.java, and add a private field, Font font. Applying the font is a two-step process. First, in the RPG.init function, load the font using FontLoader.loadFont, with a font size of 15, and store it in the font field. Second, in the RPG.render function, override the default font, using g.setFont(font).