1
General / CMD Console!?
« on: February 20, 2012, 11:59:13 pm »
Thank you for your help. the problem has been resolved.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Engine.h"
int main()
{
Engine Game;
Game.Run();
return EXIT_SUCCESS;
}
#ifndef ENGINE_H
#define ENGINE_H
class Engine
{
public:
Engine();
~Engine();
void Init();
void HandleEvents();
void Update();
void Render();
void Cleanup();
void Run();
protected:
private:
sf::RenderWindow App;
sf::Event Event;
sf::Clock Clock;
int fps;
};
#endif
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Engine.h"
#include "GUI.h"
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
GUI gui;
Engine::Engine():
fps(0)
{
App.Create(sf::VideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP), "Engine");
sf::Sleep(1.f);
}
Engine::~Engine()
{
}
void Engine::Init()
{
}
void Engine::HandleEvents()
{
if(Event.Type == sf::Event::Closed)
App.Close();
}
void Engine::Update()
{
fps++;
if(Clock.GetElapsedTime() >= 1.f)
{
fps++;
if(Clock.GetElapsedTime() >= 1.f)
{
int Framerate = (1.f / Clock.GetElapsedTime()) * 1000;
std::cout << "FPS: " << Framerate<< std::endl;
Clock.Reset();
}
}
}
void Engine::Render()
{
App.Clear(sf::Color(0,0,0));
App.Draw(gui.Rupee_GUI);
App.Draw(gui.Rupee_Amount);
App.Draw(gui.Arrow_GUI);
App.Draw(gui.Arrow_Amount);
App.Draw(gui.Bomb_GUI);
App.Draw(gui.Bomb_Amount);
App.Draw(gui.Heart[2]);
App.Display();
}
void Engine::Cleanup()
{
}
void Engine::Run()
{
Init();
while(App.IsOpened())
{
while(App.PollEvent(Event))
{
HandleEvents();
}
Update();
Render();
}
Cleanup();
}
#ifndef GUI_H
#define GUI_H
class GUI
{
public:
GUI(void);
~GUI(void);
sf::Text Rupee_Amount;
sf::Image rupee_GUI;
sf::Sprite Rupee_GUI;
sf::Text Arrow_Amount;
sf::Image arrow_GUI;
sf::Sprite Arrow_GUI;
sf::Text Bomb_Amount;
sf::Image bomb_GUI;
sf::Sprite Bomb_GUI;
sf::Image heart1;
sf::Image heart2;
sf::Image heart3;
sf::Image heart4;
sf::Image heart5;
int i;
sf::Sprite Heart[2];
int Rupees;
int Bombs;
int Arrows;
private:
};
#endif
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <sstream>
#include "GUI.h"
std::string IntToString (int number);
GUI::GUI(void)
{
sf::Font Font;
Font.LoadFromFile("Fonts/RetGanon.ttf");
// RUPEES**********************************************************
// IMAGE
rupee_GUI.LoadFromFile("Sprites/Rupee_Gui_Img.png");
Rupee_GUI.SetImage(rupee_GUI);
Rupee_GUI.SetPosition(30.0f, 558.0f);
// TEXT
std::string Rupees_Text = IntToString(Rupees);
Rupee_Amount.SetString(Rupees_Text);
Rupee_Amount.SetCharacterSize(16u);
Rupee_Amount.SetStyle(sf::Text::Bold);
Rupee_Amount.SetColor(sf::Color(252,253,255));
Rupee_Amount.Move(45.0f, 554.0f);
// ARROWS **********************************************************
// IMAGE
arrow_GUI.LoadFromFile("Sprites/Arrow_GUI.png");
Arrow_GUI.SetImage(arrow_GUI);
Arrow_GUI.SetPosition(355, 5);
// TEXT
std::string Arrow_Text = IntToString(Arrows);
Arrow_Amount.SetString(Arrow_Text);
Arrow_Amount.SetCharacterSize(16u);
Arrow_Amount.SetStyle(sf::Text::Bold);
Arrow_Amount.SetColor(sf::Color(252,253,255));
Arrow_Amount.Move(350,23);
// Bombs *************************************************************
// IMAGE
bomb_GUI.LoadFromFile("Sprites/Bomb_GUI.png");
Bomb_GUI.SetImage(bomb_GUI);
Bomb_GUI.SetPosition(450,7);
// TEXT
std::string Bomb_Text = IntToString(Bombs);
Bomb_Amount.SetString(Bomb_Text);
Bomb_Amount.SetCharacterSize(16u);
Bomb_Amount.SetStyle(sf::Text::Bold);
Bomb_Amount.SetColor(sf::Color(252,253,255));
Bomb_Amount.Move(445,23);
// HARTS ***************************************************************
heart1.LoadFromFile("Sprites/Hart1.png");
heart2.LoadFromFile("Sprites/Hart2.png");
heart3.LoadFromFile("Sprites/Hart3.png");
heart4.LoadFromFile("Sprites/Hart4.png");
heart5.LoadFromFile("Sprites/Hart5.png");
Heart[2].SetImage(heart1);
Heart[2].Scale(2.0f, 2.0f);
int x = 761;
int y = 20;
for(int i=0; i < 2; i++)
{
Heart[i].SetPosition(x, y);
x -= 20;
}
/*Heart1.SetPosition(761, 20);
Heart2.SetPosition(741, 20);
Heart3.SetPosition(721, 20);*/
}
GUI::~GUI(void)
{
}
std::string IntToString (int number)
{
std::ostringstream oss;
if(number <= 9)
{
oss << "00" << number;
}
else if(number <= 99 && number >= 10)
{
oss << "0" << number;
}
else if(number <= 999 && number >= 100)
{
oss << number;
}
return oss.str();
}