diff --git a/.gitignore b/.gitignore index b92c8d8..1193252 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ lib/libbpg*/**/*.a lib/libbpg*/bpgdec lib/libbpg*/bpgenc lib/libbpg*/bpgview +tags diff --git a/gameobj.d b/gameobj.d index 8356c51..531d274 100644 --- a/gameobj.d +++ b/gameobj.d @@ -16,6 +16,7 @@ */ module gameobj; +import derelict.sdl2.sdl; interface GameObj { void prepare(); @@ -23,3 +24,19 @@ interface GameObj { void exec(); bool wants_to_quit() const; } + +class GameObjBase : GameObj { +public: + this (SDL_Renderer* parRenderer) { + m_renderer = parRenderer; + assert(m_renderer); + } + +protected: + SDL_Renderer* renderer() { + return m_renderer; + } + +private: + SDL_Renderer* m_renderer; +} diff --git a/gameobjjumping.d b/gameobjjumping.d index 504dadf..0513ff4 100644 --- a/gameobjjumping.d +++ b/gameobjjumping.d @@ -21,14 +21,14 @@ import derelict.sdl2.sdl; import texture; import std.stdio; -class GameObjJumping : GameObj { +class GameObjJumping : GameObjBase { //Don't disable this(), it's disable automatically when you define a //custorm constructor. //@disable this(); //Take the pointer to the renderer and set initial values this (SDL_Renderer* parRenderer) { - m_renderer = parRenderer; + super(parRenderer); m_wants_to_quit = false; } @@ -39,7 +39,7 @@ class GameObjJumping : GameObj { void prepare() { string texture_name = "bcruiser_normal.bpg"; writeln("Loading texture %s", texture_name); - m_texture = Texture(texture_name, m_renderer); + m_texture = Texture(texture_name, renderer()); } void destroy() { @@ -47,9 +47,9 @@ class GameObjJumping : GameObj { //This is the function that is called at every frame void exec() { - SDL_RenderClear(m_renderer); + SDL_RenderClear(renderer()); m_texture.draw(); - SDL_RenderPresent(m_renderer); + SDL_RenderPresent(renderer()); m_wants_to_quit = do_events(); } @@ -59,7 +59,6 @@ class GameObjJumping : GameObj { private: Texture m_texture; - SDL_Renderer* m_renderer; bool m_wants_to_quit; }