Joystick position: Difference between revisions
Content added Content deleted
No edit summary |
(Added solution for Action!) |
||
Line 20: | Line 20: | ||
For the purpose of this task, we assume that the joystick is calibrated and that the first joystick is being used. <br> |
For the purpose of this task, we assume that the joystick is calibrated and that the first joystick is being used. <br> |
||
The task implementer could at their option provide a solution that includes a joystick selection facility, enabling the user to choose which joystick is to be used for this task. |
The task implementer could at their option provide a solution that includes a joystick selection facility, enabling the user to choose which joystick is to be used for this task. |
||
=={{header|Action!}}== |
|||
<lang Action!>BYTE lastStick=[255] |
|||
BYTE lastTrig=[255] |
|||
PROC DrawCross(BYTE s) |
|||
BYTE size=[5] |
|||
CARD x |
|||
BYTE y |
|||
IF s>=9 AND s<=11 THEN |
|||
x=size |
|||
ELSEIF s>=5 AND s<=7 THEN |
|||
x=159-size |
|||
ELSE |
|||
x=79 |
|||
FI |
|||
IF s=6 OR s=10 OR s=14 THEN |
|||
y=size |
|||
ELSEIF s=5 OR s=9 OR s=13 THEN |
|||
y=79-size |
|||
ELSE |
|||
y=39 |
|||
FI |
|||
Plot(x-size,y) |
|||
DrawTo(x+size,y) |
|||
Plot(x,y-size) |
|||
DrawTo(x,y+size) |
|||
RETURN |
|||
PROC UpdateStatus(BYTE currStick,currTrig) |
|||
IF currStick#lastStick THEN |
|||
Color=0 DrawCross(lastStick) |
|||
Color=1 DrawCross(currStick) |
|||
lastStick=currStick |
|||
FI |
|||
IF currTrig#lastTrig THEN |
|||
Print("Button pressed: ") |
|||
IF currTrig THEN |
|||
PrintE("no ") |
|||
ELSE |
|||
PrintE("yes") |
|||
FI |
|||
Put(28) ;move cursor up |
|||
lastTrig=currTrig |
|||
FI |
|||
RETURN |
|||
PROC Main() |
|||
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6, |
|||
CRSINH=$02F0 ;Controls visibility of cursor |
|||
BYTE currStick,currTrig |
|||
Graphics(7) |
|||
Color=1 |
|||
COLOR1=$0C |
|||
COLOR2=$02 |
|||
CRSINH=1 ;hide cursor |
|||
DO |
|||
currStick=Stick(0) |
|||
currTrig=STrig(0) |
|||
UpdateStatus(currStick,currTrig) |
|||
UNTIL CH#$FF |
|||
OD |
|||
CH=$FF |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Joystick_position.png Screenshot from Atari 8-bit computer] |
|||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |