Hi guys, im new to this forum but congratulations, i looks great

Im making a game for a TAFE class (which i will gladly send to any1). The game is a text based Role Playing Game. I am finished early so i am going to improve my current game. I was wondering whether i could add some sounds and pictures to my monsters.

struct monster
{
int strength;
int dexterity;
int hp;
char name[32];
};

That is my struct and i have an array of 4 monsters and a boss! Could i add something to the array, maybe monsterArray[].picture or monsterArray[].sound . Are there commands that allow pictures and sounds in a console application, if so can someone please tell me of them. Also feel free to get me to send you that game and/or source code!

Cheers, Peter :p

I think that is helpful to you .

# Microsoft Developer Studio Project File - Name="Sarien" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00

# TARGTYPE "Win32 (x86) Console Application" 0x0103

CFG=Sarien - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE 
!MESSAGE NMAKE /f "Sarien.mak".
!MESSAGE 
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE 
!MESSAGE NMAKE /f "Sarien.mak" CFG="Sarien - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "Sarien - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Sarien - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE 

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe

!IF  "$(CFG)" == "Sarien - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /Zi /O1 /I "..\src\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "NATIVE_WIN32" /FR /YX /FD /c
# ADD BASE RSC /l 0x416 /d "NDEBUG"
# ADD RSC /l 0x416 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib /nologo /subsystem:windows /debug /machine:I386 /FIXED:NO
# SUBTRACT LINK32 /pdb:none

!ELSEIF  "$(CFG)" == "Sarien - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /Zi /Od /I "..\SRC\INCLUDE" /D "DEBUG" /D "WIN32" /D "_WINDOWS" /D "NATIVE_WIN32" /FR /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x416 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winmm.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /pdbtype:sept /FIXED:NO
# SUBTRACT LINK32 /pdb:none

!ENDIF 

# Begin Target

# Name "Sarien - Win32 Release"
# Name "Sarien - Win32 Debug"
# Begin Group "Source Files"

# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Group "CORE_AGI"

# PROP Default_Filter "*.C"
# Begin Source File

SOURCE=..\src\core\agi.c
# End Source File
# Begin Source File

SOURCE=..\src\core\agi_v2.c
# End Source File
# Begin Source File

SOURCE=..\src\core\agi_v3.c
# End Source File
# Begin Source File

SOURCE=..\SRC\CORE\AGI_V4.C
# End Source File
# Begin Source File

SOURCE=..\src\core\checks.c
# End Source File
# Begin Source File

SOURCE=..\src\core\console.c
# End Source File
# Begin Source File

SOURCE=..\src\core\cycle.c
# End Source File
# Begin Source File

SOURCE=..\src\core\font.c
# End Source File
# Begin Source File

SOURCE=..\src\core\global.c
# End Source File
# Begin Source File

SOURCE=..\src\core\graphics.c
# End Source File
# Begin Source File

SOURCE=..\src\core\id.c
# End Source File
# Begin Source File

SOURCE=..\SRC\CORE\INV.C
# End Source File
# Begin Source File

SOURCE=..\src\core\keyboard.c
# End Source File
# Begin Source File

SOURCE=..\src\core\logic.c
# End Source File
# Begin Source File

SOURCE=..\src\core\lzw.c
# End Source File
# Begin Source File

SOURCE=..\src\core\menu.c
# End Source File
# Begin Source File

SOURCE=..\src\core\motion.c
# End Source File
# Begin Source File

SOURCE=..\src\core\objects.c
# End Source File
# Begin Source File

SOURCE=..\src\core\op_cmd.c
# End Source File
# Begin Source File

SOURCE=..\src\core\op_dbg.c
# End Source File
# Begin Source File

SOURCE=..\src\core\op_test.c
# End Source File
# Begin Source File

SOURCE=..\src\core\patches.c
# End Source File
# Begin Source File

SOURCE=..\src\core\picture.c
# End Source File
# Begin Source File

SOURCE=..\src\core\picview.c
# End Source File
# Begin Source File

SOURCE=..\src\core\rand.c
# End Source File
# Begin Source File

SOURCE=..\src\core\savegame.c
# End Source File
# Begin Source File

SOURCE=..\src\core\silent.c
# End Source File
# Begin Source File

SOURCE=..\src\core\sound.c
# End Source File
# Begin Source File

SOURCE=..\src\core\sprite.c
# End Source File
# Begin Source File

