diff --git a/bin/images/Panel.bmp b/bin/images/Panel.bmp
index 26df2fe..cb8571c 100644
Binary files a/bin/images/Panel.bmp and b/bin/images/Panel.bmp differ
diff --git a/build/Landscape.vcxproj b/build/Landscape.vcxproj
index d35d005..256802d 100644
--- a/build/Landscape.vcxproj
+++ b/build/Landscape.vcxproj
@@ -113,12 +113,13 @@
false
true
EditAndContinue
- _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ SFML_STATIC;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\Debug\
true
.\Debug\Landscape.pch
.\Debug\
.\Debug\
+ ..\extlibs\include
true
@@ -141,9 +142,10 @@
true
Windows
.\Debug\Schiffbruch.exe
- dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;dinput.lib;xinput.lib;dinput8.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
+ sfml-window-s-d.lib;sfml-system-s-d.lib;opengl32.lib;gdi32.lib;dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
+ C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86;..\extlibs\lib
false
+ /ignore:4204 %(AdditionalOptions)
@@ -155,12 +157,13 @@
MaxSpeed
true
Level3
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ SFML_STATIC;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\Release\
true
.\Release\Landscape.pch
.\Release\
.\Release\
+ ..\extlibs\include
true
@@ -182,8 +185,9 @@
true
Windows
.\Release\Schiffbruch.exe
- dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;dinput.lib;xinput.lib;dinput8.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
+ sfml-window-s.lib;sfml-system-s.lib;opengl32.lib;gdi32.lib;dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
false
+ ..\extlibs\lib
diff --git a/src/Action.hpp b/src/Action.hpp
index a0298cd..839021d 100644
--- a/src/Action.hpp
+++ b/src/Action.hpp
@@ -25,7 +25,7 @@ namespace Action
DOCK = 14,
PIPE = 15,
DESTROY = 16,
- SOS = 17,
+ SOS_SIGN = 17,
HOUSE1 = 18,
HOUSE2 = 19,
HOUSE3 = 20,
diff --git a/src/Application.cpp b/src/Application.cpp
index 3afe6eb..d3d3254 100644
--- a/src/Application.cpp
+++ b/src/Application.cpp
@@ -16,132 +16,67 @@
#include
Application::Application(const std::string& name, HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
-: m_name(name)
+: m_window({ MAXX, MAXY }, name, sf::Style::Fullscreen)
+, m_name(name)
+, m_hWnd(m_window.getSystemHandle())
, m_hInstance(hInstance)
, m_hPrevInstance(hPrevInstance)
, m_lpCmdLine(lpCmdLine)
, m_nCmdShow(nCmdShow)
{
+ // Set globals
g_hInst = m_hInstance;
-
- if (!create_window())
- throw std::runtime_error("Failed to create a valid window.");
-
hwnd = m_hWnd;
- Direct::InitDInput();
- MouseInit = true;
-
- ShowWindow(m_hWnd, m_nCmdShow);
- UpdateWindow(m_hWnd);
-
Direct::InitDDraw();
Direct::InitDSound();
- SetTimer(hwnd, 0, 1000, nullptr); // Provisorisch
srand((unsigned)time(nullptr)); // Random initialisieren
}
-LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+void Application::process_events()
{
- Application* pApp = nullptr;
-
- if (uMsg == WM_NCCREATE)
+ sf::Event event;
+ while (m_window.pollEvent(event))
{
- // Get the pointer to the window from lpCreateParams which was set in create_window
- SetWindowLong(hWnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
+ if (event.type == sf::Event::Closed)
+ {
+ Direct::finiObjects();
+ m_window.close();
+ }
+ else if (event.type == sf::Event::GainedFocus)
+ {
+ bActive = TRUE;
+ }
+ else if (event.type == sf::Event::KeyReleased)
+ {
+ if (event.key.code == sf::Keyboard::F4)
+ {
+ Direct::finiObjects();
+ m_window.close();
+ }
+ }
}
-
- // Get the pointer to the application
- pApp = Application::ptr(hWnd);
-
- // If we have the pointer, go to the message handler of the window else, use DefWindowProc
- if (pApp)
- return pApp->process_events(hWnd, uMsg, wParam, lParam);
- else
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
-LRESULT CALLBACK Application::process_events(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+int Application::run()
{
- m_hWnd = hWnd;
-
- static BYTE phase = 0;
+ sf::Clock timer;
- switch (uMsg)
+ while (m_window.isOpen())
{
- case WM_ACTIVATEAPP:
- bActive = wParam;
- Direct::SetAcquire();
- break;
-
- case WM_ACTIVATE: // Sent when window changes active state
- bActive = wParam;
- Direct::SetAcquire();
- break;
+ process_events();
- case WM_CREATE:
- break;
-
- case WM_TIMER:
- if (Refresh() == 0)
- PostMessage(hwnd, WM_DESTROY, 0, 0);
- break;
-
- case WM_QUIT:
- case WM_DESTROY:
- Direct::finiObjects();
- PostQuitMessage(0);
- break;
- }
-
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
-}
-
-bool Application::create_window()
-{
- WNDCLASS wc;
-
- // Set up and register window class
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = &Application::WindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = m_hInstance;
- wc.hIcon = LoadIcon(m_hInstance, IDI_APPLICATION);
- wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wc.hbrBackground = nullptr;
- wc.lpszMenuName = m_name.c_str();
- wc.lpszClassName = m_name.c_str();
- RegisterClass(&wc);
-
- // Create a window
- m_hWnd = CreateWindowEx(
- WS_EX_TOPMOST,
- m_name.c_str(),
- m_name.c_str(),
- WS_POPUP,
- 0,
- 0,
- GetSystemMetrics(SM_CXSCREEN),
- GetSystemMetrics(SM_CYSCREEN),
- NULL,
- NULL,
- m_hInstance,
- this);
-
- return m_hWnd != nullptr;
-}
+ if (timer.getElapsedTime() > sf::milliseconds(1000))
+ {
+ if (Refresh() == 0)
+ m_window.close();
-int Application::run()
-{
- while (GetMessage(&m_msg, nullptr, 0, 0))
- {
- TranslateMessage(&m_msg);
- DispatchMessage(&m_msg);
+ timer.restart();
+ }
}
- return m_msg.wParam;
+ return 0;
}
short Application::Refresh()
@@ -278,7 +213,7 @@ void Application::Event(short Eventnr)
case Action::DESTROY:
Action::destroy();
break;
- case Action::SOS:
+ case Action::SOS_SIGN:
Action::sos();
break;
case Action::HOUSE1:
diff --git a/src/Application.hpp b/src/Application.hpp
index 50c0d91..01f91d0 100644
--- a/src/Application.hpp
+++ b/src/Application.hpp
@@ -3,6 +3,8 @@
#include "headers.hpp"
#include "extern.hpp"
+#include
+
#include
class Application
@@ -20,17 +22,11 @@ class Application
BOOL doInit();
private:
- LRESULT CALLBACK process_events(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-
- bool create_window();
-
- // Returns a pointer the application (stored as the WindowLong)
- inline static Application *ptr(HWND hWnd)
- {
- return (Application *)GetWindowLong(hWnd, GWL_USERDATA);
- }
+ void process_events();
private:
+ sf::Window m_window;
+
std::string m_name;
MSG m_msg;
HWND m_hWnd;
diff --git a/src/Direct.cpp b/src/Direct.cpp
index 43fcbe2..a46adcf 100644
--- a/src/Direct.cpp
+++ b/src/Direct.cpp
@@ -9,6 +9,8 @@
#include "Sound.hpp"
#include "World.hpp"
+#include
+
#include
namespace Direct
@@ -184,18 +186,6 @@ namespace Direct
}
}
- void InitDInput()
- {
- DirectInputCreate(g_hInst, DIRECTINPUT_VERSION, &g_pDI, nullptr); // DirectInput
- g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, nullptr); // Mousepointer
- g_pMouse->SetDataFormat(&c_dfDIMouse); // MausDateninformation einstellen
- g_pMouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); // Exklusive Maus
-
- g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKey, nullptr); // Keyboard einrichten
- g_pKey->SetDataFormat(&c_dfDIKeyboard); // Datenformat auf KeyBoard umschalten
- g_pKey->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); // KeyBoard geht nicht exklusive
- }
-
void InitDSound()
{
HRESULT hr;
@@ -242,40 +232,19 @@ namespace Direct
}
}
- void SetAcquire()
- {
- if (!MouseInit) return;
- if (bActive)
- {
- g_pMouse->Acquire();
- if (g_pKey)g_pKey->Acquire();
-
- }
- else
- {
- g_pMouse->Unacquire();
- if (g_pKey)g_pKey->Unacquire();
-
- }
- }
-
void CheckMouse()
{
- DIMOUSESTATE dims; // Da werden die Daten der Maus gespeichert
short Button; // Welcher Knopf ist gedrückt worden
short Push; // Knopf gedrückt(1) oder losgelassen(-1) oder gedrückt(0) gehalten
short xDiff, yDiff; // Die Differenz zur vorherigen Position ((Für Scrollen)
- g_pMouse->GetDeviceState(sizeof(DIMOUSESTATE), &dims);
// Mausbewegung
- xDiff = MousePosition.x;
- MousePosition.x += (short)dims.lX;
- xDiff -= MousePosition.x;
+ xDiff = MousePosition.x - sf::Mouse::getPosition().x;
+ MousePosition.x = sf::Mouse::getPosition().x;
if (MousePosition.x < 0) MousePosition.x = 0;
if (MousePosition.x > MAXX - 2) MousePosition.x = MAXX - 2;
- yDiff = MousePosition.y;
- MousePosition.y += (short)dims.lY;
- yDiff -= MousePosition.y;
+ yDiff = MousePosition.y - sf::Mouse::getPosition().y;
+ MousePosition.y = sf::Mouse::getPosition().y;
if (MousePosition.y < 0) MousePosition.y = 0;
if (MousePosition.y > MAXY - 2) MousePosition.y = MAXY - 2;
@@ -291,7 +260,7 @@ namespace Direct
}
Button = -1;
- if (dims.rgbButtons[0] & 0x80)
+ if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
Button = 0;
if (Button0down) Push = 0;
@@ -312,7 +281,7 @@ namespace Direct
}
- if (dims.rgbButtons[1] & 0x80)
+ if (sf::Mouse::isButtonPressed(sf::Mouse::Right))
{
Button = 1;
if (Button1down) Push = 0;
@@ -391,28 +360,16 @@ namespace Direct
// die Maus ist im Panel ->
if (Math::InRect(MousePosition.x, MousePosition.y, rcPanel))
Math::MouseInPanel(Button, Push);
- /*
- dims.lX, dims.lY, dims.lZ,
- (dims.rgbButtons[0] & 0x80) ? '0' : ' ',
- (dims.rgbButtons[1] & 0x80) ? '1' : ' ',
- (dims.rgbButtons[2] & 0x80) ? '2' : ' ',
- (dims.rgbButtons[3] & 0x80) ? '3' : ' ');
- */
}
short CheckKey()
{
-#define KEYDOWN(name,key) (name[key] & 0x80)
- char buffer[256];
- short x;
-
- g_pKey->GetDeviceState(sizeof(buffer), (LPVOID)&buffer);
-
+ short x;
if (Spielzustand == SZLOGO)
{
- if ((KEYDOWN(buffer, DIK_ESCAPE)) || (KEYDOWN(buffer, DIK_RETURN)) ||
- (KEYDOWN(buffer, DIK_SPACE))) // Logo Abbrechen
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) || sf::Keyboard::isKeyPressed(sf::Keyboard::Return) ||
+ sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) // Logo Abbrechen
{
Sound::StopSound(WAVLOGO);
Game::NeuesSpiel(false);
@@ -421,8 +378,8 @@ namespace Direct
}
else if (Spielzustand == SZINTRO)
{
- if ((KEYDOWN(buffer, DIK_ESCAPE)) || (KEYDOWN(buffer, DIK_RETURN)) ||
- (KEYDOWN(buffer, DIK_SPACE))) // Intro Abbrechen
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) || sf::Keyboard::isKeyPressed(sf::Keyboard::Return) ||
+ sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) // Intro Abbrechen
{
Sound::StopSound(WAVSTURM); // Sound hier sofort stoppen
Sound::StopSound(WAVSCHWIMMEN); // Sound hier sofort stoppen
@@ -460,8 +417,8 @@ namespace Direct
}
else if (Spielzustand == SZGERETTET)
{
- if ((KEYDOWN(buffer, DIK_ESCAPE)) || (KEYDOWN(buffer, DIK_RETURN)) ||
- (KEYDOWN(buffer, DIK_SPACE)))
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) || sf::Keyboard::isKeyPressed(sf::Keyboard::Return) ||
+ sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
Spielzustand = SZABSPANN;
return(1);
@@ -469,35 +426,36 @@ namespace Direct
}
else if (Spielzustand == SZSPIEL)
{
- if (KEYDOWN(buffer, DIK_RIGHT)) Camera.x += 10;
- if (KEYDOWN(buffer, DIK_LEFT)) Camera.x -= 10;
- if (KEYDOWN(buffer, DIK_DOWN)) Camera.y += 10;
- if (KEYDOWN(buffer, DIK_UP)) Camera.y -= 10;
- if (KEYDOWN(buffer, DIK_ESCAPE))
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) Camera.x += 10;
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) Camera.x -= 10;
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) Camera.y += 10;
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) Camera.y -= 10;
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
Guy.AkNummer = 0;
Guy.Aktiv = false;
Guy.Aktion = Action::QUIT;
}
- if (KEYDOWN(buffer, DIK_F11))
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11))
{
Guy.AkNummer = 0;
Guy.Aktiv = false;
Guy.Aktion = Action::RESTART;
}
- if (KEYDOWN(buffer, DIK_G))
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::G))
{
Gitter = !Gitter;
World::Generate();
}
- if (KEYDOWN(buffer, DIK_A))
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
LAnimation = !LAnimation;
World::Generate();
}
+ // Development
/*
- if (KEYDOWN(buffer, DIK_C)) // Zum testen
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::C))
{
short x,y;
for (y=0;y