AP CSP CodeX - Mission 15: Handball
Mission 15: Handball
Students program a basic physics engine and build a single player handball game on the CodeX.
Overview
In this mission, students build the first half of a Breakout-style game: a single player game of handball on the CodeX. They create a basic physics engine, bounce the ball off the walls and a paddle, and add sound, score and lives. Along the way they use many functions, constants, global variables and delta time. There are a lot of steps, so plan on two class periods. The code continues in Mission 16.
🎯 Mission Goal: Students will apply Python programming concepts and their skills to create a single player game of handball.
Learning Targets
- I can program a basic physics game engine.
- I can use multiple functions to draw the ball, update position, clear the screen, etc.
- I can use angles to control the ball rebounds.
-
I can use delta time instead of
sleep()to manage a fast-paced game. - I can manage the game state by initializing the game, updating the game state, and handling game over.
Key Concepts
- Use functions to organize your code into reusable blocks: paddle position, collision check, updating score, etc.
- Use constants for variables that do not change.
- Define and initialize variables as local or global.
- Focus and refine your game's user experience.
- Implement collision detection algorithms to detect collisions between the ball and other game objects, such as the paddle or the walls.
Assessment Opportunities
- Mission 15 Assignment
- Handball program
Success Criteria
- Define and call 12 functions
- Draw a screen layout for the game
- Use CodeX buttons as event handlers for the game
- Keep track of score and lives
- Create 2 animated objects in the game: paddle and ball
- Game works correctly, showing a ball bounce, paddle movement, and score
Digital Resources
- ▸Mission 15 Assignment
- ▸Code Solutions and Assignment Answers - Teacher Dashboard > Educator Resources button
Classroom Materials
- ▸CodeX
- ▸USB-C cable
- ▸Computer
Real-World Applications
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AP CSP Framework
- The assignment is best completed digitally. Prepare the assignment to give through your LMS.
- Plan for two class periods. If you split the mission, stop after Objective 6 on day one.
- Optional: have the Breakout video or Wikipedia page ready for the warm-up so students can see where the game is headed.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- There are a lot of steps and code in this project. It will probably take two days to complete.
- Some objectives are heavy in math, especially trigonometry. The earlier objectives also go into detail about physics with velocity, distance and time. If the math is too advanced for your students, they can still complete the mission using the code that is given and reading through the hints. They are not required to understand all the math equations and concepts.
- Students create a lot of functions and include many global variables and constants. It is a lot to keep track of, so students need to pay attention to details and type carefully. They should scroll through the code in CodeTrek to make sure they are placing new code in the correct functions and with the correct indenting.
- Make sure each objective is correct and the code works properly before going to the next objective. Otherwise it will be very difficult to debug.
- There are no challenges, remix, or extra steps for this program. The code is continued in Mission 16.
Lesson Outline
This outline gives the narration for one way to present the lesson.
No specific warm-up for this mission. You may want to show a short video of the Breakout game so they can see what they will complete after Mission 16. Or review the background from the Wikipedia page.
Randomly group students into pairs for pair programming (or they can work individually).
Students log in to one computer. Two computers can be used if they want to have the assignment open on one computer and CodeSpace on the other computer.
Students go to make.firialabs.com and should be at the beginning of Mission 15.
NOTE: Not many lines of code, but each line is important, so be careful not to skip a step.
NOTE: There is a LOT going on in this objective. Pay attention to details!
NOTE: Remember to add from soundlib import *. This shows in CodeTrek but is not specifically mentioned.
Continue either in pairs or individually. Students go to make.firialabs.com and should be on Objective 7 of Mission 15.
NOTE: The sound_cut variable is moved from below the tone constants to above. It does not matter either way, so do not let this trip up your students.
IMPORTANT: The values for the ball velocity are changed. The new values show in CodeTrek, but they are not specifically pointed out. The speed is lowered! Use ball_v = [0.1, -0.15], which is in the serve_ball() function.
IMPORTANT: Students need to add n_lives and score to the global declaration in the check_buttons() function. It is mentioned in CodeTrek, but easily missed.
continue. You may want to trace this one with your students.IMPORTANT: The global variable ball_speed needs to be defined near the top of the program under serve_timer. This is not pointed out in CodeTrek, so be aware if students get an error message about the variable being undefined and do not get a green checkmark.
IMPORTANT: When typing the math for hit_ball(), make sure the ball_v[1] = -math.sin(angle) * ball_speed statement includes the negative!
IMPORTANT: The check_ball() function is not completely correct in CodeTrek for Objective 12. The global score and score = 0 lines are missing. If students are checking CodeTrek, they may notice this. Do not delete them!
NOTE: The second HINT mentions a line of code to add to the program. It probably is not necessary to do this, but it does not hurt to do it, either.
The assignment is complete and ready to turn in.
The post-mission reflection asks students what they learned during the mission. They may list Python or programming concepts, debugging strategies, or something about themselves.
Students complete the wrap-up question on the assignment. You can have a short discussion on their answers.