CSE 203 Closed Lab 14 Instructions

Table of Contents


1. Objectives


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. Start Phrogram, and open file Test_Bounces.kpl from folder Week06 within folder OSU (i.e., folder OSU/Week06).
  2. Save this program as Test_Bounces_Mouse_Clicks.kpl in your 0) My Own folder.
  3. Change the date, the author name(s), and the program name.
  4. Run the program to experience its behavior.
  5. This program did not use the mouse buttons, only the mouse location.  It used the keyboard buttons F1 and F2 in place of the right and left mouse buttons.  This is somewhat clumsy for the user.  Today we'll modify this program to use mouse buttons instead.  Replace the part of the comment at the top of the program that says "F1 to place your circle; F2 to launch it toward the mouse pointer." with "Right-mouse-button click to place your circle; left-mouse-button click to launch it toward the mouse pointer.".
  6. Next, replace the call to Status with the following call to Status.  The backslash character ('\') is used to continue a long program statement on to the next line.
    Status( "right-mouse-button click to place your circle; " + \
    "left-mouse-button to launch it toward the mouse pointer." )
  7. A program, such as this one, that calculates new sprite and/or drawing positions based on frame times and velocities may not have a call to Delay in it.  This program doesn't call Delay.  However, a Phrogram program that responds to the mouse ought to have in it a call to "Delay( 1 )".  Here's why.  Let's call each boundary point in time that comes every (1/60)th of a second (16.67 milliseconds) a "tick".  Between each tick is a (1/60)th of a second time interval.  Phrogram records any mouse event that occurs in one interval and passes that information along to the time interval that comes after the next tick, and holds that information steady throughout that next time interval.  If a time interval experiences no mouse activity, then the information in the next time interval shows no mouse activity.  Now, a loop could iterate several times in one time interval; if so, it is guaranteed to get the same answers from the mouse each time.  In that case, it is likely to behave as though the mouse were clicked several times rapidly during that time interval.  Such behavior could be acceptable.  On the other hand, to prevent such repeated events,  Phrogram provides the "Delay( 1 )" idiom.  "Delay( 1 )" means to delay at least one millisecond and, after that, delay even more until the next tick arrives.  A call to "Delay( 1 )" at the end of an event loop guarantees, then, that the next iteration of the event loop begins at a tick.  If we put a call to "Delay( 1 )" at the end of the event loop in this program, it will make it so that, when our program reads mouse events, it will get each mouse event only once in each iteration.  The "Delay( 1 )" puts off further action until the next tick.  Please insert "Delay( 1 )" just prior to the end of the While loop.
  8. Now we're ready to replace the keyboard tests in the selections statements with mouse event tests.
    1. Replace 'IsKeyDown( Keys.F1 )' with 'Mouse.RightPressed And Mouse.Event = "ButtonDown"'.
    2. Replace 'IsKeyDown( Keys.F2 )' with 'Mouse.LeftPressed And Mouse.Event = "ButtonDown"'.
  9. Run the program to experience its new behavior.
  10. There are new types used in this program: Point, Line, Circle, and Vector.  Use hover captions to explore some of the methods, functions, and properties of these new types that are used in this program.  You could also type a new statement using an object (a variable) of one of these new types to explore the names of all the methods, functions, and properties available for these types.  There will be time on our class discussion day to discuss these new types.
  11. Any time there is a RefreshScreen() in the main event loop, a DoEvents() is not needed.  Remove or comment out the DoEvents() and run the program to see that you don't experience any difference.
  12. BeginFrame() suspends all drawing until the next RefreshScreen().  BeginFrame() is really important in this program.  Comment it out to see what happens.  Bad, huh?  Without BeginFrame(), RefreshScreen() is not needed.  Comment it out and run the program to see no change.  Put them both back in.
  13. Save this program as a new program with a different name and make the one change in this program that would slow down the moving circle.  Try it out.
  14. Experiment with the program and make any other changes to it that capture your fancy.

4. Proctor Help

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