summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-12-01 21:29:53 +0100
committertomsmeding <hallo@tomsmeding.nl>2015-12-01 21:29:53 +0100
commitac18b3132059b5e7d5f00ccf2b56e543cf0da84b (patch)
tree490654385bf6aa87f160f79006a12289c20322e6 /main.cpp
parentdcaa318d677a1a6881ccc87640ae75c0fc578bfb (diff)
DAT GAME
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/main.cpp b/main.cpp
index 98ea6ac..f9312bd 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,12 @@
#include <iostream>
-#include <cstring>
#include <memory>
+#include <cstring>
+#include <cstdlib>
+#include <sys/time.h>
+#include "main.h"
#include "object_base.h"
#include "global.h"
+#include "library.h"
#include "build/objects.h"
#include <FL/Fl.H>
@@ -11,25 +15,49 @@
using namespace std;
-Global global;
-
-shared_ptr<Object> objectfromname(const char *name){
+shared_ptr<Object> makeobjectbyname(int x,int y,const char *name){
-#define X(objname) if(strcmp(name,#objname)==0)return make_shared<objname>();
+#define X(objname) if(strcmp(name,#objname)==0)return make_shared<objname>(x,y);
OBJECT_CLASSES_XLIST
#undef X
return NULL; //no object with that name
}
+
+Global global;
+Fl_Window_draw *window;
+
+
+
+Fl_Window_draw::Fl_Window_draw(int w,int h,const char *title=0):Fl_Window(w,h,title){}
+Fl_Window_draw::Fl_Window_draw(int x,int y,int w,int h,const char *label=0L):Fl_Window(x,y,w,h,label){}
+void Fl_Window_draw::draw(void){
+ fl_rectf(0,0,w(),h(),FL_WHITE);
+ fl_color(FL_BLACK);
+ int i;
+ for(i=0;i<(int)global.objects.size();i++){
+ global.objects[i]->draw();
+ }
+}
+
+
void stepcallback(void*){
+ int i;
+ for(i=0;i<(int)global.objects.size();i++){
+ global.objects[i]->step();
+ }
+ window->redraw();
Fl::repeat_timeout(1.0/30,stepcallback);
}
int main(int argc,char **argv){
- Fl_Window *window=new Fl_Window(640,480,GAME_NAME);
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ srand(tv.tv_sec*1000000+tv.tv_usec);
+ window=new Fl_Window_draw(640,480,GAME_NAME);
- global.objects.push_back(objectfromname("obj_control"));
+ global.objects.push_back(makeobjectbyname(0,0,"obj_control"));
global.objects[0]->create();
window->end();