Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
05-29-2023, 02:29 AM
(This post was last modified: 05-29-2023, 02:32 AM by mnrvovrfc.)
This is pretty cool. But I would remove that beep. Sorry but Wordpad made me hate sound to react to any keypress LOL. I didn't want to change the "Windows Media" settings to do something about it.
It's too bad how keyboards are designed these days. Otherwise I would change it so one hand could press [CTRL] (left) or [ALT] (right), and the other hand could use [SHIFT] (up) or [CTRL] (down) so it could behave like a real Ohio Art Etch-and-Sketch.
On my keyboard for the left hand, [CTRL] and [ALT] are too wide apart for my taste: [Fn] and [Win] keys in between. Would have to use [SHIFT] and [CTRL] for vertical motion for the left hand, and involve the application key for the right hand so it's a bit more comfortable.
On Linux probably could also reassign the "Super" [Win] key but I don't like feeling that I'm using a Macintosh. I highly respect those [Command] keys hugging the spacebar.
For a window manager on Linux using the "Super" key to help "design" application windows, it could be changed to [ALT] which ensures the [Win] key won't be involved that well in QB64 programs using _KEYDOWN().
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
05-30-2023, 04:17 PM
(This post was last modified: 05-30-2023, 04:37 PM by bplus.)
Cool Tip for doing Color Walker from Paul Dunn AKA ZXDunny: https://retrocoders.phatcode.net/index.php?topic=584.0
not exactly Beginner's stuff
In Paul Dunn's Horizontal coding style we get:
Code: (Select All) _Title "Mod 3 Ron77 Color Walker: a | d left or right, w | s for up or down, c for color change"
x = 10: y = 10: c = 1
1 K$ = InKey$: c = (c - (K$ = "c")) Mod 16: Color c: x = x + (K$ = "a") - (K$ = "d"): y = y + (K$ = "w") - (K$ = "s"): Locate y, x: Print "@";: GoTo 1
Breaking it down:
Code: (Select All) '_Title "Mod 3 Ron77 Color Walker: a|d left or right, w|s for up or down, c for color change"
'x = 10: y = 10: c = 1
'1 K$ = InKey$: c = (c - (K$ = "c")) Mod 16: Color c: x = x + (K$ = "a") - (K$ = "d"): y = y + (K$ = "w") - (K$ = "s"): Locate y, x: Print "@";: GoTo 1
' b+ 2023-05-30 Breaking the above down:
' the Title contains the instructions for keypresses
_Title "Mod 3 Ron77 Color Walker: a | d left or right, w | s for up or down, c for color change"
x = 10: y = 10: c = 1 'make assignments inside screen for x and y position of future @ printing
1 K$ = InKey$ ' this records keypress into K$
c = (c - (K$ = "c")) Mod 16
' first (K$ = c) evaluates to -1 or 0 depending if c key was pressed
' (c - (K$ = "c")) evaluates to c - 0 or c - -1 equivalent to adding 0 0r 1 to c
' Mod 16 keeps c from exceeding 15 by resetting back to 0 when it hits 16
' The Mod 16 trick is very handy in computer programming, used allot!
Color c ' colors 0 - 15, 0 = black (same as background color so might be invisible)
' having black is handy for fixing mistakes
' As with changing c, likewise x and y are changed
x = x + (K$ = "a") - (K$ = "d")
' if a or d is pressed x gets changed by -1 or +1
y = y + (K$ = "w") - (K$ = "s")
' if w or s is pressed y gets changed by -1 or +1
Locate y, x
' note: since there is no border checking Locate will get mad and bug out should you go beyond
' the screen coodinates. We are going for brevity of code here. Stay away from edges or Error!
Print "@"; ' update our @ characters position (if you can see it)
GoTo 1 ' this loops back to line labeled 1
b = b + ...
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
06-15-2023, 03:06 PM
(This post was last modified: 06-15-2023, 03:11 PM by bplus.)
Build a Scrolling Text Screen
Code: (Select All)
_Title "Building a Scrolling LED Screen" ' b+ 2021-05-08
Screen _NewImage(1200, 160, 32)
_Delay .25 'give screen time to load
_ScreenMove _Middle 'and center screen
'scroll some text
Text$ = "Try scrolling me for awhile until you got it, then press a key... "
lenText = Len(Text$)
startTextPos = 1
'put text in sign 15 chars wide in middle of screen print the message moving down 1 character evey frame
_Title "Building a Scrolling LED Screen: Step 1 get some code to scroll your message in middle of screen."
Do
k$ = InKey$
Cls
' two pieces of text? when get to end of text will have less than 15 chars to fill sign so get remainder from front
len1 = lenText - startTextPos
If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
' locate at middle of screen for 15 char long sign
_PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
startTextPos = startTextPos + 1
If startTextPos > lenText Then startTextPos = 1
_Display ' no blinking when clear screen so often
_Limit 5 ' slow down to see scroll
Loop Until Len(k$)
' OK now for the enLARGE M E N T using _PutImage
' our little sign is 16 pixels high and 8 * 15 chars pixels wide = 120
Dim sign As Long
sign = _NewImage(120, 16, 32) ' we will store the print image here
' _PUTIMAGE [STEP] [(dx1, dy1)-[STEP][(dx2, dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1, sy1)[-STEP][(sx2, sy2)]][_SMOOTH]
' use same pixel location to _printString as for _PutImage Source rectangle ie (sx1, sy1), -step( sign width and height)
' test screen capture with _putimage and then blowup with _putimage
'_PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
'Cls
'_PutImage , sign, 0 ' stretch to whole screen
'_Display
'now that that works do it on the move
' about here I resized the screen to 1200 x 160 to make the text scalable X's 10 ie 120 x 10 wide and 16 x 10 high
_Title "Building a Scrolling LED Screen: Step 2 Blow it up by using _PutImage twice once to capture, then to expand"
k$ = ""
Do
k$ = InKey$
Cls
' two pieces of text? when get to end of text will have less than 15 chars to fill sign so get remainder from front
len1 = lenText - startTextPos
If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
' locate at middle of screen for 15 char long sign
_PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
_PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
Cls
_PutImage , sign, 0 ' stretch to whole screen
_Display ' no blinking when clear screen so often
_Limit 5 ' slow down to see scroll
startTextPos = startTextPos + 1
If startTextPos > lenText Then startTextPos = 1
Loop Until Len(k$)
' now for a mask just draw a grid test grid draw here
'For x = 0 To _Width Step 10 ' verticals
' Line (x, 0)-(x + 3, _Height), &HFF000000, BF
'Next
'For y = 0 To _Height Step 10
' Line (0, y)-(_Width, y + 3), &HFF000000, BF
'Next
_Title "Building a Scrolling LED Screen: Step 3 Mask or Cover the thing with a grid or grate."
' here is the whole code with all setup variables
k$ = ""
Do
k$ = InKey$
Cls
' two pieces of text? when get to end of text will have less than 15 chars to fill sign so get remainder from front
len1 = lenText - startTextPos
If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
' locate at middle of screen for 15 char long sign
_PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
_PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
Cls
_PutImage , sign, 0 ' stretch to whole screen
' now for a mask just draw a grid best to draw this and copy and layover screen as another layer
' here QB64 is fast evough to redarw each time
For x = 0 To _Width Step 10 ' verticals
Line (x, 0)-(x + 3, _Height), &HFF000000, BF
Next
For y = 0 To _Height Step 10
Line (0, y)-(_Width, y + 3), &HFF000000, BF
Next
_Display ' no blinking when clear screen so often
_Limit 5 ' slow down to see scroll
startTextPos = startTextPos + 1
If startTextPos > lenText Then startTextPos = 1
Loop Until Len(k$)
Step one is just getting text scrolling in center of screen:
Step 2 is enlarging text to fill screen:
Step 3 is adding a grid face cover to make the letters appear to be lights:
b = b + ...
Posts: 98
Threads: 1
Joined: Jun 2023
Reputation:
3
Step 2 and 3 I can read it with out glasses. I like it. Thanks bplus for sharing.
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
(06-15-2023, 07:50 PM)GareBear Wrote: Step 2 and 3 I can read it with out glasses. I like it. Thanks bplus for sharing.
You will like working with fonts I bet!
b = b + ...
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
06-23-2023, 02:46 PM
(This post was last modified: 06-23-2023, 02:57 PM by bplus.)
Once again Charlie's post inspires b+ to dig into his files and pull out a better version in his opinion of course
Compare this to Charlie's Clay Pigeon
https://qb64phoenix.com/forum/showthread...3#pid17053
Code: (Select All) W = 800: H = 600 ' b+ updated 2023-06-23
Screen _NewImage(800, 600, 32)
a:
Cls
a = Rnd * W: b = 0: c = Rnd * 6 - 3: d = Rnd * 3 + 3: u = 0: v = 0: x = 400: y = H
Do
_Title "Click mouse to intersect incoming MC hits:" + Str$(t) + ", misses:" + Str$(m)
_PrintString (400, 594), "^"
While _MouseInput: Wend
If _MouseButton(1) Then e = _MouseX - 400: f = _MouseY - H: z = (e ^ 2 + f ^ 2) ^ .5: u = 5 * e / z: v = 5 * f / z
x = x + u: y = y + v: a = a + c: b = b + d
If x < 0 Or y < 0 Or a < 0 Or b < 0 Or x > W Or a > W Or b > H Then
If b > H Or x < 0 Or y < 0 Or x > W Then m = m + 1
GoTo a:
End If
If ((x - a) ^ 2 + (y - b) ^ 2) ^ .5 < 30 Then
For r = 1 To 20 Step 4
Circle ((x + a) / 2, (y + b) / 2), r
_Limit 60
Next
t = t + 1: GoTo a:
Else
PSet (x, y): PSet (a, b)
End If
_Limit 20
Loop
Looks like I should pull a Terry Richie and cleanup and comment code for teaching purposes, stay tuned...
b = b + ...
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
(06-23-2023, 02:46 PM)bplus Wrote: Once again Charlie's post inspires b+ to dig into his files and pull out a better version in his opinion of course
Compare this to Charlie's Clay Pigeon
https://qb64phoenix.com/forum/showthread...3#pid17053
Code: (Select All) ...snip...
Looks like I should pull a Terry Richie and cleanup and comment code for teaching purposes, stay tuned...
That's very cool. Let it be known, though, that you are standing tall on electricwalrus' work.
At most, I may have added a hair to that height by making it a hair easier to get that FB program ported to QB64pe with that intermediary BAM code. At most. For all I know, it might have been quicker/easier going straight from FB to QB64pe ...
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
06-23-2023, 08:28 PM
(This post was last modified: 06-24-2023, 02:26 PM by bplus.)
OK I have "Terryfied" enRitchied the code.
Update: I suppose I should refrain from word play with newbies but I wanted to honor Terry Ritchie's work and very notable commenting of code in a humorous way. Terry has been building a great beginner resource here:
https://www.qb64tutorial.com/games
Code: (Select All) Option _Explicit ' Get into this habit and save yourself grief from Typos
_Title "Missile Command Terryfied" ' another b+ mod 2023-06-23
' I probably picked up this game at the JB forum some years ago.
' Get Constants, Shared Variables and Arrays() declared. These Will Start with Capital Letters.
' Get Main module variables and arrays declared with starting lower case letters for local.
' This is what Option _Explicit helps, by forcing us to at least declare these before use.
' While declaring, telling QB64 the Type we want to use, we can also give brief description.
Const ScreenWidth = 800, ScreenHeight = 600 ' for our custom screen dimensions
Dim As Integer bombX, bombY ' incoming bomb screen position to shoot down
Dim As Single bombDX, bombDY ' DX and DY mean change in X position and Y position
Dim As Integer missileX, missileY ' missile position
Dim As Single missileDX, missileDY ' change X and Y of Missile position
Dim As Integer hits, misses ' score hits and misses
Dim As Integer mouseDistanceX, mouseDistanceY ' for calculations of missile DX, DY direction
Dim As Single distance ' ditto
Dim As Integer radius ' drawing hits with target like circles
Dim As Integer boolean ' to shorten the code line with a bunch of OR tests
Screen _NewImage(ScreenWidth, ScreenHeight, 32) ' sets up a graphics screen with custom dimensions
' the 32 is for _RGB32(red, green, blue, alpha) coloring.
'
_ScreenMove 250, 60 ' this centers screen in my laptop, you may need different numbers
InitializeForRound: ' reset game and start a round with a bomb falling
Cls
bombX = Rnd * ScreenWidth ' starts bomb somewhere across the screen
bombY = 0 ' starts bomb at top of screen
bombDX = Rnd * 6 - 3 ' pick rnd dx = change in x between -3 and 3
bombDY = Rnd * 3 + 3 ' pick rnd dy = change in y between 3 and 6, > 0 for falling
missileX = ScreenWidth / 2 ' missile base at middle across screen
missileY = ScreenHeight - 4 ' missile launch point at missile base is nearly at bottom of screen
missileDX = 0 ' missile is not moving awaiting mouse click for direction
missileDY = 0 ' ditto
distance = 0 ' distance of mouse click to missile base
Do
'what's the score?
_Title "Click mouse to intersect incoming Hits:" + Str$(hits) + ", misses:" + Str$(misses)
_PrintString (400, 594), "^" ' draw missle base = launch point
While _MouseInput: Wend ' poll mouse to get update
If _MouseButton(1) Then ' the mouse was clicked calc the angle from missile base
mouseDistanceX = _MouseX - missileX
mouseDistanceY = _MouseY - missileY
distance = (mouseDistanceX ^ 2 + mouseDistanceY ^ 2) ^ .5
missileDX = 5 * mouseDistanceX / distance
missileDY = 5 * mouseDistanceY / distance
End If
missileX = missileX + missileDX ' update missile position
missileY = missileY + missileDY ' ditto
bombX = bombX + bombDX ' update bomb position
bombY = bombY + bombDY ' ditto
' I am about to use a boolean variable to shorten a very long IF code line
' boolean is either 0 or -1 when next 2 statements are execued
' -1/0 or True/False is everything still in screen?
boolean = missileX < 0 Or missileY < 0 Or bombX < 0 Or bombY < 0
boolean = boolean Or missileX > ScreenWidth Or bombX > ScreenWidth Or bombY > ScreenHeight
If boolean Then ' done with this boolean
' reuse boolean to shorten another long code line checking if bomb and missile in screen
boolean = bombY > ScreenHeight Or missileX < 0 Or missileY < 0 Or missileX > ScreenWidth
If boolean Then misses = misses + 1
GoTo InitializeForRound
End If
' if the distance between missle and bomb < 20 pixels then the missile got the bomb, a hit
If ((missileX - bombX) ^ 2 + (missileY - bombY) ^ 2) ^ .5 < 20 Then ' show a strike as target
For radius = 1 To 20 Step 4 ' draw concetric circles to show strike
Circle ((missileX + bombX) / 2, (missileY + bombY) / 2), radius
_Limit 60
Next
hits = hits + 1 ' add hit to hits score
GoTo InitializeForRound
Else
PSet (missileX, missileY), &HFFFFFF00 ' draw your missle yellow
PSet (bombX, bombY), &HFF0000FF ' draw bomb blue
End If
_Limit 20
Loop
BTW you can click the mouse more than once, in fact you can turn the mouse and missile into a heat seeker and curve around back if you over shoot, pretty cool!
Look at the nice clean edges I had in the IDE, can't repeat in any code tag??? wait now old code tag looks good and it pastes correctly aligned back in IDE yea!
b = b + ...
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
Yikes, that sounds like "terrified" LOL
How about "enRitched" instead
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
06-23-2023, 09:56 PM
(This post was last modified: 06-24-2023, 02:28 PM by bplus.)
Sure don't want to use your name in vain, "enRitchied" OK? (edit with a t)*
BTW never, never, never use single letter constants if you ever hope to modify your code later and change names to make it more readable.
*Update: the humor would work better if I learned to spell Terry Ritchie's name correctly, oops sorry again Terry.
b = b + ...
|