SOURCE=..\SRC\CORE\TEXT.C
# End Source File
# Begin Source File

SOURCE=..\src\core\view.c
# End Source File
# Begin Source File

SOURCE=..\src\core\win32\winmain.c
# End Source File
# Begin Source File

SOURCE=..\src\core\words.c
# End Source File
# End Group
# Begin Group "CONSOLE"

# PROP Default_Filter "*.c"
# Begin Source File

SOURCE=..\src\graphics\win32\win32.c
# End Source File
# End Group
# Begin Group "SOUND"

# PROP Default_Filter "*.C"
# Begin Source File

SOURCE=..\src\sound\win32\sound_win32.c
# End Source File
# End Group
# Begin Group "FILESYS"

# PROP Default_Filter "*.C"
# Begin Source File

SOURCE=..\src\filesys\win32\fileglob.c
# End Source File
# Begin Source File

SOURCE=..\src\filesys\win32\path.c
# End Source File
# End Group
# End Group
# Begin Group "Header Files"

# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File

SOURCE=..\src\include\agi.h
# End Source File
# Begin Source File

SOURCE=..\src\include\cli.h
# End Source File
# Begin Source File

SOURCE=..\src\include\config.h
# End Source File
# Begin Source File

SOURCE=..\src\include\console.h
# End Source File
# Begin Source File

SOURCE=..\src\include\defines.h
# End Source File
# Begin Source File

SOURCE=..\src\include\enums.h
# End Source File
# Begin Source File

SOURCE=..\src\include\font.h
# End Source File
# Begin Source File

SOURCE=..\src\include\getopt.h
# End Source File
# Begin Source File

SOURCE=..\src\include\graphics.h
# End Source File
# Begin Source File

SOURCE=..\src\include\id.h
# End Source File
# Begin Source File

SOURCE=..\src\include\includes.h
# End Source File
# Begin Source File

SOURCE=..\src\include\keyboard.h
# End Source File
# Begin Source File

SOURCE=..\src\include\logic.h
# End Source File
# Begin Source File

SOURCE=..\src\include\lzw.h
# End Source File
# Begin Source File

SOURCE=..\src\include\machine.h
# End Source File
# Begin Source File

SOURCE=..\src\include\menu.h
# End Source File
# Begin Source File

SOURCE=..\src\include\objects.h
# End Source File
# Begin Source File

SOURCE="..\src\include\op-cmd.h"
# End Source File
# Begin Source File

SOURCE="..\src\include\op-dbg.h"
# End Source File
# Begin Source File

SOURCE="..\src\include\op-misc.h"
# End Source File
# Begin Source File

SOURCE="..\src\include\op-test.h"
# End Source File
# Begin Source File

SOURCE=..\src\include\picture.h
# End Source File
# Begin Source File

SOURCE=..\src\include\rand.h
# End Source File
# Begin Source File

SOURCE=..\src\include\savegame.h
# End Source File
# Begin Source File

SOURCE=..\src\include\sound.h
# End Source File
# Begin Source File

SOURCE=..\src\include\typedef.h
# End Source File
# Begin Source File

SOURCE=..\src\include\view.h
# End Source File
# Begin Source File

SOURCE=..\src\include\win32.h
# End Source File
# Begin Source File

SOURCE=..\src\include\words.h
# End Source File
# End Group
# Begin Group "Resource Files"

# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File

SOURCE=..\src\core\win32\winres.rc
# End Source File
# End Group
# End Target
# End Project

Introduction
This article focuses on giving an example of using the DirectX API in PC game software development by using a DirectSound wrapper class.

The DirectSound wrapper class
The wrapper class has the functionality to handle various aspects of sound playback.

The structure of the wrapper class
The DirectSound object uses double buffers to manipulate the sound data processing and playback. The DirectSound object creates a single primary buffer to deal with output devices to play the sound data. The DirectSound object creates multiple second buffers to load, store various sound data, and configure sound data performance. The object loads and mixes sound data from the secondary buffers and sends the processed sound data to the primary buffer to play it through the output device.

The wrapper class contains a pointer to the DirectSound object, a primary buffer object (a pointer of type DirectSoundBuffer), and the secondary buffer array (DirectSoundBuffer object array)

DirectSound object in the wrapper class
DirectSound is a COM interface, so the DirectSound object is the COM component object (a pointer to DirectSound). The DirectSound object is the core of sound playback and all of buffers, both primary buffer and secondary buffers are created by it, so it must be instantiated before doing any sound play back.

