Jump to content


Photo

Random Terrain Using Tiles


  • Please log in to reply
8 replies to this topic

#1 d2theRizzle

d2theRizzle

    GMC Member

  • GMC Member
  • 65 posts
  • Version:GM8.1

Posted 24 July 2013 - 11:14 PM

Hello GMC. I have been messing around with some random terrain features in Game Maker, such as polishing it up and adding caverns as well. However, I realized that even while deactivating the instances outside the view, there was still some significant lag. So I thought, could this be done using tiles?

 

I tried to recreate my terrain generation using tiles, so I basically changed "instance_create" to "tile_add". And, the basic generation works, but now I am questioning whether I'll actually be able to implement all the features I need, such as creating/destroying tiles, collisions/movement, etc.

 

I'd appreciate anyone's input on whether these features could be achieved, or any alternate routes to take.

 

Thanks!

 

BTW I'm using GM 8.1 Lite


Edited by d2theRizzle, 24 July 2013 - 11:14 PM.

  • 0

#2 Emzeror

Emzeror

    Spirit Knight

  • GMC Member
  • 158 posts
  • Version:GM8.1

Posted 24 July 2013 - 11:44 PM

Hello d2theRizzle,

 

Do it without tiles or objects like this.

for (x_ = 0; x_ < tiles_x; x_ += 1) {
    for (y_ = 0; y_ < tiles_y; y_ += 1) {
        world_map[x_, y_] = 0;
    }
}

Store the id of the tile in a multi-dimensional array (can be done with a single-dimensional) then use a controller to manipulate them.

 

This is probably thousands of times faster than objects, as you now only need to work with numbers.

 

Example

On your tile Controller

tile[0, 0] = 0;
tile[0, 1] = "Grass";
tile[0, 2] = spr_grass;
tile[1, 0] = 1;
tile[1, 1] = "Mountain";
tile[1, 2] = spr_mountain;

On your World Map Generator

world_map[2,2] = 1;
world_map[2,3] = 1;
world_map[3,2] = 1;
world_map[3,3] = 1;

On the object you want to draw the map

for (x_ = 0; x_ < tiles_x; x_ += 1) {
   for (y_ = 0; y_ < tiles_y; y_ += 1) {
      draw_sprite (tile_controller.tile[world_map[x_, y_],2], 0, x_*32, y_*32);
   }
}

What it does is that it goes through your world_map array and draws all the tiles, without actually having tiles or objects involved.

 

Emzeror


  • 0

#3 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 10230 posts
  • Version:GM8

Posted 25 July 2013 - 12:05 AM

FYI, as I've come to learn, if you're going to run your game faster than, oh say, 200 FPS (some people do for some reason), you need to create backgrounds from the tile layers and then hide the tile layers (don't delete them, just hide them). And anytime you change the tiles around, you'll need to do the same thing. At 60 FPS, it's not really noticeable, but over 100 FPS tiles can generate a lot of slowdown in the Draw Event -- a llllooootttt of slowdown. FYI the typical console game is, or was, 60 FPS.

 

And yes, anything you can do with objects you can do with tiles.


  • 0

#4 d2theRizzle

d2theRizzle

    GMC Member

  • GMC Member
  • 65 posts
  • Version:GM8.1

Posted 25 July 2013 - 12:50 AM

Hello d2theRizzle,

 

Do it without tiles or objects like this.

for (x_ = 0; x_ < tiles_x; x_ += 1) {
    for (y_ = 0; y_ < tiles_y; y_ += 1) {
        world_map[x_, y_] = 0;
    }
}

Store the id of the tile in a multi-dimensional array (can be done with a single-dimensional) then use a controller to manipulate them.

 

This is probably thousands of times faster than objects, as you now only need to work with numbers.

 

Example

On your tile Controller

tile[0, 0] = 0;
tile[0, 1] = "Grass";
tile[0, 2] = spr_grass;
tile[1, 0] = 1;
tile[1, 1] = "Mountain";
tile[1, 2] = spr_mountain;

On your World Map Generator

world_map[2,2] = 1;
world_map[2,3] = 1;
world_map[3,2] = 1;
world_map[3,3] = 1;

On the object you want to draw the map

for (x_ = 0; x_ < tiles_x; x_ += 1) {
   for (y_ = 0; y_ < tiles_y; y_ += 1) {
      draw_sprite (tile_controller.tile[world_map[x_, y_],2], 0, x_*32, y_*32);
   }
}

What it does is that it goes through your world_map array and draws all the tiles, without actually having tiles or objects involved.

 

Emzeror

 

 

Thanks for the reply. This sounds like the best way to do it, but I'm a little confused what to do with tiles_x and y. Im not sure where to make them, or what to set their value to.


  • 0

#5 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 10230 posts
  • Version:GM8

Posted 25 July 2013 - 02:26 AM

Could probably just replace tiles_x and tiles_y with room_width and room_height respectively. Also x_+=1 seems kinda overkill. Could probably get away with x_+=16 or whatever the width of your tiles is.

 

Ah! I think I understand maybe what he was doing. Since you're procedurally generating the room, tile_x would be how wide the parcel of room is and tile_y would be how high the parcel of room is. So if you're adding a 128x48 hallway, you'd set tile_x to 128 and tile_y to 48.


Edited by TheouAegis, 25 July 2013 - 02:28 AM.

  • 0

#6 d2theRizzle

d2theRizzle

    GMC Member

  • GMC Member
  • 65 posts
  • Version:GM8.1

Posted 25 July 2013 - 02:56 AM

Could probably just replace tiles_x and tiles_y with room_width and room_height respectively. Also x_+=1 seems kinda overkill. Could probably get away with x_+=16 or whatever the width of your tiles is.

 

Ah! I think I understand maybe what he was doing. Since you're procedurally generating the room, tile_x would be how wide the parcel of room is and tile_y would be how high the parcel of room is. So if you're adding a 128x48 hallway, you'd set tile_x to 128 and tile_y to 48.

 

 

I just changed them to the room width and height, and now it says unknown variable "worldmap" or out of index... I put the draw event on the world map object, because I didn't think it would really matter. but i'm not sure...


Edited by d2theRizzle, 25 July 2013 - 02:57 AM.

  • 0

#7 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 10230 posts
  • Version:GM8

Posted 25 July 2013 - 03:19 AM

How big is your room?

 

Wait, sounds like the object or event you put worldmap in hasn't been called yet. Make sure you don't put ANY of that code in a Step-class Event.


Edited by TheouAegis, 25 July 2013 - 03:20 AM.

  • 0

#8 d2theRizzle

d2theRizzle

    GMC Member

  • GMC Member
  • 65 posts
  • Version:GM8.1

Posted 25 July 2013 - 02:53 PM

How big is your room?

 

Wait, sounds like the object or event you put worldmap in hasn't been called yet. Make sure you don't put ANY of that code in a Step-class Event.

 

 

It's not, it's in the create event, except for the two for statements and the draw_sprite function.

Also, my room is the standard 640 x 480.


  • 0

#9 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 10230 posts
  • Version:GM8

Posted 26 July 2013 - 01:13 AM

It looks like the guy used at least 2 objects in his code, possibly 3. The issue is worldmap is being created in an event that hasn't run yet or in an object that hasn't been created yet. Thus the code that reads worldmap is being processed before it was ever set. ... Although the more I look at his code, the more tedious it seems. The logic is there, though.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users