QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: codevsb12 on February 19, 2020, 06:58:43 pm

Title: how to - x axis?
Post by: codevsb12 on February 19, 2020, 06:58:43 pm
as you can see, i'm making questions almost daily so i can make my good sweet first qbasic game! and since i noticed qb64 has a lot of interesting features, i want to know if theres a feature to invert my sprite horizontally (in the x axis).

i know it would be a real pain to remake the data sprite in reverse and then program it to switch sprites..
Title: Re: how to - y axis?
Post by: SMcNeill on February 19, 2020, 07:05:53 pm
Just swap the _PUTIMAGE coordinates as needed.

Instead of:

_PUTIMAGE (dx,dy), source, destination, (sx, sy)-(sx2, sy2)

use:

_PUTIMAGE (dx,dy), source, destination, (sx, sy2)-(sx2, sy)
Title: Re: how to - y axis?
Post by: codevsb12 on February 19, 2020, 07:14:23 pm
oh, forgot to mention

to store my data, i use PUT instead of _PUTIMAGE.

is a nightmare to use _NEWIMAGE and _PUTIMAGE, specially when i want to move sprites.
Title: Re: how to - y axis?
Post by: FellippeHeitor on February 19, 2020, 07:18:18 pm
Quote
i'm making questions almost daily so i can make my good sweet first qbasic game

Quote
i noticed qb64 has a lot of interesting features

Quote
to store my data, i use PUT instead of _PUTIMAGE

One thing is if you were coming with an old game and *needed* to keep old methods. Another thing is refusing to use new features, when they do exactly what you've asked for, as Steve's example does.

codevsb12: Welcome to QB64 forum. Hope your learning is productive.

And hope you're not fishing for us to finish your homework assignment for you.
Title: Re: how to - y axis?
Post by: OldMoses on February 19, 2020, 07:31:31 pm
I can attest to the fact that there is a learning curve to dealing with _PUTIMAGE, but in full disclosure, I was not a big graphics programmer prior to QB64. That is probably in no small part because it was much more difficult to deal with in the old days. Once you can get your head around how it works, it can do remarkable things with very succinct coding.
Title: Re: how to - y axis?
Post by: TerryRitchie on February 19, 2020, 07:39:02 pm
I agree. Codevsb12, the graphics commands introduced with QB64 are far superior to Qbasic's commands and much, much, much easier to use.

I'm afraid you're not going to get much help with the old method of using sprites with PUT since it was such a time consuming and mind-numbing task.

All you need for sprites in QB64 are _LOADIMAGE and _PUTIMAGE. _PUTIMAGE can can flip your sprite horizontally, vertically, or both simply by changing the X,Y coordinates around. _PUTIMAGE will even resize the image on the fly for you.

If you add _MAPTRIANGLE to the mix you can even rotate sprites easily.
Title: Re: how to - y axis?
Post by: OldMoses on February 19, 2020, 07:54:52 pm
If what you're trying to do is anything like you were doing the other day, it's a matter of loop manipulation. You can flip things in both x and y with the right loop structure.

I'd still prefer the new image commands though... once mastered they're a lot less... "fiddly"...

Code: QB64: [Select]
  1.  
  2.  
  3. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00
  4. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00
  5. DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00
  6. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00
  7. DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00
  8. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14
  9. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14
  10. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  11. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00
  12. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  13. DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00
  14. DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00
  15. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  16. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  17. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  18. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  19. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  20. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  21. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  22. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  23. DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00
  24. DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  25. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  26. DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  27. DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  28. DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00
  29. DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00
  30. DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00
  31. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00
  32. DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
  33.  
  34. FOR y = 1 TO 30
  35.     FOR x = 0 TO 20
  36.         READ sprite%: PSET (x, y), sprite%
  37.     NEXT x
  38. FOR y = 30 TO 1 STEP -1
  39.     FOR x = 0 TO 20
  40.         READ sprite%: PSET (x, y + 31), sprite%
  41.     NEXT x
  42. FOR y = 1 TO 30
  43.     FOR x = 20 TO 0 STEP -1
  44.         READ sprite%: PSET (x + 25, y), sprite%
  45.     NEXT x
  46.  
