Jump to content
  • Advertisement
Sign in to follow this  
DanielAxelsson

Help with HGE font

This topic is 2617 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 guys! I need help with my code. Iam using HGE to my game. Iam using font to make the text "Life: " to be on the screen. But no "Life: " is on the screen when I start the game. I have lock on font.fnt and font.png and they are on the right place. I have followde on the HGE website how is done and I have friends how have work with HGE before. They don't understand way this done't work. Help me with this please.

The code:

Game.h

#ifndef _GAME_
#define _GAME_
#include <hge.h>
#include "Player.h"
#include "Spawn.h"
#include "Enemy.h"

class Game
{
public:
~Game(void);
//Här hämntar den HGE till de andra klasserna
HGE* getHGE();
void setHGE(HGE* hge);
void Draw();
void Update();
Player* getPlayer();
Spawn* getSpawn();
Game* getGame();
static Game* getInstance();

private:

Game();
static Game* m_instance;
//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;

//Skapar en spelare och får en pekare till den.
Player* player;

Spawn* spawn;

hgeFont *fnt;
};


#endif



Game.cpp

#include "Game.h"
#include <hge.h>
#include "Player.h"
#include "Bullet.h"
#include "Spawn.h"
#include "Enemy.h"
//I Game skickar vi hge till allt och det är här själv spelet ska finnas. Den ska updateras i varje frame.
Game* Game::m_instance = 0;


Game::Game()
{
fnt = new hgeFont("font1.fnt");
fnt->SetScale(1.0); //set text size to normal
fnt->SetColor(ARGB(255,255,0,0)); //set color of text
fnt->SetBlendMode(BLEND_COLORADD);
}

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

//Gör så att alla klasser får tag på hge
HGE* Game::getHGE()
{
return hge;
}

Game* Game::getInstance()
{
if (!m_instance)
m_instance = new Game();

return m_instance;
}

void Game::setHGE(HGE* hge)
{
player=new Player(hge);
spawn=new Spawn(player);
this->hge=hge;
}

Player* Game::getPlayer()
{
return player;
}

Spawn* Game::getSpawn()
{
return spawn;
}



void Game::Draw()
{
fnt->printf(400, 300, HGETEXT_CENTER, "Life: ");
//fnt->Render(400, 300, HGETEXT_CENTER, "Life:"); //Skiver ut Life: Score
player->Draw();
spawn->Draw();
}

void Game::Update()
{
//Updaterar vad som händer i Spelaren.
player->Update(hge);

//Detta är dessa update som updaterar fienderna
spawn->Update(hge, player);
}

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!