程序代写代做代考 flex data structure AI assembly mips Copyright of the Programming assignment (modified MARS, project description, skeleton and sample video) belongs to COMP2611 teaching team, CSE, HKUST. No part of these materials may be reproduced, distributed, or transmitted in any form or by any means. Uploading the materials to other website (e.g. Github, Youtube, CourseHero, etc.) is strictly prohibited. We reserve the right to sue for compensation resulting from commercial breaches of our copyright.

Copyright of the Programming assignment (modified MARS, project description, skeleton and sample video) belongs to COMP2611 teaching team, CSE, HKUST. No part of these materials may be reproduced, distributed, or transmitted in any form or by any means. Uploading the materials to other website (e.g. Github, Youtube, CourseHero, etc.) is strictly prohibited. We reserve the right to sue for compensation resulting from commercial breaches of our copyright.
COMP2611: Computer Organization, Fall 2016 Programming Project: Ninja Survival Game (Submission deadline 11:59PM, Dec 2 2016 via Canvas)
1. Introduction
In this project, you will implement a Ninja Survival Game with MIPS assembly program.
Figure 1 shows a snapshot of the game. The game displays a maze, where various score points appear at random position and disappear after a while. The player moves a Ninja character
around to collect as many score points (Ninja darts) as possible. Multiple monster characters wander around the maze. When Ninja bumps into a monster, he/she loses 10
points and becomes shielded from the monsters temporarily with a ‘cloak of invisibility’, allowing her/him to cross the monsters without losing points.. When the Shield Mode is about to
end, the yellow bubble will turn into grey . When Ninja reaches 100 points in Level 1, he/she will continue to play Level 2, where 3 more monster characters wandering around a more complicated maze.
Figure 1. Ninja survival game (Left: Level 1; Right: Level 2).
COMP2611 Fall 2016 Page 1

2. Coordinate System
The game canvas is of 750 x 600 pixels as illustrated in Figure 2. The top-left corner pixel is (0, 0) and the bottom-right corner pixel is consequently (749, 599).
Figure 2. The coordinate system.
Each object in the game is represented by a square image of 30×30 pixels. Its location is referenced by its top-left corner coordinates. For example, Ninja character in Figure 2 is at (360, 540).
The maze is of the same size as the game canvas, with 20-rows by 25-columns grid of cells. Each cell is 30 x 30 pixels. A cell is either a bamboo wall or an open path as shown in Level 1,
or a stone wall or an open path as shown in Level 2. The maze is encoded as a two- dimensional bitmap array of 1s and 0s representing walls and paths respectively as shown in Figure 3.
1
01
1
1
0
1
10
01
0
10
0
0
0
1
0
1
10
1
10
1
01
01
0
01
0
0
Figure 3. Illustration of the maze grid (blue square) and bitmap.
COMP2611 Fall 2016 Page 2

3. Game Objects
There are three types of game objects: Ninja, Monster and Score point. Every object has attributes as listed below.
 Current location: (x, y) coordinate indicating the current location of the object.
 Moving speed: integer variable indicating the moving speed of the game object.
 Score Value (SV): integer variable indicating the score value of a score point object.
Table 1: Images, sizes and attributes of the game objects
4. Game Details
4.1 Game initialization
Player specifies the number of monster objects and score point objects (value 1 to 5) at the beginning of the game. Then, the monster objects, score point objects and one Ninja object are created with images retrieved from image repository. The game canvas is then created and displayed. The game has two levels: Level 1 and Level 2.
Other initial settings at the beginning of each level include:
 The location of Ninja object is set to (360, 540), with no wall on this location; COMP2611 Fall 2016 Page 3
Object
Width
Height
Speed (pixel)
SV
Initial location
Ninja
( or similar)
30
30
3

(360, 540)
Monster
( , , or similar)
30
30
2

Random path cell (far from Ninja).
Monsters do not overlap.
Score point
( , , , ,or similar)
30
30

