#ifdef __WIN32__
#include <windows.h>
#endif
#include <time.h>
#include <stdio.h>

#include <PowerPak/powerpak.h>
#include <PowerPak/powerdraw.h>
#include <PowerPak/powerinput.h>

main(int argc, char *argv[])
{
   PD_Sprite *sprite;
   int x, y, done;

   /* Initialize the library */
   PP_Init();
   PD_Init();
   if (PI_OpenJoystick(0) < 0)
      exit(0);

   /* Initialize 640x480x16bpp graphics mode */
   PD_SetGFXMode(640, 480, 16, PD_DEFAULT);
   
   sprite = PD_SpriteInit (1, 35, 35);
   PD_GetSpriteFrame (sprite, "sprite.pcx", 0);

   x = 320;
   y = 240;
   done = 0;

   /* move the circle across the screen */
   while(!done){
      PD_ClearSurface(DoubleBuffer, PD_CreateColor(Screen, 0x00, 0x00, 0x00));
      if (PI_JoyX(0) < 0){
         x -= 5;
         if (x < 0) x = 640;
         }
      else if (PI_JoyX(0) > 0){
         x += 5;
         if (x > 640) x = 0;
         }
      if (PI_JoyY(0) < 0){
         y -= 5;
         if (y < 0) y = 480;
         }
      else if (PI_JoyY(0) > 0){
         y += 5;
         if (y > 480) y = 0;
         }
    if (PI_IsJoyButtonDown(0, 0) || PI_IsJoyButtonDown(0, 1))
       done = 1;
     sprite->x = x;
     sprite->y = y;
     PD_DrawSprite(sprite, DoubleBuffer, CURRENT, 0);
     PD_ShowDoubleBuffer();
   }

   /* Cleanup */
   PI_CloseJoystick(0);
   PD_Quit();
   PP_Quit();
}
