diff --git a/Chapter10_ResponsiveHacks/Chapter10_ResponsiveHacks.vcxproj b/Chapter10_ResponsiveHacks/Chapter10_ResponsiveHacks.vcxproj index 456c809..da40261 100644 --- a/Chapter10_ResponsiveHacks/Chapter10_ResponsiveHacks.vcxproj +++ b/Chapter10_ResponsiveHacks/Chapter10_ResponsiveHacks.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter11_SearchAlgorithms/Chapter11_SearchAlgorithms.vcxproj b/Chapter11_SearchAlgorithms/Chapter11_SearchAlgorithms.vcxproj index c84198e..120cbcf 100644 --- a/Chapter11_SearchAlgorithms/Chapter11_SearchAlgorithms.vcxproj +++ b/Chapter11_SearchAlgorithms/Chapter11_SearchAlgorithms.vcxproj @@ -18,13 +18,17 @@ Application true - MultiByte + Unicode + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ Application false true Unicode + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter11_StateMachines/Chapter11_StateMachines.vcxproj b/Chapter11_StateMachines/Chapter11_StateMachines.vcxproj index bc7a4a8..2e7c7de 100644 --- a/Chapter11_StateMachines/Chapter11_StateMachines.vcxproj +++ b/Chapter11_StateMachines/Chapter11_StateMachines.vcxproj @@ -38,9 +38,11 @@ $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ diff --git a/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj b/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj new file mode 100644 index 0000000..0b1a1bf --- /dev/null +++ b/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj @@ -0,0 +1,96 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {AB736FAE-3FEF-40C0-B426-BFC3E3FA569F} + Chapter1__01 + Chapter1_BasicMemory + + + + Application + MultiByte + true + + + Application + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + $(SolutionDir)\bin\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + + + + Disabled + %(AdditionalIncludeDirectories) + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + EditAndContinue + + + allegro-5.0.10-monolith-md-debug.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + copy "$(SolutionDir)game.map" "$(OutDir)game.map" /y && copy "$(SolutionDir)arial.ttf" "$(OutDir)arial.ttf" /y + + + + + MaxSpeed + true + MultiThreadedDLL + true + Level3 + ProgramDatabase + + + %(AdditionalDependencies) + true + Windows + true + true + MachineX86 + + + copy "$(SolutionDir)game.map" "$(OutDir)game.map" /y && copy "$(SolutionDir)arial.ttf" "$(OutDir)arial.ttf" /y + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj.filters b/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj.filters new file mode 100644 index 0000000..501857d --- /dev/null +++ b/Chapter1_BasicMemory/Chapter1_BasicMemory.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + {3c8b02c5-3b42-4b99-9dbc-d301f719fc1c} + + + {1c064fd6-e3d1-47a5-b1c0-ea67fd84ce18} + + + + + Header Files + + + + + Source Hiles + + + \ No newline at end of file diff --git a/Chapter1_BasicMemory/Location-BasicMem.h b/Chapter1_BasicMemory/Location-BasicMem.h new file mode 100644 index 0000000..94a3b95 --- /dev/null +++ b/Chapter1_BasicMemory/Location-BasicMem.h @@ -0,0 +1,50 @@ +struct Location +{ + int x; + int y; + + Location(){} + Location(int x, int y) + { + this->x = x; + this->y = y; + } + const bool operator == (const Location &o) + { + return (o.x == this->x && o.y == this->y); + } + const bool operator != (const Location &o) + { + return !(*this == o); + } + const Location operator + (const Location &o) + { + return Location(this->x + o.x, this->y + o.y); + } + + const Location operator - (const Location &o) + { + return Location(this->x - o.x, this->y - o.y); + } + + const Location operator = (const Location &o) + { + this->x = o.x; + this->y = o.y; + return *this; + } + + const Location operator += (const Location &o) + { + this->x += o.x; + this->y += o.y; + return *this; + } + + const Location operator -= (const Location &o) + { + this->x -= o.x; + this->y -= o.y; + return *this; + } +}; \ No newline at end of file diff --git a/Chapter1_BasicMemory/game-BasicMem.cpp b/Chapter1_BasicMemory/game-BasicMem.cpp new file mode 100644 index 0000000..19da649 --- /dev/null +++ b/Chapter1_BasicMemory/game-BasicMem.cpp @@ -0,0 +1,222 @@ +#define ALLEGRO_STATICLINK + +#include +#include +#include +#include +#include + +#include "..\allegro_linkers.h" +#include "Location-BasicMem.h" + +Location selfLocation(12, 16); +Location ballLocation(15, 13); + +BYTE map[24][32]; + +int keys[255]; + +bool checkWin() +{ + return (map[ballLocation.y][ballLocation.x] == 4); +} +void drawBackground() +{ for (int i = 0; i <= 24; i++) + { + for (int t = 0; t <= 32; t++) + { + if (map[i][t] == 1) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(128, 255, 255)); + else if(map[i][t] == 2) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(255, 128, 0)); + else if(map[i][t] == 3) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(255, 0, 0)); + else if(map[i][t] == 4) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(0, 0, 0)); + } + } +} + +void drawObjects() +{ + al_draw_filled_rectangle(selfLocation.x * 20, selfLocation.y * 20, + (selfLocation.x + 1) * 20, (selfLocation.y + 1) * 20, + al_map_rgb(255, 255, 255)); + al_draw_filled_circle(ballLocation.x * 20 + 10, ballLocation.y * 20 + 10, + 10, al_map_rgb(100, 100, 100)); +} + +void drawHUD(ALLEGRO_FONT *font) +{ + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 10, 0, "Arrow Keys: Move"); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 25, 0, "Spacebar: Swap"); +} + +void keyboardEvent() +{ + Location moveOffset; + if (keys[ALLEGRO_KEY_UP]) + moveOffset = Location(0, -1); + else if (keys[ALLEGRO_KEY_DOWN]) + moveOffset = Location(0, 1); + else if (keys[ALLEGRO_KEY_LEFT]) + moveOffset = Location(-1, 0); + else if (keys[ALLEGRO_KEY_RIGHT]) + moveOffset = Location(1, 0); + else if (keys[ALLEGRO_KEY_SPACE]) + { + moveOffset = ballLocation - selfLocation; + if (abs(moveOffset.x) + abs(moveOffset.y) <= 1) + { + moveOffset = selfLocation; //placehold + selfLocation = ballLocation; + ballLocation = moveOffset; + } + return; + } + else + return; + + Location newSelf = selfLocation + moveOffset; + Location newBall = ballLocation; + + if (newSelf == newBall) + newBall += moveOffset; + + if (map[newBall.y][newBall.x] == 1 || map[newSelf.y][newSelf.x] == 1) + return; + + ballLocation = newBall; + selfLocation = newSelf; +} + +int main(void) +{ + char* error = ""; + ALLEGRO_DISPLAY *display = NULL; + ALLEGRO_FONT *font = NULL; + ALLEGRO_TIMER *timer = NULL; + ALLEGRO_EVENT_QUEUE *event_queue = NULL; + + do + { + ZeroMemory(&keys, 255); + + FILE* file = fopen("game.map", "rb"); + if (!file) + { + error = "failed to initialize map!"; + break; + } + else + { + fread(map, 1, 24*32, file); + fclose(file); + } + + if(!al_init()) + { + error = "failed to initialize allegro!"; + break; + } + if(!al_init_primitives_addon()) + { + error = "failed to initialize primitives!"; + break; + } + al_init_font_addon(); + if(!al_init_ttf_addon()) + { + error = "failed to initialize ttfs!"; + break; + } + if(!al_install_keyboard()) + { + error = "failed to initialize keyboard!"; + break; + } + if(!(font = al_load_ttf_font("arial.ttf", 18, 0))) + { + error = "failed to initialize font!"; + break; + } + if(!(timer = al_create_timer(1.0 / 10))) + { + error = "failed to initialize timer!"; + break; + } + if(!(display = al_create_display(640, 480))) + { + error = "failed to initialize display!"; + break; + } + if(!(event_queue = al_create_event_queue())) + { + error = "failed to initialize event_queue!"; + break; + } + + al_register_event_source(event_queue, al_get_display_event_source(display)); + al_register_event_source(event_queue, al_get_keyboard_event_source()); + al_register_event_source(event_queue, al_get_timer_event_source(timer)); + + al_start_timer(timer); + + + while(1) + { + ALLEGRO_EVENT ev; + al_wait_for_event(event_queue, &ev); + + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + { + break; + } + else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) + { + if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + break; + else if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = true; + } + else if (ev.type == ALLEGRO_EVENT_KEY_UP) + { + if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = false; + } + else if (ev.type == ALLEGRO_EVENT_KEY_CHAR) + keyboardEvent(); + + if (al_is_event_queue_empty(event_queue)) + { + al_clear_to_color(al_map_rgb(255, 255, 255)); + drawBackground(); + drawObjects(); + + if (checkWin()) + { + al_draw_text(font, al_map_rgb(200, 200, 200), 320, 240, 1, "Good job! You've completed the first lab!"); + al_flip_display(); + continue; + } + + drawHUD(font); + al_flip_display(); + } + } + } while (0); + + if (strlen(error) > 0) + { + al_show_native_message_box(NULL, NULL, "error", error, NULL, NULL); + return -1; + } + + al_destroy_timer(timer); + al_destroy_display(display); + al_destroy_event_queue(event_queue); + + return 0; +} + + diff --git a/Chapter1_MemoryPointers/Chapter1_MemoryPointers.vcxproj b/Chapter1_MemoryPointers/Chapter1_MemoryPointers.vcxproj new file mode 100644 index 0000000..d09b933 --- /dev/null +++ b/Chapter1_MemoryPointers/Chapter1_MemoryPointers.vcxproj @@ -0,0 +1,96 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {3DEAB7C6-98B4-43F0-8F71-001EB28CAE84} + Chapter1__01 + Chapter1_MemoryPointers + + + + Application + MultiByte + true + + + Application + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + $(SolutionDir)\bin\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + + + + Disabled + %(AdditionalIncludeDirectories) + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + EditAndContinue + + + allegro-5.0.10-monolith-md-debug.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + copy "$(SolutionDir)game.map" "$(OutDir)game.map" /y && copy "$(SolutionDir)arial.ttf" "$(OutDir)arial.ttf" /y + + + + + Disabled + true + MultiThreadedDLL + true + Level3 + ProgramDatabase + + + %(AdditionalDependencies) + true + Windows + true + true + MachineX86 + + + copy "$(SolutionDir)game.map" "$(OutDir)game.map" /y && copy "$(SolutionDir)arial.ttf" "$(OutDir)arial.ttf" /y + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter1_MemoryPointers/Chapter2_MemoryPointers.filters b/Chapter1_MemoryPointers/Chapter2_MemoryPointers.filters new file mode 100644 index 0000000..a506879 --- /dev/null +++ b/Chapter1_MemoryPointers/Chapter2_MemoryPointers.filters @@ -0,0 +1,19 @@ + + + + + + + + {3c8b02c5-3b42-4b99-9dbc-d301f719fc1c} + + + {1c064fd6-e3d1-47a5-b1c0-ea67fd84ce18} + + + + + Header Files + + + \ No newline at end of file diff --git a/Chapter1_MemoryPointers/Location-MemPointer.h b/Chapter1_MemoryPointers/Location-MemPointer.h new file mode 100644 index 0000000..ea5f3ea --- /dev/null +++ b/Chapter1_MemoryPointers/Location-MemPointer.h @@ -0,0 +1,93 @@ +struct Location +{ + int x; + int y; + + Location(){} + Location(int x, int y) + { + this->x = x; + this->y = y; + } + const bool operator == (const Location &o) + { + return (o.x == this->x && o.y == this->y); + } + const bool operator != (const Location &o) + { + return !(*this == o); + } + const Location operator + (const Location &o) + { + return Location(this->x + o.x, this->y + o.y); + } + + const Location operator - (const Location &o) + { + return Location(this->x - o.x, this->y - o.y); + } + + const Location operator = (const Location &o) + { + this->x = o.x; + this->y = o.y; + return *this; + } + + const Location operator += (const Location &o) + { + this->x += o.x; + this->y += o.y; + return *this; + } + + const Location operator -= (const Location &o) + { + this->x -= o.x; + this->y -= o.y; + return *this; + } +}; + +class LocationPointerSimulator +{ +public: + ~LocationPointerSimulator() + { + delete this->step->step->location; + delete this->step->step; + delete this->step; + } + + Location* getLocation() + { + return step->step->location; + } + static LocationPointerSimulator* NewLocationPointer(Location* loc) + { + LocationPointerSimulator* locationPointer1 = new LocationPointerSimulator(); + LocationPointerSimulator2* locationPointer2 = new LocationPointerSimulator2(); + LocationPointerSimulator3* locationPointer3 = new LocationPointerSimulator3(); + locationPointer3->location = loc; + + locationPointer1->step = locationPointer2; + locationPointer2->step = locationPointer3; + return locationPointer1; + } + +private: + struct LocationPointerSimulator3 + { + char placeholders[32]; + Location* location; + }; + + struct LocationPointerSimulator2 + { + char placeholders[64]; + LocationPointerSimulator3* step; + }; + + char placeholders[128]; + LocationPointerSimulator2* step; +}; diff --git a/Chapter1_MemoryPointers/game-MemPointer.cpp b/Chapter1_MemoryPointers/game-MemPointer.cpp new file mode 100644 index 0000000..9cb062d --- /dev/null +++ b/Chapter1_MemoryPointers/game-MemPointer.cpp @@ -0,0 +1,268 @@ +#define ALLEGRO_STATICLINK + +#include +#include +#include +#include +#include + +#include "..\allegro_linkers.h" +#include "Location-MemPointer.h" + + +bool testRunning = false; +int testState = 0; +int testTime = 0; +Location selfLocation(12, 16); +LocationPointerSimulator* ballLocation = LocationPointerSimulator::NewLocationPointer(new Location(15, 13)); + +BYTE map[24][32]; + +int keys[255]; + +bool checkWin() +{ + Location* blocation = ballLocation->getLocation(); + return (map[blocation->y][blocation->x] == 4); +} +void drawBackground() +{ for (int i = 0; i <= 24; i++) + { + for (int t = 0; t <= 32; t++) + { + if (map[i][t] == 1) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(128, 255, 255)); + else if(map[i][t] == 2) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(255, 128, 0)); + else if(map[i][t] == 3) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(255, 0, 0)); + else if(map[i][t] == 4) + al_draw_filled_rectangle(t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, al_map_rgb(0, 0, 0)); + } + } +} + +void drawObjects() +{ + Location* blocation = ballLocation->getLocation(); + al_draw_filled_rectangle(selfLocation.x * 20, selfLocation.y * 20, + (selfLocation.x + 1) * 20, (selfLocation.y + 1) * 20, + al_map_rgb(255, 255, 255)); + al_draw_filled_circle(blocation->x * 20 + 10, blocation->y * 20 + 10, + 10, al_map_rgb(100, 100, 100)); +} + +void drawHUD(ALLEGRO_FONT *font) +{ + if (!testRunning) + { + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 10, 0, "Arrow Keys: Move"); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 25, 0, "Spacebar: Swap"); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 40, 0, "Tab: Begin Test"); + } + else + { + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 10, 0, "Automated test running, input disabled."); + + char text[128]; + sprintf(text, "Wins: %d/10", testState); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 25, 0, text); + sprintf(text, "Time: %1.1fs", testTime / 1000.00); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 40, 0, text); + } +} + +void keyboardEvent() +{ + if (testRunning) + return; + Location* blocation = ballLocation->getLocation(); + Location moveOffset; + if (keys[ALLEGRO_KEY_UP]) + moveOffset = Location(0, -1); + else if (keys[ALLEGRO_KEY_DOWN]) + moveOffset = Location(0, 1); + else if (keys[ALLEGRO_KEY_LEFT]) + moveOffset = Location(-1, 0); + else if (keys[ALLEGRO_KEY_RIGHT]) + moveOffset = Location(1, 0); + else if (keys[ALLEGRO_KEY_TAB]) + { + testRunning = true; + return; + } + else if (keys[ALLEGRO_KEY_SPACE]) + { + moveOffset = Location(blocation->x, blocation->y) - selfLocation; + if (abs(moveOffset.x) + abs(moveOffset.y) <= 1) + { + moveOffset = selfLocation; //placehold + selfLocation.x = blocation->x; + selfLocation.y = blocation->y; + blocation->x = moveOffset.x; + blocation->y = moveOffset.y; + } + return; + } + else + return; + + Location newSelf = selfLocation + moveOffset; + Location newBall = Location(blocation->x, blocation->y); + + if (newSelf == newBall) + newBall += moveOffset; + + if (map[newBall.y][newBall.x] == 1 || map[newSelf.y][newSelf.x] == 1) + return; + + blocation->x = newBall.x; + blocation->y = newBall.y; + selfLocation = newSelf; +} + +int main(void) +{ + char* error = ""; + ALLEGRO_DISPLAY *display = NULL; + ALLEGRO_FONT *font = NULL; + ALLEGRO_TIMER *timer = NULL; + ALLEGRO_EVENT_QUEUE *event_queue = NULL; + + do + { + ZeroMemory(&keys, 255); + + FILE* file = fopen("game.map", "rb"); + if (!file) + { + error = "failed to initialize map!"; + break; + } + else + { + fread(map, 1, 24*32, file); + fclose(file); + } + + if(!al_init()) + { + error = "failed to initialize allegro!"; + break; + } + if(!al_init_primitives_addon()) + { + error = "failed to initialize primitives!"; + break; + } + al_init_font_addon(); + if(!al_init_ttf_addon()) + { + error = "failed to initialize ttfs!"; + break; + } + if(!al_install_keyboard()) + { + error = "failed to initialize keyboard!"; + break; + } + if(!(font = al_load_ttf_font("arial.ttf", 18, 0))) + { + error = "failed to initialize font!"; + break; + } + if(!(timer = al_create_timer(1.0 / 10))) + { + error = "failed to initialize timer!"; + break; + } + if(!(display = al_create_display(640, 480))) + { + error = "failed to initialize display!"; + break; + } + if(!(event_queue = al_create_event_queue())) + { + error = "failed to initialize event_queue!"; + break; + } + + al_register_event_source(event_queue, al_get_display_event_source(display)); + al_register_event_source(event_queue, al_get_keyboard_event_source()); + al_register_event_source(event_queue, al_get_timer_event_source(timer)); + + al_start_timer(timer); + + while(1) + { + ALLEGRO_EVENT ev; + al_wait_for_event(event_queue, &ev); + + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + { + break; + } + else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) + { + if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + break; + else if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = true; + } + else if (ev.type == ALLEGRO_EVENT_KEY_UP) + { + if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = false; + } + else if (ev.type == ALLEGRO_EVENT_KEY_CHAR) + keyboardEvent(); + + if (testRunning) + testTime += 100; + + if (al_is_event_queue_empty(event_queue)) + { + bool won = checkWin(); + + al_clear_to_color(al_map_rgb(255, 255, 255)); + drawBackground(); + drawObjects(); + + if (won && testRunning && testState < 50) + { + testState++; + auto clean = ballLocation; + ballLocation = LocationPointerSimulator::NewLocationPointer(new Location(15 + (testState % 4), 13 + (testState % 2))); + delete clean; + } + else if (testRunning && testState >= 50) + { + al_draw_text(font, al_map_rgb(200, 200, 200), 320, 240, 1, "Good job! You've completed the lab!"); + al_flip_display(); + continue; + } + else if (testRunning && testTime >= 11000) + { + al_draw_text(font, al_map_rgb(200, 200, 200), 320, 240, 1, "Lab failed! Ball must be moved to the winning spot 50 times in 10 seconds!"); + al_flip_display(); + continue; + } + + drawHUD(font); + al_flip_display(); + } + } + } while (0); + + if (strlen(error) > 0) + { + al_show_native_message_box(NULL, NULL, "error", error, NULL, NULL); + return -1; + } + + al_destroy_timer(timer); + al_destroy_display(display); + al_destroy_event_queue(event_queue); + + return 0; +} \ No newline at end of file diff --git a/Chapter2_BasicDebugging/Chapter2_BasicDebugging.filters b/Chapter2_BasicDebugging/Chapter2_BasicDebugging.filters new file mode 100644 index 0000000..a506879 --- /dev/null +++ b/Chapter2_BasicDebugging/Chapter2_BasicDebugging.filters @@ -0,0 +1,19 @@ + + + + + + + + {3c8b02c5-3b42-4b99-9dbc-d301f719fc1c} + + + {1c064fd6-e3d1-47a5-b1c0-ea67fd84ce18} + + + + + Header Files + + + \ No newline at end of file diff --git a/Chapter2_BasicDebugging/Chapter2_BasicDebugging.vcxproj b/Chapter2_BasicDebugging/Chapter2_BasicDebugging.vcxproj new file mode 100644 index 0000000..179fcfc --- /dev/null +++ b/Chapter2_BasicDebugging/Chapter2_BasicDebugging.vcxproj @@ -0,0 +1,90 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {DEDDE9C4-3230-433C-B829-BE8981E645C9} + Chapter1__01 + Chapter2_BasicDebugging + + + + Application + MultiByte + true + + + Application + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + $(SolutionDir)\bin\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + + + + Disabled + %(AdditionalIncludeDirectories) + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + EditAndContinue + + + allegro-5.0.10-monolith-md-debug.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + + + Disabled + true + MultiThreadedDLL + true + Level3 + ProgramDatabase + + + %(AdditionalDependencies) + true + Windows + true + true + MachineX86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter2_BasicDebugging/Location-BasicDebugging.h b/Chapter2_BasicDebugging/Location-BasicDebugging.h new file mode 100644 index 0000000..94a3b95 --- /dev/null +++ b/Chapter2_BasicDebugging/Location-BasicDebugging.h @@ -0,0 +1,50 @@ +struct Location +{ + int x; + int y; + + Location(){} + Location(int x, int y) + { + this->x = x; + this->y = y; + } + const bool operator == (const Location &o) + { + return (o.x == this->x && o.y == this->y); + } + const bool operator != (const Location &o) + { + return !(*this == o); + } + const Location operator + (const Location &o) + { + return Location(this->x + o.x, this->y + o.y); + } + + const Location operator - (const Location &o) + { + return Location(this->x - o.x, this->y - o.y); + } + + const Location operator = (const Location &o) + { + this->x = o.x; + this->y = o.y; + return *this; + } + + const Location operator += (const Location &o) + { + this->x += o.x; + this->y += o.y; + return *this; + } + + const Location operator -= (const Location &o) + { + this->x -= o.x; + this->y -= o.y; + return *this; + } +}; \ No newline at end of file diff --git a/Chapter2_BasicDebugging/game-BasicDebugging.cpp b/Chapter2_BasicDebugging/game-BasicDebugging.cpp new file mode 100644 index 0000000..b421a8a --- /dev/null +++ b/Chapter2_BasicDebugging/game-BasicDebugging.cpp @@ -0,0 +1,119 @@ +#define ALLEGRO_STATICLINK + +#include +#include +#include +#include +#include + +#include "..\allegro_linkers.h" +#include "Location-BasicDebugging.h" + + +Location ballLocation(10, 20); +Location ballIncrement(6, 3); + + +void drawFrame(ALLEGRO_FONT *font) +{ + ballLocation.x += ballIncrement.x; + ballLocation.y += ballIncrement.y; + + if (ballLocation.x > 630 || ballLocation.x < 10) + ballIncrement.x = ballIncrement.x * -1; + + if (ballLocation.y > 470 || ballLocation.y < 10) + ballIncrement.y = ballIncrement.y * -1; + + al_clear_to_color(al_map_rgb(128, 128, 255)); + + al_draw_filled_rectangle(320, 0, 321, 480, al_map_rgb(166, 166, 166)); + + if (ballLocation.x >= 320) + { + al_draw_filled_rectangle(ballLocation.x-1, 0, ballLocation.x+1, 480, al_map_rgb(196, 196, 196)); + al_draw_text(font, al_map_rgb(50, 50, 50), 10, 10, 0, "Ball hidden.."); + } + else + al_draw_filled_circle(ballLocation.x, ballLocation.y, 10, al_map_rgb(100, 100, 100)); + + al_flip_display(); +} + +int main(void) +{ + char* error = ""; + ALLEGRO_DISPLAY *display = NULL; + ALLEGRO_FONT *font = NULL; + ALLEGRO_TIMER *timer = NULL; + ALLEGRO_EVENT_QUEUE *event_queue = NULL; + + do + { + if(!al_init()) + { + error = "failed to initialize allegro!"; + break; + } + if(!al_init_primitives_addon()) + { + error = "failed to initialize primitives!"; + break; + } + al_init_font_addon(); + if(!al_init_ttf_addon()) + { + error = "failed to initialize ttfs!"; + break; + } + if(!(font = al_load_ttf_font("arial.ttf", 18, 0))) + { + error = "failed to initialize font!"; + break; + } + if(!(timer = al_create_timer(1.0 / 20))) + { + error = "failed to initialize timer!"; + break; + } + if(!(display = al_create_display(640, 480))) + { + error = "failed to initialize display!"; + break; + } + if(!(event_queue = al_create_event_queue())) + { + error = "failed to initialize event_queue!"; + break; + } + + al_register_event_source(event_queue, al_get_display_event_source(display)); + al_register_event_source(event_queue, al_get_timer_event_source(timer)); + + al_start_timer(timer); + + while(1) + { + ALLEGRO_EVENT ev; + al_wait_for_event(event_queue, &ev); + + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + break; + + if (al_is_event_queue_empty(event_queue)) + drawFrame(font); + } + } while (0); + + if (strlen(error) > 0) + { + al_show_native_message_box(NULL, NULL, "error", error, NULL, NULL); + return -1; + } + + al_destroy_timer(timer); + al_destroy_display(display); + al_destroy_event_queue(event_queue); + + return 0; +} \ No newline at end of file diff --git a/Chapter3_CloseMutex/Chapter3_CloseMutex.filters b/Chapter3_CloseMutex/Chapter3_CloseMutex.filters new file mode 100644 index 0000000..a506879 --- /dev/null +++ b/Chapter3_CloseMutex/Chapter3_CloseMutex.filters @@ -0,0 +1,19 @@ + + + + + + + + {3c8b02c5-3b42-4b99-9dbc-d301f719fc1c} + + + {1c064fd6-e3d1-47a5-b1c0-ea67fd84ce18} + + + + + Header Files + + + \ No newline at end of file diff --git a/Chapter3_CloseMutex/Chapter3_CloseMutex.vcxproj b/Chapter3_CloseMutex/Chapter3_CloseMutex.vcxproj new file mode 100644 index 0000000..234df90 --- /dev/null +++ b/Chapter3_CloseMutex/Chapter3_CloseMutex.vcxproj @@ -0,0 +1,90 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {B7A15C0B-6532-432F-864B-5381256B4D58} + Chapter1__01 + Chapter3_CloseMutex + + + + Application + MultiByte + true + + + Application + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + $(SolutionDir)\bin\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + + + + Disabled + %(AdditionalIncludeDirectories) + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + EditAndContinue + + + allegro-5.0.10-monolith-md-debug.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + + + Disabled + true + MultiThreadedDLL + true + Level3 + ProgramDatabase + + + %(AdditionalDependencies) + true + Windows + true + true + MachineX86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter3_CloseMutex/Location-CloseMutex.h b/Chapter3_CloseMutex/Location-CloseMutex.h new file mode 100644 index 0000000..94a3b95 --- /dev/null +++ b/Chapter3_CloseMutex/Location-CloseMutex.h @@ -0,0 +1,50 @@ +struct Location +{ + int x; + int y; + + Location(){} + Location(int x, int y) + { + this->x = x; + this->y = y; + } + const bool operator == (const Location &o) + { + return (o.x == this->x && o.y == this->y); + } + const bool operator != (const Location &o) + { + return !(*this == o); + } + const Location operator + (const Location &o) + { + return Location(this->x + o.x, this->y + o.y); + } + + const Location operator - (const Location &o) + { + return Location(this->x - o.x, this->y - o.y); + } + + const Location operator = (const Location &o) + { + this->x = o.x; + this->y = o.y; + return *this; + } + + const Location operator += (const Location &o) + { + this->x += o.x; + this->y += o.y; + return *this; + } + + const Location operator -= (const Location &o) + { + this->x -= o.x; + this->y -= o.y; + return *this; + } +}; \ No newline at end of file diff --git a/Chapter3_CloseMutex/game-CloseMutex.cpp b/Chapter3_CloseMutex/game-CloseMutex.cpp new file mode 100644 index 0000000..8b5a9a0 --- /dev/null +++ b/Chapter3_CloseMutex/game-CloseMutex.cpp @@ -0,0 +1,257 @@ +#define ALLEGRO_STATICLINK + +#include +#include +#include +#include +#include + +#include "..\allegro_linkers.h" +#include "Location-CloseMutex.h" + + +Location ballLocation(30, 20); +Location ballIncrement(6, 3); +Location playerPaddle(0, 235); +Location computerPaddle(0, 235); + +int keys[255]; + +int score = 0; +int highscore = 0; +bool gameRunning = true; + + +void getHighscorePath(wchar_t* path) +{ + wchar_t temp[MAX_PATH]; + GetTempPathW(MAX_PATH, &temp[0]); + wsprintfW(path, L"%s\\gh_hs_p.dat", temp); +} + +void loadHighscore() +{ + wchar_t path[MAX_PATH+40]; + getHighscorePath(path); + + FILE* file = _wfopen(path, L"rb"); + if (file) + { + fread(&highscore, 1, 4, file); + fclose(file); + } +} + +void saveHighscore() +{ + wchar_t path[MAX_PATH+40]; + getHighscorePath(path); + + FILE* file = _wfopen(path, L"wb"); + if (file) + { + fwrite(&highscore, 1, 4, file); + fclose(file); + } +} + +void drawFrame(ALLEGRO_FONT *font) +{ + if (gameRunning) + { + ballLocation.x += ballIncrement.x; + ballLocation.y += ballIncrement.y; + + if (ballLocation.y > 470 || ballLocation.y < 10) + ballIncrement.y = ballIncrement.y * -1; + + if (ballLocation.x > 625) + ballIncrement.x = ballIncrement.x * -1; + + if (ballLocation.x < 16 && ballIncrement.x < 0) + { + ballLocation.x = 16; + if (ballLocation.y >= playerPaddle.y - 35 && ballLocation.y <= playerPaddle.y + 35) + { + score += 10; + if (score > highscore) + highscore = score; + if (score % 50 == 0) + { + ballIncrement.x *= 1.5; + ballIncrement.y *= 1.5; + } + ballIncrement.x = ballIncrement.x * -1; + } + else + gameRunning = false; + } + } + + if (ballIncrement.x > 0) + { + if (computerPaddle.y < ballLocation.y && ballLocation.y - computerPaddle.y > 4) + computerPaddle.y += 8; + else if (computerPaddle.y > ballLocation.y && computerPaddle.y - ballLocation.y > 4) + computerPaddle.y -= 8; + + if (computerPaddle.y < 35) + computerPaddle.y = 35; + else if (computerPaddle.y > 445) + computerPaddle.y = 445; + } + + al_clear_to_color(al_map_rgb(128, 128, 255)); + + al_draw_filled_circle(ballLocation.x, ballLocation.y, 10, al_map_rgb(100, 100, 100)); + + al_draw_filled_rectangle(0, playerPaddle.y - 35, 5, playerPaddle.y + 35, al_map_rgb(196, 196, 196)); + al_draw_filled_rectangle(635, computerPaddle.y - 35, 640, computerPaddle.y + 35, al_map_rgb(196, 196, 196)); + + if (!gameRunning) + al_draw_text(font, al_map_rgb(200, 200, 200), 320, 240, 1, "Game over!"); + else + { + char scoretext[1024]; + sprintf(scoretext, "Score: %d", score); + al_draw_text(font, al_map_rgb(200, 200, 200), 300, 3, 0, scoretext); + + sprintf(scoretext, "High Score: %d", highscore); + al_draw_text(font, al_map_rgb(200, 200, 200), 300, 22, 0, scoretext); + } + + al_flip_display(); +} + +void keyboardEvent() +{ + if (!gameRunning) + return; + + Location moveOffset; + if (keys[ALLEGRO_KEY_UP]) + moveOffset = Location(0, -8); + else if (keys[ALLEGRO_KEY_DOWN]) + moveOffset = Location(0, 8); + else + return; + + Location newPaddle = playerPaddle + moveOffset; + + if (newPaddle.y < 35) + newPaddle.y = 35; + else if (newPaddle.y > 445) + newPaddle.y = 445; + + playerPaddle = newPaddle; +} + +int main(void) +{ + char* error = ""; + ALLEGRO_DISPLAY *display = NULL; + ALLEGRO_FONT *font = NULL; + ALLEGRO_TIMER *timer = NULL; + ALLEGRO_EVENT_QUEUE *event_queue = NULL; + + HANDLE mutex = CreateMutex(NULL, FALSE, "Chapter3_CloseMutex-Mutex"); + if (GetLastError() == ERROR_ALREADY_EXISTS) { + MessageBoxA(GetForegroundWindow(), "Only one instance of the game can run at a time.", "Chapter3_CloseMutex", MB_OK); + return 0; + } + + do + { + loadHighscore(); + if(!al_init()) + { + error = "failed to initialize allegro!"; + break; + } + if(!al_init_primitives_addon()) + { + error = "failed to initialize primitives!"; + break; + } + al_init_font_addon(); + if(!al_init_ttf_addon()) + { + error = "failed to initialize ttfs!"; + break; + } + if(!al_install_keyboard()) + { + error = "failed to initialize keyboard!"; + break; + } + if(!(font = al_load_ttf_font("arial.ttf", 18, 0))) + { + error = "failed to initialize font!"; + break; + } + if(!(timer = al_create_timer(1.0 / 20))) + { + error = "failed to initialize timer!"; + break; + } + if(!(display = al_create_display(640, 480))) + { + error = "failed to initialize display!"; + break; + } + if(!(event_queue = al_create_event_queue())) + { + error = "failed to initialize event_queue!"; + break; + } + + al_register_event_source(event_queue, al_get_display_event_source(display)); + al_register_event_source(event_queue, al_get_keyboard_event_source()); + al_register_event_source(event_queue, al_get_timer_event_source(timer)); + + al_start_timer(timer); + + while(1) + { + ALLEGRO_EVENT ev; + al_wait_for_event(event_queue, &ev); + + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + break; + else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) + { + if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + break; + else if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = true; + } + else if (ev.type == ALLEGRO_EVENT_KEY_UP) + { + if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = false; + } + else if (ev.type == ALLEGRO_EVENT_KEY_CHAR) + keyboardEvent(); + + if (al_is_event_queue_empty(event_queue) && ev.type == ALLEGRO_EVENT_TIMER) + drawFrame(font); + } + } while (0); + + if (mutex) + CloseHandle(mutex); + + if (strlen(error) > 0) + { + al_show_native_message_box(NULL, NULL, "error", error, NULL, NULL); + return -1; + } + + al_destroy_timer(timer); + al_destroy_display(display); + al_destroy_event_queue(event_queue); + saveHighscore(); + + + return 0; +} \ No newline at end of file diff --git a/Chapter3_FindingFiles/Chapter3_FindingFiles.filters b/Chapter3_FindingFiles/Chapter3_FindingFiles.filters new file mode 100644 index 0000000..a506879 --- /dev/null +++ b/Chapter3_FindingFiles/Chapter3_FindingFiles.filters @@ -0,0 +1,19 @@ + + + + + + + + {3c8b02c5-3b42-4b99-9dbc-d301f719fc1c} + + + {1c064fd6-e3d1-47a5-b1c0-ea67fd84ce18} + + + + + Header Files + + + \ No newline at end of file diff --git a/Chapter3_FindingFiles/Chapter3_FindingFiles.vcxproj b/Chapter3_FindingFiles/Chapter3_FindingFiles.vcxproj new file mode 100644 index 0000000..464a2a3 --- /dev/null +++ b/Chapter3_FindingFiles/Chapter3_FindingFiles.vcxproj @@ -0,0 +1,90 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {4188B6F0-3948-4CB8-90C6-038CED132E11} + Chapter1__01 + Chapter3_FindingFiles + + + + Application + MultiByte + true + + + Application + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + $(SolutionDir)\bin\ + $(SolutionDir)BuildTemp\$(ProjectName)$(Configuration)\ + + + + Disabled + %(AdditionalIncludeDirectories) + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + EditAndContinue + + + allegro-5.0.10-monolith-md-debug.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + + + Disabled + true + MultiThreadedDLL + true + Level3 + ProgramDatabase + + + %(AdditionalDependencies) + true + Windows + true + true + MachineX86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter3_FindingFiles/Location-FindingFiles.h b/Chapter3_FindingFiles/Location-FindingFiles.h new file mode 100644 index 0000000..94a3b95 --- /dev/null +++ b/Chapter3_FindingFiles/Location-FindingFiles.h @@ -0,0 +1,50 @@ +struct Location +{ + int x; + int y; + + Location(){} + Location(int x, int y) + { + this->x = x; + this->y = y; + } + const bool operator == (const Location &o) + { + return (o.x == this->x && o.y == this->y); + } + const bool operator != (const Location &o) + { + return !(*this == o); + } + const Location operator + (const Location &o) + { + return Location(this->x + o.x, this->y + o.y); + } + + const Location operator - (const Location &o) + { + return Location(this->x - o.x, this->y - o.y); + } + + const Location operator = (const Location &o) + { + this->x = o.x; + this->y = o.y; + return *this; + } + + const Location operator += (const Location &o) + { + this->x += o.x; + this->y += o.y; + return *this; + } + + const Location operator -= (const Location &o) + { + this->x -= o.x; + this->y -= o.y; + return *this; + } +}; \ No newline at end of file diff --git a/Chapter3_FindingFiles/game-FindingFiles.cpp b/Chapter3_FindingFiles/game-FindingFiles.cpp new file mode 100644 index 0000000..440d8d5 --- /dev/null +++ b/Chapter3_FindingFiles/game-FindingFiles.cpp @@ -0,0 +1,247 @@ +#define ALLEGRO_STATICLINK + +#include +#include +#include +#include +#include + +#include "..\allegro_linkers.h" +#include "Location-FindingFiles.h" + + +Location ballLocation(30, 20); +Location ballIncrement(6, 3); +Location playerPaddle(0, 235); +Location computerPaddle(0, 235); + +int keys[255]; + +int score = 0; +int highscore = 0; +bool gameRunning = true; + + +void getHighscorePath(wchar_t* path) +{ + wchar_t temp[MAX_PATH]; + GetTempPathW(MAX_PATH, &temp[0]); + wsprintfW(path, L"%s\\gh_hs_p.dat", temp); +} + +void loadHighscore() +{ + wchar_t path[MAX_PATH+40]; + getHighscorePath(path); + + FILE* file = _wfopen(path, L"rb"); + if (file) + { + fread(&highscore, 1, 4, file); + fclose(file); + } +} + +void saveHighscore() +{ + wchar_t path[MAX_PATH+40]; + getHighscorePath(path); + + FILE* file = _wfopen(path, L"wb"); + if (file) + { + fwrite(&highscore, 1, 4, file); + fclose(file); + } +} + +void drawFrame(ALLEGRO_FONT *font) +{ + if (gameRunning) + { + ballLocation.x += ballIncrement.x; + ballLocation.y += ballIncrement.y; + + if (ballLocation.y > 470 || ballLocation.y < 10) + ballIncrement.y = ballIncrement.y * -1; + + if (ballLocation.x > 625) + ballIncrement.x = ballIncrement.x * -1; + + if (ballLocation.x < 16 && ballIncrement.x < 0) + { + ballLocation.x = 16; + if (ballLocation.y >= playerPaddle.y - 35 && ballLocation.y <= playerPaddle.y + 35) + { + score += 10; + if (score > highscore) + highscore = score; + if (score % 50 == 0) + { + ballIncrement.x *= 1.5; + ballIncrement.y *= 1.5; + } + ballIncrement.x = ballIncrement.x * -1; + } + else + gameRunning = false; + } + } + + if (ballIncrement.x > 0) + { + if (computerPaddle.y < ballLocation.y && ballLocation.y - computerPaddle.y > 4) + computerPaddle.y += 8; + else if (computerPaddle.y > ballLocation.y && computerPaddle.y - ballLocation.y > 4) + computerPaddle.y -= 8; + + if (computerPaddle.y < 35) + computerPaddle.y = 35; + else if (computerPaddle.y > 445) + computerPaddle.y = 445; + } + + al_clear_to_color(al_map_rgb(128, 128, 255)); + + al_draw_filled_circle(ballLocation.x, ballLocation.y, 10, al_map_rgb(100, 100, 100)); + + al_draw_filled_rectangle(0, playerPaddle.y - 35, 5, playerPaddle.y + 35, al_map_rgb(196, 196, 196)); + al_draw_filled_rectangle(635, computerPaddle.y - 35, 640, computerPaddle.y + 35, al_map_rgb(196, 196, 196)); + + if (!gameRunning) + al_draw_text(font, al_map_rgb(200, 200, 200), 320, 240, 1, "Game over!"); + else + { + char scoretext[1024]; + sprintf(scoretext, "Score: %d", score); + al_draw_text(font, al_map_rgb(200, 200, 200), 300, 3, 0, scoretext); + + sprintf(scoretext, "High Score: %d", highscore); + al_draw_text(font, al_map_rgb(200, 200, 200), 300, 22, 0, scoretext); + } + + al_flip_display(); +} + +void keyboardEvent() +{ + if (!gameRunning) + return; + + Location moveOffset; + if (keys[ALLEGRO_KEY_UP]) + moveOffset = Location(0, -8); + else if (keys[ALLEGRO_KEY_DOWN]) + moveOffset = Location(0, 8); + else + return; + + Location newPaddle = playerPaddle + moveOffset; + + if (newPaddle.y < 35) + newPaddle.y = 35; + else if (newPaddle.y > 445) + newPaddle.y = 445; + + playerPaddle = newPaddle; +} + +int main(void) +{ + char* error = ""; + ALLEGRO_DISPLAY *display = NULL; + ALLEGRO_FONT *font = NULL; + ALLEGRO_TIMER *timer = NULL; + ALLEGRO_EVENT_QUEUE *event_queue = NULL; + + do + { + loadHighscore(); + if(!al_init()) + { + error = "failed to initialize allegro!"; + break; + } + if(!al_init_primitives_addon()) + { + error = "failed to initialize primitives!"; + break; + } + al_init_font_addon(); + if(!al_init_ttf_addon()) + { + error = "failed to initialize ttfs!"; + break; + } + if(!al_install_keyboard()) + { + error = "failed to initialize keyboard!"; + break; + } + if(!(font = al_load_ttf_font("arial.ttf", 18, 0))) + { + error = "failed to initialize font!"; + break; + } + if(!(timer = al_create_timer(1.0 / 20))) + { + error = "failed to initialize timer!"; + break; + } + if(!(display = al_create_display(640, 480))) + { + error = "failed to initialize display!"; + break; + } + if(!(event_queue = al_create_event_queue())) + { + error = "failed to initialize event_queue!"; + break; + } + + al_register_event_source(event_queue, al_get_display_event_source(display)); + al_register_event_source(event_queue, al_get_keyboard_event_source()); + al_register_event_source(event_queue, al_get_timer_event_source(timer)); + + al_start_timer(timer); + + while(1) + { + ALLEGRO_EVENT ev; + al_wait_for_event(event_queue, &ev); + + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + break; + else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) + { + if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + break; + else if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = true; + } + else if (ev.type == ALLEGRO_EVENT_KEY_UP) + { + if (ev.keyboard.keycode <= 255) + keys[ev.keyboard.keycode] = false; + } + else if (ev.type == ALLEGRO_EVENT_KEY_CHAR) + keyboardEvent(); + + if (al_is_event_queue_empty(event_queue) && ev.type == ALLEGRO_EVENT_TIMER) + drawFrame(font); + } + } while (0); + + if (strlen(error) > 0) + { + al_show_native_message_box(NULL, NULL, "error", error, NULL, NULL); + return -1; + } + + al_destroy_timer(timer); + al_destroy_display(display); + al_destroy_event_queue(event_queue); + saveHighscore(); + + return 0; +} \ No newline at end of file diff --git a/Chapter4_CodeToMemory/Chapter4_CodeToMemory.vcxproj b/Chapter4_CodeToMemory/Chapter4_CodeToMemory.vcxproj index b90f685..dea34f4 100644 --- a/Chapter4_CodeToMemory/Chapter4_CodeToMemory.vcxproj +++ b/Chapter4_CodeToMemory/Chapter4_CodeToMemory.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter5_AdvancedMemoryForensics_Scanning/Chapter5_AdvancedMemoryForensics_Scanning.vcxproj b/Chapter5_AdvancedMemoryForensics_Scanning/Chapter5_AdvancedMemoryForensics_Scanning.vcxproj index 9601dcd..4fc0ab5 100644 --- a/Chapter5_AdvancedMemoryForensics_Scanning/Chapter5_AdvancedMemoryForensics_Scanning.vcxproj +++ b/Chapter5_AdvancedMemoryForensics_Scanning/Chapter5_AdvancedMemoryForensics_Scanning.vcxproj @@ -39,11 +39,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter6_AccessingMemory/Chapter6_AccessingMemory.vcxproj b/Chapter6_AccessingMemory/Chapter6_AccessingMemory.vcxproj index 8e9b47b..af81ef5 100644 --- a/Chapter6_AccessingMemory/Chapter6_AccessingMemory.vcxproj +++ b/Chapter6_AccessingMemory/Chapter6_AccessingMemory.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter7_CodeInjection/Chapter7_CodeInjection.vcxproj b/Chapter7_CodeInjection/Chapter7_CodeInjection.vcxproj index 8a1c1f1..c29860c 100644 --- a/Chapter7_CodeInjection/Chapter7_CodeInjection.vcxproj +++ b/Chapter7_CodeInjection/Chapter7_CodeInjection.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter7_CodeInjection_DLL/Chapter7_CodeInjection_DLL.vcxproj b/Chapter7_CodeInjection_DLL/Chapter7_CodeInjection_DLL.vcxproj index aa6399f..e004853 100644 --- a/Chapter7_CodeInjection_DLL/Chapter7_CodeInjection_DLL.vcxproj +++ b/Chapter7_CodeInjection_DLL/Chapter7_CodeInjection_DLL.vcxproj @@ -42,11 +42,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter8_AdobeAirHook/AdobeAirHook.vcxproj b/Chapter8_AdobeAirHook/AdobeAirHook.vcxproj index aefc419..e3c3699 100644 --- a/Chapter8_AdobeAirHook/AdobeAirHook.vcxproj +++ b/Chapter8_AdobeAirHook/AdobeAirHook.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter8_ControlFlow/Chapter8_ControlFlow.vcxproj b/Chapter8_ControlFlow/Chapter8_ControlFlow.vcxproj index 512177f..2575868 100644 --- a/Chapter8_ControlFlow/Chapter8_ControlFlow.vcxproj +++ b/Chapter8_ControlFlow/Chapter8_ControlFlow.vcxproj @@ -40,11 +40,13 @@ true - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ false $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ diff --git a/Chapter8_Direct3DApplication/Chapter8_Direct3DApplication.vcxproj b/Chapter8_Direct3DApplication/Chapter8_Direct3DApplication.vcxproj index 962f0fb..bdce1e6 100644 --- a/Chapter8_Direct3DApplication/Chapter8_Direct3DApplication.vcxproj +++ b/Chapter8_Direct3DApplication/Chapter8_Direct3DApplication.vcxproj @@ -38,9 +38,11 @@ $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\ - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ diff --git a/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcproj b/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcproj deleted file mode 100644 index 87c3924..0000000 --- a/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcproj +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcxproj b/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcxproj index b39a1e6..9aa74d2 100644 --- a/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcxproj +++ b/Chapter8_Direct3DHook/Chapter8_Direct3DHook.vcxproj @@ -38,10 +38,10 @@ <_ProjectFileVersion>10.0.40219.1 - $(SolutionDir)$(Configuration)\ - $(SolutionDir)\BuildTemp\$(Configuration)\ + $(SolutionDir)\bin\DEBUG_BUILDS\ + $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ true - $(SolutionDir)$(Configuration)\ + $(SolutionDir)\bin\ $(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\ false $(ExecutablePath) @@ -50,8 +50,8 @@ Disabled - C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS;%(PreprocessorDefinitions) + C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL @@ -76,8 +76,8 @@ MaxSpeed true - C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS;%(PreprocessorDefinitions) + C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/GameHackingExamples.sln b/GameHackingExamples.sln index 9a6ca5a..5c7a97f 100644 --- a/GameHackingExamples.sln +++ b/GameHackingExamples.sln @@ -25,6 +25,25 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter11_StateMachines", " EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter11_SearchAlgorithms", "Chapter11_SearchAlgorithms\Chapter11_SearchAlgorithms.vcxproj", "{35470A34-CBB0-41D1-A54B-E1CF3DE9A3B7}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{454BEDF4-C177-4DB3-85D1-20813E9EBDCC}" + ProjectSection(SolutionItems) = preProject + LuaScripts\Chapter1_SearchingForAssemblyPatterns.lua = LuaScripts\Chapter1_SearchingForAssemblyPatterns.lua + LuaScripts\Chapter1_SearchingForStrings.lua = LuaScripts\Chapter1_SearchingForStrings.lua + LuaScripts\Chapter5_CountLinkedListNodes.lua = LuaScripts\Chapter5_CountLinkedListNodes.lua + LuaScripts\Chapter5_VerifyLinkedList.lua = LuaScripts\Chapter5_VerifyLinkedList.lua + LuaScripts\Chapter5_VerifyMap.lua = LuaScripts\Chapter5_VerifyMap.lua + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter1_BasicMemory", "Chapter1_BasicMemory\Chapter1_BasicMemory.vcxproj", "{AB736FAE-3FEF-40C0-B426-BFC3E3FA569F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter1_MemoryPointers", "Chapter1_MemoryPointers\Chapter1_MemoryPointers.vcxproj", "{3DEAB7C6-98B4-43F0-8F71-001EB28CAE84}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter2_BasicDebugging", "Chapter2_BasicDebugging\Chapter2_BasicDebugging.vcxproj", "{DEDDE9C4-3230-433C-B829-BE8981E645C9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter3_FindingFiles", "Chapter3_FindingFiles\Chapter3_FindingFiles.vcxproj", "{4188B6F0-3948-4CB8-90C6-038CED132E11}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter3_CloseMutex", "Chapter3_CloseMutex\Chapter3_CloseMutex.vcxproj", "{B7A15C0B-6532-432F-864B-5381256B4D58}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -79,6 +98,26 @@ Global {35470A34-CBB0-41D1-A54B-E1CF3DE9A3B7}.Debug|Win32.Build.0 = Debug|Win32 {35470A34-CBB0-41D1-A54B-E1CF3DE9A3B7}.Release|Win32.ActiveCfg = Release|Win32 {35470A34-CBB0-41D1-A54B-E1CF3DE9A3B7}.Release|Win32.Build.0 = Release|Win32 + {AB736FAE-3FEF-40C0-B426-BFC3E3FA569F}.Debug|Win32.ActiveCfg = Debug|Win32 + {AB736FAE-3FEF-40C0-B426-BFC3E3FA569F}.Debug|Win32.Build.0 = Debug|Win32 + {AB736FAE-3FEF-40C0-B426-BFC3E3FA569F}.Release|Win32.ActiveCfg = Release|Win32 + {AB736FAE-3FEF-40C0-B426-BFC3E3FA569F}.Release|Win32.Build.0 = Release|Win32 + {3DEAB7C6-98B4-43F0-8F71-001EB28CAE84}.Debug|Win32.ActiveCfg = Debug|Win32 + {3DEAB7C6-98B4-43F0-8F71-001EB28CAE84}.Debug|Win32.Build.0 = Debug|Win32 + {3DEAB7C6-98B4-43F0-8F71-001EB28CAE84}.Release|Win32.ActiveCfg = Release|Win32 + {3DEAB7C6-98B4-43F0-8F71-001EB28CAE84}.Release|Win32.Build.0 = Release|Win32 + {DEDDE9C4-3230-433C-B829-BE8981E645C9}.Debug|Win32.ActiveCfg = Debug|Win32 + {DEDDE9C4-3230-433C-B829-BE8981E645C9}.Debug|Win32.Build.0 = Debug|Win32 + {DEDDE9C4-3230-433C-B829-BE8981E645C9}.Release|Win32.ActiveCfg = Release|Win32 + {DEDDE9C4-3230-433C-B829-BE8981E645C9}.Release|Win32.Build.0 = Release|Win32 + {4188B6F0-3948-4CB8-90C6-038CED132E11}.Debug|Win32.ActiveCfg = Debug|Win32 + {4188B6F0-3948-4CB8-90C6-038CED132E11}.Debug|Win32.Build.0 = Debug|Win32 + {4188B6F0-3948-4CB8-90C6-038CED132E11}.Release|Win32.ActiveCfg = Release|Win32 + {4188B6F0-3948-4CB8-90C6-038CED132E11}.Release|Win32.Build.0 = Release|Win32 + {B7A15C0B-6532-432F-864B-5381256B4D58}.Debug|Win32.ActiveCfg = Debug|Win32 + {B7A15C0B-6532-432F-864B-5381256B4D58}.Debug|Win32.Build.0 = Debug|Win32 + {B7A15C0B-6532-432F-864B-5381256B4D58}.Release|Win32.ActiveCfg = Release|Win32 + {B7A15C0B-6532-432F-864B-5381256B4D58}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/allegro_linkers.h b/allegro_linkers.h new file mode 100644 index 0000000..c2ab4d6 --- /dev/null +++ b/allegro_linkers.h @@ -0,0 +1,23 @@ +#pragma comment(lib, "allegro-5.0.10-static-md.lib") + +#pragma comment(lib, "opengl32.lib") +#pragma comment(lib, "glu32.lib") + +#pragma comment(lib, "winmm.LIB") +#pragma comment(lib, "shlwapi.lib") +#pragma comment(lib, "psapi.lib") + +#ifdef _ALLEGRO_FONT_DLL +#include +#pragma comment(lib, "freetype-2.4.8-static-md.lib") +#pragma comment(lib, "allegro_font-5.0.10-static-md.lib") +#pragma comment(lib, "allegro_ttf-5.0.10-static-md.lib") +#endif + +#ifdef _ALLEGRO_DIALOG_DLL +#pragma comment(lib, "allegro_dialog-5.0.10-static-md.lib") +#endif + +#ifdef _ALLEGRO_PRIM_DLL +#pragma comment(lib, "allegro_primitives-5.0.10-static-md.lib") +#endif \ No newline at end of file diff --git a/arial.ttf b/arial.ttf new file mode 100644 index 0000000..12cc15c Binary files /dev/null and b/arial.ttf differ diff --git a/game.map b/game.map new file mode 100644 index 0000000..2d5f904 --- /dev/null +++ b/game.map @@ -0,0 +1 @@ + \ No newline at end of file