Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-andreas committed Jun 23, 2013
1 parent 83eabe8 commit 26ca517
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions gamestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ class Sweeper {
CNeuralNet brain;
};

typedef struct {
int posx, posy;
} Mine;

class Gamestate {
public:
Gamestate(int boardWidth, int boardHeight);

int boardWidth, boardHeight;

std::vector<Sweeper> sweepers;
std::vector<Mine> mines;
};

void doTurn(Gamestate *gs);
Expand Down
24 changes: 24 additions & 0 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ void plotSweepers(sdlgamestate_t *g) {
}
}

void plotMines(const sdlgamestate_t *g) {
const std::vector<Mine> &s(g->gamestate->mines);

for(std::vector<Mine>::const_iterator i = s.begin(); i != s.end(); i++) {
// Part of the bitmap that we want to draw
SDL_Rect source;
source.x = 0;
source.y = 0;
source.w = 20;
source.h = 20;

// Part of the screen we want to draw the sprite to
SDL_Rect destination;
destination.x = i->posx;
destination.y = i->posy;
destination.w = 20;
destination.h = 20;

SDL_BlitSurface(g->bitmaps.mine, &source, g->screen, &destination);
}
}

void init(sdlgamestate_t *g) {
SDL_Init( SDL_INIT_VIDEO );

Expand All @@ -50,6 +72,7 @@ void init(sdlgamestate_t *g) {
printf("No bitmap :(\n");
exit(1);
}
g->bitmaps.mine = IMG_Load("/home/ante/dev/neuralnet/res/mine.png");
}

int sdlMainLoop(sdlgamestate_t *g) {
Expand All @@ -70,6 +93,7 @@ int sdlMainLoop(sdlgamestate_t *g) {

SDL_FillRect(g->screen, NULL, SDL_MapRGB(g->screen->format, 255, 255, 255));
doTurn(g->gamestate);
plotMines(g);
plotSweepers(g);

SDL_Flip(g->screen);
Expand Down
1 change: 1 addition & 0 deletions gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef struct {
SDL_Surface *screen;
struct {
SDL_Surface *sweeper;
SDL_Surface *mine;
} bitmaps;
} sdlgamestate_t;

Expand Down
20 changes: 15 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ int main(int argc, char **argv) {
srand(time(NULL));

sdlgamestate_t g;
Gamestate gs(640, 480);
Gamestate gs(1024, 768);
g.gamestate = &gs;

gs.sweepers.push_back(Sweeper());
for(int i = 0; i < 40; i++) {
Mine m;
m.posx = rand()%gs.boardWidth;
m.posy = rand()%gs.boardHeight;

gs.mines.push_back(m);
}

gs.sweepers.push_back(Sweeper());
gs.sweepers[0].posx = 320;
gs.sweepers[0].posy = 240;
for(int i = 0; i < 20; i++) {
Sweeper s;
s.posx = rand()%gs.boardWidth;
s.posy = rand()%gs.boardHeight;

gs.sweepers.push_back(s);
}

return sdlMainLoop(&g);
}
Binary file added res/mine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 26ca517

Please sign in to comment.