Roguelike Questions(or Answers?)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Aristarh
Posts: 11
Joined: Wed Jul 14, 2010 3:47 pm
Location: Penza

Roguelike Questions(or Answers?)

Post by Aristarh »

Hello Everyone! Don't worry I will not ask how make Roguelike. My humble request is how Better do it. I don't ask bunch a code just a advice.
Prelude :

So in theory we need a Tile class/struct and a TileMap array contains a Tiles

For example:

Code: Select all

 
#define MapW   5
#define MapH   5
#define TileSize 50.f
struct Tile
{
int i,j;//Tile coords in TileMap
bool walkable; //can we walk there?
};


Tile TileMap[MapW][MapH];

void initTileMap()
{
for (int x=0;x<MapW;x++)
	{
		for(int y=0;y<MapW;y++)
		{
			tilemap[x][y].walkable=true;
			tilemap[x][y].i=x;
			tilemap[x][y].j=y;
                 }
       }
}
Question No 1: What use to visualize our Tile?
Suggestion No 1: Use addHillPlaneMesh like this:

Code: Select all

struct Tile
{
bool walkable;
int i,j;
ISceneNode* node;
};

Tile TileMap[MapW][MapH];

void initTileMap()
{
IAnimatedMesh* floor=managerScene->addHillPlaneMesh("floor", 
                           core::dimension2d<f32>(50.f,50.f), // Tile size
                           core::dimension2d<u32>(1,1), // Tile count
                           0, // Material
                           0.0f, // Hill height
                           core::dimension2d<f32>(0.0f, 0.0f), // countHills
                           core::dimension2d<f32>(1.f,1.f));// texture repeat

for (int x=0;x<MapW;x++)
	{
		for(int y=0;y<MapW;y++)
		{
			TileMap[x][y].walkable=true;
			TileMap[x][y].i=x;
			TileMap[x][y].j=y;
tilemap[x][y].node=managerScene->addAnimatedMeshSceneNode(floor);
tilemap[x][y].node->setMaterialTexture
(
0, driverVideo->getTexture("floor.bmp")
);
tilemap[x][y].node->setPosition(vector3df(x*TileSize,0.f,y*TileSize));
tilemap[x][y].node->setMaterialFlag(EMF_LIGHTING, false);
                 }
       }
}
Note No 1: But if we have 100*100 TileMap then we have 100*100 ISceneNodes this is bad for perfomance i think.
Suggestion No 2: Use ITerrainScene node and create an *Imaginary* Tiles like this:

Code: Select all

ITerrainSceneNode* nodeTerrain = managerScene->addTerrainSceneNode(
		"terrain-heightmap.bmp",
		0,
		-1,
		vector3df(0.f, 0.f, 0.f)
		,vector3df(0.f, 0.f, 0.f),
		vector3df(40.f, 4.f, 40.f),
		SColor ( 255, 255, 255, 255 ),
		5,
		ETPS_17,
		4);

	nodeTerrain->setMaterialFlag(EMF_LIGHTING, false);

	nodeTerrain->setMaterialTexture(0,driverVideo->getTexture("terrain-texture.jpg"));
	nodeTerrain->setMaterialTexture(1,driverVideo->getTexture("detailmap3.jpg"));
	
	nodeTerrain->setMaterialType(EMT_DETAIL_MAP);
	nodeTerrain->scaleTexture(10.0f, 20.0f);

position3df objectPos;
 int TileX=(int)objectPos.X/TileSize;
 int tileY=(int)objectPos.Y/TileSize;
//if object have position (100.f,10,223.f) then
it on tile (2,4)
position3df TileCenter=position3df(TileX*TileSize/2,0.f,TileY*TileSize/2)
Note No 2:But how on TerrainNode create different floors like on Tile x:2 y:3 texture is marble floor on x:3 y:1 there is oak floor?
Question No 3: How set for one node several meshes on it? e.g. we have HillPlaneMesh textured and wanna a chest on it or door on 1 TileNode, but door and Hillplane position change with node->setPosition, how position them separately?

P.S I downloaded Nethack3D Sources created with Irrlicht on SourceForge, but they very complicated, maybe there is better example?.
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

answer for question number 3:
just make the meshes children of the HillPlaneMesh.(node->setParent(...)) and they'll move automatically
Image
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

you can just save a few more variables in your struct for example texture, blablabla and then when you load the level you just draw 2d images accordingly you don't even need to use a 3d scene node for this unless you're making a 3d game (but i don't see z-axis in your function). check out tutorials from 2d engines like SDL, the approach is the same.
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
constchar*
Posts: 14
Joined: Thu Sep 20, 2007 3:57 am

Post by constchar* »

I'm building something somewhat similar (tile-based map data).
What I did was I divided the map into 16x16 chunks, and each chunk is a custom scene node responsible for managing its portion of the map (building, rendering, etc..).

So far it seems to work fairly well.
Post Reply