QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Prithak on February 16, 2019, 08:41:15 pm

Title: How to make a player jump in ONE LOOP!
Post by: Prithak on February 16, 2019, 08:41:15 pm
Here's the code I built up for a project that my teacher gave me and my friend (He is not in this forum yet, cuz he doesn't have internet connection right now, but he will be soon!) to make a game! And I need to optimize it in order for it to run on his Core 2 Duo Computer (Like 100% same as mine lol). So, I needed to do this in ONE LOOP! So, here's my code for moving the character(Make sure to download the zip file!)
Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13. SCREEN _NEWIMAGE(800, 600, 32)
  14. DIM idle&(15)
  15. DIM walk&(15)
  16. DIM jump&(15)
  17.  
  18. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  19. y = 500
  20. ic = 1
  21. FOR i = 1 TO 15
  22.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  23. FOR i = 1 TO 15
  24.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  25. FOR i = 1 TO 15
  26.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  27. i = 0
  28. type$ = "idle"
  29. bgx = 0
  30. bgy = 0
  31. bgx2 = 800
  32. bgy2 = 600
  33.     CLS
  34.     k$ = UCASE$(INKEY$)
  35.  
  36.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg
  37.  
  38.     IF k$ = "A" THEN type$ = "lwalk"
  39.     IF k$ = "D" THEN type$ = "rwalk"
  40.     IF k$ = "W" THEN type$ = "jump"
  41.     IF k$ <> "W" THEN
  42.         IF LEN(k$) = 0 THEN type$ = "idle"
  43.     END IF
  44.     IF type$ = "idle" THEN
  45.         a = a + 1
  46.         IF a > 15 THEN a = 1
  47.         IF ic = 1 THEN
  48.             _PUTIMAGE (x, y)-(x + 100, y + 100), idle&(a)
  49.         ELSEIF ic = 2 THEN
  50.             _PUTIMAGE (x + 100, y)-(x, y + 100), idle&(a)
  51.         END IF
  52.     ELSEIF type$ = "lwalk" THEN
  53.         ic = 2
  54.         b = b + 1
  55.         IF b > 14 THEN b = 1: type$ = "idle"
  56.         _PUTIMAGE (x + 100, y)-(x, y + 100), walk&(b)
  57.         x = x - 5
  58.     ELSEIF type$ = "rwalk" THEN
  59.         ic = 1
  60.         c = c + 1
  61.         IF c > 14 THEN c = 1: type$ = "idle"
  62.         _PUTIMAGE (x, y)-(x + 100, y + 100), walk&(c)
  63.         x = x + 5
  64.     END IF
  65.     LOCATE 1, 1: PRINT x; y; type$
  66.     _LIMIT 30
  67.     _DISPLAY
  68.  

IF the player presses "W", it jumps!
Title: Re: How to make a player jump in ONE LOOP!
Post by: bplus on February 16, 2019, 10:53:30 pm
Hi Prithak,

When I press w, it just blinks (a and d work).

Do you have a question? If not, I have one: How can you show a jump in only one loop? Wouldn't the character just end up down in new spot?  Opps, that's 2 questions ;)
Title: Re: How to make a player jump in ONE LOOP!
Post by: Petr on February 17, 2019, 03:33:35 am
Hi Prithak,

Nice graphics. Is that your own job? About the jump. The maximum jump height is frame 7, as I found out. So, for the animation to be smooth, you have to take the current time when you insert the first slide, that is, if the jump takes one second, you have to insert the first 7 frames within half a second. You need to watch this, for example, using TIMER or ON TIMER. Just with inserting the next image you will always find out how much the current timer is, or set a new one. This way, you will not affect the main program loop. At the same time, when inserting pictures 1 through 7, you reduce the size of the Y axis in order for the figure to go up, and after half of the jump it increases again in the same step to the original value. If the height of the jump is 50 pixels, then is one shift in the Y axis for jump 50/7. For better effect, you can add or remove a value in the X axis, depending on whether the move key is pressed, but unfortunately, if you want to combine pressed keys, forget to the INKEY$ and use _KEYHIT.
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 17, 2019, 01:40:38 pm
Hi Prithak
an expert of game engine seems to be UnseenMachine that together to other clever coders seem to be absent in these times on this forum
sob so I gain by this sentence the angryness of all the  clever coders that now are active on this forum... :-(
sorry I don't want to hit all you clever coders

Well, coming back to your question...
IMHO
a jump sequence is a mini film like the walking, but in your way to create this sequence you don't need a continuosly pressing the key W to jump while you want a continuosly pressing key for walking.... it is ok because
1. it is your game
2. it is one of the many ways to make a walking

so you have already the response....
I have coded it like my mod of your code just if you cannot figure how to do it... but it is the same manner that you have used for walking... as Petr has suggested you have to split the space of jumping in half of sequence imagines (I see they are 15 so we can use 7).... and mantain the command "jump" in your brain of engine type$ until the jump sequence is finished or the user press another key...

2 feedback:
1. passing from left idle to righ idle and vice-versa  you have coded an error because the character shifts to left or to right of 5 units...
2. you have loaded only rightward sequence of images for jump, so if your character look leftward then it jumps to righward
fine but wrong!

I hope this is useful for you

PS: just a curiosity
what do this?
Quote
    IF k$ <> "W" THEN
        IF LEN(k$) = 0 THEN type$ = "idle"
    END IF

More suggestions

you can use one counter variable instead of different variables if the number of images of sequence is the same for walk to left, walk to right, jump, die, fly, fire etc etc etc

Title: Re: How to make a player jump in ONE LOOP!
Post by: Prithak on February 18, 2019, 07:30:17 am
Hi Prithak,

Nice graphics. Is that your own job? About the jump. The maximum jump height is frame 7, as I found out. So, for the animation to be smooth, you have to take the current time when you insert the first slide, that is, if the jump takes one second, you have to insert the first 7 frames within half a second. You need to watch this, for example, using TIMER or ON TIMER. Just with inserting the next image you will always find out how much the current timer is, or set a new one. This way, you will not affect the main program loop. At the same time, when inserting pictures 1 through 7, you reduce the size of the Y axis in order for the figure to go up, and after half of the jump it increases again in the same step to the original value. If the height of the jump is 50 pixels, then is one shift in the Y axis for jump 50/7. For better effect, you can add or remove a value in the X axis, depending on whether the move key is pressed, but unfortunately, if you want to combine pressed keys, forget to the INKEY$ and use _KEYHIT.
Thanks, the background isn't my work but the character is. BTW, I am a part time animator! Thanks for the help but I already seem to have figured it out, but it still has some bugs that I know how to fix :D
Title: Re: How to make a player jump in ONE LOOP!
Post by: bplus on February 18, 2019, 10:32:20 am
OK I play with TempodiBasic's mod (nice start!)

Now when you press D the character walks right forever and if W is pressed it will jump.
Now to stop and idle the character press S, press W while idling and it will jump.
Now when you press A the characters walks left forever and if you press W it will jump while going left.

Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13. SCREEN _NEWIMAGE(800, 600, 32)
  14. DIM idle&(15)
  15. DIM walk&(15)
  16. DIM jump&(15)
  17. DIM maxJump AS INTEGER, minJump AS INTEGER
  18. maxJump = 50
  19. minJump = INT(maxJump / 7)
  20. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  21. y = 500
  22. ic = 1 '<<<<<<<<<<<<<<<<<< direction facing 1 for right 2 for left?
  23. FOR i = 1 TO 15
  24.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  25. FOR i = 1 TO 15
  26.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  27. FOR i = 1 TO 15
  28.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  29. i = 0
  30. type$ = "idle"
  31. bgx = 0
  32. bgy = 0
  33. bgx2 = 800
  34. bgy2 = 600
  35.     CLS
  36.     k$ = UCASE$(INKEY$)
  37.  
  38.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg
  39.  
  40.     ' IF k$ = "" AND type$ = "jump" THEN k$ = "W"
  41.     IF k$ = "S" THEN type$ = "idle"
  42.     IF k$ = "A" THEN type$ = "lwalk"
  43.     IF k$ = "D" THEN type$ = "rwalk"
  44.     IF k$ = "W" THEN jump = 1 '<<<<<<<<< change
  45.     'IF k$ <> "W" THEN
  46.     '    IF LEN(k$) = 0 THEN type$ = "idle"
  47.     'END IF
  48.     IF type$ = "idle" THEN
  49.         a = a + 1
  50.         IF a > 15 THEN a = 1
  51.         IF jump THEN
  52.             jump = jump + 1
  53.             IF jump = 15 THEN jump = 0
  54.             IF jump < 7 THEN
  55.                 dy = dy + minJump
  56.                 IF dy > maxJump THEN dy = maxJump
  57.             ELSE
  58.                 dy = dy - minJump
  59.                 IF dy < 0 THEN dy = 0
  60.             END IF
  61.             IF ic = 1 THEN
  62.                 _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), idle&(a)
  63.             ELSEIF ic = 2 THEN
  64.                 _PUTIMAGE (x + 100, y - dy)-(x, y + 100 - dy), idle&(a)
  65.             END IF
  66.         ELSE
  67.             IF ic = 1 THEN
  68.                 _PUTIMAGE (x, y)-(x + 100, y + 100), idle&(a)
  69.             ELSEIF ic = 2 THEN
  70.                 _PUTIMAGE (x + 100, y)-(x, y + 100), idle&(a)
  71.             END IF
  72.         END IF
  73.     ELSEIF type$ = "lwalk" THEN
  74.         ic = 2
  75.         b = b + 1
  76.         IF b > 14 THEN b = 1 ': type$ = "idle"
  77.         IF jump THEN
  78.             jump = jump + 1
  79.             IF jump = 15 THEN jump = 0
  80.             IF jump < 7 THEN
  81.                 dy = dy + minJump
  82.                 IF dy > maxJump THEN dy = maxJump
  83.             ELSE
  84.                 dy = dy - minJump
  85.                 IF dy < 0 THEN dy = 0
  86.             END IF
  87.             _PUTIMAGE (x + 100, y - dy)-(x, y + 100 - dy), walk&(b)
  88.         ELSE
  89.             _PUTIMAGE (x + 100, y)-(x, y + 100), walk&(b)
  90.         END IF
  91.         x = x - 5
  92.     ELSEIF type$ = "rwalk" THEN
  93.         ic = 1
  94.         c = c + 1
  95.         IF c > 14 THEN c = 1 ': type$ = "idle"
  96.         IF jump THEN
  97.             jump = jump + 1
  98.             IF jump = 15 THEN jump = 0
  99.             IF jump < 7 THEN
  100.                 dy = dy + minJump
  101.                 IF dy > maxJump THEN dy = maxJump
  102.             ELSE
  103.                 dy = dy - minJump
  104.                 IF dy < 0 THEN dy = 0
  105.             END IF
  106.             _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), walk&(c)
  107.         ELSE
  108.             _PUTIMAGE (x, y)-(x + 100, y + 100), walk&(c)
  109.         END IF
  110.         x = x + 5
  111.         'ELSEIF type$ = "jump" THEN
  112.         '    d = d + 1
  113.         '    IF d > 14 THEN d = 1: type$ = "idle"
  114.         '    IF d < 7 THEN
  115.         '        dy = dy + minJump
  116.         '        IF dy > maxJump THEN dy = maxJump
  117.         '    ELSE
  118.         '        dy = dy - minJump
  119.         '        IF dy < 0 THEN dy = 0
  120.         '    END IF
  121.         '    _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), jump&(d)
  122.     END IF
  123.     LOCATE 1, 1: PRINT x; y; type$
  124.     _LIMIT 30
  125.     _DISPLAY
  126.  
  127.  
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 18, 2019, 03:18:08 pm
Hi Prithak

about feedbacks

1 here I attach a version srhinked with one linear counter for image index and  looking just a little more into your code I code also for jumping leftward added to original jumping rightward

2. fixed the movement only changing the direction of looking of the character, now character moves toward if it looks already in that direction, changing direction no initial movement is made

3. when you change direction of looking of the character also if it x position changes only by 5 units it shifts more to left/right
But this is an image error.... if you see the sprites of the characters they have a large amount of white space on the right... except for the die routine.... so if you cut that white amount of space on the right making the same x dimension of each sprite of moving to left or right and to jump you can fix this bug
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 18, 2019, 03:23:27 pm
Hi Bplus
great mod of game engine!
this is one of the other ways to move a character that Prithak hasn't chosen but that I prefer if the game was mine.

Title: Re: How to make a player jump in ONE LOOP!
Post by: _vince on February 18, 2019, 08:35:05 pm
That's a lovely assignment, very clever teacher!

Here is my solution to the jump - I've changed "wasd" keys to arrow keys for my own convenience.

Code: QB64: [Select]
  1. ' & aka lil vince
  2. 'Prithak Adhikari
  3. 'Saugat Adhikari
  4. '---------------------------
  5. 'A Project From
  6. '2/16/2019
  7. 'To
  8. '-
  9. '---------------------------
  10. 'This project was created for
  11. 'us to collaborate with a game
  12. 'that we dreamt to made for
  13. 'some time!
  14. SCREEN _NEWIMAGE(800, 600, 32)
  15. DIM idle&(15)
  16. DIM walk&(15)
  17. DIM jump&(15)
  18.  
  19. bg = _LOADIMAGE("rpg/tileset/BG/BG.png")
  20. y = 500
  21. ic = 1
  22. FOR i = 1 TO 15
  23.     idle&(i) = _LOADIMAGE("rpg/char/Idle (" + LTRIM$(STR$(i)) + ").png")
  24. FOR i = 1 TO 15
  25.     walk&(i) = _LOADIMAGE("rpg/char/Walk (" + LTRIM$(STR$(i)) + ").png")
  26. FOR i = 1 TO 15
  27.     jump&(i) = _LOADIMAGE("rpg/char/Jump (" + LTRIM$(STR$(i)) + ").png")
  28. i = 0
  29. type$ = "Idle"
  30. bgx = 0
  31. bgy = 0
  32. bgx2 = 800
  33. bgy2 = 600
  34.  
  35. t = 0
  36. direction = 1
  37. base_y = y
  38. jump = 0
  39. jump_i = 0
  40.     CLS
  41.     k$ = UCASE$(INKEY$)
  42.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg
  43.  
  44.         t = t + 1
  45.         if _keydown(19200) then
  46.                 x = x - 10
  47.                 if direction = 1 then direction = direction * -1
  48.         end if
  49.         if _keydown(19712) then
  50.                 x = x + 10
  51.                 if direction = -1 then direction = direction * -1
  52.         end if
  53.         if _keydown(18432) and jump = 0 then
  54.                 'start jump sequence
  55.                 jump_i = 5
  56.                 jump = 1
  57.         end if
  58.  
  59.  
  60.         if jump then
  61.                 if jump_i > 0 then
  62.                         jump_i = jump_i - 1
  63.                         y = y - 10
  64.                 else
  65.                         y = y + vy
  66.                         vy = vy + 0.5
  67.                 end if
  68.  
  69.                 if y >= base_y then
  70.                         vy = 0
  71.                         jump = 0
  72.                 end if
  73.  
  74.                 if direction = 1 then
  75.                         _PUTIMAGE (x, y-15)-(x + direction*100, y + 100), jump&(7)
  76.                 elseif direction = -1 then
  77.                         _PUTIMAGE (x + 50, y-15)-(x + 50 + direction*100, y + 100), jump&(7)
  78.                 end if
  79.         else
  80.                 if _keydown(19200) or _keydown(19712) then
  81.                         if direction = 1 then
  82.                                 _PUTIMAGE (x, y)-(x + direction*100, y + 100), walk&(t mod 15 + 1)
  83.                         elseif direction = -1 then
  84.                                 _PUTIMAGE (x + 50, y)-(x + 50 + direction*100, y + 100), walk&(t mod 15 + 1)
  85.                         end if
  86.                 else
  87.                         if direction = 1 then
  88.                                 _PUTIMAGE (x, y)-(x + direction*100, y + 100), idle&(t mod 15 + 1)
  89.                         elseif direction = -1 then
  90.                                 _PUTIMAGE (x + 50, y)-(x + 50 + direction*100, y + 100), idle&(t mod 15 + 1)
  91.                         end if
  92.                 end if
  93.         end if
  94.  
  95.     _LIMIT 30
  96.     _DISPLAY
  97.  
Title: Re: How to make a player jump in ONE LOOP!
Post by: Prithak on February 18, 2019, 08:39:14 pm
Hi Prithak

about feedbacks

1 here I attach a version srhinked with one linear counter for image index and  looking just a little more into your code I code also for jumping leftward added to original jumping rightward

2. fixed the movement only changing the direction of looking of the character, now character moves toward if it looks already in that direction, changing direction no initial movement is made

3. when you change direction of looking of the character also if it x position changes only by 5 units it shifts more to left/right
But this is an image error.... if you see the sprites of the characters they have a large amount of white space on the right... except for the die routine.... so if you cut that white amount of space on the right making the same x dimension of each sprite of moving to left or right and to jump you can fix this bug
This mod didn't work for me, it just goes downwards and not upwards. The previous one works perfectly fine! And I think I understand what's going on in that little snippet. I'll change the code and see what I can do to change my game.
Title: Re: How to make a player jump in ONE LOOP!
Post by: Prithak on February 18, 2019, 08:40:38 pm
OK I play with TempodiBasic's mod (nice start!)

