1 / 20

Chapter 16 GPDUMB Engine Part II

Chapter 16 GPDUMB Engine Part II. GPDUMB2 Engine. Constants for Sound. #define MAX_SOUNDS 64 // max sounds in system at once #define SOUND_NULL 0 // sound not loaded #define SOUND_LOADED 1 // sound has been loaded #define SOUND_PLAYING 2 // sound is currently playing

ranger
Download Presentation

Chapter 16 GPDUMB Engine Part II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 16GPDUMB Engine Part II

  2. GPDUMB2 Engine

  3. Constants for Sound #define MAX_SOUNDS 64 // max sounds in system at once #define SOUND_NULL 0 // sound not loaded #define SOUND_LOADED 1 // sound has been loaded #define SOUND_PLAYING 2 // sound is currently playing #define SOUND_STOPPED 3 // sound has been stopped #define NVB_SIZE 6 // size of new voice block in bytes

  4. Constants for Screen Transition • fades, swipes, dissolves… • only work for 8-bit modes #define SCREEN_DARKNESS 0 // fade to black #define SCREEN_WHITENESS 1 // fade to white #define SCREEN_SWIPE_X 2 // do a horizontal swipe #define SCREEN_SWIPE_Y 3 // do a vertical swipe #define SCREEN_DISSOLVE 4 // a pixel disolve #define SCREEN_SCRUNCH 5 // a square compression #define SCREEN_BLUENESS 6 // fade to blue #define SCREEN_REDNESS 7 // fade to red #define SCREEN_GREENNESS 8 // fade to green

  5. Others… #define BOB_ATTR_CLONE 256 // the bob is a clone #define DSVOLUME_TO_DB(volume) ((DWORD)(-30*(100 - volume))) typedef struct pcm_sound_typ { LPDIRECTSOUNDBUFFER dsbuffer; // the DirectSound buffer containing the sound int state; // state of the sound int rate; // playback rate int size; // size of sound int id; // id number of the sound } pcm_sound, *pcm_sound_ptr;

  6. Globals LPDIRECTSOUND lpds; // DirectSound interface pointer DSBUFFERDESC dsbd; // DirectSound description DSCAPS dscaps; // DirectSound caps HRESULT dsresult // general DirectSound result DSBCAPS dsbcaps; // DirectSound buffer caps pcm_sound sound_fx[MAX_SOUNDS]; // array of sound buffers WAVEFORMATEX pcmwf; // generic waveformat structure LPDIRECTINPUT8 lpdi; // dinput object LPDIRECTINPUTDEVICE8 lpdikey; // dinput keyboard LPDIRECTINPUTDEVICE8 lpdimouse; // dinput mouse LPDIRECTINPUTDEVICE8 lpdijoy; // dinput joystick GUID joystickGUID; // GUID for main joystick char joyname[80]; // name of joystick // these contain the target records for all DirectInput input packets UCHAR keyboard_state[256];// contains keyboard state table DIMOUSESTATE mouse_state; // contains state of mouse DIJOYSTATE joy_state; // contains state of joystick int joystick_found; // tracks if stick is plugged in

  7. DirectSound Wrapper - 1 if (!DSound_Init(void)) { /* error */ } int boom_id = Load_VOC(“BOOM.VOC”); if (boom_id == -1) { /* error */ } int fire_id = Load_WAV(“FIRE.WAV”); if (fire_id == -1) { /* error */} // accessing sound buffer sound_fx[sound_id].dsbuffer …. if (!DSound_Shutdown()) { /* error */ }

  8. DirectSound Wrapper - 2 int gunshot_ids[8]; // this holds all the ids // load the master sound gunshot_ids[0] = Load_WAV(“GUNSHOT.WAV”); // now make copies (실제로 copy하는 것이 아니라 같은 buffer를 // pointing 하게 함. for (int index=1; index<8; index++) gunshot_ids[index] = Replicate_Sound(gunshot_ids[0]); // use gunshot_ids[0..7],they all go bang!

  9. Play Sound int Play_Sound(int id, // id of sound to play int flags=0, // 0 or DSBPLAY_LOOPING int volume=0, // unused int rate=0, // unused int pan=0); // unused int fire_id = Load_WAV(“FIRE.WAV”); Play_Sound(fire_id,0);

  10. Sound Functions • int Stop_Sound(int id); • int Stop_All_Sounds(void); • int Delete_Sound(int id); // id of sound to delete • int Delete_All_Sounds(void); // initialize DirectSound DSound_Init(); // load a sound int fire_id = Load_WAV(“FIRE.WAV”); // play the sound in single mode Play_Sound(fire_id); // wait until the sound is done (key following on one line) while(Sound_Status(fire_id) & (DSBSTATUS_LOOPING | DSBSTATUS_PLAYING)); // delete the sound Delete_Sound(fire_id); // shut down DirectSound DSound_Shutdown();

  11. Sound Functions int Set_Sound_Volume(int id, // id of sound int vol); // volume from 0-100 int Set_Sound_Freq( int id, // sound id int freq); // new playback rate from 0-100000 int Set_Sound_Pan( int id, // sound id int pan); // panning value from -10000 to 10000

  12. DirectInput Initialize / Shutdown // initialize the DirectInput system DInput_Init(); // initialize all input devices and acquire them DI_Init_Joystick(); DI_Init_Mouse(); DI_Init_Keyboard(); // input loop, insert program code here // now’s time for your program to end // first release all devices (order is unimportant) void DI_Release_Joystick(void); void DI_Release_Mouse(void); void DI_Release_Keyboard(void); // shut down DirectInput DInput_Shutdown();

  13. Reading Keyboard // read the keyboard if (!DI_Read_Keyboard()) { /* error */ } // now test the state data if (keyboard_state[DIK_RIGHT] { /* move ship right */ } else if (keyboard_state[DIK_LEFT] { /* move ship left */ }

  14. Reading Mouse // read the mouse if (!DI_Read_Mouse()) { /* error */ } // move cursor cx+=mouse_state.lX; cy+=mouse_state.lY; // test whether left button is down if (mouse_state.rgbButtons[0]) Draw_Pixel(cx,cy,col,buffer,pitch);

  15. Reading Joystick // read the joystick data if (!DI_Read_Joystick()) { /* error */ } // move the ship ship_x+=joy_state.lX; ship_y+=joy_state.lY; // test for trigger if (joy_state.rgbButtons[0]) { // fire weapon // }

  16. More Graphics Functions void HLine*(int x1, // starting x position of HLine int x2, // ending x position of HLine int y, // row or vertical position of HLine int color, // color of HLine 0-255 UCHAR *vbuffer, // destination memory buffer int lpitch); // memory pitch of buffer void VLine(int y1, // starting y position of HLine int y2, // ending y position of HLine int x, // column or horizontal pos of VLine int color, // color of HLine 0-255 UCHAR *vbuffer, // destination memory buffer int lpitch); // memory pitch of buffer

  17. Master-Clone BOB

  18. Clone_BOBX BOB master_bob, // the master BOB clone_bobs[64]; // the clones of the master // first create the master BOB (single frame, multi, etc.) Create_BOB(&master_bob, 0,0, 64,64,1,BOB_ATTR_SINGLE_FRAME); // load the image into the BOB Load_Frame(&master_bob, &bitmap8bit,0,0,0,BITMAP_EXTRACT_CELL_MODE); // create the clones for (int clone=0; clone<64; clone++) { // create the clone // don’t load imagery; just clone it Create_BOB(&clone_bobs[clone], 0,0, 64,64,1,BOB_ATTR_SINGLE_FRAME); Clone_BOBX(&master_bob, &clone_bobs[clone]; // reset the fields you want changed (code not shown) } // end for clone // now you can use all the clones

  19. Destroy Clone BOB • int Destroy_BOBX(BOB_PTR bob);

  20. Star Ferret Delux • DEMO

More Related