Game Design Lab 9
Today's lab will let you practice 3D math with coordinate systems and adding objects to the teapot game using inheritance, all that the same time!
Add a new GameObject type, SwingTarget. This should inherit from Target. It will add 4 properties:
ShiftTarget will require its own constructor to initialize base_x and base_y. These can be initialized to the given x and y position, since these will change.
- base_x : The point where the target is "hanging" in the x direction.
- base_y : The point where the target is "hanging" in the y direction.
- angle : The current angle of the string the target hangs from
- shift : The current angle shift. This will be larger mid-swing. Model this by adding shift to angle. A good value for shift is 0.001 or -0.001 depending on the direction.
If you want a "peaceful" target for testing, just set its shoots_back property to false.
- collisions() doesn't need to be overridden at all: The base class method will suffice.
- cycle(size_t etime) should be overridden, but should call the base class method as well. This will change the x and y position of the objects, so that draw and collisions continue to function as expected. It will perform the physics (adding and subtracting shift to angle), and determine the new x and y position based on base_x and base_y. Targets swing in the xy plane, with no z involvement.
- draw() will call the base class draw, and then draw a ling from (x,y,z) to (base_x, base_y, z). That's the "string" the target swings from.
For 30% extra credit on this lab (a lot!), make the target capable of swinging in planes other than xy. The user should be able to define the plane for swinging. Collision detection must continue to function correctly.