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 6209004 commit 2226161
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build

7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
project(neuralnet)
cmake_minimum_required(VERSION 2.8)

add_executable(neuralnet main.cpp)
FILE(GLOB MyCSources *.cpp)

ADD_EXECUTABLE(neuralnet ${MyCSources})

install(TARGETS neuralnet RUNTIME DESTINATION bin)

target_link_libraries(neuralnet SDL SDL_image)
13 changes: 13 additions & 0 deletions gamestate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "gamestate.h"

#include <stdlib.h>

Sweeper::Sweeper() {
int posx = 0;
int posy = 0;
}

Gamestate::Gamestate(int boardWidth, int boardHeight) {
this->boardWidth = boardWidth;
this->boardHeight = boardHeight;
}
22 changes: 22 additions & 0 deletions gamestate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _GAMESTATE_H
#define _GAMESTATE_H

#include <vector>

class Sweeper {
public:
Sweeper();

int posx, posy;
};

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

int boardWidth, boardHeight;

std::vector<Sweeper> sweepers;
};

#endif
68 changes: 68 additions & 0 deletions gfx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "gfx.h"

const char* WINDOW_TITLE = "SDL Start";

void plotSweeper(sdlgamestate_t *g, const Sweeper &sweeper) {
// Part of the bitmap that we want to draw
SDL_Rect source;
source.x = 0;
source.y = 0;
source.w = 65;
source.h = 44;

// Part of the screen we want to draw the sprite to
SDL_Rect destination;
destination.x = sweeper.posx;
destination.y = sweeper.posy;
destination.w = 65;
destination.h = 44;

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

void plotSweepers(sdlgamestate_t *g) {
const std::vector<Sweeper> &s(g->gamestate->sweepers);

for(std::vector<Sweeper>::const_iterator i = s.begin(); i != s.end(); i++) {
plotSweeper(g, *i);
}
}

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

g->screen = SDL_SetVideoMode(
g->gamestate->boardWidth, g->gamestate->boardHeight, 0, SDL_HWSURFACE | SDL_DOUBLEBUF
);
SDL_WM_SetCaption( WINDOW_TITLE, 0 );

g->bitmaps.sweeper = IMG_Load("/home/ante/dev/neuralnet/res/sweeper.png");
if(!g->bitmaps.sweeper) {
printf("No bitmap :(\n");
exit(1);
}
}

int sdlMainLoop(sdlgamestate_t *g) {
init(g);

SDL_Event event;
bool gameRunning = true;

while (gameRunning) {
if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
gameRunning = false;
}
}

plotSweepers(g);

SDL_Flip(g->screen);
}

SDL_FreeSurface(g->bitmaps.sweeper);
SDL_Quit();

return 0;
}
22 changes: 22 additions & 0 deletions gfx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _GFX_H
#define _GFH_H

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#include "gamestate.h"

typedef struct {
Gamestate *gamestate;

SDL_Surface *screen;
struct {
SDL_Surface *sweeper;
} bitmaps;


} sdlgamestate_t;

int sdlMainLoop(sdlgamestate_t *g);

#endif
27 changes: 26 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
#include <iostream>
#include <vector>

int main(int argc, char **argv) {
#include "gfx.h"

using namespace std;

typedef struct {
int inputCount;

unsigned int threshold;
unsigned int weights[4];
} neuron_t;

int oldmain(int argc, char **argv) {
neuron_t hiddenLayer[4];
neuron_t outputLayer[2];

std::cout << "Hello, world!" << std::endl;
return 0;
}

int main(int argc, char **argv) {
sdlgamestate_t g;
Gamestate gs(640, 480);
g.gamestate = &gs;

gs.sweepers.push_back(Sweeper());

return sdlMainLoop(&g);
}
Binary file added res/sweeper.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 2226161

Please sign in to comment.