Ok, I get the map concept. Thank you both.
EDIT: I figured out how to read/write from text files.
(Important)
Ok so I looked some other people's code and I understand the 2D Array. But I can't seem to get the draw to work. Can someone give me a basic example of what the code actually is.
int TownA[10][10]=
{{1,1,1,1,1,1,1,1},
{1,2,2,1,2,2,2,1},
{1,2,2,1,2,2,2,1},
{1,2,2,1,2,2,2,1},
{1,2,2,1,2,2,2,1},
{1,2,2,1,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1}};
Ok, so here is my code.
game.cpp This draws picture 1.
#include "functions.h"
//////////////////////
// INITIATE //////////
//////////////////////
void Init()
{
dbSyncOn();
dbSetDisplayMode(SCREENWIDTH,SCREENHEIGHT, DISDEPTH);
InitLoadObjImages();
InitLoadMapImages();
}
void InitLoadObjImages()
{
}
void InitLoadMapImages()
{
dbLoadImage("Grass.bmp", 2);
dbLoadImage("Wall.bmp", 1);
dbLoadImage("Dirt.bmp", 3);
}
////////////////////
// Map /////////////
////////////////////
void drawMap(int TX, int TY)
{
int a = DEFMAPMIN;
int b = OBJMAPMIN;
int x = TX;
int y = TY;
int z = 0;
int SCREENPOSITIONX = 0;
int SCREENPOSITIONY = 0;
int (*MapArray) [10];
MapArray = firstTown;
if(MapArray[y][x]==1)
{
dbSprite(1, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
if(MapArray[y][x]==2)
{
dbSprite(2, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
if(MapArray[y][x]==3)
{
dbSprite(3, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
}
///////////////////
// GAME ///////////
///////////////////
void DarkGDK()
{
Init();
while(LoopGDK())
{
drawMap(TX,TY);
dbSync();
}
}
game.cpp EDIT: This is my new one to try and make it draw each array point, but all it does is draw the grass tile instead of the wall.
Picture 2
#include "functions.h"
//////////////////////
// INITIATE //////////
//////////////////////
void Init()
{
dbSyncOn();
dbSetDisplayMode(SCREENWIDTH,SCREENHEIGHT, DISDEPTH);
InitLoadObjImages();
InitLoadMapImages();
}
void InitLoadObjImages()
{
}
void InitLoadMapImages()
{
dbLoadImage("Grass.bmp", 2);
dbLoadImage("Wall.bmp", 1);
dbLoadImage("Dirt.bmp", 3);
}
////////////////////
// Map /////////////
////////////////////
void drawMap(int TX, int TY)
{
int a = DEFMAPMIN;
int b = OBJMAPMIN;
int x = TX;
int y = TY;
int z = 0;
int SCREENPOSITIONX = 0;
int SCREENPOSITIONY = 0;
int (*MapArray) [10];
MapArray = firstTown;
for (int x=0; x<8; x = x++)
{
for (int y=0; y<8; y++)
{
if(MapArray[y][x]==1)
{
dbSprite(1, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
if(MapArray[y][x]==2)
{
dbSprite(2, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
if(MapArray[y][x]==3)
{
dbSprite(3, SCREENPOSITIONX, SCREENPOSITIONY, MapArray[y][x]);
}
}
}
}
///////////////////
// GAME ///////////
///////////////////
void DarkGDK()
{
Init();
while(LoopGDK())
{
drawMap(TX,TY);
dbSync();
}
}
And here is my functions.h file
#include "DarkGDK.h"
////////////////////
// GLOBALS /////////
////////////////////
int TX=0,TY=0;
////////////////////
// DEFINITIONS /////
////////////////////
#define PLAYERSPRITEID 1
#define PLAYERIMAGEID 1
#define PLAYERIMAGEFILE "images/Wizard.bmp"
#define SCREENHEIGHT 200
#define SCREENWIDTH 200
#define DISDEPTH 32
#define DEFMAPMIN 100
#define OBJMAPMIN 200
////////////////////
// INIT ////////////
////////////////////
void Init();
void InitLoadObjImages();
void InitLoadMapImages();
////////////////////
// GAME ////////////
////////////////////
void DarkGDK();
////////////////////
// MAP /////////////
////////////////////
//enum ZoneID{firstTown);
//ZoneID iZoneID;
int firstTown[10][10]=
{{1,1,1,1,1,1,1,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,1}};
void drawMap(int TX, int TY);
Picture 1.
Picture2
EDIT: Ok, so I figured out how to somewhat draw the tiles. But I have a problem when I run them. The first one draws the correct tile, but only draws the top left one. And the second one draws the wrong tile, and only draws the top left one. If someone can tell me where i am going wrong or how draw the full array correctly i would appreciate it.