1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <SDL/SDL.h>
#include <FMOD/fmod.h>
#include <windows.h>
int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// create a new window
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
// CHARGEMENT DES IMAGES
SDL_Surface* arp = SDL_LoadBMP("ARP.bmp");
if (!arp)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
// CREATION DES POSITIONS
SDL_Rect posARP;
posARP.x = 0;
posARP.y = 0;
SDL_Rect posB1;
posB1.x = 167;
posB1.y = 252;
SDL_Rect posB2;
posB2.x = 163;
posB2.y = 353;
//FMOD INITIALISATION
FMOD_SYSTEM *system;
FMOD_System_Create(&system);
FMOD_System_Init(system, 16, FMOD_INIT_NORMAL, NULL);
FMOD_SOUND *click = NULL;
FMOD_System_CreateSound(system, "click.wav", FMOD_CREATESAMPLE, 0, &click);
// program main loop
bool arretM = false;
bool arretJ = false;
while (!arretM)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
arretM = true;
arretJ = true;
break;
// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
arretM = true;
arretJ = true;
break;
}
case SDL_MOUSEBUTTONUP:
{
if(event.button.x /300 == posB1.x/300 && event.button.y /55 == posB1.y/55)
{
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, click, 0, NULL);
}
break;
}
} // end switch
} // end of message processing
// DRAWING STARTS HERE
// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
// draw bitmap
SDL_BlitSurface(arp, 0, screen, &posARP);
// DRAWING ENDS HERE
// finally, update the screen :)
SDL_Flip(screen);
} // end main loop
// FERMETURE SDL
SDL_FreeSurface(arp);
// FERMETURE FMOD
FMOD_Sound_Release(click);
FMOD_System_Close(system);
FMOD_System_Release(system);
return 0;
} |
Partager