CS计算机代考程序代写 gui Java assembly mips algorithm data structure 2

2
The enemy tanks enter from the top of the screen, wander around the maze, and attempt to destroy the player’s base (the falcon symbol) as well as the player tank. The player needs to strategically shoot the bullets to destroy enemy tanks, and protect its base at the same time. If all enemy tanks are destroyed, the player wins the game. The player loses the game if the base is destroyed or the player tank is destroyed.
The COMP2611 Battle City game is implemented by the joint effort of modified Mars emulator (Java-based) and MIPS. The video and audio effects, simple algorithm which controls the enemy tanks and other miscellaneous tasks are done in Mars emulator. The main game logic and your tasks in the programming assignment are implemented by MIPS.
2 Coordinate System
The game canvas is of 512 × 448 pixels as illustrated in Figure 2. The top-left corner pixel is (0, 0) and the bottom-right corner pixel is consequently (512, 448).
Fig. 2: The coordinate system
Each tank in the game is represented by a square image of 32×32 pixels, and the bullet object is represented by a square image of 6×6 pixels. Their locations are referenced by the top-left corner coordinates. For example, in Figure 2, the player tank is located at (30, 300) and the enemy tank is located at (450, 230).
Fig. 3: Maze Bitmap

COMP2611 Computer Organization Spring 2021 3
The maze is of 416 × 416 pixels, with 26-rows by 26-columns grid of cells. Each cell is 16 × 16 pixels. The maze is encoded as a two-dimensional bitmap array: 0 for empty space and grass (open path), 1 for brick wall, 2 for stone, and -1 for river (cannot be passed through) as shown Figure 3.
Fig. 4: Maze Bitmap Mapping
Tank can only move on open path grids. i.e. empty space and grass. Its move- ment is blocked by rivers, brick or stone. Brick wall can be destroyed by bullet and becomes open path, while the stone can never be destroyed. Bullets can fly through rivers, destroy brick wall, but will always blocked by stone. Note all moving objects, tanks and bullets, cannot move outside of the maze bound- ary.
3 Game Objects
There are three types of game objects: player tank, enemy tank, and bullet. Attributes for each object are listed below.
Table 1: Images, sizes and attributes of the game objects
– Current location: top-left (x, y) coordinate indicating the current location of the object.
Ob ject
Width
Height
Speed (pixels/iteration)
Initial location
Player Tank
32
32
2
(96, 384)
Enemy Tank
32
32
2

Bullet
6
6
10

4
Note the maze bitmap is generated by modified Mars but not MIPS.
4 Game Details
4.1 Game Initialization
During game initialization stage, the player specifies the number of enemy tanks (1 or 2). Multiple game objects, including player tank and enemy tank(s) are created by modified MARS. The maze is displayed in Canvas according to the bitmap array. Then the game officially starts.
4.2 Object Movement
The player controls the player tank to move to an adjacent (4 directions) empty path with “w”, “a”, “s”, “d”. Each keystroke moves the player tank by 2 pixels in 8 game iterations (for smooth animation effect). The player tank does not have the superpower of ghostwalking so no movement should be made when they bumps a wall or the boundary.
Simple algorithm in modified MARS controls the enemy tank(s). One enemy tank aims to hit the home base, while the other one chases towards the player tank. Both cannot pass through the wall or boundary, so their movement direction will be changed under such situation.
4.3 Bullet Shot
The player tank has one recyclable bullet to use. Press the space bar to shoot the bullet, which goes to the same direction as the tank. The bullet can fly through open path (i.e. empty space and grass) and river, until it goes out of the boundary or hit an object. Consequently, it may destroy an enemy tank, hit the home base or brick wall, or blocked by a stone.
When a brick wall is shot by bullets, it will disappear and turn into empty space. The stone cannot be damaged by the bullet. When the enemy tank is shot, it is destroyed. When the bullet goes out of boundary, it disappears. For all above cases, the bullet is then recycled back to be used again.
Bullets from enemy tank work similarly. The enemy tanks has unlimited supply of bullets, which makes the game more challenging.
– Moving speed: the movement of the game object in terms of number of pixels at each iteration. To create smooth animation effect, each game loop moves the object using 8 iterations.

COMP2611 Computer Organization Spring 2021 5
4.4 Collision Detection: Bullet and Wall
The game logic detects the collision between bullet and wall, then reacts ac- cordingly. Two game objects collide with each other when their (square) images intersect. Figure 5 shows all possible scenarios of Hit and not Hit. The rule is simple: when the wall grid overlaps with bullet object, it’s a Hit case. Note if the wall grid is tangent to the bullet, we’ll treat this as a NOT Hit case.
Fig. 5: Collision Detection: Hit Wall scenarios
How to detect the overlap among wall grid and bullet object? Take the brick wall as an example. One possible scenario is to take (x, y) coordinates of four corners of the bullet, and check whether there is at least one corner falls into the wall grid (i.e. the two objects intersect). Given the location (i.e. coordinate of top-left corner) and size of bullet and wall, it is a straightforward work. For example, when the bullet is at location (89, 104), since its size is 6 × 6, the coordinates of its four corners ’hit’ either 0 (open path) or -1 (river), then the bullet does not hit the wall. But bullets at location (100, 105) or (92, 105) do hit the brick wall.
4.5 Collision Detection: Bullet and Tank
Similarly, the game logic detects the collision between bullet and tank(s), and then destroy the tank objects when there is an collision.
Fig. 6: Collision Detection: Hit Tank scenarios

