Hello, dear friend, you can consult us at any time if you have any questions, add WeChat:THEend8_
Science for Multidisciplinary Studies I
Assignment 3: BeatHero
Weight: 7%
Collaboration
Discussing the assignment requirements with others is a reasonable thing to do, and a good way to learn.
However, the work you hand in must be yours and yours alone. This is essential for you to benefit from the
learning experience, and for you to be graded fairly. Handing in work that is not your original work, but is
represented as such, is plagiarism. Penalties are outlined in the university calendar. A common first penalty is an F
on a plagiarized assignment. Here are some tips to avoid plagiarism in your programming assignments.
1. Cite all sources of code that you hand in that are not your original work using comments in your program,
including the complete URL. For example, if you find and use code found on a website, include a comment
that says:
# The following code is from https://www.quackit.com/python/tutorial/python_hello_world.cfm.
2. Citing sources avoids accusations of plagiarism and penalties for academic misconduct. However, you may
still get a low grade if you submit code that is not primarily developed by yourself. Cited material should
never be used to complete core assignment specifications. Before submitting, you can and should verify any
code you are concerned about with your instructor/TA.
3. Discuss and share ideas with other programmers as much as you like, but make sure that when you write your
code it is your own. A good rule of thumb is to wait twenty minutes after talking with somebody before
writing your code.
4. Collaborative coding is strictly prohibited. Discussing anything beyond assignment requirements and ideas is a
strictly forbidden form of collaboration. This includes sharing code, discussing code itself, or modelling code
after another student's algorithm. You cannot use (even with citation) another student’s code.
5. Using a generative AI tool, such as Copilot or ChatGPT, to assist you in completing assignments is acceptable in
limited circumstances, with attribution. For example, if your assignment is to write a Tic-Tac-Toe program, you
might ask ChatGPT about a small part of that task, such as “How do I convert a string to an integer in
Python?”. You cannot ask for such a tool to do the entire assignment. For example, asking ChatGPT “How do I
write Tic-Tac-Toe in Python?” is unacceptable. If you use a tool such as this, indicate with comments which
parts of your code you asked the generative AI tool about. Keep in mind that when you write your exams, you
will not have access to these tools, so it would be wise not to rely on them too much.
6. Making your code available, even passively, for others to copy, or potentially copy, is also plagiarism.
7. We will be looking for plagiarism in all code submissions, possibly using automated software designed for the
task.
8. Remember, if you are having trouble with an assignment, it is always better to go to your TA and/or instructor
to get help than it is to plagiarize.
Late Penalty
You will have a total of five grace days per semester (across all assignments). After that, late assignments will not
be accepted without a documented university-approved excuse.
Goal
Practice using lists, tuples and dictionaries while creating a game.
Technology
Python 3, SimpleGame Package
Submission Instructions
This assignment requires you to write a computer program using Python. Use the Assignment 3 drop
box in D2L to submit your Python file. You can submit multiple times over the top of a previous
submission. Your assignment must be executable with Python version 3.9.0+. You must use the
SimpleGame library, which contains beatHeroStarter.py code to get you started. You are allowed to
import libraries taught in class, such as random and math. Do not import any other libraries to complete
this assignment.
Upload CPSC217W24A3-Name.py (e.g. CPSC217W24A3-MichelleCheatham.py)
If using your own images, sounds, or music, zip your .py file with the folders containing all the media
associated with your project.
Description
Game Overview
This game, BeatHero, was inspired by the Beat Saber Virtual Reality game. Our game is much simpler,
and you can play it on your computer using your keyboard. Watch the video in the assignment Dropbox
to get a better idea of how the game is supposed to be played (seriously, stop reading here and watch
the video before moving on!)
In our version, when the game starts, the soundtrack starts and beats start falling down your screen, at
first slowly and a few at a time, but as beats move down the zones, they speed up and tests the limits of
your dexterity. Your goal is to score as much as possible before time runs out. Each beat is represented
by an arrow. To score a point, you’ll need to press the arrow key on your keyboard in the direction
noted by the beat arrow before it hits the bottom of the screen. With multiple beats on your screen, you
must always aim for the lowest one.
Game Structure
Before the Game
When the game is run, the starting screen appears. As BeatHero is a real-time game, this step assures
that the player is ready to play before the game starts. The game will only start when the player presses
the space bar.
During the Game
Once the game starts, at the same time, the music track is played, the countdown timer starts, and
beats start falling down the screen in three different streams. The screen is divided into three horizontal
zones. When a beat enters a zone (including the first one): it randomly rotates, changes colors, speeds
up, and increases in points awarded for getting it correct. The zones from top to bottom are orange,
pink and blue. When the player presses an arrow key, a representation of that key is shown on the
screen. Each time the player correctly presses an arrow key in sync with the direction of the lowest beat
on the screen, the beat turns green with a score number beside it, shortly disappears, and the player is
awarded the appropriate number of points (1 for the orange zone, 2 for pink and 3 for blue); we refer to
this as a hit. If the player doesn’t press the correct arrow key, or the beat reaches the bottom of the
screen before any key is pressed, the beat lights up red and disappears; we refer to this as a miss.
After the Game
Once the timer hits 0, the game ends. At this stage, all the beats are removed from the screen, and no
more points will be awarded. The final score is shown on the screen.
SimpleGame
To program BeatHero, you will be using a game engine called SimpleGame which is based on PyGame
and PyGameZero! You can download it here. You will have access to all the documentation on how
SimpleGame works and how to install it. We also provide you with a sample code as a starting point for
your game. After you press the space key on your keyboard, the music starts, and a single beat pointing
to the right falls down the screen. You can write code inside any of the provided functions in this file, but
you will still need to add additional functions.
The SimpleGame package comes with a module named simplegame. All functions available through the
module are listed on here. Before beginning to code, carefully read the documentation for each
SimpleGame function (docstrings) to understand what is available to you. You are only allowed to use
the capabilities of this module for this assignment. Additionally, in your IDE, if you hover over a function
name, you will see its description, parameters (if any) and return value (if any).
In the starter code, you’ll notice three functions (update, draw, and on_key_down) that are called
internally. This means there’s no need for you to call these functions anywhere in your code, as they will
automatically be called by the game engine at the appropriate times.
update()
Like many other game engines, SimpleGame uses a game loop, which is called 60 times per second. The
60 fps (frames per second) allows the game to be updated constantly, to maintain a smooth gameplay
which is very fundamental for real-time games. In your starter code, inside the update() function, we
have provided a frameCounter which you can use to calculate the time that has passed between
different actions.
This is where you should code your game logic, such as animating/moving game elements, updating
scores, checking game conditions, etc.
draw()
This function is called every time something changes on your screen, e.g. a beat moves down by a few
pixels. Similar to simplegraphics, the (0, 0) coordinates are at the top-left of the screen and the order in
which you draw your game element matters. If you put any game logic inside this function, it will
considerably affect your game speed, even making it laggy.
Except for loops and conditions, your code should only use this function for drawing on the screen. The
drawing functions available through SimpleGame are draw_background_image(), draw_element(), and
draw_text_on_screen(). Note that you cannot draw an element before first creating it.
on_key_down()
This function is an event handler that gets called anytime a key on your keyboard is pressed. The integer
value representing the key is passed to the get_key_pressed() function from the simplegame module
and stored in the key_pressed variable inside this function. You only need to compare this value to see if
it’s a desired key, and if not, you may ignore it. Try printing the key_pressed variable and see what it
shows when you press different keys on your keyboard.
Functions inside the simplegame Module
Here, we quickly review some of the functions that are available to you through the simplegame
Module.
Creating, Drawing and Rotating Movable Elements
To place any image on the screen, you first need to call the create_element() function. You will pass the
name of the image file (without the .png extension) along with the starting position and it will return a
dictionary with a single key that contains the id for that specific element. You are encouraged to add
other key-values to this dictionary to control your elements. Note that creating an element won’t make
it appear on the screen. To do that, you must use draw_element(). To rotate the element clockwise, you
must use rotate_by().
Look inside the images folder to find a variety of beats, arrows, backgrounds, and many more.