Author Topic: Ken's Widget  (Read 3760 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Ken's Widget
« on: August 14, 2020, 02:34:21 am »
Is it a waste of time? Sure! What does it do? Probably nothing. What is it for? To prove one thing: A programming hobby can be fun even though you aren't making hardly anything!
Get yours now while the price is cheap (FREE!)
Maybe it will remind you of the simpler days, of the GREAT BIG BUTTON website that did absolutely nothing. But hey, at least this widget moves "stuff" around. Can the code be used to make anything in the future? That's up to you my friend. Maybe a game widget? An organizing widget? A PAC-MAN Widget! Do I need royalties? I wouldn't go that far. ;)

Use the arrow keys and mouse wheel in order to see intersections scatter and move. Hey, at least I tried another maze, that went South pretty fast. :)

Edit: I switched up and down arrow keys.

Code: QB64: [Select]
  1.  
  2. _TITLE "Ken's Widget - Use Arrow Keys and Mouse Wheel"
  3. SCREEN _NEWIMAGE(600, 600, 32)
  4. _LIMIT 100
  5. PAINT (2, 2), _RGB32(255, 255, 255)
  6. xx = 10
  7. yy = 10
  8.     mouseWheel = 0
  9.         mouseX = _MOUSEX
  10.         mouseY = _MOUSEY
  11.         mouseLeftButton = _MOUSEBUTTON(1)
  12.         mouseRightButton = _MOUSEBUTTON(2)
  13.         mouseMiddleButton = _MOUSEBUTTON(3)
  14.         mouseWheel = mouseWheel + _MOUSEWHEEL
  15.     LOOP
  16.     a$ = INKEY$
  17.     IF a$ = CHR$(0) + CHR$(72) THEN yy = yy - 5
  18.     IF a$ = CHR$(0) + CHR$(80) THEN yy = yy + 5
  19.  
  20.     IF a$ = CHR$(0) + CHR$(75) THEN xx = xx - 5
  21.     IF a$ = CHR$(0) + CHR$(77) THEN xx = xx + 5
  22.  
  23.     IF mouseWheel = -1 THEN xx = xx + 1: yy = yy + 1
  24.     IF mouseWheel = 1 THEN xx = xx - 1: yy = yy - 1
  25.     IF xx < 1 THEN xx = 1
  26.     IF yy < 1 THEN yy = 1
  27.     IF xx > 200 THEN xx = 200
  28.     IF yy > 200 THEN yy = 200
  29.     FOR iy = 50 + yy TO 550 + yy STEP 30 + yy
  30.         FOR ix = 50 + xx TO 550 + xx STEP 30 + xx
  31.             LINE (ix, iy)-(ix, iy + 10), _RGB32(0, 0, 0)
  32.             LINE (ix, iy + 10)-(ix - 10, iy + 10), _RGB32(0, 0, 0)
  33.  
  34.             LINE (ix + 10, iy)-(ix + 10, iy + 10), _RGB32(0, 0, 0)
  35.             LINE (ix + 10, iy + 10)-(ix + 20, iy + 10), _RGB32(0, 0, 0)
  36.  
  37.             LINE (ix, iy + 30)-(ix, iy + 20), _RGB32(0, 0, 0)
  38.             LINE (ix, iy + 20)-(ix - 10, iy + 20), _RGB32(0, 0, 0)
  39.  
  40.             LINE (ix + 10, iy + 30)-(ix + 10, iy + 20), _RGB32(0, 0, 0)
  41.             LINE (ix + 10, iy + 20)-(ix + 20, iy + 20), _RGB32(0, 0, 0)
  42.         NEXT ix
  43.     NEXT iy
  44.     _DISPLAY
  45.     CLS
  46.     PAINT (2, 2), _RGB32(255, 255, 255)
  47.  
« Last Edit: August 14, 2020, 02:38:52 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's Widget
« Reply #1 on: August 14, 2020, 12:02:02 pm »
OK nice grid practice.

Tip: Use this
Code: QB64: [Select]
  1. COLOR , &HFFFFFFFF
  2.  

before main DO loop and then you wont need the PAINT near end of loop.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's Widget
« Reply #2 on: August 14, 2020, 12:55:58 pm »
Awesome! I never knew what those color hex memories did. I'll update it below.
Yeah it was just a grid practice like you said. I thought about trying to make a maze using a grid first and randomly placing walls but it was harder than it sounds. I might work on it more another time.