Random (5, 10, 15, 20)
Random path cell (far from Ninja).
Score points do not overlap.

 Each monster object is put on a random path cell of the maze far from Ninja object, and no two monster objects overlap;
 Each score point object is put on a random path cell of the maze far from Ninja object, and no two score point objects overlap;
 The initial game score is 30;
Background music is played throughout the game. There are various sound effects for different
game events (e.g. the player obtaining score points).
4.2 Object Movements
Ninja object moves vertically or horizontally when the player press “a”, “s”, “d”, “w”. Each keystroke moves Ninja object by 3 pixels for 10 game iterations. There is no movement when Ninja bumps a wall.
Ninja can cross the border if there is a path (i.e., paths are toroids like the K-Map). This is shown in Figure 4 (a) where Ninja crossed the border at the top to re-appear at the opposite border (at the bottom) as shown in Figure 4 (b).
(a)
(b)
Figure 4. (a) Ninja partially crosses the maze’s upper border. (b) Ninja is relocated to the maze’s bottom border.
During the game, the monster objects patrol the maze in preset routes (by the game AI engine). Monsters in Level 2 are smarter (or vampiric). If a monster is too far away from Ninja, she/he teleports (with 1% probability) to a nearby or even same location of Ninja.
COMP2611 Fall 2016 Page 4

4.3 Score Points
The score point objects appear (i.e., visible) and disappear (i.e., invisible) at random path cells during the game. Each score point object carries a score value (SV), which is also visible to the player.
4.4 Collision between Game Objects
Two game objects collide with each other when their images (squares) intersect. Figure 5 shows possible collision scenarios:
(474, 522)
(479, 520)
(450, 540)
(a)
(503, 551)
(450, 540)
(b)
(508, 549)
(479, 569)
(479, 569)
(480, 520)
(450, 540)
(509, 549)
(479, 569) (c)
Figure 5. (a) Collision. (b) Collision. (c) No collision.
 Collision of Ninja and a visible score point object: Score! SV is added to game score. Score point object then turns invisible.
 Collision of Ninja and a monster object: Score deduction! 10 points is deducted from the game score. Then Shield Mode is triggered (described in Section 4.5).
 Collision of Ninja and multiple monster objects at the same time: Shield Mode is triggered only once.
 Collision of Ninja, a monster object and a score point object at the same time: take the score first, then deduct 10 points and enter the Shield Mode if the game score is still less than 100.
COMP2611 Fall 2016 Page 5

4.5 Shield mode
Collision of Ninja and monster object triggers “Shield Mode”.
Figure 6. The Shield Mode.
 Once collided with a monster, Ninja is put in “Shield Mode” (represented as or similar). Shield Mode lasts for a pre-defined period and then everything goes back to normal.
 When Ninja is protected by a ‘shield’, no monster can catch her/him. The collision does not trigger or extend Shield Mode any more, and game score is not deducted any further.
 With every collision with a monster (without the shield), 10 points are deducted from the game score. Also, it will cause Ninja to teleport to a random open-path of the maze
without overlapping with any score point object or monster object there.
4.6 Winning and Losing the game
During the game play, if the game score reaches 0 or less, the player loses the game. If the game score reaches 100 or more at Level 1, the player will pass Level 1 and promote to Level 2. There will be 3 more monsters, and more complicated maze in Level 2. The player wins the game if passing both levels.
COMP2611 Fall 2016 Page 6

