You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
5.9 KiB
C++
225 lines
5.9 KiB
C++
# include <stdio.h>
|
|
# include <windows.h>
|
|
# include <ddraw.h>
|
|
# include <dsound.h>
|
|
# include "ddutil.h"
|
|
# include "dsutil.h"
|
|
# include "resource.h"
|
|
|
|
const int ultris_nettobreite = 360; // Breite des Inneren des Haupfensters
|
|
const int ultris_nettohoehe = 520; // Hoehe des Inneren des Hauptfensters
|
|
int ultris_bruttobreite; // Breite des gesamten Haupfensters (incl. Rahmen)
|
|
int ultris_bruttohoehe; // Hoehe des gesamten Haupfensters (incl. Rahmen)
|
|
|
|
HINSTANCE ultris_instance; // Instanz der Ultris Applikation
|
|
HWND ultris_window; // Das Hauptfenster von Ultris
|
|
HMENU ultris_menu; // Das Menu von Ultris
|
|
|
|
// V2 Beginn
|
|
const int sound_start = 0; // Sound fuer neues Spiel
|
|
const int sound_dreh = 1; // Sound bei Drehung
|
|
const int sound_move = 2; // Sound bei rechts/links Bewegung
|
|
const int sound_down = 3; // Sound bei Aufprall
|
|
const int sound_row1 = 4; // Sound bei Abraeumen einer Reihe
|
|
const int sound_row2 = 5; // Sound bei Abraeumen von mehreren Reihen
|
|
const int sound_ende = 6; // Sound bei Spielende
|
|
const int sound_win = 7; // Sound bei Eintrag in Highscore Tabelle
|
|
const int anzahl_sounds = 8; // Anzahl Sounds
|
|
|
|
char *soundfiles[anzahl_sounds] =
|
|
{
|
|
"ul_start.wav",
|
|
"ul_dreh.wav",
|
|
"ul_move.wav",
|
|
"ul_down.wav",
|
|
"ul_row1.wav",
|
|
"ul_row2.wav",
|
|
"ul_ende.wav",
|
|
"ul_win.wav"
|
|
};
|
|
|
|
class sounds
|
|
{
|
|
private:
|
|
CSoundManager smgr;
|
|
CSound *snd[anzahl_sounds];
|
|
public:
|
|
int on;
|
|
sounds();
|
|
int init( HWND wnd);
|
|
void play( int snr);
|
|
~sounds();
|
|
};
|
|
|
|
sounds::sounds()
|
|
{
|
|
int i;
|
|
|
|
for( i = 0; i < anzahl_sounds; i++)
|
|
snd[i] = 0;
|
|
on = 1;
|
|
}
|
|
|
|
int sounds::init( HWND wnd)
|
|
{
|
|
HRESULT ret;
|
|
int i;
|
|
|
|
ret = smgr.Initialize( wnd, DSSCL_PRIORITY, 2, 22050, 16);
|
|
if( ret < 0)
|
|
return ret;
|
|
|
|
for( i = 0; i < anzahl_sounds; i++)
|
|
{
|
|
ret = smgr.Create( snd+i, soundfiles[i]);
|
|
if( ret < 0)
|
|
return ret;
|
|
}
|
|
return S_OK;
|
|
}
|
|
|
|
sounds::~sounds()
|
|
{
|
|
int i;
|
|
|
|
for( i = 0; i < anzahl_sounds; i++)
|
|
{
|
|
if( snd[i])
|
|
delete snd[i];
|
|
}
|
|
}
|
|
|
|
void sounds::play( int i)
|
|
{
|
|
if( !on)
|
|
return;
|
|
if( snd[i]->IsSoundPlaying())
|
|
{
|
|
snd[i]->Stop();
|
|
snd[i]->Reset();
|
|
}
|
|
snd[i]->Play(0,0);
|
|
}
|
|
|
|
sounds ultris_sounds;
|
|
// V2 Ende
|
|
|
|
|
|
|
|
/*
|
|
** ultris_windowhandler
|
|
*/
|
|
LRESULT CALLBACK ultris_windowhandler( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch(msg)
|
|
{
|
|
case WM_COMMAND:
|
|
switch( LOWORD( wParam))
|
|
{
|
|
case IDM_EXIT:
|
|
PostMessage( hWnd, WM_CLOSE, 0, 0);
|
|
return 0;
|
|
// V2 Beginn
|
|
case ID_ULTRIS_SOUND:
|
|
ultris_sounds.on = !ultris_sounds.on;
|
|
CheckMenuItem( ultris_menu, ID_ULTRIS_SOUND, ultris_sounds.on ? MF_CHECKED:MF_UNCHECKED);
|
|
return 0;
|
|
case IDM_TEST: // Testcode
|
|
static int testno = 0;
|
|
ultris_sounds.play( testno % anzahl_sounds);
|
|
testno++;
|
|
return 0;
|
|
// V2 Ende
|
|
}
|
|
break;
|
|
case WM_GETMINMAXINFO:
|
|
((MINMAXINFO *)lParam)->ptMinTrackSize.x = ((MINMAXINFO *)lParam)->ptMaxTrackSize.x = ultris_bruttobreite;
|
|
((MINMAXINFO *)lParam)->ptMinTrackSize.y = ((MINMAXINFO *)lParam)->ptMaxTrackSize.y = ultris_bruttohoehe;
|
|
return 0;
|
|
case WM_DESTROY:
|
|
PostQuitMessage( 0);
|
|
return 0;
|
|
}
|
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
|
}
|
|
|
|
/*
|
|
** WinMain
|
|
*/
|
|
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow)
|
|
{
|
|
MSG msg;
|
|
HACCEL acc;
|
|
WNDCLASSEX wcx;
|
|
|
|
ultris_instance = hInst;
|
|
|
|
wcx.cbSize = sizeof( wcx);
|
|
wcx.lpszClassName = TEXT( "Ultris");
|
|
wcx.lpfnWndProc = ultris_windowhandler;
|
|
wcx.style = CS_VREDRAW | CS_HREDRAW;
|
|
wcx.hInstance = hInst;
|
|
wcx.hIcon = LoadIcon( hInst, MAKEINTRESOURCE( IDI_MAIN));
|
|
wcx.hIconSm = LoadIcon( hInst, MAKEINTRESOURCE( IDI_MAIN));
|
|
wcx.hCursor = LoadCursor( NULL, IDC_ARROW);
|
|
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
|
wcx.lpszMenuName = MAKEINTRESOURCE( IDR_MENU);
|
|
wcx.cbClsExtra = 0;
|
|
wcx.cbWndExtra = 0;
|
|
|
|
if( !RegisterClassEx( &wcx))
|
|
return 0;
|
|
|
|
acc = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_ACCEL));
|
|
|
|
ultris_bruttohoehe = ultris_nettohoehe + 2*GetSystemMetrics( SM_CYSIZEFRAME)
|
|
+ GetSystemMetrics( SM_CYMENU)
|
|
+ GetSystemMetrics( SM_CYCAPTION);
|
|
ultris_bruttobreite = ultris_nettobreite + 2*GetSystemMetrics( SM_CXSIZEFRAME);
|
|
|
|
ultris_window = CreateWindowEx( 0, TEXT( "Ultris"), TEXT( "Ultris"), WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
ultris_bruttobreite, ultris_bruttohoehe, NULL, NULL, hInst, NULL);
|
|
if( !ultris_window)
|
|
return 0;
|
|
|
|
ultris_menu = GetMenu( ultris_window);
|
|
|
|
// V2 Beginn
|
|
if( ultris_sounds.init( ultris_window) < 0)
|
|
{
|
|
MessageBox( ultris_window, "Fehler beim Initialisieren der Sounds", "Ultris-Fehlermeldung", MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
|
|
return 0;
|
|
}
|
|
CheckMenuItem( ultris_menu, ID_ULTRIS_SOUND, ultris_sounds.on ? MF_CHECKED:MF_UNCHECKED);
|
|
// V2 Ende
|
|
|
|
MoveWindow( ultris_window, (GetSystemMetrics(SM_CXSCREEN)-ultris_bruttobreite)/2,
|
|
(GetSystemMetrics(SM_CYSCREEN)-ultris_bruttohoehe)/2,
|
|
ultris_bruttobreite, ultris_bruttohoehe, TRUE);
|
|
|
|
ShowWindow( ultris_window, nCmdShow);
|
|
|
|
while( TRUE)
|
|
{
|
|
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
|
|
{
|
|
if( GetMessage( &msg, NULL, 0, 0 ) == 0)
|
|
return 0; // Message ist WM_QUIT
|
|
|
|
if( TranslateAccelerator( ultris_window, acc, &msg) == 0)
|
|
{
|
|
TranslateMessage( &msg);
|
|
DispatchMessage( &msg);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Hier koennen wir uns um das Spiel kuemmern
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|