Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Zelda-style Tile Engine  (Read 4803 times)

0 Members and 1 Guest are viewing this topic.

DefaultAlias

Zelda-style Tile Engine
« on: May 12, 2010, 04:32:36 am »
Hey guys! let me begin by saying how cool i think this place is and i'm glad i found it.

About a week ago i got an itch to build something nostalgic, so i decided to start a top-down adventure game. I'm breaking it down into several self contained modules that i'll probably release open-source once i've had my fun with them.

To start, i'm working on a tile engine similar to the GBC Zelda titles. It's designed to manage map tiles, object placement, screen scrolling, and 2D collision. I'm leaving out specific hooks to any rendering API and instead i'm going to try and implement something that makes it easy to add your own pretty easily.

The plan is to keep the code small, use OOP best as i can, and provide a fairly high-level interface to it all so i don't have to muck around in needless details when using it.

I hope to have something for Z3 or whatever that contest is around here. Here's hoping i don't get bogged down at work :)

Also, some shots of the tileset i'm working on. The test scenario will be a 3D version of the lost woods in OOS.


Tree

Original Scene
« Last Edit: May 12, 2010, 04:59:27 pm by 4Sword »
Logged
Re: Zelda-style Tile Engine
« Reply #1 on: May 12, 2010, 05:05:21 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I'm surprised that no one has replied to this yet; also I took the liberty of altering the image tags so that they'd be visible. I am not right exactly sure if new users are able to post images that way, the BB image tags work, trying to do in in HTML will not. Anyway, your project reminds me of Flying Rooster which is in the Zelda WIP section in how both use 3D and texture style and usage. But overall what you said in your post makes it seem like you have a good start.
Logged

Xiphirx

wat
Re: Zelda-style Tile Engine
« Reply #2 on: May 12, 2010, 07:14:00 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
You look like a hardcore programmer DefaultAlias. Your project is interesting as well, and I am looking forward to seeing where it goes. I love the art style so far.

Oh, welcome to ZFGC, once you're in, you're never out. ;)
Logged
  • For The Swarm

DefaultAlias

Re: Zelda-style Tile Engine
« Reply #3 on: May 13, 2010, 02:56:40 am »
Thanks guys.

I wouldn't say i'm hardcore or anything Xiphirx, i just know enough to get by with.

