Error in my SDL Game get_box() Function

Hey guys, been programming a lot more further with this game but I've come to a stump with this bit of code. The source is pretty large so I'm just going to paste a few chunks to see if you can see whats wrong.

Main problem is I'm needing to pull out my get_box() Function but I'm not sure how to pull this out as I'm thinking it may need to be a pointer to a pointer?

The error is on line 60 of collision.cpp

ERROR:

1>------ Build started: Project: SDL_FIRST_RUN, Configuration: Debug Win32 ------
1>Compiling...
1>collision.cpp
1>c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\collision.cpp(60) : error C2676: binary '==' : 'SDL_Rect' does not define this operator or a conversion to a type acceptable to the predefined operator
1>Build log was saved at "file://c:\Documents and Settings\Scottie\My Documents\Visual Studio 2005\Projects\SDL_FIRST_RUN My Game -Using Tiling Engine\SDL_FIRST_RUN\Debug\BuildLog.htm"
1>SDL_FIRST_RUN - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

collision.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "SDL/SDL.h"
#include "collision.h"
#include "tile_class.h"

bool check_collision( SDL_Rect *pA, SDL_Rect *pB )
{
    //The sides of the rectangles
    int leftA, leftB;
    int rightA, rightB;
    int topA, topB;
    int bottomA, bottomB;

    //Calculate the sides of rect A
    leftA = pA->x;
    rightA = pA->x + pA->w;
    topA = pA->y;
    bottomA = pA->y + pA->h;
        
    //Calculate the sides of rect B
    leftB = pB->x;
    rightB = pB->x + pB->w;
    topB = pB->y;
    bottomB = pB->y + pB->h;
            
    //If any of the sides from A are outside of B
    if( bottomA <= topB )
    {
        return false;
    }
    
    if( topA >= bottomB )
    {
        return false;
    }
    
    if( rightA <= leftB )
    {
        return false;
    }
    
    if( leftA >= rightB )
    {
        return false;
    }
    
    //If none of the sides from A are outside B
    return true;
}

//Collision Checking for tiles.
bool touches_wall(SDL_Rect *pBox, Tile *tiles[], int iTOTAL_TILES, int iTILE_CENTER, int iTILE_TOPLEFT)
{
    //Go through the tiles
    for( int t = 0; t < iTOTAL_TILES; t++ )
    {
        //If the tile is a wall type tile
        if( ( tiles[t]->get_type() >= iTILE_CENTER ) && ( tiles[ t ]->get_type() <= iTILE_TOPLEFT ) )
        {
            //If the collision box touches the wall tile
			if(check_collision(pBox, tiles[t]->get_box() == true )) 
            {
                return true;    
            }
        }
    }
    
    //If no wall tiles were touched
    return false;
}


tile_class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "tile_class.h"
#include "collision.h"
#include "graphix.h"

Tile::Tile( int x, int y, int tileType, int TILE_WIDTH, int TILE_HEIGHT)
{
    //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;
}

void Tile::show(SDL_Rect *pCamera, SDL_Rect *pBox, SDL_Surface *pScreen, SDL_Surface *pTileSheet, SDL_Rect *pClips[], int type)
{
    //If the tile is on screen
    if( check_collision(pCamera, pBox) == true )
    {
        //Show the tile
        apply_surface(box.x - pCamera->x, box.y - pCamera->y, pTileSheet, pScreen, pClips[type]);    
    }
}    

int Tile::get_type()
{
    return type;
}

SDL_Rect Tile::get_box()
{
    return box;
}


tile_class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef TILE_CLASS_H
#define TILE_CLASS_H

#include "SDL/SDL.h"

//The tile
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, int TILE_WIDTH, int TILE_HEIGHT );
    
    //Shows the tile
    void show(SDL_Rect *pCamera, SDL_Rect *pBox, SDL_Surface *pScreen, SDL_Surface *pTileSheet, SDL_Rect *pClips[], int type);
    
    //Get the tile type
    int get_type();
    
    //Get the collision box
    SDL_Rect get_box();
};

#endif //TILE_CLASS_H 


This line:
if(check_collision(pBox, tiles[t]->get_box() == true ))
is not quite framed correctly - brackets in wrong place.

It should be if( (check_collision(pBox, tiles[t]->get_box() ) == true )
Just tried what you said - but now it gives me this


1>------ Build started: Project: SDL_FIRST_RUN, Configuration: Debug Win32 ------
1>Compiling...
1>collision.cpp
1>c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\collision.cpp(60) : error C2664: 'check_collision' : cannot convert parameter 2 from 'SDL_Rect' to 'SDL_Rect *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\collision.cpp(61) : error C2143: syntax error : missing ')' before '{'
1>Build log was saved at "file://c:\Documents and Settings\Scottie\My Documents\Visual Studio 2005\Projects\SDL_FIRST_RUN My Game -Using Tiling Engine\SDL_FIRST_RUN\Debug\BuildLog.htm"
1>SDL_FIRST_RUN - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Opps, just added another bracket as the one you said to do is missing one i think. That fixed that top error but i still have the same bottem error :(
The error:
1>c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\collision.cpp(60) : error C2664: 'check_collision' : cannot convert parameter 2 from 'SDL_Rect' to 'SDL_Rect *'

is saying that it cannot covert the item returned from this function
SDL_Rect Tile::get_box() - because this function returns
a Rect, and you need a Pointer to Rect to pass to the check_collision function - If you see what I mean
Yup awesome, thanks :D
Topic archived. No new replies allowed.