Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Please help me with 2d maps!

Author
Message
Dragon_Soldier
14
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 6th Dec 2009 23:24 Edited at: 7th Dec 2009 00:24
Ok,

So I have the desire to create an rpg as my first game.
Do not worry I am going in steps.
This is where I found a problem, I want to have a map in my game with walls (probably most important), enemies, items etc. though I do not need this all right away.
For more detail I want this map to be a bird's eye view.

Now to get to the point...I don't know how!

Any help would be appreciated,
Thanks in advance.

Edit: Another question I would like to ask is how do I shrink a sprite to 8x8 and still have it look good.

Once again thanks in advance.
haliop
User Banned
Posted: 7th Dec 2009 20:21 Edited at: 7th Dec 2009 20:24
ok ,
first.

you need a Tile method or a Tile Engine for all the tiles
like Grass / Dirt / Road and even Walls and Castles etc.. all of the map should be on a Tile Map Engine , now i never finished mine
but the idea of it is to do an Array like this:


int Tiles [X,Y] x,y positions on the 2D screen.
this will hold all the Tile Data in each Position on the Tile Map
/////////////////////////////////////////////////////////////////
now you need one more Array for what you actually See in the game while playing according to your Player Position as you dont see the entire map just the area you are in
so :

why 50? , well depends on how you want your game to look , you can go from 10 tiles to 100 to 1000 tiles on screen, but this may take a lot of CPU power to calculate, and it depends on how far you want to look at your player.

simple level example:
1 = Dirt
2 = Grass
3 = Trees
4 = Water Tile
5 = House (Bigger then other Tiles but still represents as the Center Tile and later i will explain on how to implent it on some tiles like 4 x 4 tiles or 10 x 10 )

so lets say you have the first map
Level One (or Starting Area) which are good for Tutorial on how to play the game , or like Pokemon where you wake up in your bed and walk out the house.. well , this is where the Story Begins)

so , we have our first Array :

now we implent the numbers we want on the Entire First Map
Tiles[1000,1000] = {1,1,1,1,1,1,1,1,1,1,1...etc...
1,1,1,1,2,,2,2,2,2,2,2,2...
1,1,1,2,2,2,2,2,2,2,2,2,2,
1,1,2,2,2,2,2,2,2,1,1,1,2,2,1,2,2,1,
}//1000 width X , and 1000 height Y

*** dont trust this code as i didnt coded for a long time ****

so you can see , that the Tiles for this level is mostly Dirt and Grass, that was a rud example
check this one , will be easier just putting 10 X and 10 Y to the entire Level

ok , you can see here , you have some Dirt and some Grass some Trees even a Lake(water Tiles) and a house.

this is just a level example.
in DarkGdk , you load the Images for the Tiles in a way that


and you load up it into Sprites , each tile is a diffrent Sprite
you have 10 x on a 10 y array
so you will need to :

TileNum = represents the ID number of that current Sprite
Xposition = the X position on Screen for where the Sprite\Tile place on the X axis.
Yposition = same as the X only on the Y axis.
TileImage = represents the Data or Image of what Tile Image to use in that Sprite.

the most Simple way to implent the Tiles[10,10] Array in Sprites is, using a Loop to implent each and everyone of the Sprites \ Tiles:

after this is done , you have all the Tiles setup in Sprites and you will see your map exactly as you arranged them before in the Tiles Array.

ok , this is it for now, you will have to look more and more on the Web , just search for Tile Based Engines or 2D Tiles Programming in C++ or even in DarkGDK you might Find something.
you can also look at the CodeBase under Community button on the menubar and search for it in DarkBasicPro or similar , the code is very much alike but there are somechanges as this is C++ and thats C#.

im sorry if i under estamate your programming knwoledge
its all with good feeling.

hope this can help , this will give you a push .
and a note to other viewers if you have better ways then please share with us and fix me if im wrong.
Dragon_Soldier
14
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 7th Dec 2009 21:32
Thanks for the help, I had no ideo how to implement this. Now if i want to not be able to walk through lets say..houses or trees would I do something like check for collision then move it a pixel away from the tile(or less)...now another question comes up... how do I check if it hit the tile from the side or the top or the bottom.......

If you have any answers they would be greatly appreciated.

@haliop: No you did not underestimate my programming knowledge I just recently started with GDK and c++ but I know enough to understand what you are saying. Thanks for the help.
haliop
User Banned
Posted: 8th Dec 2009 08:54 Edited at: 8th Dec 2009 09:16
about collision with Tiles.
its pretty simple actually becouse you already have the Tiles set.
meaning:

1 - Dirt - Passable
2 - Grass - Passable
3 - Trees - not
4 - Water - not
5 - House - not

so , lets say you have your player.
now lets do some controls:


i think this should do the job , but it may need some more help
i remmeber that DarkGDK's Collision is not so good , and i remmber that when ive tried to make this , i had some problem with it.
but that the idea behind it ,
once you Press a Move button , first you check if theres a collision (there will be always a collision in a Tile Map , you just want the Right Collision to Move so you wont move on Trees)
if collision is ok , only then you move your player.

hope this can help , you may want to Test it some more.

Edit ::::::::::::::::::::::::::::::::::::::::::::::::::::
i remmeber what my problem was , when the Sprite actually hits a Trees tile or any non passable Tile , you are stuck and cant move
why? becouse the idea of Collision is the same in every Direction
so once you got stuck , you are stuck cause the collision is still happening.
so this is how you fix it
this comes just before the end of the loop (after Keys for Move and not in them)


