Jump to content
  • Advertisement
Sign in to follow this  
doyleman77

Pointer to an array of base characters?

This topic is 2182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My CSCI class had us program a game for our final; and we had a reference game to look at for help. I just picked up game programming, and subsequently, the source to my game submission. as I was reading the header files, I came across this in the Sprite.h. It's the base class from which most entities derive. Something I dont understand is why did I have the class have a member which is a pointer to a pointer to itself (obviously a pointer to an array of itself). I know that in the virtuals, base class pointers can call functions of descendants / derived classes, but still... I can't for the life of me think why I had a member that had this, or even why I passed it intot he constructor. Here's the code:

[source lang="cpp"]#ifndef SPRITE_H
#define SPRITE_H

#include "SDL/SDL.h"
#include "img_handling.h"

class Sprite
{
protected:
Sprite** tempSprite;
int selfIndex;
float x;
float y;
int width;
int height;
SDL_Surface* image;
SDL_Rect colBox; //collision box information.
public:
Sprite()
{
}
Sprite(int sI, int xpos, int ypos, int w, int h, SDL_Surface* img, Sprite** spr)
{
x = xpos;
y = ypos;
width = w;
height = h;
image = img;
tempSprite = spr;
selfIndex = sI;
colBox.x = x;
colBox.y = y;
colBox.w = w;
colBox.h = h;
}

/********************** EMPTY VIRTUAL FUNCTIONS ************************/
virtual void move(float dt)
{
}
virtual void collide()
{
}
virtual void aniSprite()
{
}
virtual void draw(SDL_Surface* dest)
{
Draw(dest, image, x, y);
}
virtual float swapVelX()
{
return 0.0;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
int getWidth()
{
return width;
}
int getHeight()
{
return height;
}
/******** MASTER UPDATE FUNCTION ********/
void doOneTurn(float dt)
{
move(dt);
collide();
}
SDL_Rect GetRect()
{
return colBox;
}
~Sprite(){image = NULL;} //Cleanup
};

#endif[/source]


is anyone able to help me remember? I have a feeling I was a bit drunk when I did this programming. I drank a few to help calm me down on my math / csci assignments, and for the most part it helped. unsure.png

Share this post


Link to post
Share on other sites
Advertisement
You never use the value of tempSprite, so it doesn't serve any real purpose. Just remove it from your code and restore a bit of sanity to the world. :)

Share this post


Link to post
Share on other sites

You never use the value of tempSprite, so it doesn't serve any real purpose. Just remove it from your code and restore a bit of sanity to the world. smile.png


I thought so. Thank you, haha. I have been scratching my head for the last 3 hours asking myself what purpose did this serve?

:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!