Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
INFO1113 / COMP9003 Assignment
This assignment is worth 20% of your final grade.
Task Description
In this assignment, you will create a game in the Java programming language using the Processing library
for graphics and gradle as a dependency manager. In the game, players control tanks which can aim and
fire at each other. Players gain score for hitting another player’s tank, causing them to lose health. After
all levels are completed, the player with the highest score wins.
You have been given the task of developing a prototype of the game. A full description of gameplay
mechanics and entities can be found below. An artist has created a simple demonstration of the game
and has posted it on your online forum (Ed). You can also play a similar game here.
You are encouraged to ask questions on Ed under the assignments category if you are unsure of the
specification – but staff members will not be able to do any coding or debugging in this assignment for
you. As with any assignment, make sure that your work is your own, and do not share your code or
solutions with other students.
Working on your assignment
You have been given a scaffold which will help you get started with this assignment. You can download
the scaffold onto your own computer and invoke gradle build to compile and resolve dependencies. You
will be using the Processing library within your project to allow you to create a window and draw
graphics. You can access the documentation from here.
INFO1113 / COMP9003
Page 2 of 11
Gameplay
The game contains a number of entities that will need to be implemented within your application.
Level
Each level is read from a text file of characters 28x20. The size of the window should be 864x640, meaning
each character in the file corresponds to 32x32 pixels.
There are 5 main types of characters that could be present in the file:
• X – denotes the terrain height. This can change during gameplay when hit by projectiles. To
smooth out the terrain, see the section on page 3.
• Letters (A,B,C,D,E, etc.) – starting position of human players. The order of player turns, and the
order in the scoreboard, is alphabetical order.
• Numbers (0,1,2,3,4,5,6,7,8,9) – starting position of AI players (optional for extension, otherwise
they can just be normal human players as well)
• T – location of trees. They are always present on top of the terrain – so if the terrain changes, so
do any trees on top of it. The initial position of trees is randomised up to 30 pixels around its
starting point.
• Spaces – empty space, just ignore it.
The level layouts are defined in files provided in the “layout” attribute of the JSON configuration file
described below. Each level must have an associated layout file.
Note that the file does not need to contain exactly 28x20=560 characters. It may have less than this if
they are not necessary (such as spaces at the end of a line, or missing lines at the bottom). In such
situations, your program should still work, and just assume those are empty spaces.
Figure 1.
Player A (blue) has
their turn first. The
arrow pointing
down to their tank
exists for 2 seconds
to remind them
where they are –
this appears at the
beginning of each
player’s turn.
INFO1113 / COMP9003
Page 3 of 11
How to smooth the level terrain:
The terrain should comprise of a smooth curve that is formed
from computing the moving average of 32 values twice. See
below:
Figure 2.
Example level1.txt file (rendered in figure 1)
provided in the scaffold code. You should make your
own level file to test out different configurations.
Step 1.
Terrain directly from file
without any smoothing (each
character is 32 pixels wide)
Step 2.
Moving average of 32 values,
once.
Step 3.
Moving average of 32 values,
again.
INFO1113 / COMP9003
Page 4 of 11
Config
The config file is in located in config.json in
the root directory of the project (the same
directory as build.gradle and the src folder).
Use the simple json library to read it. Sample
config and level files are provided in the
scaffold.
The map layout files will also be located in
the root directory of the project. However,
sprites or images such as the background,
and trees will be located in the resources
folder (src/main/resources/Tanks/) or
(build/resources/main/Tanks/).
In addition to providing the filenames of
these files, the configuration file also
provides the colours that should be used for
the foreground of each level, and players.
The format is “R,G,B” containing the red,
green and blue components of the colour (0-
255) respectively. If it is “random”, then
choose the colour randomly.
For each level, the following properties are provided in the config:
• layout: the level file containing the characters determining the initial terrain, player positions,
and trees (see pages 2 and 3 above).
• background: the image which should be displayed in the background, behind the terrain and
everything else.
• foreground-colour: the colour to render the terrain in for this level.
• trees (optional): The sprite image to use for trees in this level. If not specified, your program
should not crash (either assume the level contains no trees so don’t render any, or use a default
sprite such as tree1.png).
INFO1113 / COMP9003
Page 5 of 11
Tanks
Initial positions of tanks are provided in each level’s layout file. Each player can control the tank’s turret
movement, move it across the terrain, or increase and decrease the power level (the key must be held for
these actions). Once they fire a shot (pressing the spacebar), their turn ends. A summary of the player
input actions are in the table below:
Keyboard input Action Rate of change
UP arrow Tank turret moves left +3 radians per second
DOWN arrow Tank turret moves right -3 radians per second
LEFT arrow Tank moves left across terrain -60 pixels per second
RIGHT arrow Tank moves right across terrain +60 pixels per second
W Turret power increases +36 units per second
S Turret power decreases -36 units per second
SPACEBAR Fire a projectile (ends turn)
Note: the rate of change should be continuous (ie. per frame) and does not have to be exact, but is an
indication to guide you in optimising user experience.
Tanks can only move across the terrain as long as they have fuel ( denoted in the top right corner).
Movement consumes 1 unit of fuel per horizontal pixel moved. Tanks start with 250 initial fuel in each
level.
Tanks have initial health of 100, and power of 50, set at the beginning of each level. This is displayed in
the HUD bar at the top. Power determines the speed (distance trajectory) of projectiles, and can never
exceed the tank’s remaining health. Once the tank’s health reduces to 0, it explodes with an explosion
radius of 15. If a tank goes below the bottom of the map, it explodes with a radius of 30.
How to change the turret’s position using the angle from the vertical:
Parachutes
A parachute is deployed for a tank when it is hovering in midair, due to the terrain
below it having been destroyed by a projectile. Each player has 3 parachutes per game.
If using a parachute, the tank descends at a rate of 60 pixels per second and sustains no
damage. If no parachutes are available, it descends at a rate of 120 pixels per second
and sustains damage of 1hp for each pixel of height (this is added as score to the player
who fired the projectile that caused the terrain to be destroyed).
Figure 7. (left)
Recall the parametric form of a circle
(rsin, rcos). In this case, the turret
length should be 15 pixels (r=15).
Note that the coordinate system in
computer graphics has +x values going
from left to right, and +y values going
top-down, which is different from what
you are familiar with in maths (x axis is
the same, but in maths the y axis +ve
values go from bottom to top).
INFO1113 / COMP9003
Page 6 of 11
Projectiles
Projectiles spawn from the tank’s location and follow a trajectory that is determined by the tank turret’s
vector. The magnitude of this vector is determined by the tank’s power level at the time the missile is
fired. The power level cannot exceed the tank’s health. The minimum magnitude of the projectile’s initial
velocity is 1 pixel (power level 0), and the maximum is 9 pixels (power level 100). You can assume
acceleration due to gravity is a constant rate of 3.6 pixels per second (applied per frame).
The player’s turn ends after they fire a projectile (press spacebar).
Explosions
When a projectile makes contact with the terrain, it causes an explosion. The default explosion radius is
30 pixels. Any tanks within the radius will sustain up to 60 hp lost depending on how close they are to the
impact site, reducing linearly the further the distance away. For example, with radius=30, a tank which is
distance 15 pixels away (half the radius) from the impact will sustain only 30hp damage. A tank which is
10 pixels away will sustain 40hp damage, and a tank which is 20 pixels away will sustain 20hp damage. A
tank which is 31 pixels away will sustain no damage since it’s outside the radius.