Now when you press D the character walks right forever and if W is pressed it will jump.
Now to stop and idle the character press S, press W while idling and it will jump.
Now when you press A the characters walks left forever and if you press W it will jump while going left.

Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13. SCREEN _NEWIMAGE(800, 600, 32)
  14. DIM idle&(15)
  15. DIM walk&(15)
  16. DIM jump&(15)
  17. DIM maxJump AS INTEGER, minJump AS INTEGER
  18. maxJump = 50
  19. minJump = INT(maxJump / 7)
  20. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  21. y = 500
  22. ic = 1 '<<<<<<<<<<<<<<<<<< direction facing 1 for right 2 for left?
  23. FOR i = 1 TO 15
  24.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  25. FOR i = 1 TO 15
  26.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  27. FOR i = 1 TO 15
  28.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  29. i = 0
  30. type$ = "idle"
  31. bgx = 0
  32. bgy = 0
  33. bgx2 = 800
  34. bgy2 = 600
  35.     CLS
  36.     k$ = UCASE$(INKEY$)
  37.  
  38.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg
  39.  
  40.     ' IF k$ = "" AND type$ = "jump" THEN k$ = "W"
  41.     IF k$ = "S" THEN type$ = "idle"
  42.     IF k$ = "A" THEN type$ = "lwalk"
  43.     IF k$ = "D" THEN type$ = "rwalk"
  44.     IF k$ = "W" THEN jump = 1 '<<<<<<<<< change
  45.     'IF k$ <> "W" THEN
  46.     '    IF LEN(k$) = 0 THEN type$ = "idle"
  47.     'END IF
  48.     IF type$ = "idle" THEN
  49.         a = a + 1
  50.         IF a > 15 THEN a = 1
  51.         IF jump THEN
  52.             jump = jump + 1
  53.             IF jump = 15 THEN jump = 0
  54.             IF jump < 7 THEN
  55.                 dy = dy + minJump
  56.                 IF dy > maxJump THEN dy = maxJump
  57.             ELSE
  58.                 dy = dy - minJump
  59.                 IF dy < 0 THEN dy = 0
  60.             END IF
  61.             IF ic = 1 THEN
  62.                 _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), idle&(a)
  63.             ELSEIF ic = 2 THEN
  64.                 _PUTIMAGE (x + 100, y - dy)-(x, y + 100 - dy), idle&(a)
  65.             END IF
  66.         ELSE
  67.             IF ic = 1 THEN
  68.                 _PUTIMAGE (x, y)-(x + 100, y + 100), idle&(a)
  69.             ELSEIF ic = 2 THEN
  70.                 _PUTIMAGE (x + 100, y)-(x, y + 100), idle&(a)
  71.             END IF
  72.         END IF
  73.     ELSEIF type$ = "lwalk" THEN
  74.         ic = 2
  75.         b = b + 1
  76.         IF b > 14 THEN b = 1 ': type$ = "idle"
  77.         IF jump THEN
  78.             jump = jump + 1
  79.             IF jump = 15 THEN jump = 0
  80.             IF jump < 7 THEN
  81.                 dy = dy + minJump
  82.                 IF dy > maxJump THEN dy = maxJump
  83.             ELSE
  84.                 dy = dy - minJump
  85.                 IF dy < 0 THEN dy = 0
  86.             END IF
  87.             _PUTIMAGE (x + 100, y - dy)-(x, y + 100 - dy), walk&(b)
  88.         ELSE
  89.             _PUTIMAGE (x + 100, y)-(x, y + 100), walk&(b)
  90.         END IF
  91.         x = x - 5
  92.     ELSEIF type$ = "rwalk" THEN
  93.         ic = 1
  94.         c = c + 1
  95.         IF c > 14 THEN c = 1 ': type$ = "idle"
  96.         IF jump THEN
  97.             jump = jump + 1
  98.             IF jump = 15 THEN jump = 0
  99.             IF jump < 7 THEN
  100.                 dy = dy + minJump
  101.                 IF dy > maxJump THEN dy = maxJump
  102.             ELSE
  103.                 dy = dy - minJump
  104.                 IF dy < 0 THEN dy = 0
  105.             END IF
  106.             _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), walk&(c)
  107.         ELSE
  108.             _PUTIMAGE (x, y)-(x + 100, y + 100), walk&(c)
  109.         END IF
  110.         x = x + 5
  111.         'ELSEIF type$ = "jump" THEN
  112.         '    d = d + 1
  113.         '    IF d > 14 THEN d = 1: type$ = "idle"
  114.         '    IF d < 7 THEN
  115.         '        dy = dy + minJump
  116.         '        IF dy > maxJump THEN dy = maxJump
  117.         '    ELSE
  118.         '        dy = dy - minJump
  119.         '        IF dy < 0 THEN dy = 0
  120.         '    END IF
  121.         '    _PUTIMAGE (x, y - dy)-(x + 100, y + 100 - dy), jump&(d)
  122.     END IF
  123.     LOCATE 1, 1: PRINT x; y; type$
  124.     _LIMIT 30
  125.     _DISPLAY
  126.  
  127.  
THANK YOU!!! This was exactly what I needed! Now, let me change my code for instance!
Title: Re: How to make a player jump in ONE LOOP!
Post by: Prithak on February 18, 2019, 08:42:51 pm
That's a lovely assignment, very clever teacher!

Here is my solution to the jump - I've changed "wasd" keys to arrow keys for my own convenience.

Code: QB64: [Select]
  1. ' & aka lil vince
  2. 'Prithak Adhikari
  3. 'Saugat Adhikari
  4. '---------------------------
  5. 'A Project From
  6. '2/16/2019
  7. 'To
  8. '-
  9. '---------------------------
  10. 'This project was created for
  11. 'us to collaborate with a game
  12. 'that we dreamt to made for
  13. 'some time!
  14. SCREEN _NEWIMAGE(800, 600, 32)
  15. DIM idle&(15)
  16. DIM walk&(15)
  17. DIM jump&(15)
  18.  
  19. bg = _LOADIMAGE("rpg/tileset/BG/BG.png")
  20. y = 500
  21. ic = 1
  22. FOR i = 1 TO 15
  23.     idle&(i) = _LOADIMAGE("rpg/char/Idle (" + LTRIM$(STR$(i)) + ").png")
  24. FOR i = 1 TO 15
  25.     walk&(i) = _LOADIMAGE("rpg/char/Walk (" + LTRIM$(STR$(i)) + ").png")
  26. FOR i = 1 TO 15
  27.     jump&(i) = _LOADIMAGE("rpg/char/Jump (" + LTRIM$(STR$(i)) + ").png")
  28. i = 0
  29. type$ = "Idle"
  30. bgx = 0
  31. bgy = 0
  32. bgx2 = 800
  33. bgy2 = 600
  34.  
  35. t = 0
  36. direction = 1
  37. base_y = y
  38. jump = 0
  39. jump_i = 0
  40.     CLS
  41.     k$ = UCASE$(INKEY$)
  42.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg
  43.  
  44.         t = t + 1
  45.         if _keydown(19200) then
  46.                 x = x - 10
  47.                 if direction = 1 then direction = direction * -1
  48.         end if
  49.         if _keydown(19712) then
  50.                 x = x + 10
  51.                 if direction = -1 then direction = direction * -1
  52.         end if
  53.         if _keydown(18432) and jump = 0 then
  54.                 'start jump sequence
  55.                 jump_i = 5
  56.                 jump = 1
  57.         end if
  58.  
  59.  
  60.         if jump then
  61.                 if jump_i > 0 then
  62.                         jump_i = jump_i - 1
  63.                         y = y - 10
  64.                 else
  65.                         y = y + vy
  66.                         vy = vy + 0.5
  67.                 end if
  68.  
  69.                 if y >= base_y then
  70.                         vy = 0
  71.                         jump = 0
  72.                 end if
  73.  
  74.                 if direction = 1 then
  75.                         _PUTIMAGE (x, y-15)-(x + direction*100, y + 100), jump&(7)
  76.                 elseif direction = -1 then
  77.                         _PUTIMAGE (x + 50, y-15)-(x + 50 + direction*100, y + 100), jump&(7)
  78.                 end if
  79.         else
  80.                 if _keydown(19200) or _keydown(19712) then
  81.                         if direction = 1 then
  82.                                 _PUTIMAGE (x, y)-(x + direction*100, y + 100), walk&(t mod 15 + 1)
  83.                         elseif direction = -1 then
  84.                                 _PUTIMAGE (x + 50, y)-(x + 50 + direction*100, y + 100), walk&(t mod 15 + 1)
  85.                         end if
  86.                 else
  87.                         if direction = 1 then
  88.                                 _PUTIMAGE (x, y)-(x + direction*100, y + 100), idle&(t mod 15 + 1)
  89.                         elseif direction = -1 then
  90.                                 _PUTIMAGE (x + 50, y)-(x + 50 + direction*100, y + 100), idle&(t mod 15 + 1)
  91.                         end if
  92.                 end if
  93.         end if
  94.  
  95.     _LIMIT 30
  96.     _DISPLAY
  97.  
