I don't know :/

This commit is contained in:
King_DuckZ 2015-09-16 14:56:36 +02:00
parent 205448d211
commit abe3d8f493
3 changed files with 23 additions and 6 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ lib/libbpg*/**/*.a
lib/libbpg*/bpgdec
lib/libbpg*/bpgenc
lib/libbpg*/bpgview
tags

View file

@ -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;
}

View file

@ -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;
}