the window doesnt even come up, all I get is a console window then it crashed. main doesnt even do one command before it hangs.
main.cpp
/*
this is the course of the includes
declarations >> init >> keyhandle >> draw >> main
that is also the order the game is going to go in
*/
#include "draw.h"
int main(int argc, char *argv[])
{
game main;
main.init();
while(main.done ==0)
{
main.gameloop();
}
return 0;
}
int game::gameloop(){
game main;
draw();
keyhandle();
SDL_Flip(main.screen);
}
draw.h
#include "keyhandle.h"
int drawIMG(SDL_Surface* image,int x,int y,int w,int h)
{
game game;
SDL_Rect dest;
dest.x = x;
dest.y = y;
dest.w = w;
dest.h = h;
SDL_BlitSurface(image,NULL,game.screen,&dest);
}
int game::draw()
{
game game;
drawIMG(game.you.surface,game.you.xpos,game.you.ypos,game.you.xsize,game.you.ysize);
}
keyhandle.h
#include "init.h"
int game::keyhandle()
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done++; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done++; }
}
}
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_UP] ) { you.yspeed = -10; }
else
you.yspeed =0;
if ( keys[SDLK_DOWN]) { you.yspeed = 10; }
else
you.yspeed=0;
if ( keys[SDLK_LEFT] ) { you.xspeed = -10; }
else
you.xspeed = 0;
if ( keys[SDLK_RIGHT] ) { you.xspeed = 10; }
else
you.xspeed = 0;
if ( keys[SDLK_ESCAPE] ) {done++;}
}
init.h
#include "declarations.h"
int game::init()
{
int loop1,loop2,xtilepos,ytilepos;
xtilepos = -10;
ytilepos = -10;
//set the screen up
for(loop1=0;loop1<81;loop1++)
{
for(loop2=0;loop2<61;loop2++)
{
back[loop1][loop2].surface = SDL_LoadBMP("images/backtile.bmp");
back[loop1][loop2].xpos= xtilepos;
back[loop1][loop2].ypos= ytilepos;
back[loop1][loop2].order=0;
back[loop1][loop2].xsize=10;
back[loop1][loop2].ysize=10;
xtilepos+=10;
xtilepos=0;
ytilepos+=10;
}
}
//init you
you.surface = SDL_LoadBMP("images/you.bmp");
//init the window
screen = SDL_SetVideoMode(800
,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Init(SDL_INIT_VIDEO);
}
declarations.h
#include <sdl.h>
#include <iostream>
using namespace std;
#include <stdio.h>
struct map_object
{
int xpos,ypos,xsize,ysize,order;
SDL_Surface *surface;
bool hit;
};
struct weapon
{
int xpos,ypos,xsize,ysize,order,damage,xspeed,yspeed;
SDL_Surface *surface;
bool hit, draw;
};
struct player
{
int xpos,ypos,xsize,ysize,order,damage,xspeed,yspeed;
SDL_Surface *surface;
weapon bullet;
bool hit,draw;
};
class game
{
public:
//function declaritons
int init(),keyhandle(),gameloop(),draw();
//game variables
SDL_Surface *screen;
map_object back[80][60];
player you;
int done;
};
I ran it in debug mode (dev-c++) and it said "an acess violation (segmentation fault) raised in your program"