OMG! THANK YOU SO MUCH! THIS WAS EXACTLY WHAT I HAD IN MY HEAD!!! Will you mind If I change the code a little bit and submit it to my teacher? :P
Title: Re: How to make a player jump in ONE LOOP!
Post by: _vince on February 18, 2019, 09:00:33 pm
This is a true sidescroller variant where the character remains stationary while the background moves. You can add obstacles and items based on value of variable x to create your map.

You are welcome to use the code as you wish

Edit: Hope I didn't just do your homework, careful submitting any code you did not write - review the policy on that
Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13. SCREEN _NEWIMAGE(800, 600, 32)
  14. DIM idle&(15)
  15. DIM walk&(15)
  16. DIM jump&(15)
  17.  
  18. bg = _LOADIMAGE("rpg/tileset/BG/BG.png")
  19. y = 500
  20. ic = 1
  21. FOR i = 1 TO 15
  22.     idle&(i) = _LOADIMAGE("rpg/char/Idle (" + LTRIM$(STR$(i)) + ").png")
  23. FOR i = 1 TO 15
  24.     walk&(i) = _LOADIMAGE("rpg/char/Walk (" + LTRIM$(STR$(i)) + ").png")
  25. FOR i = 1 TO 15
  26.     jump&(i) = _LOADIMAGE("rpg/char/Jump (" + LTRIM$(STR$(i)) + ").png")
  27. i = 0
  28. type$ = "Idle"
  29. bgx = 0
  30. bgy = 0
  31. bgx2 = 800
  32. bgy2 = 600
  33.  
  34. t = 0
  35. direction = 1
  36. base_y = y-100
  37. y = base_y
  38. jump = 0
  39. jump_i = 0
  40.     CLS
  41.     k$ = UCASE$(INKEY$)
  42.         if x>=0 then
  43.                 _PUTIMAGE (bgx-(x) mod 800, 0)-step(800,600), bg
  44.                 _PUTIMAGE (bgx-(x) mod 800+800, 0)-step(800,600), bg
  45.         else
  46.                 _PUTIMAGE (bgx+abs(x) mod 800, 0)-step(800,600), bg
  47.                 _PUTIMAGE (bgx+abs(x) mod 800-800, 0)-step(800,600), bg
  48.         end if
  49.  
  50.         t = t + 1
  51.         if _keydown(19200) then
  52.                 x = x - 10
  53.                 if direction = 1 then direction = direction * -1
  54.         end if
  55.         if _keydown(19712) then
  56.                 x = x + 10
  57.                 if direction = -1 then direction = direction * -1
  58.         end if
  59.         if _keydown(18432) and jump = 0 then
  60.                 'start jump sequence
  61.                 jump_i = 5
  62.                 jump = 1
  63.         end if
  64.  
  65.  
  66.         if jump then
  67.                 if jump_i > 0 then
  68.                         jump_i = jump_i - 1
  69.                         y = y - 20
  70.                 else
  71.                         y = y + vy
  72.                         vy = vy + 0.8
  73.                 end if
  74.  
  75.                 if y >= base_y then
  76.                         y = base_y
  77.                         vy = 0
  78.                         jump = 0
  79.                 end if
  80.  
  81.                 if direction = 1 then
  82.                         _PUTIMAGE (350, y-30)-(350 + direction*200, y + 200), jump&(7)
  83.                 elseif direction = -1 then
  84.                         _PUTIMAGE (350 + 100, y-15)-(350 + 100 + direction*200, y + 200), jump&(7)
  85.                 end if
  86.         else
  87.                 if _keydown(19200) or _keydown(19712) then
  88.                         if direction = 1 then
  89.                                 _PUTIMAGE (350, y)-(350 + direction*200, y + 200), walk&(t mod 15 + 1)
  90.                         elseif direction = -1 then
  91.                                 _PUTIMAGE (350 + 100, y)-(350 + 100 + direction*200, y + 200), walk&(t mod 15 + 1)
  92.                         end if
  93.                 else
  94.                         if direction = 1 then
  95.                                 _PUTIMAGE (350, y)-(350 + direction*200, y + 200), idle&(t mod 15 + 1)
  96.                         elseif direction = -1 then
  97.                                 _PUTIMAGE (350 + 100, y)-(350 + 100 + direction*200, y + 200), idle&(t mod 15 + 1)
  98.                         end if
  99.                 end if
  100.         end if
  101.  
  102.     _LIMIT 30
  103.     _DISPLAY
  104.  
  105.  
Title: Re: How to make a player jump in ONE LOOP!
Post by: bplus on February 18, 2019, 09:28:59 pm
Good one _vince, I don't like pressing those two keys at once but I sure do like that sidescroller method!
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 19, 2019, 04:06:19 am
Hi _vince
very fine
1. the solution to use a switch variable for _putimage output
2. and the managment of 50 more white pixel in the sprites using a costant to shift those pixel so that image doesn't shift changing side of direction

and I agree that _KEYDOWN and _KEYHIT are more suitable for input toward INKEY$.

I'll go to see the other example that you have posted!
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 19, 2019, 04:21:02 am
@Prithak


Quote
  it just goes downwards and not upwards. 
I am hungry so also in this time I have eaten something...
this in the section jump after DeltaY calculation
Code: QB64: [Select]
  1.  IF DeltaY < 0 THEN DeltaY = 0 '<-- newline
I must be sure that it is positive or max 0
:-)
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 19, 2019, 04:25:54 am
@ _vince

Hey but you have got a bigger boy ! :-)
Cool
and the horizontal scrolling by _PUTIMAGE is fine!