Title: Re: how to - y axis?
Post by: codevsb12 on February 19, 2020, 08:02:32 pm
great, but how do i use it so i can flip the sprite every time i hold "a"(left)?
Title: Re: how to - y axis?
Post by: OldMoses on February 19, 2020, 08:13:01 pm
great, but how do i use it so i can flip the sprite every time i hold "a"(left)?

Personally, I would define some variables for the loops, instead of literals, and use something like INKEY$, _KEYDOWN, or some variation of that to SWAP or otherwise determine what variables to assign to the loop, or.... go the long way and put two different loops in a SELECT CASE or IF..THEN block. There are lots of ways to go, but the easiest in the long run is to get comfortable with the new commands.
Title: Re: how to - x axis?
Post by: TerryRitchie on February 19, 2020, 08:56:41 pm
Here is a quick demo I just whipped up to show you how easy it can be to use QB64's new graphics features. You'll need to place the "smariotest.png" file in your QB64 folder. It contains the Mario images needed for animation.

Code: QB64: [Select]
  1. DIM MarioSheet AS LONG ' small sprite sheet containing a few 16x16 Mario images
  2. DIM Direction AS _BYTE ' Mario motion direction (-1, 1)
  3. DIM mx AS INTEGER '      Mario X coordinate
  4. DIM my AS INTEGER '      Mario Y coordinate
  5. DIM Size AS SINGLE '     size of Mario
  6. DIM Cell AS _BYTE '      current animation cell
  7. DIM Mario(3) AS LONG '   4 Mario animated sprite cells
  8.  
  9. MarioSheet = _LOADIMAGE("smariotest.png", 32) '                                   load the sprite sheet
  10. FOR count = 0 TO 3 '                                                              cycle through the 4 cells
  11.     Mario(count) = _NEWIMAGE(16, 16, 32) '                                        create cell image holder
  12.     _PUTIMAGE , MarioSheet, Mario(count), (count * 16, 0)-(count * 16 + 15, 15) ' grab image from sprite sheet
  13. NEXT count
  14. SCREEN _NEWIMAGE(640, 480, 32) '                                                  640x480 32bit window
  15. mx = 320 '                                                                        X,Y Mario starting point
  16. my = 240
  17. Cell = 0 '                                                                        animation cell
  18. Direction = 1 '                                                                   Mario going right
  19. DO '                                                                              master loop
  20.     _LIMIT 10 '                                                                   10 frames per second
  21.     CLS '                                                                         clear the screen
  22.     PRINT '                                                                       print instructions
  23.     PRINT " RIGHT/LEFT Arrow keys to move"
  24.     PRINT "    UP/DOWN Arrow keys to change size of Mario"
  25.     IF _KEYDOWN(19200) THEN '                                                     LEFT ARROW key?
  26.         Direction = -1 '                                                          yes, going LEFT
  27.         mx = mx - 1 '                                                             decrement Mario X location
  28.         Cell = Cell + 1 '                                                         move to next animation cell
  29.     END IF
  30.     IF _KEYDOWN(19712) THEN '                                                     RIGHT ARROW key?
  31.         Direction = 1 '                                                           yes, going RIGHT
  32.         mx = mx + 1 '                                                             increment Mario X location
  33.         Cell = Cell + 1 '                                                         move to next animation cell
  34.     END IF
  35.     IF _KEYDOWN(18432) THEN Size = Size + .1 '                                    UP ARROW? if so increase size
  36.     IF _KEYDOWN(20480) THEN Size = Size - .1 '                                    DOWN ARROW? if so decrease size
  37.     IF Size < 1 THEN Size = 1 '                                                   keep variables within limits
  38.     IF Cell > 3 THEN Cell = 0
  39.  
  40.     mx2 = mx + 16 * Size '                                                        calculate box to place image in
  41.     my2 = my + 16 * Size
  42.  
  43.     SELECT CASE Direction '                                                       which direction is Marion going?
  44.         CASE -1 '                                                                 LEFT
  45.             _PUTIMAGE (mx2, my)-(mx, my2), Mario(Cell) '                          draw image flipped horizontally
  46.         CASE 1 '                                                                  RIGHT
  47.             _PUTIMAGE (mx, my)-(mx2, my2), Mario(Cell) '                          no image flip needed
  48.     END SELECT
  49.     _DISPLAY '                                                                    update screen with changes
  50. LOOP UNTIL _KEYDOWN(27) '                                                         leave when ESC pressed
  51.  
