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 / Introduction and puzzle games

Author
Message
Vlad
19
Years of Service
User Offline
Joined: 5th Oct 2005
Location:
Posted: 16th Dec 2005 01:43
Howdie

Maybe some of you have seen me around the FPSC forum. Sometime ago I was (well) adviced to code my games, so I went back several years to code again, and C++ with DarkGameSDK is the choice.

I'm still getting in some of the C++ syntax but it's going better than I expected first, maybe because I programmed some years ago and it boils down to syntax, OO and DGSDK, so I'm trying to get my hands dirty with real problems, like coding something diferent from C++ book "Hello World!" examples.

As I was starting to put some logic I noticed that I don't have any clue on how to put up a simple 3D display for a puzzle game. I read somethings for FPS games from codebase, and the XYZ usage seems obvious, but I'm having a static camera and pieces in particular places. Setting the screen resolution, etc is fine, but getting the camera, background and starting to lay pieces is puzzling me, not the actual syntax, but how to make the calculations for things to fit nicely and in place.

Any helping hand on theory regarding this initial setup is more than welcomed and a good kick start.

Thank you in advance.

V

I'm pretty sure I know everything. Doubts are something rare in me and I am never wrong, as this signature can prove.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 16th Dec 2005 19:36
Welcome to the fun fun world of do-it-yourself coding where if things go wrong instead of being able to blame the drag-n-drop program you get everyone blaming your code xD

There really are two ways to handle the placment of objects in a 3d world. Okay theres probably more but im going to address 2 To start with its just easier on you if you orientate your world to 0,0,0 - ie, start there. First peice you place can go there.

Now, when placing the objects in your world you really have two choices. You can either mathematically calculate the position of everything (only really works if each "peice" in your world is the same size and a square) or you can devise some sort of map editor. Map editors really are essential if you have all sorts of things to place with an unfixed scale etc - they dont have to be complicated. A very basic map editor should allow you to press say a number key to select which peice you are currently placing then use the arrow keys to move it around and hit spacebar to do the final "placing" of the peice. Then the idea is you write to a data file data about the world saying which peice goes where and in your game you can open that file, read in the info and place stuff as you go.

If however you know exactally where each peice should be and how big they all are you can use a little maths to place the peices. Um, try to imagine any game with peices which are square and mainly made of walls and floors for example. Bomberman? Rock Rush (Baulder Dash)? etc. You can create these the same way you would render a 2d tilemap.

you really want an array to store the data of the world. say you have two constants, MAP_W and MAP_H which have the size of the map in TILES for width and height. you could define an array something like

int MyMap[MAP_W][MAP_H];

you would want to fill it with data somehow. Manually, with a map editor, thats upto you. Now, you need to know the width/height of every "tile" in the map, for this example we will presume they are the same size long as they are wide. We'll say thats stored in the constant T_SIZE and for the sake of consistancy we'll say T_SIZE == 20. You now use two for loops to run through the width and height of the array and by multiplying the current index by the size of the tiles you can get a perfect co-ordinate for placing the tile, ie



just a simple example, needs more work.

However the tile approach is limiting as you might of guessed. There are ways to make it more flexiable.. but really you would be better off writing a map editor anyway.

About the camera. If you write a map editor you can always create a camera entity and place it where you want the camera to start for that level. However if the camera is always fixed in the same position for each level then what I personally do is quicky write up some code to allow me to move, raise and rotate the camera with my keyboard and I write the cameras position and angle to the screen. Then I load a level, position the camera to where I think is quite nice and when im happy with it I write down the values that I see on the screen for its current position then when a level loads I can just direct position the camera there and rotate it as needed.

Right, that could be a bit much to swallow in one sitting but i;m afraid your question has a very wide berth of topics inside it and theres no easy way to answer it If you can decide on a method that will work for your game and then you get stuck implementing it then you will be able to refine your question and we'll be happy to help again if we can good luck

Vlad
19
Years of Service
User Offline
Joined: 5th Oct 2005
Location:
Posted: 16th Dec 2005 20:50
After reading what you wrote I can only say: lucky me! The first function I wrote is to determine the matching pieces, in which I used a bidimensional array.

The function I'm trying to write now and that led me to put this thread is to create the game board. This game involves pieces that will be clicked with a mouse to perform some action (here's another problem: selecting a 3D mesh with a click of a mouse) but the pieces positions are fixed. Think of chess, bejeweled and that kind of thing and you'll see the picture, it's basically a matrix of X and Y with a twitch.

The game board concept is drawn already, and I have a center piece, which I already laid on 0,0,0. So, what I have to do is position the camera on a negative z axis and start from there. So the only problem I have now is to determine the size of the pieces, which is not that obvious to me, appart from knowing all have the same size. If I can sort that out, I can build the game board easily.

