05-29-2023, 01:37 AM
To me, it's smarter to change color when change direction so Mod 2:
Not much different from the way I was using the first Mod.
Code: (Select All)
_Title "Mod 2 Ron77 Color Walker, arrows to move, change color when change direction" 'b+ 2023-05-28
' kinda cute! nice one Ron77
' Notice I put the instructions to the app in the _Title
' We will be using the default Screen 0, Shout out to Pete! :)
' This uses 16 colors 0 to 15
' We will be using _KeyHit for user input because it's real easy to get
' the arrow key numbers in IDE. Just put cursor where you need the number
' Select Tools > Insert Quick Keycode (or shortcut Ctrl+K)
' then press the direction arrow key, BAM! there's your number!
' Notice at Locate under update screen comment, its y, x.
' That's because Locate does Row, Column not x, y like all graphics commands
' eg Pset (x,y), Color
' Row Column are how Print Locations work with Row (Vertical) listed first
' followed by the Column (Horizontal) position.
' That use to mix the hell up in me back with GW BASIC years ago.
' Mod 2 Say let's change color only when we change direction.
DefLng A-Z ' all variables are long unless otherwise spec'd
x = 20
y = 20
c = 12
OldD = 1 ' OldD is 1 = North, 2 = East, 3 = South, 4 = West
' pretend the last direction was North to get things started
Color c ' Ron77 started the color at 0 and ha! Aurel is complaining nothing
' is happening, nice joke on Aurel Ron :)
'
Do
'update screen
Locate y, x: Print "@";
kh = _KeyHit ' see if user hit a key and if so which?
If kh = 18432 Then ' arrow up
If y - 1 > 0 Then
y = y - 1: d = 1: GoSub ChangeColor
Else
Beep
End If
End If
If kh = 19200 Then ' arrow left
If x - 1 > 0 Then
x = x - 1: d = 4: GoSub ChangeColor
Else
Beep
End If
End If
If kh = 19712 Then ' arrow right
If x + 1 <= _Width Then
x = x + 1: d = 2: GoSub ChangeColor
Else
Beep
End If
End If
If kh = 20480 Then ' arrow down
If y + 1 <= _Height Then
y = y + 1: d = 3: GoSub ChangeColor
Else
Beep
End If
End If
Loop Until kh = 27 ' standard escape clause that johnno always insisted on
End
ChangeColor:
' Mod 2 Say let's change color only when we change direction. changeColor:
If d <> OldD Then
c = c + 1
If c > 15 Then c = 1 ' if c exceeds 15 the last color at top range set it to 1, not 0
Color c
Locate y, x: Print "@"; ' update our @ guy immediately with color change so Aurel knows
OldD = d
End If
Return
Not much different from the way I was using the first Mod.
b = b + ...