Title: Re: how to - x axis?
Post by: OldMoses on February 19, 2020, 09:18:30 pm
TerryRitchie beat me to the punch, but anyway, here's your particular sprite loaded into a _NEWIMAGE handle (sprite&) and turning left and right using the action that Steve describes above.

Code: QB64: [Select]
  1. DEFINT A-Z
  2. main& = _NEWIMAGE(600, 400, 32)
  3. sprite& = _NEWIMAGE(21, 31, 12)
  4. _DEST sprite&
  5. FOR y = 0 TO 29
  6.     FOR x = 0 TO 20
  7.         READ sprt%: PSET (x, y), sprt%
  8.     NEXT x
  9. _DEST main&
  10. SCREEN main&
  11. xp = 64
  12. yp = 70
  13. sx = 0: sy = 0: sx2 = 20: sy2 = 30
  14.  
  15.     CLS
  16.     te$ = INKEY$
  17.     IF te$ = "d" THEN xp = xp + 2: sx = 0: sy = 0: sx2 = 20: sy2 = 30
  18.     IF te$ = "a" THEN xp = xp - 2: sx = 20: sy = 0: sx2 = 0: sy2 = 30
  19.     IF te$ = "w" THEN yp = yp - 2
  20.     IF te$ = "s" THEN yp = yp + 2
  21.     IF te$ = "q" THEN END
  22.  
  23.     _PUTIMAGE (xp, yp), sprite&, main&, (sx, sy)-(sx2, sy2)
  24.     _DISPLAY
  25.  
  26. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00
  27. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00
  28. DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00
  29. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00
  30. DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00
  31. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14
  32. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14
  33. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  34. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00
  35. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  36. DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00
  37. DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00
  38. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  39. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  40. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  41. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  42. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  43. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  44. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  45. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  46. DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00
  47. DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  48. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  49. DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  50. DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  51. DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00
  52. DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00
  53. DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00
  54. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00
  55. DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
  56.  
  57.  
  58.  
  59.  
Title: Re: how to - x axis?
Post by: TerryRitchie on February 19, 2020, 09:22:50 pm
Hey, what happened to the background within the code windows? I miss line numbers and clean look of it.
Title: Re: how to - x axis?
Post by: bplus on February 19, 2020, 09:43:05 pm
Hey, what happened to the background within the code windows? I miss line numbers and clean look of it.

That's the difference between code tag and code64 tag. Must be doing [code ] maually without # button.

Oh! It is gone. AND the "Select" option is gone from old code64 boxes too!

Oh and I just noticed the 20 sec delay switching between boards or threads is also gone, good riddance to that!
Title: Re: how to - x axis?
Post by: FellippeHeitor on February 19, 2020, 10:21:58 pm
Hey, what happened to the background within the code windows? I miss line numbers and clean look of it.

They're back.
Title: Re: how to - x axis?
Post by: bplus on February 19, 2020, 10:22:58 pm
Code: QB64: [Select]
  1. What happened? and is the delay going to be back too?
Title: Re: how to - x axis?
Post by: FellippeHeitor on February 19, 2020, 10:25:05 pm
I upgraded the forum software this morning and lost some of the customisation, specifically the QB64 codebox. Just restored it.

No correlation with the delays of yore.

Now if only I could remember how I'd added the [Select] link...
Title: Re: how to - x axis?
Post by: FellippeHeitor on February 19, 2020, 10:46:34 pm
Code: QB64: [Select]
  1. PRINT "Select is back"
Title: Re: how to - x axis?
Post by: bplus on February 19, 2020, 10:58:35 pm
Hi Fellippe,

