I see, if it wasn't a continuous scrolling thingy, the answer would be easy just a got to layout "room"&random(roomcount) but here it's something else.
Hmmm I know
You need to use two dummy sprite which would be used as a start and end point
You need to use the same objectType for ALL the elements of your room.
Just use differents animation Frame with an animation speed set to 0
And set the initial frame (in property panel) to the corresponding frame for the object you want to use
This unique sprite will have an instance variable named 'room' of type number which will hold the number of the room.
You will have the startDummy positionned at the connexion point between two room at the far left, and the endDummy positionned at the connexion point between two rooms at the far right
Each Dummy object will also have an instance variable named 'room'
The idea is that at start of frame you'll create an array with all the positions relative to startDummy (this dummy will drive all the room) and all the corresponding animation (to have the right image showing) if you use different angles you'll also have to store them.
In practice that should look like :
System: on start of layout
System: foreach startDummy
Sprite: room = startDummy.room
System: foreach sprite
-> Array: Set value at (startDummy.room,loopindex+1,0) to sprite.X-startDummy.X
-> Array: Set value at (startDummy.room,loopindex+1,1) to sprite.Y-startDummy.Y
-> Array: Set value at (startDummy.room,loopindex+1,2) to sprite.animationFrame
// Storing the number of object+1
-> Array: Set value at (startDummy.room,0,3) to loopindex+1
endDummy: room = startDummy.room
-> Array: Set value at (startDummy.room,0,0) to endDummy.X-startDummy.X
-> Array: Set value at (startDummy.room,0,1) to endDummy.Y-startDummy.Y
// Cleaning up
-> startDummy: destroy
-> endDummy: destroy
-> sprite: destroy
Basically the Array will then contain a map of each room with the startDummy as an origin. And in the first index, you'll have the X and Y position where you have to attach the next room.
Now to spawn rooms, you'll have to keep in check the position of the next room to spawn in two variable (for X and Y) (maybe if it's all at the same height level you can avoid storing/using Y)
And You'll have to loop through all the values of a room stored in the array, create Sprite, position it from the current new room to spawn, and set the proper animation frame.
Let see
Global Variable nextX = 0 //X position of the nextRoom
Global Variable nextY = 0 //Y position of the nextRoom
// next room is near the border of the window
// spawn another room
// (I assume you always scroll to player and I add 100 as a security margin)
System: nextX < Player.X+WindowWidth/2+100
Local Variable randRoom=0 // which room?
// random(5) will return a random number from 0 to 4
-> Set randRoom to random(5)
// create the room
System: for "" from 1 to Array(randRoom,0,3)
-> System: Create Sprite on layer "rooms" at nextX+Array(randRoom,loopindex,0),nextY+Array(randRoom,loopindex,1)
-> Sprite: set animation frame to Array(randRoom,loopindex,2)
// store the end point of the new room
-> System: set nextX to Array(randroom,0,0)
-> System: set nextY to Array(randroom,0,1)
And that should basically be it
Now there's still 2 issues :
- The first one is zIndex dunno how the script will behave... maybe pretty well, else you might have to use layer and also store layer position to create in the right one.
- The second one is collisions, you might create invisible collisions and store their position to the startDummy the same way... But in another Array.
Tell me if it worked, I just wrote it as it came :D