6
Figure 6 shows possible scenarios when bullet and tank are close with each other. For example, when the bullet is at location (100, 100), since it’s size is 6 × 6, it doesn’t collide with tank at location (95, 110). But bullet at location (100, 105) does collide with tank.
4.6 Wining and Losing Conditions
The player wins the game once player tank kills all the enemy tanks, AND the home base hasn’t been destroyed. The destruction of player’s home base, OR being shot by the enemy tank are both lethal to player tank. The player loses the game in both cases.
Many of you must be good game players, we hope you can enjoy the game made with MIPS after you get all tasks done!
5 Game Implementation
5.1 Data Structure
The maze map is encoded in a 2D matrix (logically) and is internally saved as 1D array maze_bitmap (row major). Other game related data are saved in quite a few variables and simple 1D arrays. All data structures used are static. Check the data segment at the very beginning of the skeleton code to know more details.
5.2 Game Loop
During the game initialization, input_game_params asks the player to input the number of enemy tanks (1 or 2). init_game then creates the game objects and places them in game canvas.
The game then starts. It works as a big loop. Each iteration follows a collection of steps, e.g. gets the keyboard input; moves the player tank; check collision among game objects; update the game status, etc. Towards the end of each game iteration, winning and losing conditions are checked to decide the game continues or not.
6 Tasks
When you code with high-level programming language, you always go through problem specification, algorithm design/workflow analysis, coding, debugging and documentation. Coding with low-level assembly programming language is pretty much the same.
Battle City game in MIPS assembly is challenging, but you won’t start every- thing from scratch. The fancy user interface is handled by modified Mars (copy- right: COMP2611 teaching team). The MIPS code mainly works on the logic of

