program myEnergyCrisis{ /* (Ñ) Bill Lane This is my attempt to program the Energy Crisis mission using Mindscript. The aim if this mission is to avoid obstacles and reach the light source before time runs out. If you hit an obstacle you will lose energy. Setup / Instructions: * Place a desk lamp some distance from your controller, this is the grid energy reserve. * Place objects heavy enough to stop your Spybot across the area leading to the lamp. * Place your Spybot in the light calibration area. * Press RUN. * The alert light will blink when your Spybot is ready. When it does move your Spybot to the start position. * Tap the bumper to start. * The arc lights will indicate energy levels in this mission. * Use the controller to steer your Spybot around the impulse generators. Striking a generator will drain energy causing you to lose arc lights. * When you are nearly out of time the alert light will flash. * Remember random bursts of static electricity may disrupt Spybot systems at any time. */ /////////////////includes//////////////////////////////////// #include #include #include /////////// //constants and variable definitions////////////////// var gv_energyLevel = 6 var gv_state = 0 var gv_shockTime var gv_lastShocktime = 0 var gv_timeSinceShock = 0 const gc_nearTime = 500 const gc_GameTimeLimit = 600 //tenths of seconds ////////////user events definitions//////////////////////////////// event lighthigh when opto.normal event timeUp when nBioTick = gc_GameTimeLimit event nearTime when nBioTick = gc_nearTime //////////user subroutines/////////////////////////////////////// sub whatNext{ select gv_state{ when 1{lightUp} when 2{hitObject} when 3{shocked} when 4{loseGame} when 5{winGame} } } sub lightUp{ if gv_state <> 0{ select gv_energyLevel{ when 6{LED[iDisplay] = 63} when 5 {LED[iDisplay] = 55} when 4 {LED[iDisplay] = 39} when 3 {LED[iDisplay] = 7} when 2 {LED[iDisplay] = 3} when 1 {LED[iDisplay] = 1} when 0 {gv_state = 4} } } } sub winGame{ try{ Action(62,1, moveDance, 2,200) wait 400 clear display stop tasks }retry on fail } sub shocked{ try{ link[iLinkID] = 1 Action(6,2,moveShake,2,100) BasicMove(moveStop,5) gv_shockTime = random 150 start randomShockCounter link[iRxChannel] = 0 gv_state = 1 } retry on fail } sub hitObject{ try{ //I've been hit //not enough energy to continue if gv_energylevel = 1{gv_state = 4 gv_energyLevel = 0} //continue else{ link[iLinkID] = 1 gv_energyLevel = gv_energyLevel - 1 Action(14,2, moveBackward,1,100) BasicMove(moveStop,5) //clear sound link[iRxChannel] = 0 gv_state = 1 } }retry on fail } sub loseGame{ try{ link[iLinkID] = 1 //ignore controller Action(sndCrash,2,moveBackward,1,100) FancyMove(moveShake, 400) wait 400 BasicMove(moveStop,5) clear sound clear display LED[iYellowBlink] = 0 LED[iYellowWarn] = 0 link[iRxChannel] = 0 //respond to controller stop Tasks }retry on fail } sub timeShort{ local flashInt = gc_GameTimeLimit - nBioTick LED[iYellowBlink] = 1 forever{ LED[iYellowBlinkInterval] = flashInt repeat 10{sound 1 wait flashInt} flashInt = gc_GameTimeLimit - nBioTick } } /////////////////////////////////////////////////// /*game states 0 ready to start 1 running 2 hit object 3 shocked 4 timeUp/out of energy 5 mission complete */ //////////////////////////////////////////////////// main { randomize link[iRxChannel] = 0 ///////start watchers///////////// start hit start lightEvent start timeUpWatch start nearTimeWatch ///////////////////////////////// } ///////////user defined tasks////////////////////////////////// task initGame{ LED[iYellowBlink] = 0 LED[iYellowWarn] = 0 sound 3 display 5 wait 100 clear sound clear display start BioTick gv_shockTime = random 150 start randomShockCounter //starts the random shock mechanism gv_state = 1 } task BioTick { clear nBioTick forever{ nBioTick += 1 wait 10 whatNext } } task randomShockCounter{ clear nStateWatcher forever{ nStateWatcher += 1 wait 10 if nStateWatcher = gv_shockTime{gv_state = 3 stop randomShockCounter} } } ////////////define watchers////////////////////////////////// watcher hit monitor BumpEvent{ //define watcher for bumpEvent select gv_state{ when 0{ start initGame} when 1{gv_state = 2} } } watcher lightEvent monitor lighthigh{ if gv_state <> 0{gv_state = 5} } watcher timeUpWatch monitor timeUp{ if gv_state = 1{gv_state = 4} } restart on event watcher nearTimeWatch monitor nearTime{ if gv_state <> 0{timeShort} } restart on event ///////////end of program follows//////////////////////////// }