rendered paste body#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include <SDL_mouse.h>
SDL_Surface *screen = NULL;
SDL_Surface *image = NULL;
SDL_Surface *background = NULL;
SDL_Rect redy;
SDL_Rect grid;
SDL_Joystick *joy = NULL;
//SDL_ShowCursor();
//
int x, y;
Sint16 xpos, ypos;
bool init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
joy = SDL_JoystickOpen(0);
if (SDL_Init (SDL_INIT_VIDEO) < 0)
atexit (SDL_Quit);
screen = SDL_SetVideoMode (1600, 1200, 32, SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF);
SDL_WM_SetCaption ("EVM-3015", NULL);
image = SDL_LoadBMP("ship.bmp");
redy.x = 800;
redy.y = 600;
SDL_EnableKeyRepeat(1, 1);
background = SDL_LoadBMP("grid.bmp");
grid.x = 800;
grid.y = 600;
return true;
}
void draw ()
{
Uint32 color;
color = SDL_MapRGB (screen->format, 0, 0, 0);
SDL_FillRect (screen, NULL, color);
SDL_BlitSurface(background, NULL, screen, &grid);
SDL_BlitSurface(image, NULL, screen, &redy);
SDL_Flip (screen);
}
void physics (Sint16 xpos, Sint16 ypos)
{
redy.x = redy.x + xpos;
redy.y = redy.y + ypos;
}
int main (int argc, char *argv[])
{
int done = 0;
Uint8 *keys;
init();
while (!done)
{
SDL_Event event;
xpos = SDL_JoystickGetAxis(joy, 0);
ypos = SDL_JoystickGetAxis(joy, 1);
xpos = xpos / 2000;
ypos = ypos / 2000;
physics(xpos,ypos);
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_ESCAPE] ) { done = 1;}
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
draw ();
}
return 0;
}