release: Sequence Module
BlitzMax Forums/BlitzMax Programming/release: Sequence Module
| ||
I'm in the process of releasing all of my modules into the public domain. (If there is a better place to post my modules, please let me know) This is a simple sequencing engine that I constructed for my Photobooth application. I have found it very helpful, and hope others will to! Download it here: http://code.google.com/p/jmd-blitzmax-modules/downloads/list To install, just unzip it into your mod folder, then build modules. Here is a small sample showing how to use the module: (the module is also fully documented) 'Sequencing example 'This is a simple example of a familiar "arcade" sequence of showing an intro screen for 10 'seconds, which then automatically transitions to the game's title screen. The title screen will 'stay on the screen for 30 seconds, waiting for user input to either quit or start the game. 'If no user input is given, then it will repeat showing the intro screen for 10 seconds, followed 'by the title screen for 30 seconds until user input is given. 'Once the user chooses to start the game (space bar), the game part of the sequence is entered. 'If the game step of the sequence is exited, then execution will return to the title screen - but 'this time, it will return the high score, and it will remain at the title screen indefinitely until user input is given. (I.e. the 'game is no longer in an "auto-advertise" mode as the user has obviously seen these before running the game.) 'This simple example is to show the utility of this sequencing engine, as well as show how easy it is to use! SuperStrict Import jmd.sequence 'Consts Const STEP_INTRO:Int = 0 Const STEP_TITLE:Int = 1 Const STEP_RUN:Int= 3 Const STEP_EXIT:Int = 1000 'no need for any specific order! 'Create a new sequence Local SEQ:TSequence = CreateSequence() 'alternatively, you can use TSequence.Create() 'Add our first 2 steps 'You can add as many sequence steps as you would like - here we are only adding 2. 'Note that you could also use the SequenceAdd() function instead... SEQ.Add(STEP_INTRO,10*1000) '10 seconds SEQ.Add(STEP_TITLE,30*1000) '30 seconds Graphics 640,480 While Not KeyDown(KEY_ESCAPE) Cls 'You can use a Select statement to get the current sequence step. 'Then you can add your code for each different sequence step! Only the code 'for the current step gets executed. Select SEQ.Get() 'alternative: SequenceGet(SEQ) Case STEP_INTRO If Not SEQ.Init() 'alternative: SequenceInit(SEQ) Print "(Intro Screen) Initialization only happens once!" EndIf DrawText "Intro Screen!",10,10 DrawText "This is a good place to show your logo after running the application",10,30 DrawText "No input is processed this step, so wait 10 seconds for it to autoexpire!",10,50 SEQ.AutoExpire() 'automatically expires step, and moves to the next 'alternative: SequenceAutoExpire(SEQ) Case STEP_TITLE If Not SEQ.Init() Print "(Title Screen) Initialization only happens once!" FlushKeys() 'Since the RUN step also uses the Q key to exit, 'we will flush this so it doesn't also exit this step EndIf DrawText "Title Screen",10,10 DrawText "Put a title screen here with choices to start your game, etc.",10,30 If SEQ.Data() 'Alternatively use SequenceData(SEQ) DrawText "Good Job! " + String(SEQ.Data()),10,50 'Since the data is an object, you must cast its type back to a string! Else DrawText "If no input is given after 30 seconds, we will advertise ourselves",10,50 DrawText "by showing the title screen again for 10 seconds then coming back here.",10,70 EndIf DrawText "Press the space bar to begin the game, or Q to quit.",10,110 'Run the application if the space key is pressed! If KeyHit(KEY_SPACE) SEQ.Add(STEP_RUN,0) SEQ.DoNext() 'alternative: SequenceDoNext(SEQ) EndIf 'Exit application if the "q" key is pressed If KeyHit(KEY_Q) SEQ.Add(STEP_EXIT) SEQ.DoNext() EndIf 'If this step is expired, lets restart the Intro/Title screen steps 'Note that after the RUN step has executed, this step is created with 'no expiration time, so this step will remain infinitely until the user 'either runs the game again, or choses to quit. If SEQ.Expire() 'alternative: SequenceExpire(SEQ) SEQ.Add(STEP_INTRO,10*1000) SEQ.Add(STEP_TITLE,30*1000) SEQ.DoNext() 'alternative: SequenceDoNext(SEQ) EndIf Case STEP_RUN If Not SEQ.Init() Print "(Main Game Screen) Initialization only happens once!" EndIf DrawText "Welcome to my game!",10,10 DrawText "This is where you would do your main game logic, for example.",10,30 DrawText "Press Q to quit",10,50 'Lets process the Exit condition! If KeyHit(KEY_Q) SEQ.Add(STEP_TITLE,0,"High Score: 5000") 'Don't autoexpire this time, and pass some data too! SEQ.DoNext() EndIf Case STEP_EXIT If Not SEQ.Init() Print "Initialization... Do stuff here..." EndIf Print "Exiting...Do cleanup code here..." End Default Print "Unknown sequence step! Skipping..." SEQ.DoNext() End Select Flip Wend |