Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created June 3, 2013 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ratstail91/5700173 to your computer and use it in GitHub Desktop.
Save Ratstail91/5700173 to your computer and use it in GitHub Desktop.
This is how I unit test.
#include "image.hpp"
#include "sprite_sheet.hpp"
#include "raster_font.hpp"
#include "surface_manager.hpp"
#include "button.hpp"
#include "SDL/SDL.h"
#include <iostream>
#include <chrono>
using namespace std;
int main(int, char**) {
SDL_Init(0);
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
SurfaceManager surfaceMgr;
surfaceMgr.Load("player","elliot2.bmp");
surfaceMgr.Load("font","pokemon_dark_font.bmp");
surfaceMgr.Load("button","button.bmp");
Image image(surfaceMgr["font"]);
SpriteSheet ssheet(surfaceMgr["player"], 32, 48);
RasterFont font(surfaceMgr["font"]);
Button button(300, 300, surfaceMgr["button"], surfaceMgr["font"], "button");
ssheet.SetInterval(0.1);
typedef std::chrono::high_resolution_clock Clock;
Clock::time_point point = Clock::now();
bool running = true;
while(running) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
running = false;
break;
case SDL_MOUSEMOTION:
button.MouseMotion(event.motion);
break;
case SDL_MOUSEBUTTONDOWN:
button.MouseButtonDown(event.button);
break;
case SDL_MOUSEBUTTONUP:
button.MouseButtonUp(event.button);
break;
case SDL_KEYDOWN:
//
break;
case SDL_KEYUP:
//
break;
}
}
//update
ssheet.Update(double((Clock::now()-point).count()) / Clock::period::den);
point = Clock::now();
//draw
SDL_FillRect(screen, 0, 0);
// image.DrawTo(screen, 0, 0);
font.DrawStringTo("hello world", screen, 100, 100);
ssheet.DrawTo(screen, 200, 200);
button.DrawTo(screen);
SDL_Flip(screen);
}
surfaceMgr.FreeAll();
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment