Currently the screen opens and then shuts down,but when it did open if I
pressed any key it would shut down.Can anyone help me?
#include “SDL.h”
#include “stdio.h”
#include
bool k = true;
int main( int argc, char* argv[] )
{
atexit(SDL_Quit);
SDL_Init ( SDL_INIT_VIDEO );
SDL_Surface* screen;
screen = SDL_SetVideoMode(1024, 768, 32, SDL_DOUBLEBUF| SDL_ANYFORMAT);
SDL_Surface* hero;
SDL_Surface* enemy;
SDL_Surface* helaser;
SDL_Surface* enlaser;
hero = SDL_LoadBMP(“ship.bmp”);
enemy = SDL_LoadBMP(“enemyship.bmp”);
helaser = SDL_LoadBMP(“helaser.bmp”);
enlaser = SDL_LoadBMP(“enlaser.bmp”);
SDL_Rect ship;
ship.x = 500;
ship.y = 579;
SDL_Event global;
enum state { UP = 2,LEFT,RIGHT,DOWN,STOP };
state image;
image = STOP;
while (k == true)
{
SDL_BlitSurface(hero,NULL,screen,&ship);
if ( global.type == SDL_QUIT )
{
k = false;
SDL_Quit();
}
while(SDL_PollEvent(&global))
{
if ( global.type == SDL_KEYDOWN )
{
if ( global.key.keysym.sym == SDLK_ESCAPE )
{
k = false;
SDL_Quit();
}
}
if ( global.key.keysym.sym == SDLK_DOWN )
{
image = UP;
}
if(image == UP)
{
ship.x += 1;
SDL_BlitSurface(hero,NULL,screen,&ship);
SDL_Flip(screen);
}
}
}
return (0);
}