Java代写|计算机代写

University of Sydney 悉尼大学

INFO1113 / COMP9003
Object-Oriented Programming

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, balls spawn and move around the screen and the player can draw lines to direct them into holes of the same colour. When balls are reflected off a player-drawn line it disappears. If a ball enters a hole of a wrong colour, score is lost and it respawns. Once all balls are captured by holes, the player wins.

Gameplay

The game contains a number of entries that will need to be implemented within your application.

Level

Each level is read from a text file of characters 18x18. The size of the window should be 576x640, meaning each character in the file corresponds to 32x32 pixels.

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 18x18=324 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 boRom). In such situations, your program should still work, and must reflect balls off the edges of the screen.


There are 5 main types of characters that could be present in the file:

• X – denotes a wall (wall0.png). Balls reflect off this, but do not change colour. The game board does not need to be surrounded by walls – balls should reflect off the edge of the screen.

• 1,2,3,4: walls 1,2,3 and 4 respecBvely, as provided in the scaffold resources. When a ball hits one of these walls, it is reflected and changes colour to that of the wall.

• S – Spawner. Balls spawn from this locaBon (one spawner is chosen randomly of all available spawners in the current level, each Bme a ball is ready to be spawned).

• H – Holes. The hole takes up 4 Bles, where the ‘H’ character is the one in the top le`. The number in the character to the right of the H is the colour of the hole.

• B – Balls. Instead of spawning a`er the spawn interval, a ball may be present immediately from the level beginning, at a specific place on the board. The colour of the ball is denoted by the character to the right of the ‘B’.

• Spaces – empty space, just ignore it (blank Ble).

For each level, the following properBes are provided in the config:


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 a 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 ballx.png, and wallx.png will be located in the resources folder (src/main/resources/inkball/) or (build/resources/main/inkball/).


• layout: the level file containing the characters determining the position of tiles in the grid for walls, holes, spawners and iniBal balls.

• time: the maximum number of seconds this level should last for. If the time is exceeded, the player loses the level and it restarts. If the time is invalid (eg, non-integer or negative value like -1) or missing, there is no timer for this level.

• spawn_interval: the number of seconds in between when balls spawn.

• score_increase_from_hole_capture: The amount of units score is increased for each ball type when they successfully enter a hole.

• score_increase_from_hole_capture_modifier: Multiply the score values gained on this level by this modifier.

• score_decrease_from_wrong_hole: The amount of units score is decreased for each ball type when they enter the wrong hole.

• score_decrease_from_wrong_hole_modifier: Multiply the score values lost (when a ball enters a wrong hole) on this level by this modifier.


Balls

Balls may appear in the level layout file, as “B0”, “B1”, “B2”, etc in which case they are spawned immediately in that location when the level begins. Alternatively, they may also be specified in the configuration file, which will cause them to be spawned at a spawner   throughout the duraBon of the game. The frequency of spawning is determined by the spawn_interval configuration property of that level, which determines how many seconds in between when balls spawn. From being iniBally at that given value * App.FPS, it counts down on each frame and is displayed in the top bar, next to the display of where balls yet to be spawned appear. The order of balls in this display should be the same as the configuration file (only the next 5 balls yet to be spawned are shown). When the spawn interval counter reaches 0, the next ball is spawned in the game. All other balls remaining yet to be spawned, will gradually move to the le` in the display at a rate of 1 pixel per frame.


When balls spawn in the game, they have a random velocity vector which is either -2, or 2 pixels in the x direction, and -2, or 2 pixels in the y direction (assuming 30fps – if using 60fps, this would be halved). Throughout this document, vectors will be notated as (i,j) where i is the velocity in the x direction and j is the velocity in the y direction. Balls collide with walls and player-drawn lines which change their velocity vector trajectory, as described below.


Hitbox

A hitbox is a series of points, which form a sequence of line segments. For example, a player-drawn line may appear as below:


The hitbox comprises of points (shown in red) that create line segments. V is the velocity vector of the ball, and U is the new velocity vector when it hits the line, shown in purple. N1 and N2 are the normal vectors of the line, shown in green.


Walls

A wall is a tile with a hitbox comprising of the points of each of its 4 corners. Collision handling for walls will work the same as above for line segments in player-drawn lines. When a ball hits an orange, blue, green or yellow wall, it will change its colour to that of the tile.

Even if the game board is not surrounded by walls at the edges, balls should still reflect off the edges.

Holes

Holes take up 2x2 regular tile spaces (64x64 pixels). When a ball is within 32 pixels of the centre of a hole (from the centre of the ball), it starts to be attracted into the hole. Its size reduces proportionally to how close it comes to the centre of the hole, unBl when it is on top of the centre, then it will be captured by the hole and disappears. The force of attraction is approximately 0.5% of the vector from the ball to the centre of the hole.

If the hole colour matches the ball’s colour (or it’s a grey ball, or grey hole), it is a success and the score increases by the amount given in the configuration file, multiplied by the level multiplier. Grey balls are allowed to enter any holes, and balls of any colour can enter a grey hole to count as a success.


If the colour capture was not successful, the ball rejoins the queue of balls yet to be spawned, and score will instead decrease by the amount specified in the configuration file.


Player Actions

During the game, players can cause the following actions to occur:

• Press ‘r’ to restart the level, or if the game has ended because all levels were completed, restart the game. The level returns to its original state, including the timer, balls, and clearing any player drawn lines. Score will return to the state it was at before the level started.

• Press spacebar to pause the game. Balls should not move unBl the spacebar is pressed again to un-pause the game. The player can still draw lines while the game is paused. To indicate that the game is paused, display *** PAUSED *** in the middle of the top bar.

Players can draw lines with the le` mouse button, and can remove those lines by right-clicking over them.


Score and Timer

The score value is persistent across levels. The timer for a level starts at the value specified in the config file, and should count down each second. When it reaches 0, the level will end, display the message === TIME’S UP === in the top bar. The player must then press ‘r’ to restart the level. In the ended state, balls do not move and the player cannot draw lines.


Level End and Game End

A level ends when all balls are captured by holes successfully, (ie, there are no more balls remaining to be spawned, and no balls currently in play). Any remaining time gets added to the player’s score, at a rate of 1 unit every 0.067 seconds. As this is occurring, two yellow tiles which begin in the top le` corner and boRom right corner will move in a clockwise direction around the edge of the game board, also at a rate of 1 tile every 0.067 seconds.

When the last level ends, the game ends – display === ENDED === in the top bar. The user may press ‘r’ to restart the game.


咨询 Alpha 小助手,获取更多课业帮助