Left some important files out of the repo
This commit is contained in:
parent
4d5770006c
commit
ed46a272b8
87
sdlrenderer.cpp
Normal file
87
sdlrenderer.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include "sdlrenderer.h"
|
||||
#include "drawutils.h"
|
||||
#include "debug.h"
|
||||
|
||||
SDLRenderer::SDLRenderer()
|
||||
{
|
||||
display = NULL;
|
||||
background = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool SDLRenderer::init()
|
||||
{
|
||||
display = SDL_SetVideoMode(1024,768,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
||||
if (display == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << "SDLRenderer::init(): error: Couldn't create main surface\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
background = DrawUtils::load("background.bmp");
|
||||
|
||||
if (background == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << "SDLRenderer::init(): error: Couldn't load background image\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SDLRenderer::render(GameData& data)
|
||||
{
|
||||
int range = data.get_range();
|
||||
int range_colour = 0x888888;
|
||||
|
||||
switch(data.get_mode())
|
||||
{
|
||||
case MODE_MOVE:
|
||||
range_colour = 0x0000ff;
|
||||
break;
|
||||
case MODE_ATTACK:
|
||||
range_colour = 0xff0000;
|
||||
break;
|
||||
}
|
||||
|
||||
DrawUtils::draw(display, background, 0, 0);
|
||||
|
||||
list<Vertex*> vertices = data.get_vertices();
|
||||
list<Edge> edges = data.get_edges();
|
||||
|
||||
if (data.get_current_vertex() != NULL)
|
||||
{
|
||||
Vertex* v = data.get_current_vertex();
|
||||
DrawUtils::draw_circle_filled(display, v->x, v->y, range, range_colour);
|
||||
}
|
||||
|
||||
for (list<Vertex*>::iterator cursor = vertices.begin();
|
||||
cursor != vertices.end(); cursor++)
|
||||
{
|
||||
Vertex v = *(*cursor);
|
||||
DrawUtils::draw_circle_filled(display, v.x, v.y, v.r,
|
||||
v.colour);
|
||||
}
|
||||
|
||||
for (list<Edge>::iterator cursor = edges.begin();
|
||||
cursor != edges.end(); cursor++)
|
||||
{
|
||||
Edge e = *cursor;
|
||||
DrawUtils::draw_line(display, e.a->x, e.a->y, e.b->x, e.b->y, 2,
|
||||
e.a->colour);
|
||||
}
|
||||
|
||||
SDL_Flip(display);
|
||||
}
|
||||
|
||||
|
||||
void SDLRenderer::cleanup()
|
||||
{
|
||||
SDL_FreeSurface(background);
|
||||
SDL_FreeSurface(display);
|
||||
}
|
36
sdlrenderer.h
Normal file
36
sdlrenderer.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* This class handles all of the messy details of SDL rendering
|
||||
* We typically want to call init() when we start up, and
|
||||
* render() when we want to render a frame
|
||||
*
|
||||
* Note that this class does NOT call SDL_init() - that should be
|
||||
* done before init()ing here
|
||||
*
|
||||
* cleanup() does the SDL destructor work - call it explicitly in case
|
||||
* we want to keep the object around and re-init it...
|
||||
*/
|
||||
|
||||
#ifndef _SDLRENDERER_H_
|
||||
#define _SDLRENDERER_H_
|
||||
|
||||
#include "gamedata.h"
|
||||
#include <SDL.h>
|
||||
|
||||
class SDLRenderer
|
||||
{
|
||||
public:
|
||||
SDLRenderer();
|
||||
|
||||
bool init();
|
||||
void render(GameData& data);
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
// Main surface - our window
|
||||
SDL_Surface* display;
|
||||
|
||||
// surfaces containing textures to draw
|
||||
SDL_Surface* background;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user