Jump to content

  • Log In with Google      Sign In   
  • Create Account


McGrane

Member Since 08 Mar 2004
Offline Last Active Sep 18 2014 08:31 AM

Posts I've Made

In Topic: Snake code review request

01 August 2014 - 04:09 AM

Currently your game's level is four walls bound by the windows size. If instead you create a class that can read information from a text file, and convert it into a map. You will then be able to edit / create new maps for your game, without the need the recompile your code. This means you can expand your game quickly, and / or other people may create maps for you.

For example, if you created a text file; map1.txt, and it contained the following:

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 

1, 0, 0, 0, 0, 0, 0, 0, 0, 1,

1, 0, 0, 0, 0, 0, 0, 0, 0, 1,

1, 0, 0, 0, 0, 0, 0, 0, 0, 1,

1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 

1, 1, 1, 1, 1, 1, 1, 1, 1, 1 

Where a '1' would represent a wall. You could then quickly expand this into may variations of levels in different files:

Map2.txt

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 

1, 0, 1, 0, 0, 0, 0, 1, 0, 1,

1, 0, 1, 0, 0, 0, 0, 1, 0, 1,

1, 0, 0, 0, 1, 0, 0, 0, 0, 1,

1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 

1, 1, 1, 1, 1, 1, 1, 1, 1, 1 

 

Now that your level is no longer hard coded, but saved in files as data, you can update and create new maps for your game as needed, or other people playing your game, could make their own levels.

 

This could also be expanded using a config file, containing a list of all maps. To add a new level to the game, all one would have to do then is create a new text file containing a map, and add the text files name to the config file.

 

I think this is a good way to code most projects as it makes you think of how to make your code more reusable, and thus, can be reused in other games :)


In Topic: Looking for source code for a tiled 2d scroller

10 July 2014 - 08:30 AM

Hey Nick

 

Displaying and scrolling a map is relatively easy, and i'm sure you can find someone who may sell you this code.. but i don't think its worth purchasing. If you wish to build a platform game, but are unable to build the map, we may not be at a stage to progress said game, so it may not be any faster to develop - you may just be out of pocket.

 

For a simple example of a tile map, use and array, you use the indices to calculate the postion of each tile, and use the value for your tile type, eg 1: Wall, 0: Grass, 2: Water 

int tileSize = 128;
int map[5][5] = {
1,1,1,1,1,
1,0,0,0,1,
1,0,2,0,1,
1,0,0,0,1,
1,1,1,1,1
}
 
...
 
for( int y = 0; y < 5; y++ ) {
     for( int x = 0; x < 5; x++ ) {
         DrawTile( x * tileSize, y * tileSize, map[y][x] )
    }
}
 
...
 
DrawTile( int postionX, int positionY, int tileID ) {
...
}

In Topic: Image detection

10 July 2014 - 01:40 AM

Hi destluk,

 

Maybe im missing something here, but do you need image detection if you just want to match two images? Could you not just give your images a unique id, and check them off each other? Just from your screen shot, im not sure why you would need something so complex ( but im sure there could be a reason smile.png )

 

[Edit] I now see that anti-macro is a game, and you want to use this in said game - Disregard ;)


In Topic: Beginning GLSL - Quick Question

08 June 2014 - 02:57 PM

All right, I understand enough now, and have taken up enough time ;) I had assumed to send them to the GPU was the way to go for speed, and had avoided doing any calculations on the CPU, I see now that it should not be solely done by either. And that most my problems are stemming from assumptions :P

 

I have enough information now, and have a working example, that I can now further my reading into everything matrix related, and modern opengl related. Its just demotivating if you cant get something simple to go correctly

 

Thanks for the help, its greatly appreciated

Regards

David


In Topic: Beginning GLSL - Quick Question

08 June 2014 - 08:22 AM

Just on a further thought, I'm currently changing my view matrix to move the map / players around the screen. Would this not then require me to rebuild the so called view projection matrix at each frame anyway? Im sure its something im doing incorrectly, like i said im just beginning with matrices.

 

My view matrix is initialized as follows:

m_matrixView[0]  = 1.f;	m_matrixView[1]  = 0.f;	m_matrixView[2]  = 0.f;	m_matrixView[3]  = 0.f;
m_matrixView[4]  = 0.f;	m_matrixView[5]  = 1.f;	m_matrixView[6]  = 0.f;	m_matrixView[7]  = 0.f;
m_matrixView[8]  = 0.f;	m_matrixView[9]  = 0.f;	m_matrixView[10] = 1.f;	m_matrixView[11] = 0.f;
m_matrixView[12] = 0.f;	m_matrixView[13] = 0.f;	m_matrixView[14] = 0.f;	m_matrixView[15] = 1.f;

and my ortho projection is initialized as:

float tx = - ( _fRight + _fLeft   ) / ( _fRight - _fLeft   );
float ty = - ( _fTop   + _fBottom ) / ( _fTop   - _fBottom );

m_matrixOrtho[0]  = 2.f/(_fRight-_fLeft); m_matrixOrtho[1]  = 0.f; m_matrixOrtho[2]  = 0.f; m_matrixOrtho[3]  =   tx;
m_matrixOrtho[4]  = 0.f; m_matrixOrtho[5]  = 2.f/(_fTop-_fBottom); m_matrixOrtho[6]  = 0.f; m_matrixOrtho[7]  =   ty;   
m_matrixOrtho[8]  = 0.f; m_matrixOrtho[9]  = 0.f; m_matrixOrtho[10] = 0.f; m_matrixOrtho[11] =  0.f;   
m_matrixOrtho[12] = 0.f; m_matrixOrtho[13] = 0.f; m_matrixOrtho[14] = 0.f; m_matrixOrtho[15] =  1.f; 

I'm aware of GLM, but i want to learn about Matrices smile.png

 

To move things in my world im just editing the view matrix as follows:

void SetPosition( float _fPositionX, float _fPositionY ) {
     m_matrixView[3] = _fPositionX;
     m_matrixView[7] = _fPositionY;
}

Maybe im just jumping the gun, im gona sit down now and work out the combined matrices, but im assuming that they would have to be recalculated each time i moved something anyway ?


PARTNERS