CS计算机代考程序代写 mips Java assembly Project 2: MIlliPedeS

Project 2: MIlliPedeS
Released: 11�59 PM Tuesday, October 26th, 2021.

Due: 11�59 PM Sunday, November 21st, 2021.

Creating an interactive game with graphics.

Important: Read this
Please read this document to the end before you start. I give a LOT of useful information

that should help you on the project.

Make sure you start by reading/solving Lab 7, it was designed to help you start with this

project.

It you havenʼt, read this brief introduction to game development.

REMEMBER: There are points given for meeting with your TA! Iʼll

make no exceptions if you donʼt do it by the deadline!

Finally, Download this code to start working on your project. It contains mostly the same

files you used in Lab 7.B, except the files with the pixel code. Donʼt forget to review the

detailed explanation of those files here.

Now, we are ready to start!

Introduction

Millipede is a famous game first released in the 1980 s̓! It was a sequel to the game

centipede, but I couldnʼt find a way to butcher the name centipede to make the most awful

joke with MIPS, so MIlliPedeS it is! 🙁

The game is played in an arena where mushrooms grow!, luckily they can be destroyed

>:-). Also in the arena, live the millipedes, terrible enemies that crawl across the fields with

an evil intent (I think… cause I never stopped to ask).

The objective, destroy the evil millipedes.

However, it turns out that when a millipede is shot, the piece you shoot turns into a

CS 447 Computer Organization and Assembly Language

Luis Oliveira General Info Syllabus Schedule Resources Labs Projects

https://luisfnqoliveira.gitlab.io/cs447_f2021/labs/07/
https://luisfnqoliveira.gitlab.io/cs447_f2021/interactive/
https://luisfnqoliveira.gitlab.io/cs447_f2021/projects/02/P2_package.zip
https://luisfnqoliveira.gitlab.io/cs447_f2021/lab7_helper/
https://luisfnqoliveira.gitlab.io/cs447_f2021/
https://luisfnqoliveira.gitlab.io/cs447_f2021/aboutme
https://luisfnqoliveira.gitlab.io/cs447_f2021/general
https://luisfnqoliveira.gitlab.io/cs447_f2021/syllabus/
https://luisfnqoliveira.gitlab.io/cs447_f2021/schedule
https://luisfnqoliveira.gitlab.io/cs447_f2021/resources/
https://luisfnqoliveira.gitlab.io/cs447_f2021/labs/
https://luisfnqoliveira.gitlab.io/cs447_f2021/projects/

, p , p y

mushroom :0. And the millipede splits in two :O

How many millipedes will you be able to destroy? Well, you need to implement the game

first 😀

Start early
The deadline will approach fast! Life happens, sickness happens, so if you start early you

can minimize the impact.

Do a little bit every day! 1 hour every day! 30 minutes every day! SOMETHING!

You know you will have questions, and if you decide to ask them in the last week, I may not

be able to answer them all!

Game elements

The game arena

The MARS LED display is 64×64 pixels. You will need to split the screen into two areas.

�. The top area where the action unravels

�. The bottom where information about the number of points/lives is displayed.

The arena can be as large as you wish, but make sure you save some space at the bottom

for the rest of the display information. If you look closely at my implementation, youʼll

notice that a piece of the screen is unused. That s̓ because my 5×5 images move in

increments of 5 pixels. The arena will contain obstacles, mushrooms. When the game

begins, the arena should have some mushrooms.

You will control the player character. The player should be able to move in all 4 directions,

