[solved] lazy foo tiling trouble

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

[solved] lazy foo tiling trouble

Post by pythip »

I am trying to do Lazy foo's tiling tutorial, and am having trouble following it, is there a better tutorial on this subject?

the problem I am having is understanding the following code.
I understand that it initialises the class creates a pointer of it, what I don't get is what is the array about?

Code: Select all

Tile *tiles [TOTAL_TILES];
Tile class

Code: Select all

class Tile

{

    private:

    //The attributes of the tile

    SDL_Rect box;


    //The tile type

    int type;


    public:

    //Initializes the variables

    Tile( int x, int y, int tileType );


    //Shows the tile

    void show();


    //Get the tile type

    int get_type();


    //Get the collision box

    SDL_Rect get_box();


Tile::Tile( int x, int y, int tileType )

{

    //Get the offsets

    box.x = x;

    box.y = y;



    //Set the collision box

    box.w = TILE_WIDTH;

    box.h = TILE_HEIGHT;



    //Get the tile type

    type = tileType;

}


};
Last edited by pythip on Mon May 03, 2010 10:30 am, edited 3 times in total.
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

Re: lazy foo tiling trouble

Post by davidthefat »

A map is not just a single tile, you need more than one tile, hence explaining the array
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: lazy foo tiling trouble

Post by pythip »

so its just he made many instances of the class? the part that I was confused about was the initialisation process, I thought he was trying to pass an array though it.
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: lazy foo tiling trouble

Post by GroundUpEngine »

pythip wrote:so its just he made many instances of the class? the part that I was confused about was the initialisation process, I thought he was trying to pass an array though it.
Ye, so in the code set_tiles( Tile *tiles[] ) an array of Tile pointers is passed, then in the loop if a tile type is recognized then the current tile the loop is on 't', will be initialized with new using the init constuctor Tile( int x, int y, int tileType ) else the file is invalid ;)

snippet from set_tiles() ->

Code: Select all

//If the number is a valid tile number
if( ( tileType >= 0 ) && ( tileType < TILE_SPRITES ) )
{
	tiles[ t ] = new Tile( x, y, tileType );
}
//If we don't recognize the tile type
else
{
	//Stop loading map
	map.close();
	return false;
}
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: lazy foo tiling trouble

Post by pythip »

oh, I get it now, thanks for the help
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: [solved] lazy foo tiling trouble

Post by GroundUpEngine »

No prob :)
Post Reply