|
Creating a user pointer
Requirements: .Chris Module Studio
If you want to build a pointer that a user can move then you need to introduce
a variable. First set the program up:
10 Let R = 10
20 Let D = 10
30 SCREEN 7
40 CLS
50 DRAW "BM" + R + "," + D + "U5D10U5R5L10"
This program would draw a cross centered on the point 10, 10. This is because
R and D are replaced by the values we gave them at the start of the program.
Now to add the users interactivity.
60 IF INKEY$ = "R" THEN GOTO 110
70 IF INKEY$ = "L" THEN GOTO 130
80 IF INKEY$ = "U" THEN GOTO 150
90 IF INKEY$ = "D" THEN GOTO 170
100 IF INKEY$ = "E" THEN GOTO 200
110 GOTO 60
120 LET R = R + 10
130 GOTO 40
140 LET R = R + 10
150 GOTO 40
160 LET D = D - 10
170 GOTO 40
180 LET D = D + 10
190 GOTO 40
200 END
I also added an exit to the loop too.
IF INKEY$ = "E" THEN GOTO 200
This allows the user to press E to exit. Now the program is ready. You can
make the pointer move left and right by using L and R, and up and down by using
U and D. Heres the full program:
10 Let R = 10
20 Let D = 10
30 SCREEN 7
40 CLS
50 DRAW "BM" + R + "," + D + "U5D10U5R5L10"
60 IF INKEY$ = "R" THEN GOTO 110
70 IF INKEY$ = "L" THEN GOTO 130
80 IF INKEY$ = "U" THEN GOTO 150
90 IF INKEY$ = "D" THEN GOTO 170
100 IF INKEY$ = "E" THEN GOTO 200
110 GOTO 60
120 LET R = R + 10
130 GOTO 40
140 LET R = R + 10
150 GOTO 40
160 LET D = D - 10
170 GOTO 40
180 LET D = D + 10
190 GOTO 40
200 END |