//---------------------------------------------------------------------------- // Lesson5 // Where we learn that windows are actually updating all the time! //---------------------------------------------------------------------------- // // Okay, so each window can just be a simple description of its contents. // But, it can also have switches associated with it, which initialize data, // update data, and resolve data for the closing of the window. // // This means we can actually have window content that changes while we are // watching the window! This is cool. This means we can respond to the // player, or show them windows that seem alive. In the end, this means // that we can make little games in the window. // // But for now, let's see how we can update a window in a meaningful way. We // will animate a little character. Let's animate a little guy walking. // //---------------------------------------------------------------------------- // // Windows can have three switches associated with them: startswitch, // thinkswitch, and finishswitch. // // The STARTSWITCH is responsible for initializing all the data. If you // were making a game, this would set up all tables and initialize necessary // data for the game to function. (Initialize is a term for assigning the // first "default" value.) // // // The THINKSWITCH is responsible for constantly updating the window while it // is open. It can check for changing variables, user input, and other things. // Upon these values, it can change the locations of its images, or the // contents of its text. Programmers, think of this as your main loop. // // The FINISHSWITCH is responsible for doing cleanup--you can unset variables // here, or set variable to be left after the Flow window concludes. // // // Instead of waiting for a mouseclick, like the following routine does, you // can manually close the window (and call the finishswitch automatically) // by using the closewindow command: // closewindow 2:1 // // The easiest way to understand these commands is to see them in action. Here // they are, making a little character animate in place. To run this: // // MAP TEST // LOADAPE Lesson5 // INVOKE 2:1 // // After you check that out, go on to Lesson 6, where we'll see how we can move // the guy around! // //############################################################################# // DEFINES //############################################################################# #define $Lesson5 "2" #define $Animation "1" #define $Before "2" #define $During "3" #define $After "4" //############################################################################# // CODE //############################################################################# #window $Lesson5:$Animation startswitch $Lesson5:$Before thinkswitch $Lesson5:$During finishswitch $Lesson5:$After //------------------------------------------------------- width 256 height 256 body "Haylo." image pooper\Guy$counter$.pcx 10,30 //======================================================= #switch $Lesson5:$Before set counter = 0 return //======================================================= #switch $Lesson5:$During set counter = counter + 1 if (counter > 3) set counter = 0 return //======================================================= #switch $Lesson5:$After // called when you click on window unset counter return