Skip to content

Assignment 3

drebain edited this page Feb 15, 2020 · 2 revisions

For this assignment you will be given partially completed skeleton code that contains some of the logic you will need. All areas that you need to add or modify code to to complete the assignment requirements will be marked with a TODO comment and some more specific instructions. It is not necessary to add or modify code outside these sections.

Tasks

(1 mark) Add Walls

Add four block objects to obj_list as walls so that the ball will appear to bounce off the sides of the screen.

(1 mark) Draw the Ball

Implement the draw() method for the case where self.obj_type == "ball".

Note: You will need to set a position and velocity in the init() function before you draw so that you have a position to draw the ball at, otherwise you will get NaN errors.

(1 mark) Draw an arrow

When the mouse is being pressed, draw an arrow from the point (INIT_X, INIT_Y) to (CUR_X, CUR_Y).

(1 mark) Shoot the ball

The init() function will be called when the user releases the mouse button. Modify the code there so that the ball will start with a velocity determined by how the user moves their mouse, as shown in the demo.

(4 marks) Find Collision Direction and Change Velocity

Implement the solve_direction() function and modify_velocity() method so that the ball correctly responds to colliding with the walls.

Resources

The resources from the previous assignments are still applicable here, and additionally you may want to read up on classes if you are not familiar with them.

Clone this wiki locally