Thanks for the replies!
Hmm, so create another class playArea?
How about a rect named playArea private to Sprite?
Edit: Ok, I made it a private member.
However when trying to compiler I get some strange errors (?)
#ifndef MY_SDL_FUNCTIONS_H#define MY_SDL_FUNCTIONS_H#include "SDL/SDL.h"#include "rect.h"bool pointInRect(const int pointX, const int pointY, const SDL_Rect &rect);bool collision(const Rect &rectA, const Rect &rectB);bool collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);bool collision(const SDL_rect &rectA, const SDL_Rect &rectB);#endif
#include "mySDLfunctions.h"bool pointInRect(const int pointX, const int pointY, const SDL_Rect &rect){ if(pointX >= rect.x && pointX <= rect.x + rect.w ) if(pointY >= rect.y && pointY <= rect.y + rect.h ) return true; return false;}bool collision(const Rect &rectA, const Rect &rectB){ // create a temporary SDL_Rect struct so the values of rectB can be passed to pointInRect easily SDL_Rect temp; temp.x = rectB.x; temp.y = rectB.y; temp.w = rectB.Width(); temp.h = rectB.Height(); for(int i = rectA.x; i <= rectA.x + rectA.Width(); ++i) { for(int j = rectA.y; j <= rectA.y + rectA.Height(); ++j) { if(pointInRect(i, j, temp)) return true; } } return false;}bool collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2){ SDL_Rect temp; temp.x = x2; temp.y = y2; temp.w = w2; temp.h = h2; for(int i = x1; i <= x1 + w1; ++i) { for(int j = y1; j <= y1 + h1; ++j) { if(pointInRect(i, j, temp)) return true; } } return false;}bool collision(const SDL_rect &rectA, const SDL_Rect &rectB){ for(int i = rectA.x; i <= rectA.x + rectA.w; ++i) { for(int j = rectA.y; j <= rectA.y + rectA.h; ++j) { if(pointInRect(i, j, rectB)) return true; } } return false;}
1>------ Build started: Project: Pong, Configuration: Debug Win32 ------
1>Compiling...
1>mySDLfunctions.cpp
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.h(12) : error C2143: syntax error : missing ',' before '&'
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(54) : error C2143: syntax error : missing ',' before '&'
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(56) : error C2228: left of '.w' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2065: 'rectA' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(58) : error C2228: left of '.h' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.cpp(60) : error C2065: 'rectB' : undeclared identifier
1>Generating Code...
1>Compiling...
1>main.cpp
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2008\projects\pong\pong\mysdlfunctions.h(12) : error C2143: syntax error : missing ',' before '&'
1>Generating Code...
1>Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2008\Projects\Pong\Pong\Debug\BuildLog.htm"
1>Pong - 19 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
EDIT:
Found it, I had SDL_rect instead of SDL_Rect :p
[Edited by - sheep19 on January 8, 2009 4:46:05 AM]