2 Replies - 251 Views - Last Post: 02 June 2013 - 06:53 AM Rate Topic: -----

#1 steven_bishop  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 37
  • Joined: 20-October 12

c++ Problem linking Player to appropriate Sprite base header/class

Posted 02 June 2013 - 06:09 AM

I can't seem to have the Player.cpp override the functionality of the Sprite header/cpp

without code re-use of the Sprite header/cpp Id have to write a header for player and every other game object which I think is a waste of time?.

I always get multiple definitions of Sprite/ first defined here ,and so forth. Please have a look and try explain to me why I get the error. after hacking around for 3 hours and having a bit of a read here and there I still don't get the problem ? and I'm quite exuasted with the time Ive wasted.

Anyone please help I will be most gratefull of your efforts.


/*                                     :NOTE this comment is not yet in practice, well worry about using just one base sprite class later
(INHERITABLE PARENT BASE CLASS)

This header file class has all attributes to be inherited and to be initialised values by all other sprite objects of the game.
*/

#ifndef SPRITE_H
#define SPRITE_H

#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "Sprite.h"
using namespace std ;

class Sprite
{
      private:
             // variables
             unsigned short int lives ;
             unsigned short int health ;
            
             unsigned int x ;
             unsigned int y ;
             float xv ;
             float yv ;
             
             bool is_Alive ;
             bool is_Dead ;
             bool is_Walking ;
             bool is_Running ;
             bool is_Jumping ;
             bool is_Falling ;
             // not needed to be passed through constructor
            // SDL_Surface* sprite ;
             SDL_Rect sprite_Clip[0] ;
             SDL_Rect sprite_Dimensions[0] ;            
        public:
             // constructor / de-constructor
             Sprite(int p_lives, int p_health, int p_x, int p_y, float p_xv, float p_yv, bool p_is_Alive, bool p_is_Dead, bool p_is_Walking, bool p_is_Running, bool p_is_Jumping, bool p_is_Falling)
             {
                    lives = p_lives ;
                    health = p_lives ;
                    
                    x = p_x ;
                    y = p_y ;
                    xv = p_xv ;
                    yv = p_yv ;
                    
                    is_Alive = p_is_Alive ;
                    is_Dead = p_is_Dead ;
                    is_Walking = p_is_Walking ;
                    is_Running = p_is_Running ;
                    is_Jumping = p_is_Jumping ;
                    is_Falling = p_is_Falling ;                         
             } 
             ~Sprite()
             {
             }
             // Prototype head getters and setters             
             void set_Lives(int p_lives) ;           
             int get_Lives() ;                       
             void set_Health(int p_health) ;
             int get_Health() ;

             void set_X(int p_x) ;
             int get_X() ;            
             void set_Y(int p_y) ;
             int get_Y() ; 
             void set_XV(float p_xv);
             float get_XV();            
             void set_YV(float p_yv) ;
             float get_YV() ;
    
             void set_Is_Alive(bool p_is_Alive) ;
             bool get_Is_Alive() ;
             void set_Is_Dead(bool p_is_Dead) ;
             bool get_Is_Dead() ;
             void set_Is_Walking(bool p_is_Walking) ;
             bool get_Is_Walking() ;
             void set_Is_Running(bool p_is_Running) ;
             bool get_Is_Running() ;
             void set_Is_Jumping(bool p_is_Jumping) ;
             bool get_Is_Jumping() ;
             void set_Is_Falling(bool p_is_Falling) ;
             bool get_Is_Falling() ;
             // Prototype head functions   
             int draw_Sprite(int x, int y) ;
             SDL_Rect clip_Sprite(SDL_Rect p_sprite_Clip[]) ;                 
};

#endif





#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "Sprite.h"
using namespace std ;

 // SDL_Surface* Player::sprite = IMG_Load("Player.png") ;

// Prototype body getters and setters   
void Sprite::set_Lives(int p_lives) 
{
        lives = p_lives ;            
}
int Sprite::get_Lives()
{
     return lives ; 
}
void Sprite::set_Health(int p_health)
{
    health = p_health ;
}
int Sprite::get_Health()
{
    return  health ;
}


void Sprite::set_X(int p_x)
{
     x = p_x ;
}
int Sprite::get_X()
{
     return x ;
}
void Sprite::set_Y(int p_y)
{
     y = p_y ;
}
int Sprite::get_Y()
{
    return y ;
}
void Sprite::set_XV(float p_xv)
{
     xv = p_xv ;
}
float Sprite::get_XV()
{
    return xv ;
}
void Sprite::set_YV(float p_yv)
{
     yv = p_yv ;
}
float Sprite::get_YV()
{
      return yv ;
}


void Sprite::set_Is_Alive(bool p_is_Alive)
{
     is_Alive = p_is_Alive ;
}
bool Sprite::get_Is_Alive()
{
     return is_Alive ;
}
void Sprite::set_Is_Dead(bool p_is_Dead)
{
     is_Dead = p_is_Dead ;
}
bool Sprite::get_Is_Dead()
{
     return is_Dead ;
}
void Sprite::set_Is_Walking(bool p_is_Walking)
{
     is_Walking = p_is_Walking ;
}
bool Sprite::get_Is_Walking()
{
     return is_Walking ;
}
void Sprite::set_Is_Running(bool p_is_Running)
{
     is_Running = p_is_Running ;
}
bool Sprite::get_Is_Running()
{
     return is_Running ;
}
void Sprite::set_Is_Jumping(bool p_is_Jumping)
{
     is_Jumping = p_is_Jumping ;
}
bool Sprite::get_Is_Jumping()
{
     return is_Jumping ;
}
void Sprite::set_Is_Falling(bool p_is_Falling)
{
     is_Falling = p_is_Falling ;
}
bool Sprite::get_Is_Falling()
{
     return is_Falling ;
}

// Prototype body functions
int Sprite::draw_Sprite(int p_x, int p_y)
{
    x = p_x ;
    y - p_y ;
}
SDL_Rect Sprite::clip_Sprite(SDL_Rect p_sprite_Clip[])
{
         sprite_Clip[0].x = p_sprite_Clip[0].x ;
         sprite_Clip[0].y = p_sprite_Clip[0].y ;
         sprite_Clip[0].h = p_sprite_Clip[0].h ;
         sprite_Clip[0].w = p_sprite_Clip[0].w ;   
         
         SDL_Surface* image = IMG_Load("Player.png");     
}


 






/*                                     :NOTE this comment is not yet in practice, well worry about using just one base sprite class later
(INHERITABLE PARENT BASE CLASS)

This header file class has all attributes to be inherited and to be initialised values by all other sprite objects of the game.
*/

#ifndef PLAYER_H
#define PLAYER_H

#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "Sprite.h"
using namespace std ;

using namespace std ;

class Player: public Sprite
{
      private:
             // variables
             unsigned short int lives ;
             unsigned short int health ;
            
             unsigned int x ;
             unsigned int y ;
             float xv ;
             float yv ;
             
             bool is_Alive ;
             bool is_Dead ;
             bool is_Walking ;
             bool is_Running ;
             bool is_Jumping ;
             bool is_Falling ;
             // not needed to be passed through constructor
            // SDL_Surface* sprite ;
             SDL_Rect sprite_Clip[0] ;
             SDL_Rect sprite_Dimensions[0] ;            
        public:
             // constructor / de-constructor
             Player(int p_lives, int p_health, int p_x, int p_y, float p_xv, float p_yv, bool p_is_Alive, bool p_is_Dead, bool p_is_Walking, bool p_is_Running, bool p_is_Jumping, bool p_is_Falling)
             {
                    lives = p_lives ;
                    health = p_lives ;
                    
                    x = p_x ;
                    y = p_y ;
                    xv = p_xv ;
                    yv = p_yv ;
                    
                    is_Alive = p_is_Alive ;
                    is_Dead = p_is_Dead ;
                    is_Walking = p_is_Walking ;
                    is_Running = p_is_Running ;
                    is_Jumping = p_is_Jumping ;
                    is_Falling = p_is_Falling ;                         
             } 
             ~Player()
             {
             }
             // Prototype head getters and setters             
             void set_Lives(int p_lives) ;           
             int get_Lives() ;                       
             void set_Health(int p_health) ;
             int get_Health() ;

             void set_X(int p_x) ;
             int get_X() ;            
             void set_Y(int p_y) ;
             int get_Y() ; 
             void set_XV(float p_xv);
             float get_XV();            
             void set_YV(float p_yv) ;
             float get_YV() ;
    
