im a total beginner to make it easier for you, here my code:
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
////////////////////////////////////////////////////////////
/// Entry point of application
////////////////////////////////////////////////////////////
int main()
{
// Create main window
RenderWindow App;
App.Create(sf::VideoMode(800, 600, 32), "SFML Window", sf::Style::Fullscreen);
// Cursor is not being shown
ShowCursor(0);
// Build a custom convex shape
Shape Polygon;
{
Polygon.AddPoint(0, 0, sf::Color(255, 0, 0), sf::Color(0, 128, 128));
Polygon.AddPoint(50, 0, sf::Color(255, 85, 85), sf::Color(0, 128, 128));
Polygon.AddPoint(50, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
Polygon.AddPoint(0, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
Polygon.SetOutlineWidth(0);
Polygon.EnableFill(true);
Polygon.EnableOutline(true);
Polygon.SetColor(Color(255, 255, 255, 255));
Polygon.Scale(3, 1);
Polygon.SetPosition(400,550);
}
Shape Ball;
{
Ball.AddPoint(0,0, sf::Color(255,255,255),sf::Color(255,255,255));
Ball.AddPoint(10,0, sf::Color(255,255,255),sf::Color(255,255,255));
Ball.AddPoint(10,10, sf::Color(255,255,255),sf::Color(255,255,255));
Ball.AddPoint(0,10, sf::Color(255,255,255),sf::Color(255,255,255));
}
int movex = 50;
int movey = 50;
Vector2<float> ballvec;
Vector2<float> shapevec;
Clock Spieluhr;
Clock Uhr;
String Text;
Text.SetFont(sf::Font::GetDefaultFont());
Text.SetSize(20);
while (App.IsOpened())
{
// Process events
Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == Event.Closed)
App.Close();
// keybord-events
if ((Event.Type == Event.KeyPressed) && (Event.Key.Code == Key::Escape))
{
App.Close();
}
if ((Event.Type == Event.KeyPressed) && (Event.Key.Code == Key::Num1))
{
Polygon.Rotate(15);
}
// mouse-events
if (Event.Type == Event.MouseMoved)
{
Polygon.SetPosition(Event.MouseMove.X,550);
}
}
// Manage Ball
ballvec = Ball.GetPosition();
shapevec = Polygon.GetPosition();
if((ballvec.y + movey *App.GetFrameTime() >= 540) && (ballvec.x >= shapevec.x) && (ballvec.x <= shapevec.x +150) )
{
movey = -movey;
}
if(ballvec.y +movey *App.GetFrameTime() <= 0)
{
movey = -movey;
}
if(ballvec.x + movex *App.GetFrameTime() >= 790)
{
movex = -movex;
}
if(ballvec.x + movex *App.GetFrameTime() <= 0)
{
movex = -movex;
}
if(Uhr.GetElapsedTime() > 5.0)
{
if (movex > 0)
{
movex = movex + 50;
}
if (movex < 0)
{
movex = movex - 50;
}
if (movey > 0)
{
movey = movey + 50;
}
if (movey < 0)
{
movey = movey - 50;
}
Uhr.Reset();
}
Text.SetText("hallo");
Ball.Move(movex * App.GetFrameTime(), movey * App.GetFrameTime());
// Draw it
App.Draw(Text);
App.Draw(Ball);
App.Draw(Polygon);
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
its not perfect yet but i think its playable now;
can anyone tell me how to convert a float into String?