QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Jaze on May 02, 2021, 03:57:48 pm
-
I have one loop keeping track of something moving diagonally in one of the four directions. I have a second thing going vertically down. They have to be running at the same time but I don't know how to run two separate loops simultaneously. Is this even possible?
-
You can draw things individually and then _DISPLAY all when at end of loop.
-
OK. I'm not sure how to implement that suggestion. But I just thought of a way to put them both in the same loop. Thanks for pointing me to that tutorial because I'm going to need to study collision detection when I get there
-
Hey if you get stuck just post code and describe problem, we will try to help.
-
Just perform both movements\Actions in a single loop. thats your best bet.
-
OK. I'm not sure how to implement that suggestion. But I just thought of a way to put them both in the same loop. Thanks for pointing me to that tutorial because I'm going to need to study collision detection when I get there
A simple example:
DO
CLS
Y = Y + 1
X = X + 1
LOCATE Y, 1: PRINT “HELLO”
LOCATE Y, X: PRINT “WORLD”
_DISPLAY
_DELAY .5
LOOP UNTIL Y > 20
One locate prints from top tobottom, moving down the screen. The other prints and moves diagonally across the screen.
-
That only works if you want the characters to move at the same speed
-
You can make them move different speeds by adding a different offset i.e
Char1X = Char1X + 1
Char2X = Char2X + 2
Will make character 2 move twice as fast as character 1 horizontally
-
That only works if you want the characters to move at the same speed
use x, y to track object location like objX, objY
then use dx to track object "speeds" along x axis and dy to track object speed on y axis (per frame or drawing loop)
dx, dy = change of x, y on respective axis like objDX, objDY
Use the x, y for drawing obj, and dx, dy for updating the location ie
x = x + dx
y = y + dy
so
objX = objX + objDX
objY = objY = objDY
then check if x, y still inbounds correcting x, y and dx, dy when not.
-
That might work. Putting them in the same loop will be a challenge but I think I'm up to it
-
Hi Jaze
Good luck hope you get it working. I think you would find that's how game loops are programmed for example in my invaders game the game loop updates the players ship, the players bullets, the aliens, the random alien ship and explosion effects that's 5 different elements moving at various speeds.