So, I'm down to determine piece size and the relationship between the 3D and the 800x600 screen and discovering how to select a piece by clicking it.

Any help is welcomed, but thank you very much for your help!

I'm pretty sure I know everything. Doubts are something rare in me and I am never wrong, as this signature can prove.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 16th Dec 2005 21:21 Edited at: 16th Dec 2005 21:58
The peices are 3d, correct? If they are 3d then you dont need to know the relationship between the world and the screen, just position them in 3d.

dbObjectWidth() and dbObjectLength() (i think its length) will give you the size of your peices, but what you really want to know is the size of a square on the board. This can easilly be obtained by getting the width of your board object (its one solid 3d object yes?) using the dbObjectWidth() command and then divide its width by the number of squares along the boards width. That will give you the width of one square, then do the same for the length of the board. Output those values to the screen so you can write them down for easy remembering.

Now, if you want to fill the entire board with peices that are all the same, use the tile method I mentioned in the first post. If however some peices need to start in certain places/theres different peices/etc then if you know which square of the board a peice needs to be on then you can position it using

dbPositionObject(nPeiceObjectNumber, BoardSquareX * SquareWidth, BoardSquareZ * SquareHeight);

SquareWidth/Height being the width and height of one board square you calculated earlier.

If you are using 2d sprites for your peices.. well getting them positioned and rotated exactally right is a pain. I wont even attempt to explain in full incase you arnt needing them, but if i remember correctly then off the top of my head you would need to get the 3d coordinate of where you would position the peice if it was 3d then do something like
screenx = peicex / peicez;
screeny = peicey / peicez;

theres other methods.

Right, for selecting a 3d object with your mouse you want to look at the dbPickObject() command. It will return the object id of an object from a screen position. There first two parameters are the x/y screen location to start from - in your case you would want to pass dbMouseX() and dbMouseY() as the first two parameters respectivly. The last two parameters are the object start and end which specifys a range of object id's to scan for a collision with.

Now, the more objects it has to scan the slower it is obviously so you want to limit this to only objects that you ever need to select. In this case, you dont want to be able to select the board (right?) only the peices. What I like to do is in my games I define a set of constants (or occasionally enumerations depending on the situation) which define offsets for my object loading. For example I might define something like

#define PLAYER_MODELS 100
#define WORLD_ENTITIES 200

and when I load objects like for the players I would say dbLoadObject(PLAYER_MODELS + nPlayerIndex, blah blah etc)

not only does this make it easier to see whats what because you can for example see there that any object id between 100 and 199 belongs to a player, but it gives you an easy range for doing checks like this. Back to your problem, if you do as I did there you could make the last two parameters of the function PEICE_MODELS and PEICE_MODELS + nTotalPeices so the function would end up like:

int nResult = dbPickObject(dbMouseX(), dbMouseY(), PEICE_MODELS, PEICE_MODELS + nTotalPeices);

with nTotalPeices obviously being the total amount of peice objects on the board. That limits the range nicely to only the things you want to select, did all that make sense? Im afraid I tend to go on a bit when I should be summarising

dbPickObject will return the object id that it collides with, if any, within the range you specify. So if you have an array already storing peices on the board then just add the objectid into that array when you first generate it then when someone clicks and dbPickObject returns an object id you can scan the array for a matching object id and you will know exactally which was clicked on, ya?

Hope that helped





#####################EDIT#####################
Oh I forgot to mention, if your board is CENTERED at 0, 0, 0 so half of it is in the negitive side of world co-ordinates then you cant just directly do


dbPositionObject(nPeiceObjectNumber, BoardSquareX * SquareWidth, BoardSquareZ * SquareHeight);

it will have to become


dbPositionObject(nPeiceObjectNumber, (BoardSquareX * SquareWidth) - (BoardWidth / 2), (BoardSquareZ * SquareHeight) - (BoardHeight / 2));

get the width and height of the board the same way you would anything else, dbObjectWidth() etc.

Also for clarfication, alot of the time I appear to be saying Height when in all honesty I should be saying Length - im talking about the z plane. Too much 2d work for me has left me with a habbit of saying height :o

Vlad
19
Years of Service
User Offline
Joined: 5th Oct 2005
Location:
Posted: 16th Dec 2005 22:48
You just gave me all I need for a tremendous coding weekend.

I was just reading the dbPickObject and thinking "there must be a way of picking the XY mouse coordinates."

Regarding the game board, I don't even need to draw it, the pieces do it for me, since the pieces are 3D, getting it's length, will give me all I need to know to put the board up.

Thank you very much. *Closes all IE windows and opens Visual Studio*

V

I'm pretty sure I know everything. Doubts are something rare in me and I am never wrong, as this signature can prove.

Login to post a reply

Server time is: 2024-11-19 03:37:06
Your offset time is: 2024-11-19 03:37:06