I have a question for all you guys out there that have written tile based games: how do you implement scrolling, and how do you store your map vs screen in memory? The screen (what's visible to the player) is like a window into the much larger map. Maps i'm assuming are static and usually stored on the disk to begin with, and the screen is constantly being re-created. So what are some ways you've seen these implemented?

One idea i had is to read in the map from a file as i need it to populate some kind of 2D array or linked list that will represent the screen. To prevent a lot of io operations, i'd probably chunk up the map into sections and load/unload them as i need them. Maybe keep like the nearest 9 chunks in memory and change them out when the player enters a new sector.

Any thoughts are appreciated.
Logged

Xiphirx

wat
Re: Zelda-style Tile Engine
« Reply #4 on: May 13, 2010, 02:59:50 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Thanks guys.

I wouldn't say i'm hardcore or anything Xiphirx, i just know enough to get by with.

I have a question for all you guys out there that have written tile based games: how do you implement scrolling, and how do you store your map vs screen in memory? The screen (what's visible to the player) is like a window into the much larger map. Maps i'm assuming are static and usually stored on the disk to begin with, and the screen is constantly being re-created. So what are some ways you've seen these implemented?

One idea i had is to read in the map from a file as i need it to populate some kind of 2D array or linked list that will represent the screen. To prevent a lot of io operations, i'd probably chunk up the map into sections and load/unload them as i need them. Maybe keep like the nearest 9 chunks in memory and change them out when the player enters a new sector.

Any thoughts are appreciated.

Im currently developing a 2d Tile map editor. I have two variables, scrLeft and scrTop. These are the offsets from the top left corner of the map. So, you would draw in relation to those variables. I believe its something like (i*tile_dim)+scrLeft, I'm at college without my source code. Anyway, its also helpful to only draw what is on the screen, and not the whole map.
Logged
  • For The Swarm

Mamoruanime

@Mamoruanime
Re: Zelda-style Tile Engine
« Reply #5 on: May 13, 2010, 03:07:45 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Thanks guys.

I wouldn't say i'm hardcore or anything Xiphirx, i just know enough to get by with.

I have a question for all you guys out there that have written tile based games: how do you implement scrolling, and how do you store your map vs screen in memory? The screen (what's visible to the player) is like a window into the much larger map. Maps i'm assuming are static and usually stored on the disk to begin with, and the screen is constantly being re-created. So what are some ways you've seen these implemented?

One idea i had is to read in the map from a file as i need it to populate some kind of 2D array or linked list that will represent the screen. To prevent a lot of io operations, i'd probably chunk up the map into sections and load/unload them as i need them. Maybe keep like the nearest 9 chunks in memory and change them out when the player enters a new sector.

Any thoughts are appreciated.

Im currently developing a 2d Tile map editor. I have two variables, scrLeft and scrTop. These are the offsets from the top left corner of the map. So, you would draw in relation to those variables. I believe its something like (i*tile_dim)+scrLeft, I'm at college without my source code. Anyway, its also helpful to only draw what is on the screen, and not the whole map.

I always use a 1d array for my tiles :s personal preference I guess; but then again, I don't use Gamemaker either D:
Logged

Xiphirx

wat
Re: Zelda-style Tile Engine
« Reply #6 on: May 13, 2010, 06:56:03 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Who uses Game Maker D:?

;)
Logged
  • For The Swarm

Mamoruanime

@Mamoruanime
Re: Zelda-style Tile Engine
« Reply #7 on: May 13, 2010, 07:29:09 pm »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Who uses Game Maker D:?

;)

Oh I totally thought I saw the gamemaker icon :P
Logged

DefaultAlias

Re: Zelda-style Tile Engine
« Reply #8 on: May 13, 2010, 09:17:05 pm »
Nah man, I'm just using C++. I tried GameMaker once upon a time and i didn't like it.

Never thought about using a 1d array though. I might mess around with that some. When you need to know what tile is at a specific coordinate, how do you go about retrieving it?
Logged
Re: Zelda-style Tile Engine
« Reply #9 on: May 13, 2010, 10:08:45 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I would use a 2D array. I would make several maps for each area of the overworld depending on the theme and dungeon floors. Load the entire map data for each part. And then use screenX and screenY to get what part needs to be drawn. To get the indexes of where to start in the array use the following:

Xindex = (int)(screenX/tilesize)
Yindex = (int)(screenY/tilesize)
Logged

Mamoruanime

@Mamoruanime
Re: Zelda-style Tile Engine
« Reply #10 on: May 13, 2010, 10:17:48 pm »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Never thought about using a 1d array though. I might mess around with that some. When you need to know what tile is at a specific coordinate, how do you go about retrieving it?

Usually it's just a matter of saving their array slot position with the tile itself, and simply checking the tile ID with the room's size. Basically just room width*height will give you the amount of slots you need for your array, and to get a Tile's x/y, you simply compare the number to the number of tiles per col and how many per row :p

Never really saw the point in using a 2d array when your rooms are the same size and tile positions don't step outside of the set gridsize. Especially with 2d Zelda games :p
Logged
Re: Zelda-style Tile Engine
« Reply #11 on: May 14, 2010, 12:47:26 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
I imagine that using a 1d array would be faster based on the fact that, at least in c, in order to allocate a 2d array it requires an extra loop.  Otherwise, AFAIK there is no difference.
Logged

DefaultAlias

Re: Zelda-style Tile Engine
« Reply #12 on: May 17, 2010, 02:29:19 am »
Sorry for the lack of updates.

Here's what's done so far:
-Rough file format (will probably need to be revised)
-Loading tiles from the file based on coordinates
-Skeleton of the screen and map objects
-Rough interface design is complete

So i've got the rough skeleton worked out and i'm filling it all in now. My engine uses 2 main concepts right now: a map, and a screen.

The map is a global look at the world, and it's primary purpose is retrieving data from a map file. It can do this on a per-tile basis, or in chunks called sectors which are basically just arrays of tiles. It's pretty simple and straightforward.

The screen is a small view into the map, and this can be moved around in the world. It's main purpose is to maintain and update an array of tiles that represent what the screen can see.

It begins by requesting the nearest 9 sectors from the map, and loads/unloads them as it moves into other sectors. This helps prevent a lot of read operations at the expense of memory. Currently i'm filling an array with the tiles that are visible to the screen, but it's not efficient. It's got some overhead memory wise, and the screen object needs to keep it updated which is costly. So next up is to replace this array with a method that will perform the simple math to grab a tile from the screen object on request.

C&C on the design so far is welcome.

EDIT:
I coded some stupid stuff last night and didn't comment any of it. It works for the most part, but it's so messy and i have no clue what the hell i was trying to do. So i removed a lot of the code, simplified the sectors idea, and extended the file format to include the sector info explicitly instead of trying to generate the info on the fly.

EDIT:
And now i'm done with the map class for the most part. Onto the screen class. I've also realized i'm going to need to create a map editor somewhere down the line..

Btw, what's the policy on double posting?
« Last Edit: May 23, 2010, 10:43:34 pm by DefaultAlias »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.34 seconds with 64 queries.