• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Looping Room and Scrolling Shooter Mix

Bentley

Member
I am trying to remake a game like Fantasy Zone. The game is a scrolling shooter but the player can move right and left in a looping room. The background loops (the right side leads to the left side, and vice versa).

Does anyone know how I can keep the player centered on screen at all times in a room that loops?

Thanks for reading.
 

Paskaler

Member
I've done such a thing for one of the games I've been working on. Here's a project that contains only that feature as a test:

https://ufile.io/u40dy

Note: Sorry for the weird site for download, but Dropbox was really slow for some reason and I gave up waiting. Hope it helps you out.
 

Bentley

Member
A "seamless world" is harder than I thought. I assumed there was something simple I was missing. Solved (too advanced for me atm)
 
Last edited:

TheouAegis

Member
Seamless worlds aren't that difficult, @Bentley

A seamless world requires a couple considerations:

1) If the world takes up just one screen, then the player and all NPCs can move freely with a simple wrap code.
2) If the world takes up multiple screens, then either
a) the player moves with a simple wrap code while NPCs and terrain are handled with a wrap code and special draw code, or
b) the player stays still while the terrain and NPCs are handled by a controller​
3) Collisions can be calculated by comparing distances from the center of the room.
4) If the camera follows the player, then the terrain needs to be copied on the opposite sides of the room as buffers

Regarding point 4, consider a room comprised of 4 backgrounds:

A B
C D


If the camera follows the player, then the room needs to be designed as

D C D C
B A B A
D C D C

B A B A

And from this diagram we can see how point 3 is derived. A' (the bold A) is 1 spot away from the middle of the room. B' is 1 spot away from the middle of the room on the other side. In other words, abs(A.X - room_width/2)==abs(B.X - room_width/2). The same can be applied to instances. So if abs(abs(obj_player.x-room_width/2) - abs(obj_enemy.x - room_width/2)) is less than (obj_player.sprite_width+obj_enemy..sprite_width)/2, the two instances are overlapping horizontally (you'd have to do the same for vertical calculations). You could even use point_distance() instead, if you wanted -- the principle is the same, however.


It's really all quite simple once you wrap your head around the concepts. Point 2a is probably the easiest to work with but is not GM-user-friendly. If the extent of your GM familiarity is only tutorials, then neither point 2a nor 2b will be that easy for you starting out.
 

Bentley

Member
Seamless worlds aren't that difficult, @Bentley

A seamless world requires a couple considerations:

1) If the world takes up just one screen, then the player and all NPCs can move freely with a simple wrap code.
2) If the world takes up multiple screens, then either
a) the player moves with a simple wrap code while NPCs and terrain are handled with a wrap code and special draw code, or
b) the player stays still while the terrain and NPCs are handled by a controller​
.
Thanks for the reply TheouAegis, I really appreciate it. My first plan was something like 2b (but in a way a beginner would go about it). I was going to use background hspeed to move the world. The faster the player "moves" right, the faster the world scrolls left (and vice versa). "Moves" is in quotes because the player would never change position. But I didn't continue because I'm not good enough : (

I'm very curious about 1 and 2b. How would you handle 2b. With the player not moving, how would, for example, enemy bullets be dodged? (This might be your third point). Do you udate the bullet's speed based on the player's speed?

Anything you can break down for a beginner would be awesome. Thanks again for the replies.
 
Last edited:

TheouAegis

Member
If you press right, you move the background left and tell all the instances in the room to move left as well (subtract from their x-coordinates).

The controller would check if a background has moved too far in a particular direction and then wrap it to the other side of the room.

Same with enemies.

If the world is going to be very big, you'd store everything inside data libraries.
 

Bentley

Member
If you press right, you move the background left and tell all the instances in the room to move left as well (subtract from their x-coordinates).

The controller would check if a background has moved too far in a particular direction and then wrap it to the other side of the room.

Same with enemies.
Awesome. Thanks for the help. Solved.
 
Top