i think ive forgot something
try this out and tell me what you think on it.
Dragon_Soldier
14
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 16th Jan 2010 01:46
Ok,
I finally tried to use this to make a map...and I failed...but not horribly.

If I need to do something different please tell me...any help would be appreciated...keep in mind the longest i could have tried is probably 20 mins.

Heres the code i've been trying to fix...


While I'm waiting for a suggestion I'll be trying to solve this problem...and I'll post an improved code for other people to use.
Dragon_Soldier
14
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 16th Jan 2010 02:08 Edited at: 18th Jan 2010 01:39
(this is a second post and not an edit because my first post is not up yet because i'm new)
OK,
Well 20 minutes and I got it...
So as I promised here is the new code that works perfectly for a 10 by 10 map with 20 by 20 tiles
If new dimensions are needed change it in the "Tiles" array and for the tile dimensions you change it in the actual loop where its drawing...where it says x*20 and y*20.

HERE IS THE CODE AND THANK YOU HALIOP!

// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );




dbLoadImage("dirt.bmp",1); // Dirt Tile
dbLoadImage("grass.bmp",2); // Grass Tile
dbLoadImage("tree.bmp",3); // Trees Tile
dbLoadImage("water.bmp",4); // Water Tile
dbLoadImage("house.bmp",5); // House Tile

int Tiles[10][10] = {1,2,2,2,2,2,2,2,2,1,
1,2,2,2,3,3,3,2,3,3,
1,1,1,2,3,3,3,3,2,3,
1,1,2,2,2,2,4,4,4,4,
/*house(5)>*/1,2,2,5,2,2,4,4,4,4,
1,2,2,2,2,2,4,4,2,3,
2,2,2,2,2,2,4,4,4,3,
2,3,3,3,2,4,4,4,3,3,
2,3,3,2,2,4,4,4,2,3,
3,3,3,3,3,2,2,4,4,4};


int TileNum = 1; //Represents Tile ID in Sprites

for (int y=0; y < 10; y++)
{
for (int x=0; x < 10; x++)
{
dbSprite(TileNum, x*20, y*20, Tiles[y][x]);
TileNum++;
}
}

// our main loop
while ( LoopGDK ( ) )
{
// update the screen
dbSync ( );
}

for (int i = 1; i<6; i++)
{
dbDeleteImage (i);
dbDeleteSprite (i);
}

// return back to windows
return;
}


I hope this helps some people not have to go through the frustration I went through.



EDIT:
I changed some of the code above so that it works better...I guess it didn't work perfectly before...


Ok, I am now trying to get collision with tiles to work...The only one that works is trying to move up onto the tile.

Thank you in advance for any help and here is the code...

// our main loop
while ( LoopGDK ( ) )
{
int CollisionTile = dbSpriteCollision(PlayerSprite,0);
int CollisionData = dbSpriteImage(CollisionTile);

if (dbKeyState(30)==1)
{
dbRotateSprite(102,90);
dbMoveSprite(102, -1);
dbRotateSprite(102,0);
}


if (dbKeyState(32)==1)
{
dbRotateSprite(102,90);
dbMoveSprite(102, 1);
dbRotateSprite(102,0);
}

if (dbKeyState(31)==1)
{
dbMoveSprite(102, -1);
}

if (dbKeyState(17)==1)
{
dbMoveSprite(102, 1);

}

if (CollisionData == 3 |CollisionData == 4 |CollisionData == 5)

{
// Checking Old X position and calculating a New one.

if (dbSpriteX(PlayerSprite) < OldX)
{
dbRotateSprite(PlayerSprite,90);
dbMoveSprite(PlayerSprite, (dbSpriteX(PlayerSprite)-OldX));
dbRotateSprite(PlayerSprite, 0);
}
else if (dbSpriteX(PlayerSprite) > OldX)
{
dbRotateSprite(PlayerSprite,90);
dbMoveSprite(PlayerSprite, (dbSpriteX(PlayerSprite)- OldX));
dbRotateSprite(PlayerSprite, 0);
}

// Cecking Old Y position ...

if (dbSpriteY(PlayerSprite) < OldY)
{
dbMoveSprite(PlayerSprite, (dbSpriteY(PlayerSprite) - OldY));
}

else if (dbSpriteY(PlayerSprite) > OldY)
{
dbMoveSprite(PlayerSprite, (dbSpriteY(PlayerSprite)- OldY));
}
}



OldX=dbSpriteX(PlayerSprite),OldY=dbSpriteY(PlayerSprite);


EDIT #2:

Ok well I got tired of the whole collision thing, so until I have an idea I'm trying to make a class called Level that has a constructor to include the height, width and tiles,(and a name if possible)
After I get the whole constructor thing worked out I'm going to put in functions to draw the map, and set the map name to lets say the top middle...
Here is what the class looks like so far...I'm a noob still so I probably did 100 things wrong with the constructor...

class Level
{
public:
int LevelHeight, LevelWidth;
int LevelMap[10][10];
char LevelName[99];

Level(int LevelHeight, int LevelWidth, int MapData[10][10], char MapName[10])
{
MapData[10][10] = LevelMap[LevelHeight][LevelWidth];
MapName[99] = LevelName[99];
}
};
void DarkGDK (void)
{
BLAH BLAH BLAH
}

Edit #3:
Yes another edit... anyways something was definately wrong with the class because I kept on getting errors when exiting and nothing was working
So I converted it back to the basic thing I had above and it works...and I'm very frustrated.
Any ideas would be GREATLY GREATLY appreciated, as this is my new main project...

Login to post a reply

Server time is: 2024-11-20 09:18:30
Your offset time is: 2024-11-20 09:18:30