From ac18b3132059b5e7d5f00ccf2b56e543cf0da84b Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 1 Dec 2015 21:29:53 +0100 Subject: DAT GAME --- Makefile | 5 ++++- library.cpp | 9 ++++++++- library.h | 1 + main.cpp | 42 +++++++++++++++++++++++++++++++++++------- main.h | 12 ++++++++++++ object_base.cpp | 8 ++++++-- object_base.h | 1 + object_header_extractor.cpp | 3 ++- object_header_maker.cpp | 2 ++ object_wrapper.cpp | 11 +++++++---- src/objects/obj_control.cpp | 16 +++++++++++++--- 11 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 main.h diff --git a/Makefile b/Makefile index 05676ee..a7baecc 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ base_src := $(wildcard *_base.cpp) base_src += library.cpp main.cpp base_obj := $(patsubst %.cpp,build/%.o,$(base_src)) -.PHONY: all clean remake +.PHONY: all clean remake run #keep all intermediate files! .SECONDARY: @@ -24,6 +24,9 @@ clean: remake: clean all +run: all + ./$(BIN) + $(BIN): $(base_obj) $(object_obj) $(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^ diff --git a/library.cpp b/library.cpp index 5cfb68f..f59d542 100644 --- a/library.cpp +++ b/library.cpp @@ -1,8 +1,15 @@ #include #include "library.h" +#include "main.h" using namespace std; +extern Fl_Window_draw *window; + void draw_text(int x,int y,const char *s){ - cerr<<"draw_text: x="< -#include #include +#include +#include +#include +#include "main.h" #include "object_base.h" #include "global.h" +#include "library.h" #include "build/objects.h" #include @@ -11,25 +15,49 @@ using namespace std; -Global global; - -shared_ptr objectfromname(const char *name){ +shared_ptr makeobjectbyname(int x,int y,const char *name){ -#define X(objname) if(strcmp(name,#objname)==0)return make_shared(); +#define X(objname) if(strcmp(name,#objname)==0)return make_shared(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(); diff --git a/main.h b/main.h new file mode 100644 index 0000000..b49d507 --- /dev/null +++ b/main.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include + +class Fl_Window_draw : public Fl_Window{ +public: + Fl_Window_draw(int w,int h,const char *title); + Fl_Window_draw(int x,int y,int w,int h,const char *label); + void draw(void); +}; diff --git a/object_base.cpp b/object_base.cpp index d37aa12..39c2bde 100644 --- a/object_base.cpp +++ b/object_base.cpp @@ -1,13 +1,17 @@ #include #include "object_base.h" +#include "library.h" using namespace std; Object::Object(void){ - cerr<<"Object constructed!"< +OUT #include + EVENT(create){ - x=y=10; - draw_text(42,42,"Control object wow!"); + x=10; + y=240; + log("Control object wow!"); } EVENT(step){ + static double yd=0; x++; + y+=yd; + yd+=(double)rand()/RAND_MAX*2-y/240; } EVENT(draw){ - draw_text(x,y,"yay!"); + char *s; + asprintf(&s,"controllll: x=%g y=%g",x,y); + draw_text(x,y,s); + free(s); } -- cgit v1.2.3-70-g09d2