/* BOUNCE                                                         */
/* Gîupi programik autorstwa WizArta (of ANTIBIOTIC, of course)   */
/* F R E E W A R E                                                */

#include <dos/dos.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <graphics/sprite.h>
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/dos.h>

#include <math.h>
#include <stdio.h>

#define X_POS 240
#define Y_POS 10

struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct IntuiMessage *msg;
struct Screen *scr;

UWORD chip A_letter [ 46 ] =
	{
		0x0000, 0x0000,

		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0080, 0x0000,
 		0x0080, 0x0000,
 		0x01C0, 0x0000,
 		0x01C0, 0x0000,
 		0x02E0, 0x0000,
  		0x02E0, 0x0000,
  		0x0470, 0x0000,
  		0x0470, 0x0000,
  		0x0838, 0x0000,
  		0x0FF8, 0x0000,
  		0x101C, 0x0000,
  		0x101C, 0x0000,
  		0x200E, 0x0000,
  		0x200E, 0x0000,

  		0x0000, 0x0000
	};

struct SimpleSprite litera_A=
{
  A_letter,       /* posctldata, pointer to the sprite data. */
  20,             /* height, 16 lines tall. */
  0, 0,         /* x, y, position on the screen. */
  2,              /* num, this field is automatically initialized when  */
                  /* you call the GetSprite() function, so we set it to */
                  /* -1 for the moment.                                 */
};

UWORD chip M_letter [ 46 ] =
	{
  		0x0000, 0x0000,

		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
  		0xF006, 0x0000,
  		0x7006, 0x0000,
  		0x780E, 0x0000,
  		0x780E, 0x0000,
  		0x5C1E, 0x0000,
  		0x5C1E, 0x0000,
  		0x4E2E, 0x0000,
  		0x4E2E, 0x0000,
  		0x474E, 0x0000,
  		0x474E, 0x0000,
  		0x438E, 0x0000,
  		0x438E, 0x0000,
  		0x410E, 0x0000,
  		0x410E, 0x0000,

  		0x0000, 0x0000
	};

struct SimpleSprite litera_M=
{
  M_letter,       /* posctldata, pointer to the sprite data. */
  20,             /* height, 16 lines tall. */
  0, 0,         /* x, y, position on the screen. */
  3,              /* num, this field is automatically initialized when  */
                  /* you call the GetSprite() function, so we set it to */
                  /* -1 for the moment.                                 */
};

UWORD chip I_letter [ 46 ] =
	{
 		0x0000, 0x0000,

		0x0000, 0x0060,
		0x0000, 0x01E0,
		0x0000, 0x01F0,
		0x0000, 0x00F0,
		0x0000, 0x00C0,
		0x0000, 0x0000,
  		0x01E0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x01C0, 0x0000,
  		0x03E0, 0x0000,

  		0x0000, 0x0000
	};

struct SimpleSprite litera_I=
{
  I_letter,       /* posctldata, pointer to the sprite data. */
  20,             /* height, 16 lines tall. */
  0, 0,         /* x, y, position on the screen. */
  4,              /* num, this field is automatically initialized when  */
                  /* you call the GetSprite() function, so we set it to */
                  /* -1 for the moment.                                 */
};

UWORD chip G_letter [ 46 ] =
	{
  		0x0000, 0x0000,

		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
  		0x03F8, 0x0000,
  		0x0E1E, 0x0000,
  		0x1C06, 0x0000,
  		0x1802, 0x0000,
  		0x3800, 0x0000,
  		0x3800, 0x0000,
  		0x3800, 0x0000,
  		0x380F, 0x0000,
  		0x3807, 0x0000,
  		0x3807, 0x0000,
  		0x1806, 0x0000,
  		0x1C0E, 0x0000,
  		0x0E1C, 0x0000,
  		0x03F0, 0x0000,

  		0x0000, 0x0000
	};

struct SimpleSprite litera_G=
{
  G_letter,       /* posctldata, pointer to the sprite data. */
  20,             /* height, 16 lines tall. */
  0, 0,         /* x, y, position on the screen. */
  5,              /* num, this field is automatically initialized when  */
                  /* you call the GetSprite() function, so we set it to */
                  /* -1 for the moment.                                 */
};

UWORD chip A2_letter [ 46 ] =
	{
		0x0000, 0x0000,

		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0000, 0x0000,
		0x0080, 0x0000,
 		0x0080, 0x0000,
 		0x01C0, 0x0000,
 		0x01C0, 0x0000,
 		0x02E0, 0x0000,
  		0x02E0, 0x0000,
  		0x0470, 0x0000,
  		0x0470, 0x0000,
  		0x0838, 0x0000,
  		0x0FF8, 0x0000,
  		0x101C, 0x0000,
  		0x101C, 0x0000,
  		0x200E, 0x0000,
  		0x200E, 0x0000,

  		0x0000, 0x0000
	};

struct SimpleSprite litera_A2=
{
  A2_letter,      /* posctldata, pointer to the sprite data. */
  20,             /* height, 16 lines tall. */
  0, 0,           /* x, y, position on the screen. */
  6,              /* num, this field is automatically initialized when  */
                  /* you call the GetSprite() function, so we set it to */
                  /* -1 for the moment.                                 */
};

main ( )
{
	struct Window *wnd; 
	BOOL end = FALSE;
	ULONG class;
	DOUBLE y, y1, b = NULL, b1 = NULL;

	if ( IntuitionBase = ( struct IntuitionBase * )
		OpenLibrary ( "intuition.library", 0 ) )
	{
		if ( GfxBase = ( struct GfxBase * )
			OpenLibrary ( "graphics.library", 0 ) )
		{
			if ( scr = LockPubScreen ( NULL ) )
			{
				if ( wnd = OpenWindowTags ( 0,
					WA_Left, 0,
					WA_Top, scr -> BarHeight + 1,
					WA_Width, 200,
					WA_Height, scr -> Font -> ta_YSize + scr -> WBorTop + 1,
					WA_Flags, WFLG_DRAGBAR | WFLG_CLOSEGADGET | WFLG_DEPTHGADGET |
						WFLG_ACTIVATE,
					WA_IDCMP, IDCMP_CLOSEWINDOW, 
					WA_ScreenTitle, "B O U N C E v1.0 -- WizArt of ANTIBIOTIC",
					WA_Title, "B O U N C E",
					TAG_END ) )
				{		

					SetRGB4( &wnd->WScreen->ViewPort, 21, 0x0, 0x0, 0x0 ); 
  					SetRGB4( &wnd->WScreen->ViewPort, 25, 0x0, 0x0, 0x0 ); 
					SetRGB4( &wnd->WScreen->ViewPort, 26, 0xF, 0x0, 0x0 );			
					SetRGB4( &wnd->WScreen->ViewPort, 29, 0x0, 0x0, 0x0 ); 
					if ( GetSprite ( &litera_A, 2 ) == 2 &&
						 GetSprite ( &litera_M, 3 ) == 3 &&
						 GetSprite ( &litera_I, 4 ) == 4 &&
						 GetSprite ( &litera_G, 5 ) == 5 &&
						 GetSprite ( &litera_A2, 6 ) == 6 )
					{
						while ( end == FALSE )
						{													
							b++;
							b1++;
					
							if ( b == 50 )
							{
								b = NULL;
							}	
								if ( b1 == 50 )
							{
								b1 = NULL;
							}							

							y = sin __ARGS(( b )) * 10; 
							y1 = cos __ARGS(( b1 )) * 10; 
							WaitTOF ( );
							MoveSprite ( 0, &litera_A, ( LONG ) 0 + X_POS , ( LONG ) y1 / 4 + Y_POS );
							MoveSprite ( 0, &litera_M, ( LONG ) 16 + X_POS , ( LONG ) y + Y_POS );
							MoveSprite ( 0, &litera_I, ( LONG ) 27 + X_POS , ( LONG ) y * 2 + Y_POS );
							MoveSprite ( 0, &litera_G, ( LONG ) 39 + X_POS , ( LONG ) y + Y_POS );
							MoveSprite ( 0, &litera_A2, ( LONG ) 55 + X_POS , ( LONG ) y1 / 4 + Y_POS );
							if ( msg = ( struct IntuiMessage * ) 
								GetMsg ( wnd -> UserPort ) )
							{
								class = msg -> Class;
								ReplyMsg ( ( struct Message * ) msg );
							
								switch ( class )
								{
									case IDCMP_CLOSEWINDOW:
										end = TRUE;
									break;
								} 
							}
							Delay ( 1 );
						}	
						FreeSprite ( 2 );	
						FreeSprite ( 3 );					
						FreeSprite ( 4 );	
						FreeSprite ( 5 );	
						FreeSprite ( 6 );	
					}
					CloseWindow ( wnd );
				}
				UnlockPubScreen ( NULL, scr );
			}
			CloseLibrary ( ( struct Library * ) GfxBase );		
		}
		CloseLibrary ( ( struct Library * ) IntuitionBase );
	}

	return( 0 );
}

