diff --git a/Enemies.cpp b/Enemies.cpp index 80204fb..e8da0ea 100644 --- a/Enemies.cpp +++ b/Enemies.cpp @@ -129,10 +129,10 @@ int CheckEnemyHit(int n1, int n2) { } void Enemies::ProcessMessage(const char* msg) { - if (msg == "CheckEnemyHit") { + if (strcmp(msg, "CheckEnemyHit") == 0) { int* params = GetMessageParams(); SetMessageReturn(CheckEnemyHit(params[0], params[1])); - } else if (msg == "ResetEnemies") { + } else if (strcmp(msg, "ResetEnemies") == 0) { betweenWaves = 420; ResetEnemies(); } } diff --git a/Explosions.cpp b/Explosions.cpp index edd65bc..45132cf 100644 --- a/Explosions.cpp +++ b/Explosions.cpp @@ -88,7 +88,7 @@ void GenerateExplosion(int x, int y) { } void Explosions::ProcessMessage(const char* msg) { - if (msg == "GenerateExplosion") { + if (message_eq("GenerateExplosion")) { int* params = GetMessageParams(); GenerateExplosion(params[0], params[1]); } diff --git a/Lasers.cpp b/Lasers.cpp index 5e7b187..c4d79f8 100644 --- a/Lasers.cpp +++ b/Lasers.cpp @@ -72,7 +72,7 @@ void CreateNewLaser(float x1, float y1, float x2, float y2, unsigned char r, uns } void Lasers::ProcessMessage(const char* msg) { - if (msg == "CreateNewLaser") { + if (message_eq("CreateNewLaser")) { int* params = GetMessageParams(); if (params[4] == 0) { CreateNewLaser(params[0], params[1], params[2], params[3], 255, 0, 0); diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..5729371 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +game : + g++ *.cpp -std=c++11 -lSDL2 -o mathwars + +run : game + ./mathwars + diff --git a/Score.cpp b/Score.cpp index 7c0d4c9..1e481fa 100644 --- a/Score.cpp +++ b/Score.cpp @@ -15,7 +15,8 @@ Score::Score() { void Score::Update() { char strScore[10]; - itoa(score, strScore, 10); + sprintf(strScore, "%d", score); + //itoa(score, strScore, 10); Print(220, 4, strScore, 255, 255, 0); if (lives > 0) Draw(5, 5, 10, 85, 18, 18); if (lives > 1) Draw(25, 5, 10, 85, 18, 18); @@ -23,10 +24,10 @@ void Score::Update() { } void Score::ProcessMessage(const char* msg) { - if (msg == "IncreaseScore") { + if (message_eq("IncreaseScore")) { int* params = GetMessageParams(); score += params[0]; - } else if (msg == "DecreaseLives") { + } else if (message_eq("DecreaseLives")) { lives--; } } diff --git a/StarField.cpp b/StarField.cpp index 9b5dcea..007fdf1 100644 --- a/StarField.cpp +++ b/StarField.cpp @@ -34,7 +34,7 @@ void StarField::Update() { } void StarField::ProcessMessage(const char* msg) { - if (msg == "SetStarFieldVelocity") { + if (message_eq("SetStarFieldVelocity")) { int* params = GetMessageParams(); speed = params[0] * 0.01f; } diff --git a/Xwing.cpp b/Xwing.cpp index 054e34d..5244aba 100644 --- a/Xwing.cpp +++ b/Xwing.cpp @@ -72,10 +72,11 @@ void SetNumbers(int p1, int p2) { } void Xwing::ProcessMessage(const char* msg) { - if (msg == "HeroHit") { + if (message_eq("HeroHit")) { + //if (msg == "HeroHit") { int* params = GetMessageParams(); HeroHit(params[0], params[1]); - } else if (msg == "SetNumbers") { + } else if (message_eq("SetNumbers")) { int* params = GetMessageParams(); SetNumbers(params[0], params[1]); } diff --git a/api.cpp b/api.cpp index 5bf0461..d5d2887 100644 --- a/api.cpp +++ b/api.cpp @@ -1,6 +1,7 @@ #include "api.h" #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" +#include #include #include diff --git a/api.h b/api.h index 4591743..796295e 100644 --- a/api.h +++ b/api.h @@ -1,9 +1,11 @@ #pragma once -#include +#include #include "System.h" #include +#define message_eq(m) strncmp(msg, m, 20) + enum BlendMode { BlendNone, BlendBlend, BlendAdd, BlendMod }; struct Point { diff --git a/keyHandlers.cpp b/keyHandlers.cpp index 4fd771d..b777dee 100644 --- a/keyHandlers.cpp +++ b/keyHandlers.cpp @@ -1,4 +1,3 @@ -#pragma once #include "api.h" @@ -14,24 +13,30 @@ int digit = -1; void keyHandler(SDL_Scancode key) { + int num = 0; if (key >= 89 && key <= 98) { - int num = key == 98 ? 0 : key - 88; - if (digit == -1) { - digit = num; - SendMessage("CheckEnemyHit", 0, num); - if (GetMessageReturn() != 0) { - SendMessage("SetNumbers", -1, num); - digit = -1; - } else { - SendMessage("SetNumbers", num, -1); - } - } - else { + num = key == 98 ? 0 : key - 88; + } else if (key >= 30 && key <= 39) { + num = key == 39 ? 0 : key - 29; + } else { + return; + } + + if (digit == -1) { + digit = num; + SendMessage("CheckEnemyHit", 0, num); + if (GetMessageReturn() != 0) { SendMessage("SetNumbers", -1, num); - SendMessage("CheckEnemyHit", digit, num); digit = -1; + } else { + SendMessage("SetNumbers", num, -1); } } + else { + SendMessage("SetNumbers", -1, num); + SendMessage("CheckEnemyHit", digit, num); + digit = -1; + } } void menuKeyHandler(SDL_Scancode key) { diff --git a/main.cpp b/main.cpp index 73fed16..36fd383 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include "api.h" +#include #include "keyHandlers.h" #include "StarField.h" @@ -16,4 +17,4 @@ int main(int argc, char* argv[]) { while (!Update()) {} Quit(); return 0; -} \ No newline at end of file +} diff --git a/mathwars.sln b/mathwars.sln deleted file mode 100644 index b3ef1ae..0000000 --- a/mathwars.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mathwars", "mathwars.vcxproj", "{5CCE4316-2638-47DA-9C0B-3075E1120FD1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5CCE4316-2638-47DA-9C0B-3075E1120FD1}.Debug|Win32.ActiveCfg = Debug|Win32 - {5CCE4316-2638-47DA-9C0B-3075E1120FD1}.Debug|Win32.Build.0 = Debug|Win32 - {5CCE4316-2638-47DA-9C0B-3075E1120FD1}.Release|Win32.ActiveCfg = Release|Win32 - {5CCE4316-2638-47DA-9C0B-3075E1120FD1}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/mathwars.vcxproj b/mathwars.vcxproj deleted file mode 100644 index 3385473..0000000 --- a/mathwars.vcxproj +++ /dev/null @@ -1,110 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {5CCE4316-2638-47DA-9C0B-3075E1120FD1} - Win32Proj - mathwars - 10.0.17134.0 - - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - - - - - - - - - - - true - C:\dev\lib\sdl2\include;$(IncludePath) - C:\dev\lib\sdl2\lib\x86;$(LibraryPath) - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Windows - true - SDL2.lib;SDL2main.lib;%(AdditionalDependencies) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mathwars.vcxproj.filters b/mathwars.vcxproj.filters deleted file mode 100644 index 53ed518..0000000 --- a/mathwars.vcxproj.filters +++ /dev/null @@ -1,84 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Source Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file