I apologize for being so off topic (Terry started it) but did you do something about delays or has the twilight zone just drifted away for awhile?
Title: Re: how to - x axis?
Post by: FellippeHeitor on February 19, 2020, 11:05:10 pm
As I told you, I upgraded the forum software this morning. That surely put things in place.
Title: Re: how to - x axis?
Post by: bplus on February 19, 2020, 11:36:33 pm
Great! Oh that's what you mean by delays of yore. :)
Title: Re: how to - x axis?
Post by: TerryRitchie on February 20, 2020, 12:29:37 am
Code: QB64: [Select]
  1. PRINT "Select is back"

Sweet ... sorry to get off topic. I noticed the change after I posted the code. Should have started a new topic.
Title: Re: how to - x axis?
Post by: bplus on February 20, 2020, 12:42:17 am
Terry, I hope you know I was kidding when I said you started it, ha! You and Old Moses did great job of answering codevsb12, original post IMO, I thought we were done anyway.

Time will tell or codevsb12 :)

Is this really homework? I'd kill for homework like this when I was in school!

No, I think someone had older QB and just found QB64.
Title: Re: how to - x axis?
Post by: codevsb12 on February 20, 2020, 05:55:47 pm
great

one last thing, there was supposed to be a border around the screen and its not being drawn over when i use the line statement.

same to my circle.
Title: Re: how to - x axis?
Post by: bplus on February 20, 2020, 07:27:34 pm
great

one last thing, there was supposed to be a border around the screen and its not being drawn over when i use the line statement.

same to my circle.

Here is Old Moses code with a frame around the screen,
Code: QB64: [Select]
  1. DEFINT A-Z
  2. main& = _NEWIMAGE(600, 400, 32)
  3. sprite& = _NEWIMAGE(21, 31, 12)
  4. _DEST sprite&
  5. FOR y = 0 TO 29
  6.     FOR x = 0 TO 20
  7.         READ sprt%: PSET (x, y), sprt%
  8.     NEXT x
  9. _DEST main&
  10. SCREEN main&
  11. xp = 64
  12. yp = 70
  13. sx = 0: sy = 0: sx2 = 20: sy2 = 30
  14.  
  15.     CLS
  16.     FOR i = 0 TO 10 'framed
  17.         LINE (0 + i, 0 + i)-(_WIDTH - i, _HEIGHT - i), _RGB32(255 - i * 10, 128 - i * 5, 64 - i * 3), B
  18.     NEXT
  19.     te$ = INKEY$
  20.     IF te$ = "d" THEN xp = xp + 2: sx = 0: sy = 0: sx2 = 20: sy2 = 30
  21.     IF te$ = "a" THEN xp = xp - 2: sx = 20: sy = 0: sx2 = 0: sy2 = 30
  22.     IF te$ = "w" THEN yp = yp - 2
  23.     IF te$ = "s" THEN yp = yp + 2
  24.     IF te$ = "q" THEN END
  25.  
  26.     _PUTIMAGE (xp, yp), sprite&, main&, (sx, sy)-(sx2, sy2)
  27.     _DISPLAY
  28.  
  29. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00
  30. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00
  31. DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00
  32. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00
  33. DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00
  34. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14
  35. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14
  36. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  37. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00
  38. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  39. DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00
  40. DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00
  41. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  42. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  43. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  44. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  45. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  46. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  47. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  48. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  49. DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00
  50. DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  51. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  52. DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  53. DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  54. DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00
  55. DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00
  56. DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00
  57. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00
  58. DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
  59.  
  60.  
  61.  

same with circle ????
Title: Re: how to - x axis?
Post by: codevsb12 on February 20, 2020, 08:40:50 pm
ok, lets test it out. btw idk why you made all those things with rgb32 bu- OMG this is way better than i had in mind!

and there's a thing you guys may be confused about. my game is about a player having to collect a bouncing ball before it touches on a spike. i'm now feeling a little bit noob for having to copy paste everything the proes make to me.
Title: Re: how to - x axis?
Post by: bplus on February 20, 2020, 10:17:18 pm
Quote
OMG this is way better than i had in mind!

;-)) Have a ball!