Thanks
I would have time to develop also vertical scrolling, but I need some free time  so we see after some days.
Thanks again to capture my imagination!
Title: Re: How to make a player jump in ONE LOOP!
Post by: Prithak on February 20, 2019, 09:09:26 pm
This is a true sidescroller variant where the character remains stationary while the background moves. You can add obstacles and items based on value of variable x to create your map.

You are welcome to use the code as you wish

Edit: Hope I didn't just do your homework, careful submitting any code you did not write - review the policy on that
Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13. SCREEN _NEWIMAGE(800, 600, 32)
  14. DIM idle&(15)
  15. DIM walk&(15)
  16. DIM jump&(15)
  17.  
  18. bg = _LOADIMAGE("rpg/tileset/BG/BG.png")
  19. y = 500
  20. ic = 1
  21. FOR i = 1 TO 15
  22.     idle&(i) = _LOADIMAGE("rpg/char/Idle (" + LTRIM$(STR$(i)) + ").png")
  23. FOR i = 1 TO 15
  24.     walk&(i) = _LOADIMAGE("rpg/char/Walk (" + LTRIM$(STR$(i)) + ").png")
  25. FOR i = 1 TO 15
  26.     jump&(i) = _LOADIMAGE("rpg/char/Jump (" + LTRIM$(STR$(i)) + ").png")
  27. i = 0
  28. type$ = "Idle"
  29. bgx = 0
  30. bgy = 0
  31. bgx2 = 800
  32. bgy2 = 600
  33.  
  34. t = 0
  35. direction = 1
  36. base_y = y-100
  37. y = base_y
  38. jump = 0
  39. jump_i = 0
  40.     CLS
  41.     k$ = UCASE$(INKEY$)
  42.         if x>=0 then
  43.                 _PUTIMAGE (bgx-(x) mod 800, 0)-step(800,600), bg
  44.                 _PUTIMAGE (bgx-(x) mod 800+800, 0)-step(800,600), bg
  45.         else
  46.                 _PUTIMAGE (bgx+abs(x) mod 800, 0)-step(800,600), bg
  47.                 _PUTIMAGE (bgx+abs(x) mod 800-800, 0)-step(800,600), bg
  48.         end if
  49.  
  50.         t = t + 1
  51.         if _keydown(19200) then
  52.                 x = x - 10
  53.                 if direction = 1 then direction = direction * -1
  54.         end if
  55.         if _keydown(19712) then
  56.                 x = x + 10
  57.                 if direction = -1 then direction = direction * -1
  58.         end if
  59.         if _keydown(18432) and jump = 0 then
  60.                 'start jump sequence
  61.                 jump_i = 5
  62.                 jump = 1
  63.         end if
  64.  
  65.  
  66.         if jump then
  67.                 if jump_i > 0 then
  68.                         jump_i = jump_i - 1
  69.                         y = y - 20
  70.                 else
  71.                         y = y + vy
  72.                         vy = vy + 0.8
  73.                 end if
  74.  
  75.                 if y >= base_y then
  76.                         y = base_y
  77.                         vy = 0
  78.                         jump = 0
  79.                 end if
  80.  
  81.                 if direction = 1 then
  82.                         _PUTIMAGE (350, y-30)-(350 + direction*200, y + 200), jump&(7)
  83.                 elseif direction = -1 then
  84.                         _PUTIMAGE (350 + 100, y-15)-(350 + 100 + direction*200, y + 200), jump&(7)
  85.                 end if
  86.         else
  87.                 if _keydown(19200) or _keydown(19712) then
  88.                         if direction = 1 then
  89.                                 _PUTIMAGE (350, y)-(350 + direction*200, y + 200), walk&(t mod 15 + 1)
  90.                         elseif direction = -1 then
  91.                                 _PUTIMAGE (350 + 100, y)-(350 + 100 + direction*200, y + 200), walk&(t mod 15 + 1)
  92.                         end if
  93.                 else
  94.                         if direction = 1 then
  95.                                 _PUTIMAGE (350, y)-(350 + direction*200, y + 200), idle&(t mod 15 + 1)
  96.                         elseif direction = -1 then
  97.                                 _PUTIMAGE (350 + 100, y)-(350 + 100 + direction*200, y + 200), idle&(t mod 15 + 1)
  98.                         end if
  99.                 end if
  100.         end if
  101.  
  102.     _LIMIT 30
  103.     _DISPLAY
  104.  
  105.  
Thanks for making this _Vince xD. No, I am not like flat on CHR$(3) + CHR$(22) it, but referencing it and making something of my own out of it :D. (i hope you see what I did there xD).
- Prithak
Title: Re: How to make a player jump in ONE LOOP!
Post by: TempodiBasic on February 24, 2019, 12:29:24 pm
Hi guys
Hi Prithak