5. Game Skeleton
A skeleton file comp2611_Fall2016_project_skeleton.s is provided to you. After the game initialization, the game will proceed in a loop, whose iteration is quoted as game iteration. Each iteration follows the steps listed below:
1. Get the current time: jal get_time
2. Get the keyboard input: jal get_keyboard_input
Note: Holding down the key generates a sequence of keystrokes, which moves ninja object continuously. For MAC users, if it does not work, enable it by entering the following command in the Terminal application: “defaults write -g ApplePressAndHoldEnabled – bool false”. Replacing false by true in the command will produce the opposite effect.
3. Check collisions with score point objects: jal check_scorepoint_collisions. For each visible score point object, check whether the ninja object has collided with it. If a collision has happened, then update the game score, hide that score point object and skip further collision checking with any other score point objects.
4. Check whether the game level reached the winning condition, and perform the corresponding action: jal check_level_end. If the player wins the game, terminate the game. If the game has promoted to Level 2, go to step 1, otherwise go to step 5.
5. If the game is in the Shield Mode, go to step 10.
6. Check collisions with monsters: jal check_monster_collisions. Check collision among ninja-monster for every monster object. If there is a collision, skip further collision checking with any other monster objects and go to step 7, otherwise go to step 10.
7. Process the game to enter the Shield Mode: jal process_shield_mode. Following actions are performed:
Action
1
Activate Shield Mode.
2
Deduct 10 points from current game score.
COMP2611 Fall 2016 Page 7

3
(1) If game score becomes 0 or less, skip any other actions and return (2) If not, play the sound of losing game score
8. Check whether the game reaches the losing condition: jal check_level_end. If game is over, terminate the game.
9. Go to step 14.
10. Move all the monster objects: use the syscall 213.
11. Update the visible or hidden status of all the score point objects: jal update_scorepoint_status.
12. Process the current keyboard input for changing the game status: jal process_status_input. If the input is valid, perform the corresponding action.
Valid input
Action
m
Toggle the playing of the background music.
0
If the game is not in the Shield Mode, trigger the Shield Mode. This is a cheat code built for you to enforce the Shield Mode for easy debugging.
13. Continue any previous ninja movement or process the latest movement input: jal process_move_input. First, save the current keyboard input as the latest movement input if it is a valid input as shown in the table below. Then, if a 10-iteration ninja movement started in a past iteration has not finished yet, continue the movement, otherwise perform the corresponding action of the saved latest movement input (if any) and then remove this saved input.
Valid input
Action
w
Start the upward movement of the ninja object (moving it upward by its speed for 10 game iterations starting from the current iteration, and if the game is in the Shield mode, also update the mode’s status, using jal
COMP2611 Fall 2016 Page 8

update_shield_time, in each of those iterations).
a
Start the leftward movement of the ninja object.
s
Start the downward movement of the ninja object.
d
Start the rightward movement of the ninja object.
14. Refresh the game screen to reflect any screen changes: use the syscall 201.
15. Take a nap: jal have_a_nap. The interval between two consecutive game iterations of this
loop is usually about 30 milliseconds.
16. Go to step 1.
COMP2611 Fall 2016 Page 9

6. Programming Tasks
Read the skeleton code and understand how it works. Try to understand the data structures used in the skeleton too. Complete the following MIPS procedures. You should not modify the skeleton code but only add your code to those procedures.
Note: You don’t need to understand every single detail of the skeleton code. You can discuss with your friends if you have difficulty in understanding it. But every single line of your code should be your own work (not something copied from your friends).
Procedure
Inputs
Outputs
Description
Task1:
move_Ninja_left
$a0 = 1 or 0
$v0 = 1 if a movement has been made, or else 0
Move Ninja object leftward by its speed for one game iteration. If $a0 is not 0, do not move the object if it will overlap with a wall cell in the movement.
Task2: move_Ninja_right
$a0 = 1 or 0
$v0 = 1 if a movement has been made, or else 0
Move Ninja object rightward by its speed for one game iteration. If $a0 is not 0, do not move the object if it will overlap with a wall cell in the movement.
Task3: check_intersection
RectA: ((x1,y1), (x2, y2))
RectB: ((x3,y3), (x4, y4))
$v0: 1 for true (intersection happened); 0 for false
Check whether the given two rectangles intersect.
(x1, y1) and (x2, y2) are the coordinates of top-left and bottom-right corners of rectangle RectA.
(x3, y3) and (x4, y4) are the coordinates of top-left and bottom-right corners of rectangle RectB.
The eight coordinates are passed via the stack.
Task4:
check_monster_collisi
ons
$v0 = 1 if a collision has been found, or else 0
Check whether Ninja object has collided with a monster object.
This procedure pushes the coordinates of two game objects into the stack, and then
COMP2611 Fall 2016 Page 10