Code: QB64: [Select]
  1. 'DEFINT A-Z
  2. main& = _NEWIMAGE(600, 400, 32)
  3. sprite& = _NEWIMAGE(21, 31, 12)
  4. _DEST sprite&
  5. FOR y = 0 TO 29
  6.     FOR x = 0 TO 20
  7.         READ sprt%: PSET (x, y), sprt%
  8.     NEXT x
  9. _DEST main&
  10. SCREEN main&
  11. xp = 64
  12. yp = 70
  13. sx = 0: sy = 0: sx2 = 20: sy2 = 30
  14. bx = _WIDTH / 2: by = _HEIGHT / 2
  15. bdx = 2 * (RND * 5 - 2.5): bdy = 2 * (RND * 5 - 2.5)
  16.     CLS
  17.     FOR i = 0 TO 10 'framed
  18.         LINE (0 + i, 0 + i)-(_WIDTH - i, _HEIGHT - i), _RGB32(255 - i * 10, 128 - i * 5, 64 - i * 3), B
  19.     NEXT
  20.     te$ = INKEY$
  21.     IF te$ = "d" THEN xp = xp + 2: sx = 0: sy = 0: sx2 = 20: sy2 = 30
  22.     IF te$ = "a" THEN xp = xp - 2: sx = 20: sy = 0: sx2 = 0: sy2 = 30
  23.     IF te$ = "w" THEN yp = yp - 2
  24.     IF te$ = "s" THEN yp = yp + 2
  25.     IF te$ = "q" THEN END
  26.  
  27.  
  28.     _PUTIMAGE (xp, yp), sprite&, main&, (sx, sy)-(sx2, sy2)
  29.     drawBall bx, by
  30.     bx = bx + bdx: by = by + bdy
  31.     IF bx < 20 THEN bx = 20: bdx = -bdx
  32.     IF bx > _WIDTH - 20 THEN bx = _WIDTH - 20: bdx = -bdx
  33.     IF by < 20 THEN by = 20: bdy = -bdy
  34.     IF by > _HEIGHT - 20 THEN by = _HEIGHT - 20: bdy = -bdy
  35.  
  36.     _DISPLAY
  37.     _LIMIT 60
  38.  
  39. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00
  40. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00
  41. DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00
  42. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00
  43. DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00
  44. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14
  45. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14
  46. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  47. DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00
  48. DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00
  49. DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00
  50. DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00
  51. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  52. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  53. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  54. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  55. DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  56. DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  57. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  58. DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00
  59. DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00
  60. DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  61. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00
  62. DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  63. DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00
  64. DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00
  65. DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00
  66. DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00
  67. DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00
  68. DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
  69.  
  70. SUB drawBall (x, y)
  71.     FOR r = 0 TO 10 STEP .25
  72.         CIRCLE (x, y), r, _RGB32(255 - r * 10, 150 - r * 10, 0)
  73.     NEXT
  74.  
Title: Re: how to - x axis?
Post by: _vince on February 20, 2020, 11:23:56 pm
Code: [Select]
deflng a-z
const sw = 640
const sh = 480
screen _newimage(sw, sh, 32)

w = 400
h = 400
dim a as double, b as double
a = 0.08
b = 0.03

line (0,0)-(sw,sh),_rgb(237,221,255),bf
for y=0 to h
for x=0 to w
if (sqr((x + a*w)^2 + (y - h/2)^2) > (w/2 + b*w)) and (sqr((x - w - a*w)^2 + (y - h/2)^2) > (w/2 + b*w)) or (sqr((y + a*h)^2 + (x - w/2)^2) > (h/2 + b*h)) and (sqr((y - h - a*h)^2 + (x - w/2)^2) > (h/2 + b*h))then pset (sw/2 - w/2 + x, sh/2 + h/2 - y),_rgb(187,0,0)
next
next

sleep
system
Title: Re: how to - x axis?
Post by: OldMoses on February 21, 2020, 06:49:14 am
ok, lets test it out. btw idk why you made all those things with rgb32 bu-

_RGB32 is the heart of the border effect. It sets the colors of each concentric line box. Giving over 16.7 million color combinations. The suntax is:

