A Simple Timer
This here is a simplified version of the timer program. I put it here just to clarify that there are other ways to do this. The previous version was used to show LOOP construct, but this version is an optimized version of it. Notice that duplicate codes are collapsed into one, thus simplifying the whole structure.
- 'TIMER PROGRAM BY HARRY HARDJONO
- SPSET 1,156,0,0,0,0
- SPOFS 1,-50,-50
- SPANIM 1,4,15
- SPSCALE 1,200
- @INIT
- CLS
- SPOFS 1,0,96,0
- SPREAD(1),X,Y
- ?"HOW MANY SECONDS?"
- INPUT T
- IF 0>=T GOTO @END
- CLS
- ?"A STARTS TIMER"
- ?"B SETS NEW TIME"
- ?"X EXIT"
- ?"Y PAUSE"
- @LOOP
- VSYNC 1:B=BTRIG()
- IF (SPCHK(1) AND 1) THEN SPOFS 1,X,Y,0
- IF (B AND 16) THEN SPOFS 1,224,96,FLOOR((224-X)*T/224)*60:GOTO @TICK
- IF (B AND 32) GOTO @INIT
- IF (B AND 64) GOTO @END
- GOTO @LOOP
- @TICK
- IF (BUTTON(0) AND 128) GOTO @LOOP
- LOCATE 0,8:SPREAD(1),X,Y:?"TIME LEFT: ";FLOOR((224-X)*T/224);" "
- IF (SPCHK(1) AND 1) THEN BEEP 28:WAIT 60:GOTO @TICK
- ?"TIME'S UP!":SPOFS 1,0,96,0:X=0:BEEP 50:WAIT 120
- GOTO @LOOP
- @END
- ?"GOODBYE!"
- SPCLR 1:WAIT 300
No comments:
Post a Comment