Author Topic: how to - x axis?  (Read 7411 times)

0 Members and 1 Guest are viewing this topic.

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
how to - x axis?
« 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..
« Last Edit: February 19, 2020, 08:28:14 pm by codevsb12 »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: how to - y axis?
« Reply #1 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)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: how to - y axis?
« Reply #2 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.

FellippeHeitor

  • Guest
Re: how to - y axis?
« Reply #3 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.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: how to - y axis?
« Reply #4 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.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: how to - y axis?
« Reply #5 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.
In order to understand recursion, one must first understand recursion.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: how to - y axis?
« Reply #6 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.  
« Last Edit: February 19, 2020, 10:06:21 pm by odin »

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: how to - y axis?
« Reply #7 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)?

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: how to - y axis?
« Reply #8 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.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: how to - x axis?
« Reply #9 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.  
« Last Edit: February 19, 2020, 10:06:32 pm by odin »
In order to understand recursion, one must first understand recursion.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: how to - x axis?
« Reply #10 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.  
« Last Edit: February 19, 2020, 10:06:39 pm by odin »

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: how to - x axis?
« Reply #11 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.
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: how to - x axis?
« Reply #12 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!
« Last Edit: February 19, 2020, 09:51:00 pm by bplus »

FellippeHeitor

  • Guest
Re: how to - x axis?
« Reply #13 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: how to - x axis?
« Reply #14 on: February 19, 2020, 10:22:58 pm »
Code: QB64: [Select]
  1. What happened? and is the delay going to be back too?