Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
b+ Beginners Corner
#10
To me, it's smarter to change color when change direction so Mod 2:
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 + ...
Reply


Messages In This Thread
b+ Beginners Corner - by bplus - 05-20-2023, 06:34 PM
RE: b+ Beginners Corner - by vince - 05-20-2023, 06:47 PM
RE: b+ Beginners Corner - by bplus - 05-20-2023, 07:11 PM
RE: b+ Beginners Corner - by PhilOfPerth - 05-26-2023, 12:12 AM
RE: b+ Beginners Corner - by bplus - 05-26-2023, 04:11 PM
RE: b+ Beginners Corner - by PhilOfPerth - 05-26-2023, 11:18 PM
RE: b+ Beginners Corner - by mnrvovrfc - 05-27-2023, 12:15 AM
RE: b+ Beginners Corner - by PhilOfPerth - 05-27-2023, 02:27 AM
RE: b+ Beginners Corner - by bplus - 05-29-2023, 12:07 AM
RE: b+ Beginners Corner - by bplus - 05-29-2023, 01:37 AM
RE: b+ Beginners Corner - by mnrvovrfc - 05-29-2023, 02:29 AM
RE: b+ Beginners Corner - by bplus - 05-30-2023, 04:17 PM
RE: b+ Beginners Corner - by bplus - 06-15-2023, 03:06 PM
RE: b+ Beginners Corner - by GareBear - 06-15-2023, 07:50 PM
RE: b+ Beginners Corner - by bplus - 06-15-2023, 10:42 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 02:46 PM
RE: b+ Beginners Corner - by CharlieJV - 06-23-2023, 03:26 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 08:28 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-23-2023, 09:45 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 09:56 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-24-2023, 02:47 AM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 10:02 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 02:35 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 02:52 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 07:48 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-24-2023, 08:02 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 08:40 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-24-2023, 10:07 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 09:08 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 09:12 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-24-2023, 11:44 PM
RE: b+ Beginners Corner - by bplus - 06-25-2023, 02:27 PM
RE: b+ Beginners Corner - by OldMoses - 06-25-2023, 05:49 PM
RE: b+ Beginners Corner - by bplus - 06-25-2023, 06:40 PM
RE: b+ Beginners Corner - by OldMoses - 06-25-2023, 08:03 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 01:14 AM
RE: b+ Beginners Corner - by mnrvovrfc - 06-26-2023, 02:26 AM
RE: b+ Beginners Corner - by Ultraman - 06-26-2023, 11:29 AM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 12:17 PM
RE: b+ Beginners Corner - by Ultraman - 06-26-2023, 12:21 PM
RE: b+ Beginners Corner - by Dimster - 06-26-2023, 02:38 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 03:32 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 04:48 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 01:29 AM
RE: b+ Beginners Corner - by OldMoses - 06-27-2023, 11:49 AM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 12:40 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-27-2023, 02:12 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 03:22 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-27-2023, 05:21 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 05:48 PM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 03:20 AM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 02:54 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-28-2023, 07:07 PM
RE: b+ Beginners Corner - by Dimster - 06-28-2023, 09:50 PM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 10:27 PM
RE: b+ Beginners Corner - by bplus - 06-04-2024, 01:17 AM
RE: b+ Beginners Corner - by PhilOfPerth - 06-04-2024, 11:37 PM
RE: b+ Beginners Corner - by bplus - 06-05-2024, 12:42 AM
RE: b+ Beginners Corner - by gaslouk - 06-05-2024, 02:37 PM
RE: b+ Beginners Corner - by bplus - 06-30-2024, 07:38 PM
RE: b+ Beginners Corner - by bplus - 07-01-2024, 03:42 PM
RE: b+ Beginners Corner - by aurel - 07-01-2024, 06:16 PM
RE: b+ Beginners Corner - by bplus - 07-01-2024, 07:39 PM
RE: b+ Beginners Corner - by bplus - 07-07-2024, 06:42 PM



Users browsing this thread: 9 Guest(s)