Thanks to Vince's demo that rose up my imagination after a battle with _PUTIMAGE that is very powerful but you must enter in the idea of the function here my version of walking suggested by Vince and horizontal scrolling and horizontal plus vertical scrolling

Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13.  
  14. ' variable and constants declarations
  15. CONST HalfWImage = 50, HImage = 100, MaxJump = 50, Cstep = 5
  16. DIM idle&(15)
  17. DIM walk&(15)
  18. DIM jump&(15)
  19. DIM minJump AS INTEGER, i AS INTEGER
  20.  
  21. SCREEN _NEWIMAGE(800, 600, 32) ' screen initialization
  22. _TITLE "Continuosly walking"
  23. ' variables initialization
  24. minJump = INT(MaxJump / 7) 'vertical step unit = numframeSequence DIV 2
  25. x = 90 'starter X of character
  26. y = 500 'starter Y of character
  27. ic = 1 'starter direction
  28. i = 0
  29. type$ = "idle"
  30. bgx = 0
  31. bgy = 0
  32. bgx2 = 800
  33. bgy2 = 600
  34.  
  35. ' images initialization
  36. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  37. IF bg > 0 THEN PRINT "Error loading bg.pgn"
  38. FOR i = 1 TO 15
  39.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  40.     IF idle&(i) > 0 THEN PRINT "Error loading  idle(" + LTRIM$(STR$(i)) + ").png"
  41. FOR i = 1 TO 15
  42.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  43.     IF walk&(i) > 0 THEN PRINT "Error loading  walk(" + LTRIM$(STR$(i)) + ").png"
  44. FOR i = 1 TO 15
  45.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  46.     IF jump&(i) > 0 THEN PRINT "Error loading  jump(" + LTRIM$(STR$(i)) + ").png"
  47.  
  48. ' main loop
  49.  
  50.     k$ = UCASE$(INKEY$) 'this is input manager
  51.  
  52.     ' this is command manager
  53.     IF NOT k$ = "" THEN
  54.         IF k$ = "A" THEN
  55.             type$ = "lwalk"
  56.             IF ic = 1 THEN x = x + HalfWImage * -ic
  57.             ic = -1
  58.         END IF
  59.         IF k$ = "D" THEN
  60.             type$ = "rwalk"
  61.             IF ic = -1 THEN x = x + HalfWImage * -ic
  62.             ic = 1
  63.         END IF
  64.         IF k$ = "W" THEN type$ = "jump"
  65.         IF k$ = "S" THEN type$ = "idle"
  66.         IF k$ = CHR$(27) THEN END ' hotkey to quit
  67.     END IF
  68.  
  69.     ' this is command executor
  70.     IF a < 15 THEN a = a + 1 ELSE a = 1 'this calculates frame to use
  71.     IF type$ = "jump" THEN
  72.         IF a < 7 THEN ' this calculates movement toward sky
  73.             dy = dy + minJump
  74.             IF dy > MaxJump THEN dy = MaxJump
  75.         ELSE
  76.             dy = dy - minJump
  77.             IF dy < 0 THEN dy = 0
  78.             IF a = 15 THEN type$ = "idle"
  79.         END IF
  80.     END IF
  81.     IF type$ = "lwalk" OR type$ = "rwalk" THEN x = x + Cstep * ic
  82.  
  83.  
  84.     _PUTIMAGE (bgx, bgy)-(bgx2, bgy2), bg ' this create level background
  85.  
  86.     ' manager of image set by command
  87.     IF type$ = "idle" THEN
  88.         ' HalfWImage let us to use x position as center of the image
  89.         _PUTIMAGE (x - HalfWImage * ic, y)-(x + HalfWImage * ic, y + HImage), idle&(a)
  90.     ELSEIF type$ = "lwalk" OR type$ = "rwalk" THEN
  91.         _PUTIMAGE (x - HalfWImage * ic, y)-(x + HalfWImage * ic, y + HImage), walk&(a)
  92.     ELSEIF type$ = "jump" THEN
  93.         _PUTIMAGE (x - HalfWImage * ic, y - dy)-(x + HalfWImage * ic, y + HImage - dy), jump&(a)
  94.     END IF
  95.  
  96.     ' debug manager
  97.     LOCATE 1, 1: PRINT x; y; type$
  98.  
  99.     ' output screen manager
  100.     _LIMIT 30
  101.     _DISPLAY
  102.  

running it you can  appreciate the difference of input method that is just a bit more delayed  than _KEYDOWN  :-)

Here Horizontal scrolling idea
Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13.  
  14. ' variable and constants declarations
  15. CONST HalfWImage = 50, HImage = 100, MaxJump = 100, Cstep = 5
  16. DIM idle&(15)
  17. DIM walk&(15)
  18. DIM jump&(15)
  19. DIM minJump AS INTEGER, i AS INTEGER
  20.  
  21. SCREEN _NEWIMAGE(800, 600, 32) ' screen initialization
  22.  
  23. ' variables initialization
  24. minJump = INT(MaxJump / 15) 'vertical step unit = MaxJump DIV numframeSequence
  25. x = 0 'starter X of character
  26. y = 500 'starter Y of character
  27. ic = 1 'starter direction
  28. cx = 0 ' starter X correction to avoid flip effect changing direction of movement
  29. i = 0
  30. type$ = "idle"
  31. bgx = 0
  32. bgy = 0
  33. bgx2 = 800
  34. bgy2 = 600
  35.  
  36. ' images initialization
  37. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  38. IF bg > 0 THEN PRINT "Error loading bg.pgn"
  39. FOR i = 1 TO 15
  40.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  41.     IF idle&(i) > 0 THEN PRINT "Error loading  idle(" + LTRIM$(STR$(i)) + ").png"
  42. FOR i = 1 TO 15
  43.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  44.     IF walk&(i) > 0 THEN PRINT "Error loading  walk(" + LTRIM$(STR$(i)) + ").png"
  45. FOR i = 1 TO 15
  46.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  47.     IF jump&(i) > 0 THEN PRINT "Error loading  jump(" + LTRIM$(STR$(i)) + ").png"
  48.  
  49. ' main loop
  50.  
  51.     k$ = UCASE$(INKEY$) 'this is input manager
  52.  
  53.     ' this is command manager
  54.     IF NOT k$ = "" THEN
  55.         a = 0
  56.         IF k$ = "A" THEN
  57.             type$ = "lwalk"
  58.             IF ic = 1 THEN cx = -HalfWImage
  59.             ic = -1
  60.         END IF
  61.         IF k$ = "D" THEN
  62.             type$ = "rwalk"
  63.             IF ic = -1 THEN cx = 0
  64.             ic = 1
  65.         END IF
  66.         IF k$ = "W" THEN type$ = "jump"
  67.         IF k$ = "S" THEN type$ = "idle"
  68.         IF k$ = CHR$(27) THEN END ' hotkey to quit
  69.     END IF
  70.  
  71.     ' this is command executor
  72.     IF a < 15 THEN a = a + 1 ELSE a = 1 'this calculates frame to use
  73.     IF type$ = "jump" THEN
  74.         IF a < 7 THEN ' this calculates movement toward sky
  75.             dy = dy + minJump
  76.             IF dy > MaxJump THEN dy = MaxJump
  77.         ELSE
  78.             dy = dy - minJump
  79.             IF dy < 0 THEN dy = 0
  80.             IF a = 15 THEN type$ = "idle"
  81.         END IF
  82.     END IF
  83.     '         -ic because background goes in direction opposite to walking
  84.     IF type$ = "lwalk" OR type$ = "rwalk" THEN x = x + Cstep * -ic
  85.     IF x > 795 THEN x = 5
  86.     IF x < 5 THEN x = 795
  87.  
  88.     ' this create level background
  89.     ' this creates a background with 3 panel
  90.     '  |left|central|right|
  91.     'in this manner you can cover space left to left or right from scrolling central panel
  92.     ' at time 0 where x = 0 bgx =0 bgx2 = 800
  93.     _PUTIMAGE (bgx + x, bgy)-(bgx2 + x, bgy2), bg ' central panel
  94.     _PUTIMAGE (-bgx2 + x, bgy)-(bgx + x, bgy2), bg ' left panel
  95.     _PUTIMAGE (bgx2 + x, bgy)-((2 * bgx2) + x, bgy2), bg ' right panel
  96.  
  97.  
  98.     ' manager of image set by command
  99.     IF type$ = "idle" THEN
  100.         ' HalfWImage let us to use x position as center of the image
  101.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y)-((350 + cx) + HalfWImage * ic, y + HImage), idle&(a)
  102.     ELSEIF type$ = "lwalk" OR type$ = "rwalk" THEN
  103.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y)-((350 + cx) + HalfWImage * ic, y + HImage), walk&(a)
  104.     ELSEIF type$ = "jump" THEN
  105.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y - dy)-((350 + cx) + HalfWImage * ic, y + HImage - dy), jump&(a)
  106.     END IF
  107.  
  108.     ' output screen manager
  109.     _LIMIT 30
  110.     _DISPLAY
  111.  

