1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <iostream>
#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 "build/sprites.h"
using namespace std;
static shared_ptr<Object> makeobjectbyname(int x,int y,const char *name){
#define X(objname) if(strcmp(name,#objname)==0)return make_shared<objname>(x,y);
OBJECT_CLASSES_XLIST
#undef X
return nullptr; //no object with that name
}
Global global;
static 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=nullptr)
: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){
struct timeval tv;
gettimeofday(&tv,nullptr);
srand(tv.tv_sec*1000000+tv.tv_usec);
window=new Fl_Window_draw(640,480,GAME_NAME);
global.objects.push_back(makeobjectbyname(0,0,"obj_control"));
global.objects[0]->create();
window->end();
Fl::visual(FL_RGB);
window->show(argc,argv);
Fl::add_timeout(1.0/30,stepcallback);
int ret=Fl::run();
for(shared_ptr<Object> p : global.objects){
p->destroy();
}
return ret;
}
|