_RGB32(red component, green component, blue component) with each color component being a value between 0-255

Bplus is taking advantage of the fact that I set up a 32bit color main screen and using a 32 bit color scheme, subtly shading each color component at different rates for each iteration of the border loop to give it a picture frame effect.
Title: Re: how to - x axis?
Post by: bplus on February 21, 2020, 12:24:37 pm
Holy Tilapia _vince!

Code: QB64: [Select]
  1. _TITLE "Holy Tilapia" ' _vince 2020-02-21  https://www.qb64.org/forum/index.php?topic=2204.msg114487#msg114487
  2. ' overlay b+ version
  3. 'DEFLNG A-Z
  4. CONST xmax = 500, ymax = 500, white = &HFFFFFFFF, red = &HFFBB0000
  5. CONST sw = 640 ' to match b+  640 original
  6. CONST sh = 480 ' ditto        480 original
  7. SCREEN _NEWIMAGE(sw, sh, 32)
  8.  
  9. ' b+ code prep for overlay ============================================
  10. TC& = _NEWIMAGE(xmax, ymax, 32)
  11. _DEST TC&
  12. LINE (50, 50)-(450, 450), red, BF
  13. CIRCLE (0, 250), 220, white
  14. CIRCLE (500, 250), 220, white
  15. CIRCLE (250, 0), 220, white
  16. CIRCLE (250, 500), 220, white
  17. PAINT (150, 150), white
  18. PAINT (350, 150), white
  19. PAINT (150, 350), white
  20. PAINT (350, 350), white
  21. FOR r = 29 TO 45 STEP .25
  22.     CIRCLE (250, 250), r, red
  23.  
  24. '=======================================================================
  25.  
  26. ' vince code  ==========================================================
  27. w = 400
  28. h = 400
  29. a = 0.08
  30. b = 0.03
  31.  
  32. LINE (0, 0)-(sw, sh), _RGB(237, 221, 255), BF
  33. FOR y = 0 TO h
  34.     FOR x = 0 TO w
  35.         IF (SQR((x + a * w) ^ 2 + (y - h / 2) ^ 2) > (w / 2 + b * w)) AND (SQR((x - w - a * w) ^ 2 + (y - h / 2) ^ 2) > (w / 2 + b * w)) OR (SQR((y + a * h) ^ 2 + (x - w / 2) ^ 2) > (h / 2 + b * h)) AND (SQR((y - h - a * h) ^ 2 + (x - w / 2) ^ 2) > (h / 2 + b * h)) THEN PSET (sw / 2 - w / 2 + x, sh / 2 + h / 2 - y), _RGB(187, 0, 0)
  36.     NEXT
  37.  
  38. ''' overlay b+ cross +++++++++++++++++++++++++++++++++++++++++++++++++++++
  39. FOR y = 0 TO ymax - 20
  40.     FOR x = 0 TO xmax
  41.         _SOURCE TC&
  42.         IF POINT(x, y) = red THEN bRed = -1 ELSE bRed = 0
  43.         _SOURCE 0
  44.         IF POINT(x + 70, y - 10) = red THEN vRed = -1 ELSE vRed = 0
  45.  
  46.         IF bRed AND vRed THEN
  47.             PSET (x + 70, y - 10), &HFF880088
  48.         ELSEIF bRed THEN
  49.             PSET (x + 70, y - 10), &HFFFFFF00
  50.         ELSEIF vRed THEN
  51.             PSET (x + 70, y - 10), &HFFFF0000
  52.         END IF
  53.     NEXT
  54.  
  55.  
  56.  

EDIT: Update with combined codes
Title: Re: how to - x axis?
Post by: TerryRitchie on February 21, 2020, 01:38:37 pm
Code: [Select]
deflng a-z
const sw = 640
const sh = 480
screen _newimage(sw, sh, 32)

w = 400
h = 400
dim a as double, b as double
a = 0.08
b = 0.03

line (0,0)-(sw,sh),_rgb(237,221,255),bf
for y=0 to h
for x=0 to w
if (sqr((x + a*w)^2 + (y - h/2)^2) > (w/2 + b*w)) and (sqr((x - w - a*w)^2 + (y - h/2)^2) > (w/2 + b*w)) or (sqr((y + a*h)^2 + (x - w/2)^2) > (h/2 + b*h)) and (sqr((y - h - a*h)^2 + (x - w/2)^2) > (h/2 + b*h))then pset (sw/2 - w/2 + x, sh/2 + h/2 - y),_rgb(187,0,0)
next
next

sleep
system

Holy shiznit!
Title: Re: how to - x axis?
Post by: codevsb12 on February 21, 2020, 06:30:17 pm
alright, first, _vince, im a newbie, that's what it says under my name.

and second, the balls not appearing and my player is not moving.

lemme try some things to fix it because i've asked a lot for help this week...

hmm...

i don't see any problem in the code

maybe i don't have the eye of a programmer

gotta try another method, then...
...
nothing?

w? s? d? a? Q????? NO?

oh, i forgot the randomize timer in the beginning...
injustice...

one last try...

yay! now it works!

important note: no defint a-z from now on...
Title: Re: how to - x axis?
Post by: _vince on February 21, 2020, 07:11:36 pm
Holy Tilapia _vince!

try this, bplus

Code: QB64: [Select]
  1. a = 50/400
  2. b = 20/400
  3.  
Title: Re: how to - x axis?
Post by: bplus on February 21, 2020, 07:26:09 pm
try this, bplus

Code: QB64: [Select]
  1. a = 50/400
  2. b = 20/400
  3.  

Yep! 100% purple. You did a marvelous job of duplicating my newest avatar. I love the really long IF block with AND OR AND.
First thing I did to check it out was this:
Code: QB64: [Select]
  1. DEFLNG A-Z
  2. CONST sw = 640
  3. CONST sh = 480
  4. SCREEN _NEWIMAGE(sw, sh, 32)
  5.  
  6. w = 400
  7. h = 400
  8. a = 0.08
  9. b = 0.03
  10.  
  11. LINE (0, 0)-(sw, sh), _RGB(237, 221, 255), BF ' blue off by only 1 tick too low in red = &heeddff
  12. FOR y = 0 TO h
  13.     FOR x = 0 TO w
  14.         IF (SQR((x + a * w) ^ 2 + (y - h / 2) ^ 2) > (w / 2 + b * w)) THEN
  15.             IF (SQR((x - w - a * w) ^ 2 + (y - h / 2) ^ 2) > (w / 2 + b * w)) THEN
  16.                 PSET (sw / 2 - w / 2 + x, sh / 2 + h / 2 - y), _RGB(187, 0, 0) 'nailed red!
  17.             END IF
  18.         END IF
  19.         IF (SQR((y + a * h) ^ 2 + (x - w / 2) ^ 2) > (h / 2 + b * h)) THEN
  20.             IF (SQR((y - h - a * h) ^ 2 + (x - w / 2) ^ 2) > (h / 2 + b * h)) THEN
  21.                 PSET (sw / 2 - w / 2 + x, sh / 2 + h / 2 - y), _RGB(187, 0, 0) 'nailed  red!
  22.             END IF
  23.         END IF
  24.     NEXT
  25.  
  26.  
  27.  

Apologies again to codevsb12 for getting off track but again, I didn't start it ;-))

BTW codevsb12 some code to go with your commentary (reply #30) would be nice. ;-)
Title: Re: how to - x axis?
Post by: _vince on February 21, 2020, 07:56:50 pm
As a note, bplus, the above expansion would execute much faster because it will not evaluate the other conditions if the first fails.  Other languages have 'short circuiting' or 'logic' operators that would evaluate equivalently to the above expansion, ie && and || as opposed to & and | in C. Freebasic also supports them:

https://www.freebasic.net/forum/viewtopic.php?t=25782 (https://www.freebasic.net/forum/viewtopic.php?t=25782)

I personally believe they don't have a place in QB64, or any 'pure' BASIC, it would just add confusion for no real gain. I would never use ANDALSO or ORELSE in freebasic code, what an abomination