Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- // Headers
- ////////////////////////////////////////////////////////////
- #define SFML_DYNAMIC
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <ctime>
- #include <string.h>
- #include <map>
- #include <SFML/System.hpp>
- #include <SFML/Window.hpp>
- #include <SFML/Graphics.hpp>
- #include <SFML/Graphics/RenderWindow.hpp>
- #include <windows.h>
- using namespace sf;
- #define TANK1_FORWARD 10
- #define TANK1_BACK 11
- #define TANK1_LEFT 12
- #define TANK1_RIGHT 13
- #define TANK1_FIRE 14
- #define TANK2_FORWARD 20
- #define TANK2_BACK 21
- #define TANK2_LEFT 22
- #define TANK2_RIGHT 23
- #define TANK2_FIRE 24
- int width, height;
- sf::Clock Clock;
- void initWindow () {
- width = 1024;
- height = 810;
- }
- std::string ftos ( float x ) {
- std::ostringstream oss;
- oss << x;
- return oss.str();
- }
- void defaultControll ( std::map<int, int>& pole ) {
- pole.insert( std::make_pair( TANK1_FORWARD, Key::Up ));
- pole.insert( std::make_pair( TANK1_BACK, Key::Down ));
- pole.insert( std::make_pair( TANK1_LEFT, Key::Left ));
- pole.insert( std::make_pair( TANK1_RIGHT, Key::Right ));
- pole.insert( std::make_pair( TANK1_FIRE, Key::Space ));
- pole.insert( std::make_pair( TANK2_FORWARD, Key::W ));
- pole.insert( std::make_pair( TANK2_BACK, Key::S ));
- pole.insert( std::make_pair( TANK2_LEFT, Key::A ));
- pole.insert( std::make_pair( TANK2_RIGHT, Key::D ));
- pole.insert( std::make_pair( TANK2_FIRE, Key::LControl ));
- }
- int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- initWindow ();
- //std::map< Key::H ,int> pole;
- // Create main window
- RenderWindow App;
- //App.Create(sf::VideoMode(width, height), "SFML Fonts");
- App.Create(VideoMode(width, height, 16), "SFML Test", Style::Fullscreen );
- App.Clear( sf::Color( 0, 255, 255) );
- //sf::RenderWindow::SetBackgroundColor ( const Color & Col )
- Event input;
- bool fullscreen = true;
- float timeCounter = 0;
- float framesCounter = 0;
- float frameLatencyCounter = 0;
- float fNumber = 0.f;
- int speed = 5;
- // Load a font from a file
- Font MyFont;
- if (! MyFont.LoadFromFile("Veloped.ttf", 50))
- return EXIT_FAILURE;
- sf::Clock Clock;
- // Create a graphical string
- String Hello;
- Hello.SetText("Hello !\nHow are you ?");
- Hello.SetFont( MyFont );
- Hello.SetColor( Color(0, 128, 128));
- Hello.SetPosition(100.f, 100.f);
- //Hello.SetRotation(15.f);
- Hello.SetSize(50.f);
- String TimeText;
- TimeText.SetText( "abcd");
- TimeText.SetColor( Color(128, 128, 128));
- TimeText.SetPosition(0.f, 0.f);
- TimeText.SetSize(20.f);
- float Framerate = 0.f;
- float msecSave = 0;
- unsigned int odStartuSecSave = 0;
- unsigned int odStartuSec = (unsigned int) ( ((int) clock()) / 1000);
- // Start game loop
- while (App.IsOpened())
- {
- // Process events
- App.Clear( sf::Color(255,255,255) );
- while (App.GetEvent(input)) {
- //Exit
- if (input.Type == Event::Closed) App.Close();
- if ( (input.Type == Event::KeyPressed) && (input.Key.Code == Key::Escape) )
- App.Close();
- if ( (input.Type == Event::KeyPressed) && (input.Key.Code == Key::H ) )
- App.Window::Show ( false );
- if ( (input.Type == Event::KeyPressed) && (input.Key.Code == Key::S ) )
- App.Window::Show ( true );
- //Fullscreen toggle
- if (( input.Type == Event::KeyPressed ) && (input.Key.Code == Key::F ) ) {
- fullscreen = !fullscreen;
- if ( fullscreen )
- App.Create(VideoMode(width, height, 16), "SFML Test", Style::Fullscreen );
- else
- App.Create(VideoMode(width, height, 16), "SFML Test", Style::Resize|Style::Close );
- }
- }
- App.Clear( sf::Color( 0, 255, 255) );
- TimeText.SetPosition(30.f, 30.f);
- float Framerate = 1.f / Clock.GetElapsedTime();
- Clock.Reset();
- framesCounter++;
- frameLatencyCounter += Framerate;
- odStartuSec = (unsigned int) (clock()/ 1000);
- if ( odStartuSecSave != odStartuSec ) {
- odStartuSecSave = odStartuSec;
- speed = ( speed + 2 ) % 30;
- Framerate = frameLatencyCounter / framesCounter;
- framesCounter = 0;
- frameLatencyCounter = 0;
- timeCounter = 0;
- TimeText.SetText( ftos ( Framerate ) );
- std::cout << "====" << odStartuSec << std::endl;
- } else {
- std::cout << "<" << odStartuSec << std::endl;
- }
- // std::count << Time ;
- const Vector2f& positionVector = Hello.GetPosition ();
- if ( positionVector.x + speed <= width )
- Hello.SetPosition(positionVector.x + speed, positionVector.y);
- else
- Hello.SetPosition( 0, positionVector.y);
- App.Draw(Hello);
- App.Draw(TimeText);
- App.Display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement