46
General discussions / Visuel c++ 2010
« on: December 12, 2009, 10:07:02 pm »
Is it possible to let it work, I just tried to use the 2008 libary from the none svn but it ain't working
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.
// The class which needs to update
Cockpit::Cockpit()
{
std::cout << "Cockpit" << std::endl;
turningspeed = 4;
direction = 0.f;
if (!Image.LoadFromFile("Cockpit.png"))
{
std::cout << "Error loading image file !" << std::endl;
}
sprite.SetImage(Image);
sprite.SetScale(0.5f,0.5f);
float Width = sprite.GetSize().x;
float Height = sprite.GetSize().y;
sprite.SetRotation(direction);
sprite.SetCenter(Width/2, Height/2);
sprite.SetPosition(400.f,300.f);
x,target_x = 400;y,target_y,y = 300;
}
void Cockpit::Think(sf::RenderWindow &Render)
{
direction = atan2(target_y-y,target_x-x)*180/PI;
sprite.SetRotation(direction);
}
// Inputmanager
void InputManager::Think(sf::RenderWindow &Render)
{
const sf::Input &Input = Render.GetInput();
mouse_x = Input.GetMouseX();
mouse_y = Input.GetMouseY();
mouse_right = Input.IsMouseButtonDown(sf::Mouse::Right);
sprite.SetPosition(mouse_x,mouse_y);
if (mouse_right == true)
{
hold_right += Render.GetFrameTime();
}
if (mouse_right == false && hold_right > 0)
{
if (hold_right >= 0.5)
{
hold_right = 0;
std::cout << "Window" << std::endl;
} else {
hold_right = 0;
player->Goto(mouse_x,mouse_y);
}
}
if(Render.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Render.Close();
if((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::Escape))
Render.Close();
if (Event.Key.Code == sf::Key::F1)
{
sf::Image Screen = Render.Capture();
Screen.SaveToFile("screenshot.jpg");
}
}
}
#ifndef WORLD
#define WORLD
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
#include "BaseEnt.hpp"
#include "Cockpit.hpp"
class World
{
private:
sf::Input& Input;
sf::Event Event;
sf::RenderWindow GameWindow;
public:
std::vector<BaseEnt*> Entities;
World();
void Draw();
void Think();
void CreateCockpit();
sf::RenderWindow &GetApp() {return GameWindow;}
};
#endif
#include "world.hpp"
World::World()
{
GameWindow.Create(sf::VideoMode(800,600,32),"Space Snapper",sf::Style::Close,sf::WindowSettings(8,24,2));
GameWindow.SetFramerateLimit(100);
Input = GameWindow.GetInput();
std::cout<<"World Created !" << std::endl;
}
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
class Debug
{
private:
sf::RenderWindow& Render;
sf::String Text;
sf::Font IDK;
public:
Debug(sf::RenderWindow& app);
void Draw();
};
Debug::Debug(sf::RenderWindow& app) : Render(app)
{
if (!IDK.LoadFromFile("arial.ttf"))
{
std::cout<<"Cannot load font !";
}
Text.SetText("FPS :");
Text.SetFont(sf::Font::GetDefaultFont());
Text.SetSize(10);
Text.SetPosition(5.f, 5.f);
Text.SetColor(sf::Color(0,0,0,255));
}
void Debug::Draw()
{
Render.Draw(Text);
}