CSE 203 Closed Lab 20 Instructions

Table of Contents


1. Objectives

To continue practicing allowing the user, by using the keyboard, to influence the movement of one or more sprites around in a window.  In doing so, to continue practicing the use of the program control constructs of sequencing, selection, and iteration.


2. Set Up

  1. Two students should work together at one workstation.
  2. In one student's account, follow the instructions given below in section 3, Method.  Remember, trading roles (driver and non-driver) for each new session is a very good idea.

3. Method

  1. In class earlier, we discussed the program Launching_a_Projectile.  In that program, the user can control a space ship's forward/backward acceleration using the up and down arrow keys.  The user can turn the ship using the left and right arrow keys.
  2. Start Phrogram, and open file Launching_a_Projectile.kpl from folder Week07 within folder OSU (i.e., folder OSU/Week07).
  3. Run the program, get the ship moving forward, and turn it using, say, the left arrow key.  Notice how turning the ship changes its direction.  This behavior is pretty natural for an automobile in a parking lot or on a highway; however, a space ship doesn't have to behave this way.  A space ship could change which way it is facing without changing which way it is moving.  A space ship could "slide sideways".  The next program that we will examine will allow the space ship to have this behavior.
  4. Open file Turn_Ship_Without_Changing_Velocity.kpl from folder Week07 within folder OSU (i.e., folder OSU/Week07).
  5. Run the program and play with it to compare it's behavior with that of Launching_a_Projectile.
  6. Examine this program to see if you can understand how it accomplishes what is described in the following sentences.  This program uses the sprite's ForwardDirection property to indicate the direction the sprite is moving.  The Rotation property indicates the direction the sprite is pointing.  When the Rotation gets changed, the ForwardDirection automatically changes with it, so this program changes the ForwardDirection the same amount (in the opposite direction) as the change in Rotation so that the ForwardDirection keeps pointing in the same direction in the window.  As a consequence, we have to do something differently about accelerating the ship's velocity than in program Launching_a_Projectile.kpl.  We need to add a speed in the direction the ship is pointing to the current speed of the ship in the current ForwardDirection to obtain a new speed in a new ForwardDirection.  That is the role of the side-effecting function NewSpeedNCSD().
  7. You may or may not use in your course project the ideas offered in this program.  We hope it's fun to examine and learn new ideas.  If you have any questions about it, please ask.
  8. Open file Spin_Ship.kpl from folder Week07 within folder OSU (i.e., folder OSU/Week07).
  9. Run the program and play with it to compare it's behavior with that of Turn_Ship_Without_Changing_Velocity.
  10. In Spin_Ship.kpl, instead of having the left and right arrow keys control the ship's rotation, they accelerate the ship's rotation in the given direction.  Once the ship starts spinning, it keeps on spinning until the opposite arrow key is used to slow down the spinning in that direction and maybe start a spin in the opposite direction.
  11. In this program, the projectile also accelerates after launch.  We made this change to match the missile sprite's pictured suggestion that the missile has its own thrust.
  12. Work on your course project.  Your partnership may elect to create a project program jointly, or to work on one partner's project for a while, then switch and give time to the other partner's project.
  13. Stay in closed lab until the bell rings: there's plenty to do when you're making an interactive situation.

4. Proctor Help

If you have a question or get stuck, raise your hand and one of the proctors will come by to chat.