Jump to content
  • Advertisement
Sign in to follow this  
Twiggy

Highschool student starting work on a project and seeking info, please help!

This topic is 5216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You need a million HDC and HBITMAP objects if you're gonna write this in Win32. DO NOT USE Win32. Your timespan is very limited, so go with SDL. It doesn't have a large learning curve(Direct3D/DirectDraw/OpenGL do have larger curves then SDL).

SDL is very easy to use, there are a million articles out there, and more important, there are also alot of libraries for it. I bet someone wrote an SDL GUI library which you can use.

Toolmaker

Share this post


Link to post
Share on other sites
Advertisement
Yeah, i think i'll stick with SDL. I don't have the time to spend on learning Win32. I really need to get goind, and still have to learn C++ on the way.

Anywayz, please post links to articles of the things i need, if you have, please.

Share this post


Link to post
Share on other sites
Ok here is my opinion base on my experience. I think Winapi knowledge is not required, you just have to learn some simple stuff, like creating windows, working with messages etc. But still understanding and learning this would take you about 1 month of time minimum , OpenGl is another fast way to start programming games , it took me about 1 month to learn some basic things.I firstly started learning directdraw , but it is really limited , doesn't have basic functions like putpixel , rotation is slow .So direct3d or opengl is better choice. For me openGl is the simpliest and the most easy to learn.

Here is the best place to learn OpenGL -> NeHe

Share this post


Link to post
Share on other sites
But dude, OpenGL is basically for 3d, and i don't need that in my game. SDL is a simplier, more comfortable thing for me to learn.

Share this post


Link to post
Share on other sites
SDL uses OpenGL and textured quads(IIRC). But the point is, he doesn't have to spent alot of time setting up OGL, learning how to do quads, etc.

Toolmaker

Share this post


Link to post
Share on other sites
Calm down Twiggy. See what you can get out of the functionality SDL provides. Whether SDL uses DirectDraw or OpenGL internally is not important - treat it as a blck-box that does the dirty work for you.

I'd *suggest* starting with a design doc for your game project. Figure out exactly what you want to achieve and try some basic functions to see how it can be done with SDL. You can still remove items from your initial design later, so don't make it too minimalistic.

A simple top-down map can be produced out of text files so you won't need any sophisticated editors for starters:

file: simplemap.txt
Simple Map
16
8
MMMMMMMMMMMMMMMM
....t.t........M
.....t..........
...t...t....M...
.............M..
................
.....======.....
....========....

In the above sample, dots ('.') are representing ground tiles (e.g. dirt or grass), t's are trees, M's are mountains and equal signs ('=') are water.
A very rudimentary map loader could look like this:

file: maploader.c

#define MAX_TILE_TYPE = 5;
#define EMPTY_TILE = 0;
#define GRASS_TILE = 1;
#define TREE_TILE = 2;
#define MOUNTAIN_TILE = 3;
#define WATER_TILE = 4;

// a tile
typedef struct __Tile {
int type; // ground, water, mountain, tree
int unit; // type of the unit that is on this tile
SDL_Surface *image; // tile image - will be setup seperately
} Tile;

// a very basic map structure
typedef struct __Map {
char name[32];
int width;
int height;
Tile **tiles;
};

// images for all tiles (tile 0 is an empty tile)
SDL_Surface *tileImages[MAX_TILE_TYPE];

// load tile images (path is optional, e.g. different tile sets)
int LoadTileImages(const char *path) {
char tileName[256];
int i, loaded = 0;
for (i = 0; i < MAX_TILE_TYPE; ++i) {
if (path == 0)
sprintf(tileName, "tile%02i.bmp", i);
else
snprintf(tileName, sizeof(tileName), "%s/tile%02i.bmp", path, i);
timeImages = IMG_Load(tileName);
if (timeImages != 0) ++loaded;
}
return loaded;
}

// delete a loaded tile set
void DeleteTileImages(void) {
int i;
for (i = 0; i < MAX_TILE_TYPE; ++i) {
if (tileImages != 0) {
SDL_FreeSurface(tileImages);
tileImages = 0;
}
}
}

// evaluate tile symbols and return an image from the array
SDL_Surface *GetImageForTile(int type) {
switch (type) {
case '.': return tileImages[GRASS_TILE];
case 't': return tileImages[TREE_TILE];
case 'M': return tileImages[MOUNTAIN_TILE];
case '=': return tileImages[WATER_TILE];
default: return tileImages[EMPTY_TILE];
}
}

