LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to run two loops at once?

Root / Programming Questions / [.]

Jbomb6Created:
Since I'm not the best at programming I've been just making games that don't really have a premise. One of these games right now I just call space. In it your a little space man flying around and there is this black hole slowly getting bigger and bigger. Once you touch it you die, eventually I want to turn it into more but that's all I have made so far. But anyway so the guy will move I made a loop and so the black hole will get bigger I made another loop too. But the thing is I can't have those going at once without adding something extra, I don't know that that extra is. I tried combining the loops but that won't work so if someone could help me it would be much appreciated.

You'll have to put all the code into one loop Make sure you're using different variables for each section

I tried combining the loops but that won't work
You mean, you tried combining the loops but the way you tried didn't work. What did you do, that didn't work? In what way didn't it work?

Late response but you could put the loops in DEFs and call them in a single loop.
VAR S: VAR HIT: VAR B:VAR X=150:VAR Y=100

SPSET 0,'SpaceMan sprite
SPSET 1,'Blackhole Sprite
SPOFS 0,X,Y:SPOFS 1,150,0:SPCOL 0

WHILE 1
 INC S,0.2
 SpaceMan
 Blackhole

 IF HIT==TRUE THEN BREAK

 VSYNC
WEND

END

DEF SpaceMan
 B=BUTTON()
 IF B AND #UP THEN DEC Y
 IF B AND #RIGHT THEN INC X
 IF B AND #DOWN THEN INC Y
 IF B AND #LEFT THEN DEC X
 SPOFS 0,X,Y
END

DEF Blackhole
 HIT=SPHITSP(1)
 SPCOL 1,TRUE: SPSCALE 1,S,S
END
Note: I didn't test this but it should be a simple way of achieving what you want.

Late response but you could put the loops in DEFs and call them in a single loop.
I second this. Especially if you're going to make the game bigger, you should make each function modular with DEF blocks.

Late response but you could put the loops in DEFs and call them in a single loop.
...
Note: I didn't test this but it should be a simple way of achieving what you want.
The SPCOL for the black hole needs to have scale adjustment enabled.

Late response but you could put the loops in DEFs and call them in a single loop.
...
Note: I didn't test this but it should be a simple way of achieving what you want.
The SPCOL for the black hole needs to have scale adjustment enabled.
Honestly, for something that's always going to be a circle, wouldn't a simple radius check be more advised? Edit: Now that I think about it, wouldn't GCIRCLE be better than scaling a sprite?

Late response but you could put the loops in DEFs and call them in a single loop.
...
Note: I didn't test this but it should be a simple way of achieving what you want.
The SPCOL for the black hole needs to have scale adjustment enabled.
Honestly, for something that's always going to be a circle, wouldn't a simple radius check be more advised? Edit: Now that I think about it, wouldn't GCIRCLE be better than scaling a sprite?
Idk, I figured scaling a sprite is easy to comprehend so I went with that option. Also, not noted in the code but if going with the scaling sprite option, I would recommend using SPHOME to center the point of collision (or wherever it needs to be)

I think you only need to do the SPCOL 1,TRUE once, though I haven't really used SPCOL much so I'm not entirely certain.

Ah, that would make sense, but I'm not entirely certain either. I'll test it out later.

I would use a radius distance check for collision rather than using the sprite, because otherwise that hitbox is gonna be a square, not a circle, and that'll get more and more noticeable as it grows.