and here Horizontal and Vertical scrolling together
Code: QB64: [Select]
  1. 'Prithak Adhikari
  2. 'Saugat Adhikari
  3. '---------------------------
  4. 'A Project From
  5. '2/16/2019
  6. 'To
  7. '-
  8. '---------------------------
  9. 'This project was created for
  10. 'us to collaborate with a game
  11. 'that we dreamt to made for
  12. 'some time!
  13.  
  14. ' variable and constants declarations
  15. CONST HalfWImage = 50, HImage = 100, MaxJump = 100, Cstep = 5
  16. DIM idle&(15)
  17. DIM walk&(15)
  18. DIM jump&(15)
  19. DIM minJump AS INTEGER, i AS INTEGER
  20.  
  21. SCREEN _NEWIMAGE(800, 600, 32) ' screen initialization
  22. _TITLE "Vertical scrolling"
  23. ' variables initialization
  24. minJump = INT(MaxJump / 15) 'vertical step unit = MaxJump DIV numframeSequence
  25. x = 0 'starter X of character
  26. y = 500 'starter Y of character
  27. ic = 1 'starter direction
  28. cx = 0 ' starter X correction to avoid flip effect changing direction of movement
  29. i = 0
  30. type$ = "idle"
  31. bgx = 0
  32. bgy = 0
  33. bgx2 = 800
  34. bgy2 = 600
  35.  
  36. ' images initialization
  37. bg = _LOADIMAGE("rpg/tileset/bg/bg.png")
  38. IF bg > 0 THEN PRINT "Error loading bg.pgn"
  39. FOR i = 1 TO 15
  40.     idle&(i) = _LOADIMAGE("rpg/char/idle (" + LTRIM$(STR$(i)) + ").png")
  41.     IF idle&(i) > 0 THEN PRINT "Error loading  idle(" + LTRIM$(STR$(i)) + ").png"
  42. FOR i = 1 TO 15
  43.     walk&(i) = _LOADIMAGE("rpg/char/walk (" + LTRIM$(STR$(i)) + ").png")
  44.     IF walk&(i) > 0 THEN PRINT "Error loading  walk(" + LTRIM$(STR$(i)) + ").png"
  45. FOR i = 1 TO 15
  46.     jump&(i) = _LOADIMAGE("rpg/char/jump (" + LTRIM$(STR$(i)) + ").png")
  47.     IF jump&(i) > 0 THEN PRINT "Error loading  jump(" + LTRIM$(STR$(i)) + ").png"
  48.  
  49. ' main loop
  50.  
  51.     k$ = UCASE$(INKEY$) 'this is input manager
  52.  
  53.     ' this is command manager
  54.     IF NOT k$ = "" THEN
  55.         a = 0
  56.         IF k$ = "A" THEN
  57.             type$ = "lwalk"
  58.             IF ic = 1 THEN cx = -HalfWImage
  59.             ic = -1
  60.         END IF
  61.         IF k$ = "D" THEN
  62.             type$ = "rwalk"
  63.             IF ic = -1 THEN cx = 0
  64.             ic = 1
  65.         END IF
  66.         IF k$ = "W" THEN type$ = "jump"
  67.         IF k$ = "S" THEN type$ = "idle"
  68.         IF k$ = CHR$(27) THEN END ' hotkey to quit
  69.     END IF
  70.  
  71.     ' this is command executor
  72.     IF a < 15 THEN a = a + 1 ELSE a = 1 'this calculates frame to use
  73.     IF type$ = "jump" THEN
  74.         IF a < 7 THEN ' this calculates movement toward sky
  75.             dy = dy + minJump
  76.             IF dy > MaxJump THEN dy = MaxJump
  77.         ELSE
  78.             dy = dy - minJump
  79.             IF dy < 0 THEN dy = 0
  80.             IF a = 15 THEN type$ = "idle"
  81.         END IF
  82.     END IF
  83.     '         -ic because background goes in direction opposite to walking
  84.     IF type$ = "lwalk" OR type$ = "rwalk" THEN x = x + Cstep * -ic
  85.     IF x > 795 THEN x = 5
  86.     IF x < 5 THEN x = 795
  87.  
  88.     ' this create level background
  89.     ' this creates a background with 3 panel
  90.     '  |left|central|right|
  91.     'in this manner you can cover space left to left or right from scrolling central panel
  92.     ' at time 0 where x = 0 bgx =0 bgx2 = 800
  93.     _PUTIMAGE (bgx + x, bgy + dy)-(bgx2 + x, bgy2 + dy), bg ' central panel
  94.     _PUTIMAGE (-bgx2 + x, bgy + dy)-(bgx + x, bgy2 + dy), bg ' left panel
  95.     _PUTIMAGE (bgx2 + x, bgy + dy)-((2 * bgx2) + x, bgy2 + dy), bg ' right panel
  96.  
  97.  
  98.     ' manager of image set by command
  99.     IF type$ = "idle" THEN
  100.         ' HalfWImage let us to use x position as center of the image
  101.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y)-((350 + cx) + HalfWImage * ic, y + HImage), idle&(a)
  102.     ELSEIF type$ = "lwalk" OR type$ = "rwalk" THEN
  103.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y)-((350 + cx) + HalfWImage * ic, y + HImage), walk&(a)
  104.     ELSEIF type$ = "jump" THEN
  105.         _PUTIMAGE ((350 + cx) - HalfWImage * ic, y)-((350 + cx) + HalfWImage * ic, y + HImage), jump&(a)
  106.     END IF
  107.  
  108.     ' output screen manager
  109.     _LIMIT 30
  110.     _DISPLAY
  111.  

the 3 file.BAS are attached for those don't like to copy and paste into QB64IDE.

Thanks to read