void DeleteMap(Map **map) {
if (map != 0 && *map) {
if ((*map)->tiles != 0) {
int i;
for (i = 0; i < (*map)->height; ++i) {
free((*map)->tiles);
}
free((*map)->tiles);
}
free((*map));
// set the variable to null
*map = 0;
}
}

Map *LoadMap(const char *fileName) {
Map *map = 0;
char line[128];

FILE *file = fopen(fileName, "r");

if (file != 0) {
// this variable tracks errors
int error = 0;
int i;
// create map if file reads ok.
map = (Map*)malloc(sizeof(Map));

while (true) {
// read the map name
if (0 != fgets(line, sizeof(line), file)) {
strncpy(map->name, line, sizeof(map->name));
} else { error = 1; break; }
// first comes width
if (0 != fgets(line, sizeof(line), file)) {
map->width = atoi(line);
} else { error = 1; break; }
// next line is height
if (0 != fgets(line, sizeof(line), file)) {
map->width = atoi(line);
} else { error = 1; break; }
// now allocate and clear the tiles
map->tiles = (Tile**)malloc(map->height);
for (i = 0; i < map->height; ++i) {
map->tiles = (Tile*)malloc(map->width);
memset(map->tiles, 0, map->width * sizeof(Tile));
}
// read all rows
for (i = 0; i < map->height && error == 0; ++i) {
if (0 != fgets(line, sizeof(line), file)) {
int j;
// line is too short
if (strlen(line) < map->width) {
error = 1;
break;
}
for (j = 0; j < map->width; ++j) {
map->tiles[j].type = line[j];
}
} else { error == 1; }
}
break;
}
fclose(file);
if (error != 0) {
DeleteMap(&map);
}
}
return map;
}

// apply the currently loaded tile set to a map
int SetTileImages(Map *map) {
int i, j;
// error if the map is invalid
if (map == 0 || map->tiles == 0) {
return -1;
}

for (i = 0; i < map->height; ++i) {
for (j = 0; j < map->width; ++j) {
map->tiles[j].image = GetImageForTile(map->tiles[j].type);
}
}
}

// sample usage:

int loaded;
Map *map;

// first load all tiles
loaded = LoadTileImages(0);
// now load a map
map = LoadMap("simplemap.txt");
SetTileImages(map);

if (map == 0) abort();

PlayGame(map);

DeleteMap(&map);
DeleteTileImages();

// or something like that - you get the idea, I hope :)



More ideas include overlays, smooth scrolling, animated tiles a.s.o. but this should be considered when the rest (loading and rendering a map) is working.

Hope this helps a little,
Pat.

[edit]Forgot a function in the sample source code.[/edit]

Share this post


Link to post
Share on other sites
Wow, thanks. really really REALLY thanks. that really helps me.
More articles, please! :)

I haven't even thought HOW to set the map yet. thanks!

Share this post


Link to post
Share on other sites
At the risk of being flamed by my peers, C++ is a very difficult language to learn, especially if you haven't cut your teeth on another language or three first. Your project time-line may be too short to be blundering through learning C++ while you try to learn everything else.

C++ is my favorite language for writing graphics/game code, but C is like a high-level language without safety belts (it's like a cross between Pascal and assembler), and C++ is C with object orientation grafted onto it (which tends to make its implementation less clean than other object-oriented languages). Without a strong foundation in C, especially where pointers and memory allocation come into play, your program will have an awful lot of very hard-to-fix bugs in it. Without a strong foundation in the C++ extensions on top of C, you will encounter even more bugs due to some of the subtle nuances of things like copy constructors.

And if you use the Standard Template Library (STL), which I would recommend if you're using C++, you also need to have some degree of familiarity with C++ templates. Templates are powerful, but the syntax and some of the implementation details are horrendous. Rarely in my life have I seen messier-looking code or more obscure warnings and error messages. Using them across libraries (DLL's) doesn't always work well, and I've seen the debugger do some strange things with them.

I really hate to say this without giving a clear alternative, but I'm not sure that there is one. VB just plain sucks for this sort of thing. I would recommend Java or C#, but I'm not sure if the Java multimedia libraries are up to the task yet and you don't have access to Visual Studio .Net (the C# compiler/debugger). Does anyone else have any good recommendations?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!