diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 57 |
1 files changed, 54 insertions, 3 deletions
@@ -3,7 +3,7 @@ #include <cstring> #include <cstdlib> #include <sys/time.h> -#include "main.h" +#include <SFML/Graphics.hpp> #include "object_base.h" #include "global.h" #include "library.h" @@ -24,7 +24,58 @@ OBJECT_CLASSES_XLIST Global global; -static Fl_Window_draw *window; + +sf::RenderWindow window; + + +void eventCycle(){ + sf::Event event; + while(window.pollEvent(event)){ + if(event.type==sf::Event::Closed){ + window.close(); + return; + } else if(event.type==sf::Event::KeyPressed){ + if(event.key.code==sf::Keyboard::Escape){ + window.close(); + return; + } + } + } + + for(int i=0;i<(int)global.objects.size();i++){ + global.objects[i]->step(); + } + + window.clear(sf::Color::White); + + for(int i=0;i<(int)global.objects.size();i++){ + global.objects[i]->draw(); + } + + window.display(); +} + +int main(void){ + struct timeval tv; + gettimeofday(&tv,nullptr); + srand(tv.tv_sec*1000000+tv.tv_usec); + + window.create(sf::VideoMode(640,480),GAME_NAME); + window.setVerticalSyncEnabled(true); + + global.objects.push_back(makeobjectbyname(0,0,"obj_control")); + global.objects[0]->create(); + + while(window.isOpen()){ + eventCycle(); + } + + for(shared_ptr<Object> p : global.objects){ + p->destroy(); + } +} + +/*static Fl_Window_draw *window; @@ -70,4 +121,4 @@ int main(int argc,char **argv){ p->destroy(); } return ret; -} +}*/ |