             void set_Is_Alive(bool p_is_Alive) ;
             bool get_Is_Alive() ;
             void set_Is_Dead(bool p_is_Dead) ;
             bool get_Is_Dead() ;
             void set_Is_Walking(bool p_is_Walking) ;
             bool get_Is_Walking() ;
             void set_Is_Running(bool p_is_Running) ;
             bool get_Is_Running() ;
             void set_Is_Jumping(bool p_is_Jumping) ;
             bool get_Is_Jumping() ;
             void set_Is_Falling(bool p_is_Falling) ;
             bool get_Is_Falling() ;
             // Prototype head functions   
             int draw_Sprite(int x, int y) ;
             SDL_Rect clip_Sprite(SDL_Rect p_sprite_Clip[]) ;                 
};

#endif




#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "Sprite.h"
using namespace std ;

 // SDL_Surface* Player::sprite = IMG_Load("Player.png") ;

// Prototype body getters and setters   
void Sprite::set_Lives(int p_lives) 
{
        lives = p_lives ;            
}
int Sprite::get_Lives()
{
     return lives ; 
}
void Sprite::set_Health(int p_health)
{
    health = p_health ;
}
int Sprite::get_Health()
{
    return  health ;
}


void Sprite::set_X(int p_x)
{
     x = p_x ;
}
int Sprite::get_X()
{
     return x ;
}
void Sprite::set_Y(int p_y)
{
     y = p_y ;
}
int Sprite::get_Y()
{
    return y ;
}
void Sprite::set_XV(float p_xv)
{
     xv = p_xv ;
}
float Sprite::get_XV()
{
    return xv ;
}
void Sprite::set_YV(float p_yv)
{
     yv = p_yv ;
}
float Sprite::get_YV()
{
      return yv ;
}


void Sprite::set_Is_Alive(bool p_is_Alive)
{
     is_Alive = p_is_Alive ;
}
bool Sprite::get_Is_Alive()
{
     return is_Alive ;
}
void Sprite::set_Is_Dead(bool p_is_Dead)
{
     is_Dead = p_is_Dead ;
}
bool Sprite::get_Is_Dead()
{
     return is_Dead ;
}
void Sprite::set_Is_Walking(bool p_is_Walking)
{
     is_Walking = p_is_Walking ;
}
bool Sprite::get_Is_Walking()
{
     return is_Walking ;
}
void Sprite::set_Is_Running(bool p_is_Running)
{
     is_Running = p_is_Running ;
}
bool Sprite::get_Is_Running()
{
     return is_Running ;
}
void Sprite::set_Is_Jumping(bool p_is_Jumping)
{
     is_Jumping = p_is_Jumping ;
}
bool Sprite::get_Is_Jumping()
{
     return is_Jumping ;
}
void Sprite::set_Is_Falling(bool p_is_Falling)
{
     is_Falling = p_is_Falling ;
}
bool Sprite::get_Is_Falling()
{
     return is_Falling ;
}

// Prototype body functions
int Sprite::draw_Sprite(int p_x, int p_y)
{
    x = p_x ;
    y - p_y ;
}
SDL_Rect Sprite::clip_Sprite(SDL_Rect p_sprite_Clip[])
{
         sprite_Clip[0].x = p_sprite_Clip[0].x ;
         sprite_Clip[0].y = p_sprite_Clip[0].y ;
         sprite_Clip[0].h = p_sprite_Clip[0].h ;
         sprite_Clip[0].w = p_sprite_Clip[0].w ;   
         
         SDL_Surface* image = IMG_Load("Player.png");     
}





Is This A Good Question/Topic? 0
  • +

Replies To: c++ Problem linking Player to appropriate Sprite base header/class

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: c++ Problem linking Player to appropriate Sprite base header/class

Posted 02 June 2013 - 06:43 AM

This is because you lack knowledge in C++. Without looking at the specific cause of the issue I can see that you're not using virtual methods and consequently have no understanding of function overriding.

You need to do some research on this.
Was This Post Helpful? 0
  • +
  • -

#3 steven_bishop  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 37
  • Joined: 20-October 12

Re: c++ Problem linking Player to appropriate Sprite base header/class

Posted 02 June 2013 - 06:53 AM

View PostButchDean, on 02 June 2013 - 06:43 AM, said:

This is because you lack knowledge in C++. Without looking at the specific cause of the issue I can see that you're not using virtual methods and consequently have no understanding of function overriding.

You need to do some research on this.


Ok then.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1