Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Bob The Hun on Thu 26/06/2003 04:25:09

Title: 2D arrays [A large field with interactive tiles]
Post by: Bob The Hun on Thu 26/06/2003 04:25:09
First, to better explain what I'm getting at here, I'll give some backstory.
The other day I was playing 'Vegetable Patch Extreem Turbo', and it sorta reminded me of the old game 'Harvest Moon'. So, I fired up the old Super Nintendo and played it for awhile. (for those of you not familiar with the game, it was a farming simulator, think VPET on a much larger scale, along with social elements similar to those of games such as Animal Crossing and The Sims) While playing it, I started thinking about if a similar game would be possible with AGS.
I've come up with a way for everything to work in such a game except for the large field, which is the very backbone of the game itself.
In other words, I'm wondering if it's possible to make a field with tiles that could have their status changed (i.e., they might start out full of weeds, you could pick the weeds to get clear ground, break the ground with a hoe, sow the seeds, etc.)
I couldn't think of anyway to accomplish this on such a large scale (since instead of 9 tiles like VPET, there would be hundreds)

Is there any way to accomplish this?
Title: Re:A large field with interactive tiles-is it possible?
Post by: Squinky on Sun 29/06/2003 08:16:04
I think you could do it with what all these smarty-arty guys around here call arrays...
Title: Re:A large field with interactive tiles-is it possible?
Post by: evilspacefart on Sun 29/06/2003 10:05:25
is it possible to use 2 dimension arrays?  ???
example:

int tile(100,100) = 5; //set tile at x 100 and y 100 to status 5 or whatever you want.

that's the only way i see it so far.
Title: Re:A large field with interactive tiles-is it possible?
Post by: Scorpiorus on Sun 29/06/2003 12:37:20
Yep, in order to implement tiled engine you need an array + raw* family functions (ex: RawDrawImage()). The last however could slowdown a game in case the game is run at high resolutions and has too much sprites drawn per game loop.

Quoteis it possible to use 2 dimension arrays?
example:

int tile(100,100) = 5; //set tile at x 100 and y 100 to status 5 or whatever you want.

that's the only way i see it so far.
It's possible. Actually having an ability to use 1D arrays is the only condition has to be true to create any-dimension arrays. Technically any-dimension array are represented as one 1D array because of "linear" memory structure.

Example of the implementaion of 2D array:



//main global script:

#define TILES_WIDTH  200
#define TILES_HEIGHT 200

// the value of TILES_TOTAL always must be TILES_WIDTH*TILES_HEIGHT
#define TILES_TOTAL 40000

int tile[TILES_TOTAL];

function SetTile (int i, int j, int value) {
 if (i<0 || i>=TILES_HEIGHT || j<0 || j>=TILES_WIDTH) {
   Display("error: out of bounds"); QuitGame(0);
 }
 tile[i*TILES_WIDTH + j] = value;
}

function GetTile (int i, int j) {
 if (i<0 || i>=TILES_HEIGHT || j<0 || j>=TILES_WIDTH) {
   Display("error: out of bounds"); QuitGame(0);
 }
 return tile[i*TILES_WIDTH + j];
}

//script header:

import function SetTile (int i, int j, int value);
import function GetTile (int i, int j);




so equivalent of tile(100,100) = 5 would be SetTile(100,100,5);
to store an array value in a variable:
int status = GetTile(100, 100);

but, as scotch pointed out, it would take a lot of work, especially if you want to add interactability to that map.

-Cheers
Title: Re:A large field with interactive tiles-is it possible?
Post by: evilspacefart on Sun 29/06/2003 18:12:52
that's awesome. good idea using functions instead of vars.
Title: Re:A large field with interactive tiles-is it possible?
Post by: Ghormak on Sun 29/06/2003 19:26:08
I used a kind of tile-system in Moose Wars, by faking a 2d-array much like Scorpiorus described.

So yes, I do think it would be possible. Not easy, but possible.

Title: Re:A large field with interactive tiles-is it possible?
Post by: cornjob on Mon 30/06/2003 00:50:08
Yeah, I did try this a small one-screen grid. Using Rawdrawing to put down each tile shouldn't be slow. Of the Raw functions, I think RawRestoreScreen is the only slow one. Just dropping down sprites should be fast. Now making certain tiles block the player's movement, that's more of a challenge.

By the way, I was also thinking about Harvest moon a while ago, even before Mostly's Veggie Patch. Harvest Moon is almost like a combination of simulation and adventure already...
Title: Re:A large field with interactive tiles-is it possible?
Post by: Bob The Hun on Mon 30/06/2003 04:48:46
 ;D
Yay! It is possible!
It's a low-res game, so it shouldn't cause slowdown too much.
Thanks everybody!
Title: Re:A large field with interactive tiles-is it possible?
Post by: Scorpiorus on Mon 30/06/2003 10:26:47
Yep, RawRestoreScreen() is slow, but in case the tiled sprites cover the whole screen you even do not need to restore the original screen so you don't need to call RawRestoreScreen() at all. As about RawDrawImage() it become slow when it repeatedly fills the screen with, for example, 20x20 sprites at 640x480 resolution and 16bit colour depth. Here I assume you redraw the map every game loop (in repeatedly_execute) which might be useful for it to scroll smoothly. If you needn't it's scrolling then there is no problem at all. You just draw the tiled map once the player enters the room.
Using the low resolution (or 8bit colors) will rise performance as well.

As about collisions the easiest way would be assume that the tile is a rectangular area which can or not block the character's movements. :P

-Cheers