Starting the Project
So the next thing we’re going to do is we’re going to add some items to create the Rooms first. So to do that, we need to add a few things. So first, we will add a System and choose On start of layout.
Technically, you don’t need to make it a layout. You can call this a function if you want to redraw it. But for now, you can make it in a layout style and what we need is a nested For Loops. So we’re going to add a sub-condition, and we’re going to go to System and choose For Loops.
We call this LoopX, which will loop X from one to a hundred.
Now you can play with these numbers here. You can even turn them into variables. And inside this LoopX, we will immediately add a sub-condition to this Loop.
And we’ll call this LoopY and do it again from one to a hundred. So we will make this Room reasonably large.
So that means we need to add the rest of the code here. Now let’s add an object. We go to System and select Create object, and that object will be Wall.
We will create the Wall. So the X here will be 32. And the reason why we made it 32 is that the width of that Wall is 32. And if you create LoopX, you will only generate x values. So LoopY is for generating both x and y.
Now again, if you run this.
They won’t work. So obviously we have a lot more to do. We have Loops.
I will close that up.
I will add a sub-condition again, and this is another For Loops, which will be a LoopRoom, which is from one to ten.
And then this one is that we’re going to create the Room. We’re going to go to the System and create an object, and that object, of course, will be the Room.
And the Room here is just going to be made 0 0. That’s everything there. Now next thing we’re going to do is set up the Room and the ID.
And to make this Room work, let’s add an instance variable.
So we need to number these Rooms by an ID.
So we’re going to set the Room.
The value of the ID is LoopRoom.
The LoopRoom ID is from one to ten. So, we’ve created the fifth instance of LoopRoom. And then, we need to set the size.
So we’ll go to Room and set size.
And we can make this, for instance, random. And we’ll make it 50 by 150.
So we’re going to be making random size rooms. Remember, this Loop goes around one to ten times, so each Room created is a different size. So the next thing is we will add a Room and set position.
And we’re just going to set up a random Room here.
Then we need to generate the RoomCenter. So we’re going to go to Room and spawn another object, RoomCenter.
Now, the other thing we need to do is add an instance variable to the RoomCenter.
And we’ll call it ID.
And we will also have to set the value for RoomCenter.
It will also create RoomCenter.
As you can see here, it isn’t straightforward. So the next thing is to add a sub-condition from RoomCenter and compare the instance variable, then set the value to 1.
If the ID number equals 1, we will set the ID value to 10.
It still needs to be completed; we need to add more to see this work in the next section.