Because the DirectSound object is a COM object, it can be instantiated by either the generic way of creation COM components, or by calling DirectSoundCreate. In my wrapper class, I find the generic method of creating a COM object is more reliable. Remember: The DirectX interfaces are a subset of the COM interfaces, so before you use them, call CoInitialize/ CoInitializeEx, and call CoUninitialize at the end of your application.

// To start...
BOOL CSoundManager::CoInitializeDSound(void)
{
    HRESULT  hr;
    GUID     guID;

    // Clear the GUID
    ::memset(&guID, 0, sizeof(GUID));
 
    // Initialize COM service, create STA 
    hr = ::CoInitialize(NULL);
    ................................. 
    .................................
    // Create the IDirectSound object with the realiable way (create
    // standard COM object)
    hr = CoCreateInstance(CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
              IID_IDirectSound, (void**)&m_pIDS);
    ................................. 
    ................................
    // Initialize the IDirectSound object
    hr = IDirectSound_Initialize(m_pIDS, &guID);
    ................................. 
    .................................
    return TRUE;
}

// To finish up...
void CSoundManager::CoUnInitializeDSound(void)
{
    if(m_pIDS)
    {
        m_pIDS->Release();
        m_pIDS = NULL;
        ::CoUninitialize();
    }	
}

Primary Buffer
The primary buffer is a DirectSoundBuffer object, and its main task is to receive the processed sound data from the DirectSound object and send it to the output device to play. The primary’s format settings determine the sound play effect of the output device. The primary’s format is a WAVEFORMATEX structure and must be set before play.

Second Buffer
The second buffer loads sound data and sets the sound performance, then sends the sound to the DirectSound object. The second buffer is a DirectSoundBuffer object and is created by the DirectSound object.

In my library, I use a wrapper class of DirectSoundBuffer for the second buffer. This wrapper class has the DirectSoundBuffer object, and the methods to set sound performances, such as adjustment of volume, frequency and channel.

A special feature of the DirectSoundBuffer wrapper class is the special sound effect of Fade-In (volume up step by step) and Fade-Out (volume down step by step).

To avoid the concurrency of incoming function calls, a mutex object is used in the DirectSoundBuffer wrapper class to synchronize the function calls.

Timer Event
The DirectSound wrapper class needs a timer to monitor and manipulate the sound status and performance in a special time interval. The DirectSound wrapper class is a generic class, so it is hard to use a windows timer in the class. As an alternative, a waitable timer is used in the class. A thread is created to check the timer event when the class object is instantiated.

The test program
The test program is a Dialog box application written in MFC. It tests the various wrapper class features, such as volume, frequency, channel, looping, mixing and fade-in and fade-out, etc.

Introduction
Loading images under windows can always be a painful process, especially if the image formats are like JPEG, GIF or PNG. There's always the Imgdecmp library, that does a good job, but its also a bit of a bother with the documentation being so thin and all that. The other day I was trying to load a bitmap from my device using LoadImage, but somehow I kept getting the dreaded "The handle is invalid" error. So I did a search on the MFC code that ships with the PPC SDK in hope of finding a piece of code that will help me solve the puzzle.

One thing led to another. I suddenly came across HBITMAP SHLoadImageFile(LPCTSTR pszFileName) in aygshell.h. Bingo! I had suddenly uncovered an undocumented API! No trace of it in MSDN, a search in Google produced nothing!! Since then, I've tried this API with gif's and bmp's also and I guess it will work fine for jpeg's and png's too. Here's a code sample...

// assuming code is in the OnDraw method of a view....

CBitmap bitmap;

// Attach the bitmap object to the HBITMAP returned by SHLoadImageFile
bitmap.Attach(SHLoadImageFile(_T("/My Documents/mcdonalds.gif")));

BITMAP bmpInfo;
bitmap.GetBitmap(&bmpInfo);

CDC bitmapDC;
bitmapDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);

pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC, 
            0, 0, SRCCOPY);

bitmapDC.SelectObject(pOldBitmap);
bitmap.DeleteObject();

That's all for now.

umm... THX a lot for trying mate but im not really that advanced at programming yet (im makinging a DOS 32 app thing). Ive included my source code (so far), if anyone could have a look and tell me if i could do this i would really appreciate it! Also any other suggestions to improve it would be greatly appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.