calls the procedure check_intersection to detect whether they intersect each other.
Task5:
check_scorepoint_coll
isions
Check whether Ninja object has collided with a score point object.
If a collision has been found, then hide the score point object, increase the game score by its SV and skip further collision checking with any other score point objects.
This procedure pushes the coordinates of two game objects into the stack, and then calls the procedure check_intersection to detect whether they intersect each other.
Task6: process_shield_mode
Perform the action of score deduction and activate Shield Mode.
If the score becomes 0 or less, skip the rest of actions and return to main flow.
If not, play the sound of losing game score, teleport Ninja, and return to main flow.
COMP2611 Fall 2016 Page 11

7. syscall Services
We have implemented a group of additional syscall services to support game related functions (e.g. monsters’ movements). For your code to work, you should use the modified MARS (NewMars.jar) provided in the project section of our course website. 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.
Service
Code
Parameters
Result
Create the game screen
200
Refresh the game screen
201
Play game sound or stop playing it
202
$a0 = sound ID
$a1 = 0: play once; 1: play repeatedly in loop; 2: stop playing
The sound IDs are described as follows:
0: the background music;
1: the sound effect of obtaining game scores;
2: the sound effect of losing game scores;
3: the sound effect of losing the game;
4: the sound effect of passing a game level;
5: the sound effect of ending Shield mode.
Play the sound of the given sound ID or stop any playing of it, depending on the given value in $a1.
Set the game score
203
$a0 = new game score
Set the game level
204
$a0 = new level no.
Create an object
205
$a0 = unique ID of the object
$a1 = x-coordinate
A new object of the given ID and object type is created, replacing any existing object of the same ID and object type.
COMP2611 Fall 2016 Page 12

$a2 = y-coordinate
$a3 = object type: 0 for score point; 1 for Ninja; 2 for monster
The location of the object is set to the given x- and y-coordinates.
Set the location of an object
206
$a0 = ID of the object $a1 = x-coordinate $a2 = y-coordinate
$a3 = the object’s type: 0 for score point; 1 for Ninja
The location of the object is set to the given x- and y-coordinates.
Create a Text object
207
$a0 = unique ID of the object
$a1 = x-coordinate $a2 = y-coordinate
$a3 = base address of a text string
Create an object for displaying the text string at the given x- and y- coordinates.
Get the location of a monster object
208
$a0 = ID of the object
$v0 = x-coordinate of the location. $v1 = y-coordinate of the location.
Get a random path cell of the maze
209
$v0 = x-coordinate (at the top-left corner) of the cell.
$v1 = y-coordinate of the cell.
Get a random duration for a score point object
210
$v0 = random number of game iterations for the duration of the visible or hidden status of a score point object
Update the Shield mode
212
$a0 = 0 for ending the mode; 1 for triggering the mode; 2 for updating the mode’s display near its expiration
Move monsters
213
Move all the monster objects for one game iteration.
COMP2611 Fall 2016 Page 13

8. Submission
You should *ONLY* submit the file comp2611_project_yourStudentID.s with your completed code for the project. Please write down your name, student ID, and email address (as code comments) at the beginning of the file.
As a good programming habit, comment your code properly and use registers wisely.
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.
9. 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. It must also work in a computer in our lab room 4213.
10. Self-Proposed Project
The modified MARS actually provides flexibility of creating your own Maze game. If you want to implement a brand-new Maze game from scratch, email Dr. Cindy LI (lixin@ust.hk) for discussion. Once approved, you can work on self-proposed project instead.
COMP2611 Fall 2016 Page 14