' 2020 03 19
' Update now character can turn himself in air and when he lands he walks in the last direction choosen
' to be more visible this last feature I have doubled the space that he jumps adjusting the variables and adding a flag
' and more control on setting variables
' 2020 03 19
' a little bug, you you turn character while he is jumping the bottom Y
' of the character increases letting walk in air him :-)
'2020 03 18 posting this demo at forum QB64
' I have had some suggestions among these
' 1---jumping directional with the starting movement
' 2---continue the action of starting movement made before to jump
'--------------
' 2019 03 02
' TempodiBasic modification to demonstrate
' an one loop game engine for
' action in a scrolling world
' scrolling to left and to right for walking
' scrolling up to jump
'original idea from:
'Prithak Adhikari
'Saugat Adhikari
'---------------------------
'A Project From
'2/16/2019
'To
'-
'---------------------------
'This project was created for
'us to collaborate with a game
'that we dreamt to made for
'some time!
' variable and constants declarations
CONST HalfWImage
= 50, HImage
= 100, MaxJump
= 200, Cstep
= 5 DIM idle&
(15) 'array for idle images DIM walk&
(15) ' array for walk image DIM jump&
(15) 'array for jump image
_TITLE "Horizontal and Vertical scrolling" ' variables initialization
minJump
= INT(MaxJump
/ 15) 'vertical step unit = MaxJump DIV numframeSequencex = 0 'starter X of character
y = 500 'starter Y of character
ic = 1 'starter direction
cx = 0 ' starter X correction to avoid flip effect changing direction of movement
i = 0 'index for arrays
TYPE$
= "idle" ' default command of character a = 0.5 ' index of image to display
jumping = 0 ' no jump at start
bgx = 0 'left background
bgy = 0 'up background
bgx2 = 800 'right backgorund
bgy2 = 600 ' bottom background
' images initialization
bg
= _LOADIMAGE("rpg/tileset/bg/bg.png") ' background fileIF bg
> 0 THEN PRINT "Error loading bg.pgn" 'it test if file is loaded FOR i
= 1 TO 15 ' this FOR loads images of idle of character FOR i
= 1 TO 15 'this FOR loads images of walk of character FOR i
= 1 TO 15 ' this FOR loads images of jump of character
' main loop
' this is command manager
IF (k
= 65 OR k
= 97 OR k
= 19200) AND TYPE$
<> "lwalk" THEN ' if user press A or a and char is not leftwalk TYPE$
= "lwalk" ' command for engine executor IF ic
= 1 THEN cx
= -HalfWImage
ic = -1
IF (k
= 68 OR k
= 100 OR k
= 19712) AND TYPE$
<> "rwalk" THEN ' if user press D or d and char is not rightwalk ic = 1
IF (k
= 87 OR k
= 119 OR k
= 18432) AND TYPE$
<> "jump" THEN ' if user press W or w and char is not jumping IF (k
= 83 OR k
= 115 OR k
= 20480) AND TYPE$
<> " idle" THEN ' if user press S or s and char is not idle
' this is command executor
IF a
< 15 THEN a
= a
+ .5 ELSE a
= .5 'this calculates frame to use IF a
< 7 THEN ' this calculates movement towards sky dy = dy + minJump
IF dy
> MaxJump
THEN dy
= MaxJump
ELSE ' this calculates movement towards hearth dy = dy - minJump
IF dy
< 0 THEN dy
= 0: jumping
= 0 x = x + Cstep * -ic ' this lets movement of character
' -ic because background goes in direction opposite to walking
IF x
> 795 THEN x
= 5 ' x cycle in the range of visible 5-795
' output screen manager
' this create level background
' this creates a background with 3 panel
' |left|central|right|
'in this manner you can cover space left to left or right from scrolling central panel
' at time 0 where x = 0 bgx =0 bgx2 = 800
_PUTIMAGE (bgx
+ x
, bgy
+ dy
)-(bgx2
+ x
, bgy2
+ dy
), bg
' central panel _PUTIMAGE (-bgx2
+ x
, bgy
+ dy
)-(bgx
+ x
, bgy2
+ dy
), bg
' left panel _PUTIMAGE (bgx2
+ x
, bgy
+ dy
)-((2 * bgx2
) + x
, bgy2
+ dy
), bg
' right panel
' manager of image set by command
' HalfWImage let us to use x position as center of the image
_PUTIMAGE ((350 + cx
) - HalfWImage
* ic
, y
)-((350 + cx
) + HalfWImage
* ic
, y
+ HImage
), idle&
(b
) _PUTIMAGE ((350 + cx
) - HalfWImage
* ic
, y
)-((350 + cx
) + HalfWImage
* ic
, y
+ HImage
), walk&
(b
) _PUTIMAGE ((350 + cx
) - HalfWImage
* ic
, y
)-((350 + cx
) + HalfWImage
* ic
, y
+ HImage
), jump&
(b
)
' frame rate