and then make a vector of entity pointers and have all my game objects in that vector, so it would be easier to check collision and things?
what is good and what i bad about this and can it be done in a better way? :P
thx

Moderator: Coders of Rage
I'm not really sure thats the best way to do it. A lot of ppl make a generic sprite class and then make every object that will appear on screen inherit from it but i don't think it's a good idea to make every object inherit from it. For example there are alot of things that may be implemented behind the scenes and that will never appear on screen so it wouldn't be necessary to have such direct access to them(for collision detection etc.), too much access can be a bad thing, that's why we create private members/functions. Saying that i could be completely wrong this is just an opinionZer0XoL wrote:is it good if i make every object and things inherit from the class entity( wich i made)
and then make a vector of entity pointers and have all my game objects in that vector, so it would be easier to check collision and things?
what is good and what i bad about this and can it be done in a better way? :P
thx
Well, you probably don't want EVERYTHING to inherit from an Entity class.MrDeathNote wrote:I'm not really sure thats the best way to do it. A lot of ppl make a generic sprite class and then make every object that will appear on screen inherit from it but i don't think it's a good idea to make every object inherit from it. For example there are alot of things that may be implemented behind the scenes and that will never appear on screen so it wouldn't be necessary to have such direct access to them(for collision detection etc.), too much access can be a bad thing, that's why we create private members/functions. Saying that i could be completely wrong this is just an opinionZer0XoL wrote:is it good if i make every object and things inherit from the class entity( wich i made)
and then make a vector of entity pointers and have all my game objects in that vector, so it would be easier to check collision and things?
what is good and what i bad about this and can it be done in a better way? :P
thx.
Code: Select all
/*
UNTESTED CODE, PROBABLY REALLY CRAPPY STUFF D:
*/
class Entity
{
public:
Entity(SDL_Surface* image);
Entity();
~Entity();
void move(float nvx, float nvy);
private:
int x, y;
float vx, vy;
// Assuming you use SDL
SDL_Surface* sprite;
}
Entity(SDL_Surface* image) // load with sprite
{
x = y = 0;
vx = vy = 0.0;
sprite = image;
}
Entity() // Blank sprite
{
x = y = 0;
vx = vy = 0.0;
sprite = NULL;
}
~Entity()
{
SDL_FreeSurface(sprite);
}
void Entity::move(float nvx, float nvy)
{
vx = nvx;
vy = nvy;
x += int(vx);
y += int(vy);
vx = vy = 0.0;
}
I did not get the idea from quake, but that class you made is almost the same as the one im using :Dxiphirx wrote:Did you get this idea from quake?
Like others have said, I would only use it for stuff that is active (moving etc).
a sample class would beCode: Select all
/* UNTESTED CODE, PROBABLY REALLY CRAPPY STUFF D: */ class Entity { public: Entity(SDL_Surface* image); Entity(); ~Entity(); void move(float nvx, float nvy); private: int x, y; float vx, vy; // Assuming you use SDL SDL_Surface* sprite; } Entity(SDL_Surface* image) // load with sprite { x = y = 0; vx = vy = 0.0; sprite = image; } Entity() // Blank sprite { x = y = 0; vx = vy = 0.0; sprite = NULL; } ~Entity() { SDL_FreeSurface(sprite); } void Entity::move(float nvx, float nvy) { vx = nvx; vy = nvy; x += int(vx); y += int(vy); vx = vy = 0.0; }
Yes, ofc i know what that is and how to use it, its just i ask how to keep it somewhat structured as tiles and still have it animated.. hmmxiphirx wrote:Yes, you might want to look into spritesheets and SDL_Rect s.
Well, if your tile is a class that inherits properties from entity, then you can add a SDL_Rect to hold clips if the tile's image is wider than a normal tile.Zer0XoL wrote:Yes, ofc i know what that is and how to use it, its just i ask how to keep it somewhat structured as tiles and still have it animated.. hmmxiphirx wrote:Yes, you might want to look into spritesheets and SDL_Rect s.
Code: Select all
//clips is a SDL_Rect array declared in the tile class assuming it inherits things from entity
if (sprite->w > YOUR_NORMAL_TILE_DIMENSION)
{
animated = true; //bool that can tell your rendering process to render the animation
for (int i = 0; i < sprite->w/2; i++)
{
clips[i].x = i*YOUR_NORMAL_TILE_DIMENSION;
clips[i].y = 0;
clips[i].w = clips[i].h = YOUR_NORMAL_TILE_DIMENSION;
}
}
You would just create another class eg. animatedTile and have code very similar to your sprite animation. The tile itself would need to be a spritesheet so it mite actually be better to create that tile as an animated sprite. But really it's up to you there are numerous ways to deal with this, i'd prob create a new class for animated tiles but thats just my opinion.Zer0XoL wrote:Yes, ofc i know what that is and how to use it, its just i ask how to keep it somewhat structured as tiles and still have it animated.. hmmxiphirx wrote:Yes, you might want to look into spritesheets and SDL_Rect s.
Thanks for the idea :DMrDeathNote wrote:You would just create another class eg. animatedTile and have code very similar to your sprite animation. The tile itself would need to be a spritesheet so it mite actually be better to create that tile as an animated sprite. But really it's up to you there are numerous ways to deal with this, i'd prob create a new class for animated tiles but thats just my opinion.Zer0XoL wrote:Yes, ofc i know what that is and how to use it, its just i ask how to keep it somewhat structured as tiles and still have it animated.. hmmxiphirx wrote:Yes, you might want to look into spritesheets and SDL_Rect s.
Souunds like a good planZer0XoL wrote:Thanks for the idea :DMrDeathNote wrote:You would just create another class eg. animatedTile and have code very similar to your sprite animation. The tile itself would need to be a spritesheet so it mite actually be better to create that tile as an animated sprite. But really it's up to you there are numerous ways to deal with this, i'd prob create a new class for animated tiles but thats just my opinion.Zer0XoL wrote:Yes, ofc i know what that is and how to use it, its just i ask how to keep it somewhat structured as tiles and still have it animated.. hmmxiphirx wrote:Yes, you might want to look into spritesheets and SDL_Rect s.
I think im going to inherit the original tile class and have it contain a value of how many tiles the animation is and a value for the speed of animating it :D