global [line light lightprev ballprev eyestate ambient-light] ; "line" is threshold for white line ; "light" threshold for light ; "lightprev" records current state of light ; "ballprev" records current state of ball ; "eyestate" records state of eyes (aggressive, etc.) to DRAGON reset eyes on signal on forever [eye-control] waituntil [start-sensor] go-straight wait 20 loop [attack] end to EYE-CONTROL if eyestate = 1 [eyes thisway onfor 20 wait 5];aggressive if eyestate = 2 [eyes on wait 1 rd]; injured if eyestate = 3 [eyes on thatway]; defeated if eyestate = 4 [eyes on wait (random 15) rd]; victory end to ATTACK ; doesn't need loops or concurrency b/c ;already within loop in "dragon". ;dragon's ongoing behaviour pattern until ;defeated. print-state ifelse (or (is-defeated?) (is-victorious?)) [ifelse is-defeated? [seteyestate 3 act-defeated] [seteyestate 4 victory-dance] ] [if (or (is-hit-by-light) (is-hit-by-ball)) ;continually check dragon's vital stats [update-state seteyestate 2]] end to is-hit-by-ball ;checks if dragon has been hit by ball at ;its target spot output (touch-sensor) end to is-hit-by-light ;checks if dragon has been zapped by ;flashlight beam output light-sensor < (ambient-light / 2) end to update-state ;call when dragon's been hit to record injury if (is-hit-by-light) [setlightprev 1] if (is-hit-by-ball) [setballprev 1] end to print-state top type "e ;eyestate type eyestate type "l ; light type lightprev type "b ; ball print ballprev end to is-defeated? ;player has hit dragon w/ both ball and light output (and (lightprev = 1) (ballprev = 1)) end to is-victorious? ; this means dragon has crossed line output (reflect-sensor < line) ; threshold changeable end to act-defeated seteyestate 3 stop-motion signal off ; cricket on tower will raise tower end to victory-dance seteyestate 4 shake-booty-dance circle-dance end to shake-booty-dance repeat 3 [ left-wheel thisway onfor 20 ;? random number right-wheel thatway onfor 20 left-wheel thatway onfor 20 right-wheel thisway onfor 20] end to circle-dance left-wheel thisway onfor 40 right-wheel thisway onfor 40 end to reflect-sensor output sensor 0 end to light-sensor ; lower than 8, set light variable to 1 output sensor 1 end to touch-sensor output switch 7 end to start-sensor output switch 8 end to turn-left left-wheel off right-wheel on thisway end to turn-right right-wheel off left-wheel on thisway end to go-straight left-wheel on thisway right-wheel on thisway end to stop-motion left-wheel off right-wheel off end to right-wheel a, end to left-wheel b, end to eyes c, end to signal d, end to light+10 setlight (light + 10) printlight end to light-10 setlight (light - 10) printlight end to printlight type [light = ] print light end to RESET ; the dragon won't move back to its original ; positon, but it will remember to clear ;"setlightprev" and "setballprev" both to 0 so that ;a new player can play setlightprev 0 setballprev 0 seteyestate 1 setline 15 ; we can change this later setambient-light light-sensor bottom type "ambient= print ambient-light signal on end ;tower will be on cricket