and shoot bullets (one at a time) If you shoot amushroom it should disappear (in the

CS447 Project 2 F21CS447 Project 2 F21

and shoot bullets (one at a time). If you shoot a mushroom, it should disappear (in the

original game this takes multiple shots, in my implementation one shot is enough). And if

you shoot a segment of a millipede, that segment spawns a mushroom. Also, the millipede

splits into 2 😀 Making the game that much more fun! 🙂

The millipede should spawn at the top of the screen, and crawl sideways. If the millipede

finds an obstacle, it needs to crawl down (ignoring possible obstacles in the row below).

Check the video I shared.

Each block in the arena is a 5×5 block, why?

I do give you functions that draw 5×5 blits right? O.o

Start your development here.

�. Create some variables to hold how many points the player has, and a variable to

represent how many lives the player has.

�. Make a function to display this information at the bottom of the screen. Feel free to

display this information as youʼd like! I really donʼt care, as long as I can understand

what is represented.

�. Create arena.

Check this help and look into functions display_draw_int , display_draw_text , and

display_blit_5x5 if you want to show numbers or sprites; if you want to show a bar,

check function display_draw_hline/vline . Have fun with your design 🙂

This was my approach.

Implementation hints

The bottom of the screen where the game info is shown should be pretty straightforward!

Just create a function that draws what you need and call it every single frame!

Blits (drawn with function display_blit_5x5 ) are 5×5 images. So each tile is a 5×5

block. This means that (my) arena is 12×10 tiles (each a 5×5 block), thus the size in pixels is

60×50, out of the 64×64 pixels available.

E.g. of a blit:

.data
blit: .byte 1, 2, 3, 4, 5
1, 2, 3, 4, 5
1, 2, 3, 4, 5
1, 2, 3, 4, 5
1, 2, 3, 4, 5

How can you represent an arena of 5×5 blocks? (ermmm…mat … hummm… rix … ermmm)

Maybe 1 for “There is a mushroom” and 0 for “There is no mushroom”? The arena

should be generated randomly (maybe generate a couple of random coordinates (x,y)?).

But to begin with, you can go ahead and create it manually. (The image comes from

https://luisfnqoliveira.gitlab.io/cs447_f2021/lab7_helper/

But to begin with, you can go ahead and create it manually. (The image comes from

another project, but the same principle applies)

Then implement the function that prints it on the screen. The first time you print the

mushrooms, you may be surprised that it looks sideways O.o

This happens because our brains suck (well, at least mine does)!

When you have a coordinate in the screen (x, y):

x is the column of the matrix!

y is the row of the matrix!

I also implemented a function that allows me to ask if there is a mushroom in this (x,y)

coordinate?

Implement the function, and test it!

The player

The player starts the game at the bottom. The keyboard arrow keys are used to control the

player character (up, left, down, right), and pressing the “b” key shoots a bullet. The player

cannot move though mushrooms. The player cannot leave the board, so you must check

for edge collisions.

The player behaves similarly to the pixels in Lab 7! (hint hint) But it s̓ a 5×5 blit, and there is

only one player!

The size of the player does change how you check for the arena bounds, but it shouldnʼt

be too hard. Note that the player cannot move through all the screen; since it cannot go

over the information at the bottom of the screen, or through the mushrooms in the arena.

The player starts with zero points, and the value increases with actions it makes. It s̓ up to

you to decide what awards points, and how many 🙂

Function display_blit_5x5_trans can be used to draw the player. As for the player

blit, use your imagination! (Mine looks terrible)

Implementation hints

Here you should follow the same technique I suggested in Lab 7: split the implementation

in three parts: Model, View, and Control. (Using three separate files is naturally facultative,

but highly advised).

Think what information about the player you need to keep track of (the model):

�. x coordinate!

�. y coordinate!

�. How does it look like?

�. How many points and lives does the player have?

Then implement the code:

�. Start by creating the player and placing it on the screen! (Remember that you can

change the initial value of the variables to run tests)

Done? Ok!

�. Now, you can make the player move left and right (function

player_move_left_right ?) (Lab 7!)

�. Then make the player move up and down (function player_move_up_down ?) with the

keyboard! (Lab 7!)

HINT: DO NOT IGNORE MY HINTS!!!

HINT 2: Implement one movement at a time! (1) Place the player in the middle of the

screen and implement the code that moves the player right. Test it! (2) Implement the code

that moves the player left and test it. (3) Implement move down and test it. (4) Implement

move up and test it.

TEST IN SMALL BATCHES!!! If you write 100 lines and it doesnʼt work, then it s̓ hard to

know where the error is.

Then, worry about mushrooms. Make sure the player cannot go through mushrooms by

checking if there is a mushroom at the place the player wants to move to. If there is, then

donʼt Store the new position.

Once movement is working, the player cannot leave the bounds of the screen, and that is

not going through mushrooms. TEST your implementation, by placing the player in

different places in the arena, and moving it.

When you complete this, your player is (mostly) done! You still need to implement the

shooting capabilities, but those can wait.

The millipedes

The game should start with a single millipede. You can decide its size, but it must have at

least 5 segments (the code will be the same whatever is the size). They should move

horizontally in the map. When they reach the edge or collide with a mushroom, the

millipede must move one space downwards and move the opposite direction.

The millipede can ignore mushrooms when moving one space downwards to avoid getting

stuck 🙂

Choose the speed of the millipede to make the game playable; you can also make them all

move at the same speed, or at different speeds according to their size. Just keep the game

playable :).

When your player shoots a millipede, the segment that gets shot turns into a mushroom

and the millipede splits into 2.

If a millipede reaches the bottom of the playing arena, the player loses a life and the

millipede is removed from the game.

When all millipede segments are destroyed, or reach the bottom, it should reappear at the

top of the screen.

Implementation hints

Think carefully about how you are going to represent the millipede. I used an array of

structs (each representing a segment of the millipede). The struct stored data such as

position of the segment, if it s̓ active or not, and if it s̓ the head of a millipede or not. There

are other ways of doing this, so take some time to think about how you want to implement

are other ways of doing this, so take some time to think about how you want to implement

it.

Then think how you can make it move, what happens to each segment when the millipede

moves? They all take the position of the next segment. Now… depending on how you

represent the millipedes (one array, multiple arrays, etc.) the way you accomplish

movement will be different. Plan this carefully.

Again, implement this incrementally.

�. Start with a single segment of a millipede. Does it move correctly?

�. Add a single segment behind the head. Make it work!

�. Add another segment, one at a time, and keep testing and fixing bugs.

Then you can manually change the initial millipede state to make it multiple millipedes.

Does the code still work?

Bullet

The player can shoot a bullet at a time. When a player presses b, a bullet will appear in the

same block as the player. Then, the bullet will travel upwards in a straight line until it hits

something or reaches the top of the screen. At that point, it should disappear.

If the bullet hits a mushroom, the mushroom is removed. If it hits the millipede, a segment

turns into a mushroom and the millipede is split in two (if possible).

Starting and ending the game

When the game starts, it should wait for the player to press any key. Only then should it

begin. Maybe function input_get_keys_pressed can be useful. When the game ends,

you should display the player s̓ score. Check display_draw_int and

display_draw_text .

Losing the game

The player loses the game when it runs out of lives.

Helpful Tidbits

Block colours

You can use any colour you like, as long as elements are distinguishable (yellow and orange

look the same). Feel free to do your own thing! As long as the game is playable!

Testing

DO NOT TRY TO WRITE THE WHOLE PROGRAM BEFORE TESTING IT!!!!

Really! Do not do it! It s̓ the easiest way to get overwhelmed and confused without

knowing what to do!

Implement small parts of the code and test them!

Split your code into functions

Use functions, then use more functions. If your function has more than 40-ish lines of code

(not a rule really, use your instinct), consider splitting it.

Donʼt create new paradigms

Stick to structures you know (while, for, if, etc.)! And start by planning what the code will

do! It is 0^0 times more difficult to write code if you donʼt know what it is supposed to do.

Make drawings, write Java code, write down a paragraph. ANYTHING!

Input Handling

Our game loop has a handleInput function. Here, we will look at our hardware to detect

whether or not an input was pressed. For this type of game, we can simply modify a

variable for each direction and the one “b” button.

The code to handle input is provided to you.

Project Stages

In order to help you we aware of your progress, I will recommend a series of mile markers

to help you divide up the work. You can, of course, ignore these if you wish. However, if you

find you need some direction, by all means follow along.

You have around four weeks to complete this project, and Iʼve divided this into three

stages. You could consider accomplishing each stage for each week. (Or do everything in

the last three days at your own peril! 🙂

Stage 1 – Create the base arena and the make the player move

Create the arena layout according to the project specification. At this stage, you do not

have to worry about the millipede or the bullets!

Create a matrix containing the locations of the mushrooms hardcoded, implement the

function to display it. And (idk) maybe (just maybe) a function to figure out if a certain

index of the matrix contains a mushroom?

int has_mushroom(int x, int y)

Once the mushrooms are in place, add the player and make it move. Again:

�. Create the model (variables that keep the state of the player)

�. Write a function to draw the player

�. Make the player move (bit by bit)

Move left/right

Move up/down

Check arena bounds

Check for collisions with the mushrooms

�. Write a function that generates (ikd) 5-10 randomly placed mushrooms

�. Add the bottom display with the number of lives and the player points

Stage 2 – Add the millipede

Once the base stuff is in place, we can worry about the millipede. Make a single segment

millipede and implement its movement (it may be useful to slow down the movement for

debug purposes).

The millipede will be the most challenging part of this project (I think). So take it slow.

�. Start by implementing the most basic millipede: a single segment.

What do you need?

Where is the segment? (x and y)

Is it active? (should it be displayed/moved)

How does it look like? (blit)

Is it the head of the millipede (it moves) or a segment (follows the head)

Is it going left or right?

�. Display the millipede:

Hardcode the position and see if it is printed

Make it move left/right until the program crashes because it leaves the screen

Make it stop when it reaches the edge of the screen or finds a mushroom

Make it move down when it reaches the edge of the screen or finds a mushroom

Make it move back after that

�. Add a body segment to the millipede

Make the body segment move after the head

Add more segments and check that it still works

�. Manually create multiple millipedes:

Make sure it still works with multiple millipedes

Stage 3 – Bullets

The last step is adding the bullets! When the player presses “b” it shoots a bullet. The

bullet should spawn where the player is (or right in front of it, your choice). The bullet

should travel in a straight line upwards until:

�. It hits a segment of the millipede.

�. It hits a mushroom

�. It reaches the top of the screen.

In any case, once it stops, it should despawn (removed from the screen).

Submission
Submit a single ZIP file with your project named username_proj2.zip (e.g. lun8_proj2.zip).

In the zip file, there should be no folder!, just the following files:

All files required to run the game. Put your name and username at the top of each file in

comments! A readme.txt file. DO NOT SUBMIT A README.DOCX. DO NOT SUBMIT A

README.PDF. SUBMIT A PLAIN TEXT FILE. PLEASE. It should contain:

Your name

Your Pitt username

Anything that does not work

Anything else you think might help the grader grade your project more easily

Submit into Canvas. Let me know immediately if there are any problems submitting your

work.

Grading Rubric (A guideline – it may change

slightly)

Grading Rubric (A guideline – it may change slightly within the

next week or so)

Rubric
[10] Planning

You have until Tuesday the 9th of November to meet with your TA and discuss your

plan to solve the project. ITʼS ALL OR NOTHING

[90] The game

[5] Submitted as per instructions

No exceptions! includes file with correct name, files, and everything I asked

for!!! It s̓ all or nothing!

[15] Coding style

[5] Functions include a C/Java pseudo-code implementation as a comment at

the top

[5] Commented the code, so the grader and I can understand what is going

on!!!!!!!!

[5] Split code into functions that follow conventions (no functions, no points)

Must preserve saved registers

ONLY JAL and JR instructions are used to call a function and return

Passed arguments in “a” registers and returned in “v” registers

etc.

[10]: Game flow

[4]: No crashes encountered during normal operation

[3]: Main loop works and ends when player looses all lives

[3]: When game ends, it stops (syscall 10)

[10]: The arena – must be drawn

[5]: The arena is created with randomly placed mushrooms

[5]: The bottom area displays the player lives and points

[15]: Player – must exist and be drawn

[4] Player moves as up/down/left/right

[4] Player doesnʼt walk through mushrooms

[4] Player loses lives when millipede reaches the bottom, [and/or hits the

player (optional)]

[3] Player gains points when actions are executed (e.g. hit

millipede/mushrooms/survives a millipede)

[15] Bullet

[3] Bulled is displayed and moves

[6] Bullet destroys mushrooms

[6] Bullet destroys segments of the millipede

[20]: Millipede – must have at least 5 drawn in the board

[4] Millipede is on screen and moves

[6] Movement follows description (left-right-downwards) as a single entity

[2] Millipede reappears once it fully disappears from screen

[3] When a segment is destroyed, a separate/independent millipede is created

[5] A millipede (head+body) is removed once it reaches the bottom

Note: You may lose points for significantly deviating from the described game, even if the

items are not described in the rubric. If you are unsure about any missing feature, talk to

your TA/Instructor.

Note2: You may lose points for significantly understating the status of your project in the

readme file! The purpose of the readme is assisting in the grading, so I donʼt want to see

any readme files stating everything works when it clearly doesnʼt. If you do that, you

will lose (more) points! If you are unsure about any missing feature, talk to your

TA/Instructor.

Extra credit

Have fun (up to 10 points: the grader will decide based on difficulty)

Implement something extra. I will not be strict with what, as long as it significantly changes

(for better!) the gameplay 🙂 Here are some suggestions:

Maybe add different types of bullets?

Power ups?

Extra lives?

Do you have your own idea? Do it! But donʼt make it too hard on yourself 🙂

As your TAs what they did 🙂

CS 447 Computer Organization
and Assembly Language

luisfnqoliveira CS 447 // M-W

CS 447 Computer Organization and Assembly Language

mailto:
https://github.com/luisfnqoliveira