Code: QB64: [Select]
  1. _TITLE "Ken's Widget - Use Arrow Keys and Mouse Wheel"
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3. _LIMIT 100
  4. xx = 10
  5. yy = 10
  6. COLOR , &HFFFFFFFF
  7.     mouseWheel = 0
  8.         mouseX = _MOUSEX
  9.         mouseY = _MOUSEY
  10.         mouseLeftButton = _MOUSEBUTTON(1)
  11.         mouseRightButton = _MOUSEBUTTON(2)
  12.         mouseMiddleButton = _MOUSEBUTTON(3)
  13.         mouseWheel = mouseWheel + _MOUSEWHEEL
  14.     LOOP
  15.     a$ = INKEY$
  16.     IF a$ = CHR$(0) + CHR$(72) THEN yy = yy - 5
  17.     IF a$ = CHR$(0) + CHR$(80) THEN yy = yy + 5
  18.  
  19.     IF a$ = CHR$(0) + CHR$(75) THEN xx = xx - 5
  20.     IF a$ = CHR$(0) + CHR$(77) THEN xx = xx + 5
  21.  
  22.     IF mouseWheel = -1 THEN xx = xx + 1: yy = yy + 1
  23.     IF mouseWheel = 1 THEN xx = xx - 1: yy = yy - 1
  24.     IF xx < 1 THEN xx = 1
  25.     IF yy < 1 THEN yy = 1
  26.     IF xx > 200 THEN xx = 200
  27.     IF yy > 200 THEN yy = 200
  28.     FOR iy = 50 + yy TO 550 + yy STEP 30 + yy
  29.         FOR ix = 50 + xx TO 550 + xx STEP 30 + xx
  30.             LINE (ix, iy)-(ix, iy + 10), _RGB32(0, 0, 0)
  31.             LINE (ix, iy + 10)-(ix - 10, iy + 10), _RGB32(0, 0, 0)
  32.  
  33.             LINE (ix + 10, iy)-(ix + 10, iy + 10), _RGB32(0, 0, 0)
  34.             LINE (ix + 10, iy + 10)-(ix + 20, iy + 10), _RGB32(0, 0, 0)
  35.  
  36.             LINE (ix, iy + 30)-(ix, iy + 20), _RGB32(0, 0, 0)
  37.             LINE (ix, iy + 20)-(ix - 10, iy + 20), _RGB32(0, 0, 0)
  38.  
  39.             LINE (ix + 10, iy + 30)-(ix + 10, iy + 20), _RGB32(0, 0, 0)
  40.             LINE (ix + 10, iy + 20)-(ix + 20, iy + 20), _RGB32(0, 0, 0)
  41.         NEXT ix
  42.     NEXT iy
  43.     _DISPLAY
  44.     CLS
  45.  

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Ken's Widget
« Reply #3 on: August 14, 2020, 01:00:05 pm »
Very interesting, Ken!
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's Widget
« Reply #4 on: August 14, 2020, 01:17:01 pm »
Oh I missed the arrow keys thing, yeah good practice, this stuff comes in handy later if it does not inspire something while fooling around.

Maybe try some plaid patterns? Colorful overlapping grids with different thickness lines (BF's)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's Widget
« Reply #5 on: August 14, 2020, 09:02:47 pm »
Today I started on a game project using a grid. You move your guy around city blocks. I think I will have things you collect on the way. I have the blocks and a chr$(1) happy face you move around. I might change the happy face to something else since he's so tiny. I wish I could make him larger. Anyway, here is what I have so far:

Code: QB64: [Select]
  1. _TITLE "City Blocks - Use Arrow Keys"
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3. x = 5
  4. y = 5
  5. player$ = CHR$(1)
  6. COLOR , _RGB32(0, 0, 255)
  7.     _LIMIT 100
  8.     a$ = INKEY$
  9.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  10.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  11.     IF a$ = CHR$(0) + CHR$(75) THEN d = 3
  12.     IF a$ = CHR$(0) + CHR$(77) THEN d = 4
  13.     IF a$ = CHR$(27) THEN END
  14.  
  15.     FOR iy = 50 TO 550 STEP 60
  16.         FOR ix = 50 TO 550 STEP 60
  17.             FOR t = -7 TO 30
  18.                 FOR tt = -7 TO 30
  19.                     IF x = ix + tt AND y = iy + t THEN
  20.                         IF d = 3 THEN x = x + 2
  21.                         IF d = 4 THEN x = x - 2
  22.                         IF d = 1 THEN y = y + 2
  23.                         IF d = 2 THEN y = y - 2
  24.                         d = 0
  25.                         GOTO nex:
  26.                     END IF
  27.                 NEXT tt
  28.             NEXT t
  29.         NEXT ix
  30.     NEXT iy
  31.  
  32.     IF d = 1 THEN y = y - 1
  33.     IF d = 2 THEN y = y + 1
  34.     IF d = 3 THEN x = x - 1
  35.     IF d = 4 THEN x = x + 1
  36.     nex:
  37.  
  38.  
  39.     IF x < 1 THEN x = 600
  40.     IF y < 1 THEN y = 600
  41.     IF x > 600 THEN x = 1
  42.     IF y > 600 THEN y = 1
  43.     COLOR _RGB32(0, 255, 0)
  44.     _FONT 16
  45.     _PRINTSTRING (x, y), player$
  46.     FOR iy = 50 TO 550 STEP 60
  47.         FOR ix = 50 TO 550 STEP 60
  48.             LINE (ix, iy)-(ix + 30, iy + 30), _RGB32(255, 0, 0), BF
  49.         NEXT ix
  50.     NEXT iy
  51.     _DISPLAY
  52.     CLS
  53.