COMP2611 Computer Organization Spring 2021 7
the game. The programming assignment package already includes a skeleton file for you to start with.
’Divide-n-conquer’ strategy is used in the skeleton. The skeleton code is well organized with sub-tasks handled by different MIPS procedures. The tasks of the programming assignment include a reading task (Task 0), you will need to read through the skeleton and grasp a big picture of the code structure.
The remaining tasks (Task 1-6) are coding tasks. You will focus on implementing a few MIPS procedures with well-defined interface.
6.1 Task 0 Reading Task
Spend a few hours to read the skeleton code. You should 1. understand the data structures used in the skeleton; 2. trace the game loop 3. figure out the functionality of each procedure.
Show your understanding of the big picture of the project by drawing a flow chart (https://en.wikipedia.org/wiki/Flowchart). Feel free to draw the flow chart with drawing tools or simple paper-and-pencil.
Your flowchart should
– include enough details, e.g. every single procedure should be included in your flow chart.
– have good layout so that it’s easy to trace and understand. 6.2 Task 1 to 6 Programming Tasks
Once you build up a big picture of the project, you can zoom in to the following coding tasks.
Table 2 lists all the programming tasks you need to implement. You need to complete the following functions.
Note: You should not modify the skeleton code but only add your code to those procedures. Try to follow good conventions, e.g. comment your code properly and use registers wisely.
You can discuss with your friends if you encounter difficulty in the project, or actively seek help from the teaching team. But every single line of your code should be your own work (not something copied from your friends). Do not show your code to others. Do not upload your code to GitHub or Cloud unless you set the access right to be private.

8
Task
Input
Output
Description
Task1: move_player_left
$v0 = 1 if a movement has been made, otherwise 0.
Move player leftward by its speed for one game iteration. Do not move the object if it will overlap with a wall cell in the movement.
Task2: move_player_right
$v0 = 1 if a movement has been made, otherwise 0.
Move player rightward by its speed for one game iteration. Do not move the object if it will overlap with a wall cell in the movement.
Task3: hit_border
x, y, size
$v0=1 if the object hit the border
$v0=0 other- wise (Notice that if the ob- ject is tangent to the border $v0 should also be set to 0)
Check wether an object hits the border of the maze We assume the object is a square (width=height)
Task4: new_bullet
($v0, $v1 ) is the location of the bullet be- ing created
You should complete nb down bullet and nb left bullet
Task5:
check_bullet_collision
x, y, size: (x,y) is the location of the bullet size is half the size of the bul- let
Check whether the bullet collides with border, ene- mys, brick wall, stone or home.
You should complete cbc top right and cbc top right grid.
Task6: check_hit_enemy
x, y
$v0=4 if hit enemy1 5 if hit enemy2 and 0 if hit no enemy
check whether a certain cor- ner of the bullet hit any en- emy
Table 2: Programming task description

7 Bonus
COMP2611 Computer Organization Spring 2021 9
If you’re excited in MIPS programming and wish to further challenge yourself, we’d like to invite you to implement additional functionalities in the Battle City game. The more sophisticated, and of course, more interesting version of the game includes various enemy tanks requiring more shots to destroy, different types of obstacles, and collections of power-ups for abilities and bonus items. Refer to https://strategywiki.org/wiki/Battle City for more details.
You’re also welcomed to create a brand-new version of the Battle City game from scratch with your imagination.
Fill in the expression of interest form by Apr 16 (Friday). It is on COMP2611 Canvas as an assignment carrying 0 points. We’ll give feedback to your proposal by Apr 19 (Monday). For those who propose to work on the extension of the game, you need to make sure the original tasks in the programming assignment are all implemented. If you’re proposing a brand-new version of the Battle City game, you don’t need to work on the original programming assignment. NOTE: You have to get prior approval before you start. Email on detailed Bonus submis- sion arrangement will be sent to those who get approval to work on the Bonus work later.
You will be invited to give a 10-min demonstration to show the add-on features during study break. The teaching team would evaluate the bonus point. The bonus point will be 1 to 5 points depending on how much work is involved and the final result. It will be added to your course overall after the course grade assignment. Grades of students who decide not to work on the bonus will not be influenced.
8 Syscall Services
A modified MARS (NewMars.jar) with additional set of syscall services is needed to support the game (e.g. fancy UI, music, etc.). Table 3 and Table 4 list all the provides syscall services to implement the game.
Note that not all the new syscalls are necessary in your code, some are described here for you to understand the skeleton. Syscall code should be passed to $v0 before usage.
The GUI part of this game is implemented in modified MARS, but the game logic, e.g. whether the brick wall is hit by the wall, is determined by MIPS code.

10
Service
Code
Parameters
Result
Create the game screen
100
Refresh the game screen
101
Play game sound
102
$a0 = sound ID
$a1 = 0: play once; 1: play repeat- edly in loop; 2: stop playing
The sound IDs are described as fol- lows:
0: the starup music;
2: the sound effect of tank crack; 4: the sound effect of shooting bullet
Play the sound of the given sound ID or stop any playing of it, depending on the given value in $a1.
Create an game ob ject
103
$a0 = unique ID of the object
$a1 = x-coordinate
$a2 = y-coordinate
$a3 = object type: 1 for player tank; 3 for bullet; 5 for tank explosion; 6 for broken home; 7 for game over;
A new object of the given ID and object type is created, replacing any existing object of the same ID and object type.
The location of the object is set to the given x- and y- coordinates.
Set the object location
104
$a0 = ID of the object $a1 = x-coordinate
$a2 = y-coordinate
$a3 = the object’s type
The location of the object is set to the given x- and y- coordinates.
Create a game text
105
$a0 = unique ID of the object
$a1 = x-coordinate
$a2 = y-coordinate
$a3 = base address of a text string
Create an object for display- ing the text string at the given x- and y- coordinates.
Get the location of an object
106
$a0 = ID of the object
$v0 = x-coordinate of the lo- cation.
$v1 = y-coordinate of the lo- cation.
Table 3: Syscall Services 100 – 106

COMP2611 Computer Organization Spring 2021 11
Change the direction of an object
107
$a0 = ID of the object
$a1 = the object’s type
$a2 = the target direction: 0 for north 1 for west; 2 for south; 3 for east
Change the direction of ob- ject $a0 to $a2
Create Enemy
108
$a0 = number of enemy tanks $a1 = ID of enemy 1
$a2 = ID of enemy 2
Create specified number of enemy tanks in canvas
Move Enemy
109
$a0 = ID of the enemy
Move the enemy for one it- eration.
$v0=x-coordinate of the up- dated enemy location $v1=y-coordinate of the up- dated enemy location
Hit the brick wall
110
$a0=the index of the bitmap cell of the brick wall
Show the effect that the brick wall disappear
Hit Enemy
111
$a0 = ID of the enemy
Show that the enemy is ex- ploded
Enemy Shoot
112
$a0=ID of the enemy
Deal with enemy shooting and bullet collision check $v0=1 if enemy bullet col- lides with the player or home, 2 if collides with player bullet
$v1=1 or 2 denotes the num- ber of brick wall hit by the enemy bullet
$a0 and $a1 denotes the in- dex of the brick walls being hit on the bitmap
Table 4: Syscall Services 107 – 112

12
9 Submission
You should *ONLY* submit a single file comp2611_project_yourStudentID.zip.
The zip file should include a picture/pdf of the flow chart, and your com- pleted MIPS code for the project comp2611_project_yourStudentID.s. Please write down your name, student ID, and email address at the beginning of the files.
Submission is via Canvas. The deadline is a hard deadline. Try to avoid uploading in the last minute. If you upload multiple times, we will grade the latest version by default.
10 Grading
Your project will be graded on the basis of the functionality listed in the project description and requirements. You should ensure that your completed program can run properly in our modified MARS.
For suspected plagiarism cases, we will invite you to a QA session and explain your code. If you fail to do so, your project score will be 0 and an additional 10% will be deducted from your course overall score.