Sign in to follow this  

Creating Objects Problems with my Players

This topic is 4337 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

im having problems with the code while making my football game Here is the layout of my game GAME(main.cpp) --- HAS 20---> PLAYER (player.cpp(base class)) My problem is that when i create 10 Player objects for team 1, and 10 for team 2, all are using a single objects values. If i set team 1 - player 1 to be 100m tall every player in team 1 and team 2 become 100m tall if i choose team 1 players all to have red shirts and team 2 players all have blue shirts, ALL players (both teams) end up wearing red shirts. -------------------------------------------------------------------- Here is my code inside GAME AttackPlayer *Attacker[10]; for(count =0; count< 10; count++) { Attacker[count] = new AttackPlayer; Attacker[count] -> InitialisePlayer(TEAM1); } for(count =0; count< 10; count++) { AttackerData[count][rotation] = AttackerSetRunFacing(count); Attacker[count]->PlayerPrepare(AttackerData[count][RunAniSpeed]); Attacker[count]->DrawPlayer(AttackerData[count][currentx], AttackerData [count][currenty], AttackerData[count][currentz], AttackerData[count][rotation]); } ------------------------------------------------------------------------------ TEAM1 is a variable passed to the initialisation function of the player class. It tells it which team shirt the player should wear. Other values like player height, colour and animation speed are passed from GAME to the individual PLAYER. Attackerdata is a double array holding the individuals stats like location and current status in the game world. ------------------------------------------------------------------------------ I think its because i have confused pointers to objects and actual objects or something, I want each of the 20 players to have their own PLAYER object with their own variables. Please Help :) Paul

Share this post


Link to post
Share on other sites
AttackPlayer Header file
--------------------------------------------------------------------
class CTargaImage;

class AttackPlayer
{
private:




public:

AttackPlayer();
virtual ~AttackPlayer();

bool Shutdown();

void InitialisePlayer(int whotheyr);

void PlayerDrawCube(float xPos, float yPos, float zPos);

void PlayerDrawFoot(float xPos, float yPos, float zPos);

void PlayerDrawArm(float xPos, float yPos, float zPos);

void PlayerDrawHead(float xPos, float yPos, float zPos);

void PlayerDrawTorso(float xPos, float yPos, float zPos);

void PlayerDrawLeg(float xPos, float yPos, float zPos);

void DrawPlayer(float xPos, float yPos, float zPos, float Rotates);

void PlayerPrepare(float dt);

};

Attack Player Cpp file
------------------------------------------------------------------------------

#define TEXclear 0
#define TEXskin 1
#define TEXfrontshirt 2
#define TEXbackshirt 3
#define TEXtopsideshirt 4
#define TEXarm 5
#define TEXshorts 6
#define TEXface 7
#define TEXhair 8

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
#include <time.h>
#include "AttackPlayer.h"
#include "FileHandler.h"


char legStates[2];
char armStates[2];

float legAngles[2];
float armAngles[2];

const char LEFT = 0;
const char RIGHT = 1;

const char BACKWARD_STATE = 0;
const char FORWARD_STATE = 1;
float rotationAngle = 2.0f;

int TextureSet;

unsigned int attackTex[9];
FileHandler *attackFileGet = NULL;

int chosenTex[6];


AttackPlayer::AttackPlayer()
{
armAngles[LEFT] = 0.0;
armAngles[RIGHT] = 0.0;
legAngles[LEFT] = 0.0;
legAngles[RIGHT] = 0.0;

armStates[LEFT] = FORWARD_STATE;
armStates[RIGHT] = BACKWARD_STATE;

legStates[LEFT] = FORWARD_STATE;
legStates[RIGHT] = BACKWARD_STATE;
}

AttackPlayer::~AttackPlayer()
{
}

void AttackPlayer::InitialisePlayer(int whotheyr)
{
TextureSet = whotheyr;

attackFileGet = new FileHandler;

attackFileGet -> InitialiseTextures(attackTex, TextureSet);
chosenTex[0] = TEXclear;
}

Share this post


Link to post
Share on other sites
Ahhh right, im not the best programmer in the world and always make silly mistakes and forget these types of rules.

Could you please show me how to change my code to allow each instance of my PLAYER class to have its own member variables.

I want each player to have his own height/ animation speed etc

Share this post


Link to post
Share on other sites

This topic is 4337 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this