Jump to content
  • Advertisement
Sign in to follow this  
DanielAxelsson

Can't render with hgeFont

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

Hey! Iam working with a game with the help with Hge. The problem I have is that I want to render out "Life: " och "Score: " on the screen. I have use hgeFont to do that but it don't work. The code:

Game.h:

#ifndef _GAME_
#define _GAME_
#include <hge.h>
#include <vector>
#include "Enemy.h"
#include "Explosion.h"
#include <hgefont.h>


class Player;

class Game
{
public:
~Game(void);
HGE* getHGE();
void Update();
void Game::setHGE(HGE* hge);
void Draw();
Game* getGame();
static Game* getInstance();
void CreatePlayer();
std::vector<Explosion*>ExplosionList;
std::vector<Enemy*> EnemyList;
private:

float mTimer, mRandomDir, mX, mY, mScore;


Game();
static Game* mInstance;
//Den här ska finnas över allt på HGE. Men för att slippa att skriva över allt skrev jag den här.
HGE* hge;

char tempLifeString[100];
char tempScoreString[100];

// Pythagoras sats c
double c, cPlayer, cEnemybullet;
hgeFont* mLifeFont;
hgeFont* mScoreFont;
Player* player;
};

#endif

Game.cpp:

#include "Game.h"
#include <hge.h>
#include "Player.h"
#include <ctime>
#include <time.h>
#include <cmath>
#include <stdlib.h>

Game* Game::mInstance = 0;


Game::Game()
{
mScore=0;
mRandomDir=0;
mLifeFont= new hgeFont("font1.fnt");
mScoreFont = new hgeFont("font1.fnt");
mScoreFont->SetColor(0xFFFFFFFF);
mLifeFont->SetColor(0xFFFFFFFF);
}

Game::~Game(void)
{
delete player;
}


Game* Game::getInstance()
{
if (!mInstance)
{
mInstance = new Game();
}
return mInstance;
}

void Game::CreatePlayer()
{
player=new Player();
}

void Game::setHGE(HGE* hge)
{
this->hge=hge;

}

void Game::Update()
{


player->Update();


static clock_t mTimer = clock() + CLOCKS_PER_SEC * 0.25;
mRandomDir= rand() % 2;

//Skapar fiender på skrämen
if(mTimer <= clock())
{
//if(mRandomDir==0)
//{
EnemyList.push_back(new Enemy(0));

mTimer = clock() + 0.25 * CLOCKS_PER_SEC;

//}

//else if(mRandomDir==1)
//{
//EnemyList.push_back(new Enemy(-1));

//mTimer = clock() + 0.25 * CLOCKS_PER_SEC;

//}
}

for(int i=0; i < EnemyList.size(); i++)
{

EnemyList->Update();

cPlayer = pow(player->GetX() - EnemyList->GetX(), 2) + pow(player->GetY() - EnemyList->GetY(), 2);

//Player and Enemy collide
if(cPlayer < (player->GetRadius() + EnemyList->GetRadius()))
{
//Skapar en Explosion och lägger den i en vector.
ExplosionList.push_back(new Explosion((EnemyList->GetX()-EnemyList->GetRadius()),(EnemyList->GetY()-EnemyList->GetRadius())));
EnemyList->Collide();
player->Collide();
mScore=mScore+50;
}


//Playerbullet collide with enemy
for(int j=0; j < player->GetPlayerBullet().size() ; j++)
{

c = pow(player->GetPlayerBullet()[j]->GetX() - EnemyList->GetX(), 2) + pow(player->GetPlayerBullet()[j]->GetY() - EnemyList->GetY(), 2);


if(c < (player->GetPlayerBullet()[j]->GetRadius() + EnemyList->GetRadius()))
{
//Skapar en Explosion och lägger den i en vector.
ExplosionList.push_back(new Explosion((EnemyList->GetX()-EnemyList->GetRadius()),(EnemyList->GetY()-EnemyList->GetRadius())));
EnemyList->Collide();
delete player->GetPlayerBullet()[j];
player->GetPlayerBullet().erase(player->GetPlayerBullet().begin()+j);
mScore=mScore+50;
}


}

//Enemybullet collide with player
for(int k=0; k < EnemyList->EnemyBullets.size(); k++)
{
cEnemybullet = pow(player->GetX() - EnemyList->EnemyBullets[k]->GetX() , 2) + pow(player->GetY() - EnemyList->EnemyBullets[k]->GetY(), 2);

if(cEnemybullet < (player->GetRadius() + EnemyList->EnemyBullets[k]->GetRadius()))
{
player->Collide();
delete EnemyList->EnemyBullets[k];
EnemyList->EnemyBullets.erase(EnemyList->EnemyBullets.begin()+k);
}

}



if(EnemyList->GetY()>600)
{
EnemyList->Collide();
}
if(EnemyList->IsAlive()==0)
{
delete EnemyList;
EnemyList.erase(EnemyList.begin()+i);
}

}

for(int i=0; i < ExplosionList.size(); i++)
{
ExplosionList->Update();

if(ExplosionList->mTime<=0)
{
delete ExplosionList;
ExplosionList.erase(ExplosionList.begin()+i);
}

}

}



void Game::Draw()
{

for(int i=0; i < ExplosionList.size(); i++)
{
ExplosionList->Render();
}

for(int i=0; i < EnemyList.size(); i++)
{
EnemyList->Render();
}
player->Render();

//This is where I use to render out Life and Score
mLifeFont->printfb(20.0, 20.0, 40.0, 40.0, 2, "Life:");
mLifeFont->printfb(40.0, 20.0, 40.0, 40.0, 2, itoa(player->GetLife(), tempLifeString, 10));
mScoreFont->printfb(120, 20, 40, 40, 2, "Score:");
mScoreFont->printfb(140, 20, 40, 40, 2, itoa(mScore, tempScoreString, 10));

}


HGE* Game::getHGE()
{
return hge;
}


I have check mLifeFont->printfb(20.0, 20.0, 40.0, 40.0, 2, "Life:"); on debug I get: CXX0052: Error: member function not present. I have tride everything but nothing works! Help me!

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!