diff --git a/Chapter01/07558_CenturyGothic.ttf b/Chapter01/07558_CenturyGothic.ttf new file mode 100644 index 00000000..879704e3 Binary files /dev/null and b/Chapter01/07558_CenturyGothic.ttf differ diff --git a/Chapter12/AudioSystem.cpp b/Chapter12/AudioSystem.cpp index 73c5feff..ae7ad891 100644 --- a/Chapter12/AudioSystem.cpp +++ b/Chapter12/AudioSystem.cpp @@ -56,7 +56,8 @@ bool AudioSystem::Initialize() } // Save the low-level system pointer - mSystem->getLowLevelSystem(&mLowLevelSystem); + //mSystem->getLowLevelSystem(&mLowLevelSystem); + mSystem->getCoreSystem(&mLowLevelSystem); // Load the master banks (strings first) LoadBank("Assets/Master Bank.strings.bank"); diff --git a/Chapter12/Game.vcxproj b/Chapter12/Game.vcxproj index 5ddbc62f..9545abe7 100644 --- a/Chapter12/Game.vcxproj +++ b/Chapter12/Game.vcxproj @@ -98,19 +98,19 @@ {BC508D87-495F-4554-932D-DD68388B63CC} Win32Proj Game - 10.0.16299.0 + 10.0 Application true - v141 + v143 Unicode Application false - v141 + v143 true Unicode @@ -126,6 +126,8 @@ true + C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\fsbank\inc;C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\studio\inc;C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc;$(IncludePath) + C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86;C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\fsbank\lib\x86;C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\studio\lib\x86;$(LibraryPath) false diff --git a/Chapter12/SoundEvent.cpp b/Chapter12/SoundEvent.cpp index 6edbda39..d064dddd 100644 --- a/Chapter12/SoundEvent.cpp +++ b/Chapter12/SoundEvent.cpp @@ -80,7 +80,8 @@ void SoundEvent::SetParameter(const std::string& name, float value) auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { - event->setParameterValue(name.c_str(), value); + //event->setParameterValue(name.c_str(), value); + event->setParameterByName(name.c_str(), value); } } @@ -123,7 +124,8 @@ float SoundEvent::GetParameter(const std::string& name) auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { - event->getParameterValue(name.c_str(), &retVal); + //event->getParameterValue(name.c_str(), &retVal); + event->getParameterByName(name.c_str(), &retVal); } return retVal; } diff --git a/Chapter14/AudioSystem.cpp b/Chapter14/AudioSystem.cpp index 73c5feff..56b77542 100644 --- a/Chapter14/AudioSystem.cpp +++ b/Chapter14/AudioSystem.cpp @@ -56,8 +56,8 @@ bool AudioSystem::Initialize() } // Save the low-level system pointer - mSystem->getLowLevelSystem(&mLowLevelSystem); - + //mSystem->getLowLevelSystem(&mLowLevelSystem); + mSystem->getCoreSystem(&mLowLevelSystem); // Load the master banks (strings first) LoadBank("Assets/Master Bank.strings.bank"); LoadBank("Assets/Master Bank.bank"); diff --git a/Chapter14/Chapter14-windows.sln b/Chapter14/Chapter14-windows.sln index f560df0f..69f7c776 100644 --- a/Chapter14/Chapter14-windows.sln +++ b/Chapter14/Chapter14-windows.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "Game.vcxproj", "{BC508D87-495F-4554-932D-DD68388B63CC}" EndProject @@ -11,12 +11,15 @@ Global Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.ActiveCfg = Debug|Win32 - {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.Build.0 = Debug|Win32 + {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.ActiveCfg = Release|Win32 + {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.Build.0 = Release|Win32 {BC508D87-495F-4554-932D-DD68388B63CC}.Release|Win32.ActiveCfg = Release|Win32 {BC508D87-495F-4554-932D-DD68388B63CC}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B052FD90-B43E-4B41-A851-20A742F12A37} + EndGlobalSection EndGlobal diff --git a/Chapter14/Game.vcxproj b/Chapter14/Game.vcxproj index aef575d9..7ab8dd74 100644 --- a/Chapter14/Game.vcxproj +++ b/Chapter14/Game.vcxproj @@ -111,19 +111,19 @@ {BC508D87-495F-4554-932D-DD68388B63CC} Win32Proj Game - 10.0.16299.0 + 10.0 Application true - v141 + v143 Unicode Application false - v141 + v142 true Unicode @@ -139,6 +139,8 @@ true + C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc;$(IncludePath) + C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\lib\x86;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86;$(LibraryPath) false diff --git a/Chapter14/SoundEvent.cpp b/Chapter14/SoundEvent.cpp index 6edbda39..a6ce8a9e 100644 --- a/Chapter14/SoundEvent.cpp +++ b/Chapter14/SoundEvent.cpp @@ -80,7 +80,7 @@ void SoundEvent::SetParameter(const std::string& name, float value) auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { - event->setParameterValue(name.c_str(), value); + event->setParameterByName(name.c_str(), value); } } @@ -123,7 +123,7 @@ float SoundEvent::GetParameter(const std::string& name) auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { - event->getParameterValue(name.c_str(), &retVal); + event->getParameterByName(name.c_str(), &retVal); } return retVal; } diff --git a/HybridPong/07558_CenturyGothic.ttf b/HybridPong/07558_CenturyGothic.ttf new file mode 100644 index 00000000..879704e3 Binary files /dev/null and b/HybridPong/07558_CenturyGothic.ttf differ diff --git a/HybridPong/Ball.cpp b/HybridPong/Ball.cpp new file mode 100644 index 00000000..03e37345 --- /dev/null +++ b/HybridPong/Ball.cpp @@ -0,0 +1,27 @@ +#include "Ball.h" + +Ball::Ball() +{ + +} +Ball::~Ball() +{ + +} +Vector2 Ball::getPosition() +{ + return mPosition; +} + +void Ball::setPosition(Vector2 position) +{ + mPosition = position; +} +Vector2 Ball::getVelocity() +{ + return mVelocity; +} +void Ball::setVelocity(Vector2 velocity) +{ + mVelocity = velocity; +} \ No newline at end of file diff --git a/HybridPong/Ball.h b/HybridPong/Ball.h new file mode 100644 index 00000000..3f881866 --- /dev/null +++ b/HybridPong/Ball.h @@ -0,0 +1,16 @@ +#pragma once +#include "Maths.h" + +class Ball +{ +public: + Ball(); + ~Ball(); + Vector2 getPosition(); + void setPosition(Vector2 position); + Vector2 getVelocity(); + void setVelocity(Vector2); +private: + Vector2 mPosition; + Vector2 mVelocity; +}; \ No newline at end of file diff --git a/HybridPong/Chapter01-mac.xcodeproj/project.pbxproj b/HybridPong/Chapter01-mac.xcodeproj/project.pbxproj new file mode 100644 index 00000000..cf8a87e1 --- /dev/null +++ b/HybridPong/Chapter01-mac.xcodeproj/project.pbxproj @@ -0,0 +1,316 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 9223C4781F009428009A94D7 /* Game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4671F009428009A94D7 /* Game.cpp */; }; + 9223C47D1F009428009A94D7 /* Main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4711F009428009A94D7 /* Main.cpp */; }; + 92D324FB1B697389005A86C7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92D324FA1B697389005A86C7 /* CoreFoundation.framework */; }; + 92E46E941B6353E50035CD21 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E46E931B6353E50035CD21 /* OpenGL.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 9223C4671F009428009A94D7 /* Game.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Game.cpp; sourceTree = ""; }; + 9223C4701F009428009A94D7 /* Game.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Game.h; sourceTree = ""; }; + 9223C4711F009428009A94D7 /* Main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Main.cpp; sourceTree = ""; }; + 92D324FA1B697389005A86C7 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + 92E46DF71B634EA30035CD21 /* Game-mac */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Game-mac"; sourceTree = BUILT_PRODUCTS_DIR; }; + 92E46E931B6353E50035CD21 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 92E46DF41B634EA30035CD21 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 92D324FB1B697389005A86C7 /* CoreFoundation.framework in Frameworks */, + 92E46E941B6353E50035CD21 /* OpenGL.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 92E46DEE1B634EA30035CD21 = { + isa = PBXGroup; + children = ( + 9223C4671F009428009A94D7 /* Game.cpp */, + 9223C4701F009428009A94D7 /* Game.h */, + 9223C4711F009428009A94D7 /* Main.cpp */, + 92E46DF81B634EA30035CD21 /* Products */, + 92D324FA1B697389005A86C7 /* CoreFoundation.framework */, + 92E46E931B6353E50035CD21 /* OpenGL.framework */, + ); + sourceTree = ""; + }; + 92E46DF81B634EA30035CD21 /* Products */ = { + isa = PBXGroup; + children = ( + 92E46DF71B634EA30035CD21 /* Game-mac */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 92E46DF61B634EA30035CD21 /* Game-mac */ = { + isa = PBXNativeTarget; + buildConfigurationList = 92E46DFE1B634EA40035CD21 /* Build configuration list for PBXNativeTarget "Game-mac" */; + buildPhases = ( + 92E46DF31B634EA30035CD21 /* Sources */, + 92E46DF41B634EA30035CD21 /* Frameworks */, + 92E46EA11B63615B0035CD21 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Game-mac"; + productName = "Game-mac"; + productReference = 92E46DF71B634EA30035CD21 /* Game-mac */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 92E46DEF1B634EA30035CD21 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0920; + ORGANIZATIONNAME = "Sanjay Madhav"; + TargetAttributes = { + 92E46DF61B634EA30035CD21 = { + CreatedOnToolsVersion = 6.4; + }; + }; + }; + buildConfigurationList = 92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter01-mac" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 92E46DEE1B634EA30035CD21; + productRefGroup = 92E46DF81B634EA30035CD21 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 92E46DF61B634EA30035CD21 /* Game-mac */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXShellScriptBuildPhase section */ + 92E46EA11B63615B0035CD21 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [ -d \"$BUILD_DIR/Debug\" ]; then\n cp \"$SRCROOT\"/../external/GLEW/lib/mac/*.dylib $BUILD_DIR/Debug\n cp \"$SRCROOT\"/../external/SDL/lib/mac/*.dylib $BUILD_DIR/Debug\nfi\n\nif [ -d \"$BUILD_DIR/Release\" ]; then\n cp \"$SRCROOT\"/../external/GLEW/lib/mac/*.dylib $BUILD_DIR/Release\n cp \"$SRCROOT\"/../external/SDL/lib/mac/*.dylib $BUILD_DIR/Release\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 92E46DF31B634EA30035CD21 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9223C47D1F009428009A94D7 /* Main.cpp in Sources */, + 9223C4781F009428009A94D7 /* Game.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 92E46DFC1B634EA40035CD21 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 92E46DFD1B634EA40035CD21 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 92E46DFF1B634EA40035CD21 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_ENABLE_CPP_RTTI = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../external/SDL/include", + "$(SRCROOT)/../external/GLEW/include", + "$(SRCROOT)/../external/SOIL/include", + ); + LIBRARY_SEARCH_PATHS = ( + "$(SRCROOT)/../external/GLEW/lib/mac", + "$(SRCROOT)/../external/SDL/lib/mac", + "$(SRCROOT)/../external/SOIL/lib/mac", + ); + OTHER_LDFLAGS = ( + "-lGLEW.2.1.0", + "-lSDL2-2.0.0", + "-lSDL2_mixer-2.0.0", + "-lSDL2_ttf-2.0.0", + "-lSOIL", + "-lSDL2_image-2.0.0", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 92E46E001B634EA40035CD21 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_ENABLE_CPP_RTTI = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../external/SDL/include", + "$(SRCROOT)/../external/GLEW/include", + "$(SRCROOT)/../external/SOIL/include", + ); + LIBRARY_SEARCH_PATHS = ( + "$(SRCROOT)/../external/GLEW/lib/mac", + "$(SRCROOT)/../external/SDL/lib/mac", + "$(SRCROOT)/../external/SOIL/lib/mac", + ); + OTHER_LDFLAGS = ( + "-lGLEW.2.1.0", + "-lSDL2-2.0.0", + "-lSDL2_mixer-2.0.0", + "-lSDL2_ttf-2.0.0", + "-lSOIL", + "-lSDL2_image-2.0.0", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter01-mac" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 92E46DFC1B634EA40035CD21 /* Debug */, + 92E46DFD1B634EA40035CD21 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 92E46DFE1B634EA40035CD21 /* Build configuration list for PBXNativeTarget "Game-mac" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 92E46DFF1B634EA40035CD21 /* Debug */, + 92E46E001B634EA40035CD21 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 92E46DEF1B634EA30035CD21 /* Project object */; +} diff --git a/HybridPong/Chapter01-mac.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/HybridPong/Chapter01-mac.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..403d96cd --- /dev/null +++ b/HybridPong/Chapter01-mac.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/HybridPong/Chapter01-mac.xcodeproj/xcshareddata/xcschemes/Game-mac.xcscheme b/HybridPong/Chapter01-mac.xcodeproj/xcshareddata/xcschemes/Game-mac.xcscheme new file mode 100644 index 00000000..21a91dfd --- /dev/null +++ b/HybridPong/Chapter01-mac.xcodeproj/xcshareddata/xcschemes/Game-mac.xcscheme @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HybridPong/Chapter01-windows.sln b/HybridPong/Chapter01-windows.sln new file mode 100644 index 00000000..f560df0f --- /dev/null +++ b/HybridPong/Chapter01-windows.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "Game.vcxproj", "{BC508D87-495F-4554-932D-DD68388B63CC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.ActiveCfg = Debug|Win32 + {BC508D87-495F-4554-932D-DD68388B63CC}.Debug|Win32.Build.0 = Debug|Win32 + {BC508D87-495F-4554-932D-DD68388B63CC}.Release|Win32.ActiveCfg = Release|Win32 + {BC508D87-495F-4554-932D-DD68388B63CC}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HybridPong/Game.cpp b/HybridPong/Game.cpp new file mode 100644 index 00000000..80ba8b0d --- /dev/null +++ b/HybridPong/Game.cpp @@ -0,0 +1,284 @@ +// ---------------------------------------------------------------- +// From Game Programming in C++ by Sanjay Madhav +// Copyright (C) 2017 Sanjay Madhav. All rights reserved. +// +// Released under the BSD License +// See LICENSE in root directory for full details. +// ---------------------------------------------------------------- + +#include "Game.h" + +const int thickness = 15; +const float paddleH = 100.0f; + +Game::Game() +:mWindow(nullptr) +,mRenderer(nullptr) +,mTicksCount(0) +,mIsRunning(true) +{ + mPaddle.setDirection(0); +} + +bool Game::Initialize() +{ + // Initialize SDL + int sdlResult = SDL_Init(SDL_INIT_VIDEO); + if (sdlResult != 0) + { + SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); + return false; + } + + // Create an SDL Window + mWindow = SDL_CreateWindow( + "Game Programming in C++ (Chapter 1)", // Window title + 100, // Top left x-coordinate of window + 100, // Top left y-coordinate of window + 1024, // Width of window + 768, // Height of window + 0 // Flags (0 for no flags set) + ); + + if (!mWindow) + { + SDL_Log("Failed to create window: %s", SDL_GetError()); + return false; + } + + //// Create SDL renderer + mRenderer = SDL_CreateRenderer( + mWindow, // Window to create renderer for + -1, // Usually -1 + SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC + ); + + if (!mRenderer) + { + SDL_Log("Failed to create renderer: %s", SDL_GetError()); + return false; + } + // + StartGame(); + + return true; +} +void Game::StartGame() +{ + mPaddle.setPosition(Vector2(10.0f, 768.0 / 2.0f)); + mBall.setPosition(Vector2(1024.0f / 2.0f, 768.0f / 2.0f)); + mBall.setVelocity(Vector2(-200.0f, 235.0f)); +} +void Game::RunLoop() +{ + + while (mIsRunning) + { + ProcessInput(); + UpdateGame(); + GenerateOutput(); + } +} + +void Game::ProcessInput() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + // If we get an SDL_QUIT event, end loop + case SDL_QUIT: + mIsRunning = false; + break; + } + } + + // Get state of keyboard + const Uint8* state = SDL_GetKeyboardState(NULL); + // If escape is pressed, also end loop + if (state[SDL_SCANCODE_ESCAPE]) + { + mIsRunning = false; + } + + // Update paddle direction based on W/S keys + //mPaddleDir = 0; + mPaddle.setDirection(0); + if (state[SDL_SCANCODE_W]) + { + //mPaddleDir -= 1; + mPaddle.setDirection(-1); + }else if (state[SDL_SCANCODE_S]) + { + //mPaddleDir += 1; + mPaddle.setDirection(1); + } + else + { + mPaddle.setDirection(0); + } +} + +void Game::UpdateGame() +{ + // Wait until 16ms has elapsed since last frame + while (!SDL_TICKS_PASSED(SDL_GetTicks(), mTicksCount + 16)) + ; + + // Delta time is the difference in ticks from last frame + // (converted to seconds) + float dt = (SDL_GetTicks() - mTicksCount) / 1000.0f; + + // Clamp maximum delta time value + if (dt > 0.05f) + { + dt = 0.05f; + } + + // Update tick counts (for next frame) + mTicksCount = SDL_GetTicks(); + + // Update paddle position based on direction + if (mPaddle.getDirection() != 0) + { + //mPaddlePos.y += mPaddleDir * 300.0f * dt; + mPaddle.setPosition(Vector2(mPaddle.getPosition().getX(), mPaddle.getPosition().getY() + 300.0f * dt)); + // Make sure paddle doesn't move off screen! + if (mPaddle.getPosition().getY() < (paddleH / 2.0f + thickness)) + { + mPaddle.setPosition(Vector2(paddleH / 2.0f + thickness, mPaddle.getPosition().getY())); + } + else if (mPaddle.getPosition().getY() > (768.0f - paddleH / 2.0f - thickness)) + { + mPaddle.setPosition(Vector2(768.0f - paddleH / 2.0f - thickness, mPaddle.getPosition().getY())); + } + } + + // Update ball position based on ball velocity + mBall.setPosition(Vector2(mBall.getVelocity().getX() * dt, mBall.getPosition().getY() * dt)); + + // Bounce if needed + // Did we intersect with the paddle? + float diff = mPaddle.getPosition().getY() - mBall.getPosition().getY(); + // Take absolute value of difference + diff = (diff > 0.0f) ? diff : -diff; + if ( + // Our y-difference is small enough + diff <= paddleH / 2.0f && + // We are in the correct x-position + mBall.getPosition().getX() <= 25.0f && mBall.getPosition().getX() >= 20.0f && + // The ball is moving to the left + mBall.getVelocity().getX() < 0.0f) + { + //mBall.getVelocity().getX() *= -1.0f; + mBall.setVelocity(Vector2(mBall.getVelocity().getX() * -1.0f, mBall.getVelocity().getY())); + } + // Did the ball go off the screen? (if so, end game) + else if(mBall.getPosition().getX() <= 0.0f) + //else if (mBallPos.x <= 0.0f) + { + //mIsRunning = false; + StartGame(); + } + // Did the ball collide with the right wall? + else if (mBall.getPosition().getX() >= (1024.0f - thickness) + && mBall.getVelocity().getX()> 0.0f) + { + mBall.setVelocity(Vector2(mBall.getVelocity().getX() * -1.0f, mBall.getPosition().getY())); + } + + // Did the ball collide with the top wall? + if (mBall.getPosition().getY() <= thickness && mBall.getVelocity().getY() < 0.0f) + { + mBall.setVelocity(Vector2(mBall.getVelocity().getX(), mBall.getVelocity().getY() * -1)); + } + // Did the ball collide with the bottom wall? + else if (mBall.getPosition().getY() >= (768 - thickness) && + mBall.getVelocity().getY() > 0.0f) + { + mBall.setVelocity(Vector2(mBall.getVelocity().getX(), mBall.getVelocity().getY() * -1)); + } +} + +void Game::GenerateOutput() +{ + // Set draw color to blue + SDL_SetRenderDrawColor( + mRenderer, + 0, // R + 0, // G + 255, // B + 255 // A + ); + + // Clear back buffer + SDL_RenderClear(mRenderer); + + // Draw walls + SDL_SetRenderDrawColor(mRenderer, 255, 255, 255, 255); + //Draw player wall top + // + SDL_Rect playerWallTopOfGoal{ + 0, + 0, + thickness, + (1024 / 2) - 15 + }; + SDL_Rect playerWallBottomOfGoal{ + 0, + (1024 / 2) + 15, + thickness, + 1024 / 2 - 15 + }; + SDL_RenderFillRect(mRenderer, &playerWallTopOfGoal); + SDL_RenderFillRect(mRenderer, &playerWallBottomOfGoal); + // Draw top wall + SDL_Rect wall{ + 0, // Top left x + 0, // Top left y + 1024, // Width + thickness // Height + }; + SDL_RenderFillRect(mRenderer, &wall); + + + // Draw bottom wall + wall.y = 768 - thickness; + SDL_RenderFillRect(mRenderer, &wall); + + // Draw right wall + wall.x = 1024 - thickness; + wall.y = 0; + wall.w = thickness; + wall.h = 1024; + SDL_RenderFillRect(mRenderer, &wall); + + // Draw paddle + SDL_Rect paddle{ + static_cast(mPaddle.getPosition().getX()), + static_cast(mPaddle.getPosition().getY() - paddleH / 2), + thickness, + static_cast(paddleH) + }; + SDL_RenderFillRect(mRenderer, &paddle); + + // Draw ball + SDL_Rect ball{ + static_cast(mBall.getPosition().getX() - thickness / 2), + static_cast(mBall.getPosition().getY() - thickness / 2), + thickness, + thickness + }; + SDL_RenderFillRect(mRenderer, &ball); + + // Swap front buffer and back buffer + SDL_RenderPresent(mRenderer); +} + +void Game::Shutdown() +{ + SDL_DestroyRenderer(mRenderer); + SDL_DestroyWindow(mWindow); + SDL_Quit(); +} diff --git a/HybridPong/Game.h b/HybridPong/Game.h new file mode 100644 index 00000000..49a657d9 --- /dev/null +++ b/HybridPong/Game.h @@ -0,0 +1,53 @@ +// ---------------------------------------------------------------- +// From Game Programming in C++ by Sanjay Madhav +// Copyright (C) 2017 Sanjay Madhav. All rights reserved. +// +// Released under the BSD License +// See LICENSE in root directory for full details. +// ---------------------------------------------------------------- + +#pragma once +#include "SDL/SDL.h" +#include "Ball.h" +#include "Paddle.h" +#include "Maths.h" + +// Game class +class Game +{ +public: + Game(); + // Initialize the game + bool Initialize(); + // Runs the game loop until the game is over + void RunLoop(); + // Shutdown the game + void Shutdown(); +private: + // Helper functions for the game loop + void StartGame(); + void ProcessInput(); + void UpdateGame(); + void GenerateOutput(); + + // Window created by SDL + SDL_Window* mWindow; + // Renderer for 2D drawing + SDL_Renderer* mRenderer; + // Number of ticks since start of game + Uint32 mTicksCount; + // Game should continue to run + bool mIsRunning; + + Paddle mPaddle; + Ball mBall; + // Pong specific + // Direction of paddle + //int mPaddleDir; + // Position of paddle + //Vector2 mPaddlePos; + // Position of ball + //Vector2 mBallPos; + // Velocity of ball + //Vector2 mBallVel; +}; diff --git a/HybridPong/Game.vcxproj b/HybridPong/Game.vcxproj new file mode 100644 index 00000000..aaeba45a --- /dev/null +++ b/HybridPong/Game.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + {BC508D87-495F-4554-932D-DD68388B63CC} + Win32Proj + Game + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + ..\external\SDL\include;..\external\GLEW\include;..\external\SOIL\include;%(AdditionalIncludeDirectories) + false + Sync + + + Console + true + ..\external\SDL\lib\win\x86;..\external\GLEW\lib\win\x86;..\external\SOIL\lib\win\x86;%(AdditionalLibraryDirectories) + opengl32.lib;SDL2.lib;SDL2main.lib;SDL2_ttf.lib;SDL2_mixer.lib;SDL2_image.lib;glew32.lib;SOIL.lib;%(AdditionalDependencies) + /NODEFAULTLIB:msvcrt.lib %(AdditionalOptions) + + + xcopy "$(ProjectDir)\..\external\SDL\lib\win\x86\*.dll" "$(OutDir)" /i /s /y +xcopy "$(ProjectDir)\..\external\GLEW\lib\win\x86\*.dll" "$(OutDir)" /i /s /y + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + ..\external\SDL\include;..\external\GLEW\include;..\external\SOIL\include;%(AdditionalIncludeDirectories) + false + Sync + + + Console + true + true + true + ..\external\SDL\lib\win\x86;..\external\GLEW\lib\win\x86;..\external\SOIL\lib\win\x86;%(AdditionalLibraryDirectories) + opengl32.lib;SDL2.lib;SDL2main.lib;SDL2_ttf.lib;SDL2_mixer.lib;SDL2_image.lib;glew32.lib;SOIL.lib;%(AdditionalDependencies) + + + xcopy "$(ProjectDir)\..\external\SDL\lib\win\x86\*.dll" "$(OutDir)" /i /s /y +xcopy "$(ProjectDir)\..\external\GLEW\lib\win\x86\*.dll" "$(OutDir)" /i /s /y + + + + + + \ No newline at end of file diff --git a/HybridPong/Game.vcxproj.filters b/HybridPong/Game.vcxproj.filters new file mode 100644 index 00000000..a7b16b3d --- /dev/null +++ b/HybridPong/Game.vcxproj.filters @@ -0,0 +1,43 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {c1839d52-4ab7-4353-8b6a-ce3757db6244} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Headers + + + Headers + + + Headers + + + Headers + + + \ No newline at end of file diff --git a/HybridPong/Main.cpp b/HybridPong/Main.cpp new file mode 100644 index 00000000..22ea0c69 --- /dev/null +++ b/HybridPong/Main.cpp @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------- +// From Game Programming in C++ by Sanjay Madhav +// Copyright (C) 2017 Sanjay Madhav. All rights reserved. +// +// Released under the BSD License +// See LICENSE in root directory for full details. +// ---------------------------------------------------------------- + +#include "Game.h" + +int main(int argc, char** argv) +{ + Game game; + bool success = game.Initialize(); + if (success) + { + game.RunLoop(); + } + game.Shutdown(); + return 0; +} diff --git a/HybridPong/Maths.cpp b/HybridPong/Maths.cpp new file mode 100644 index 00000000..6b149a40 --- /dev/null +++ b/HybridPong/Maths.cpp @@ -0,0 +1,20 @@ +#include "Maths.h" + +Vector2::Vector2() +{ + mx = 0.0f; + my = 0.0f; +} +Vector2::Vector2(float x, float y) +{ + mx = x; + my = y; +} +float Vector2::getX() +{ + return mx; +} +float Vector2::getY() +{ + return my; +} \ No newline at end of file diff --git a/HybridPong/Maths.h b/HybridPong/Maths.h new file mode 100644 index 00000000..2d7ebd47 --- /dev/null +++ b/HybridPong/Maths.h @@ -0,0 +1,14 @@ +// Vector2 struct just stores x/y coordinates +// (for now) +#pragma once +class Vector2 +{ +public: + Vector2(); + Vector2(float x, float y); + float Vector2::getX(); + float Vector2::getY(); +private: + float mx; + float my; +}; diff --git a/HybridPong/Paddle.cpp b/HybridPong/Paddle.cpp new file mode 100644 index 00000000..2e6740be --- /dev/null +++ b/HybridPong/Paddle.cpp @@ -0,0 +1,26 @@ +#include "Paddle.h" +Paddle::Paddle() +{ + mPosition = Vector2(0, 0); + mDirection = 0; +} +Paddle::~Paddle() +{ + +} +Vector2 Paddle::getPosition() +{ + return mPosition; +} +void Paddle::setPosition(Vector2 position) +{ + mPosition = position; +} +int Paddle::getDirection() +{ + return mDirection; +} +void Paddle::setDirection(int direction) +{ + mDirection = direction; +} \ No newline at end of file diff --git a/HybridPong/Paddle.h b/HybridPong/Paddle.h new file mode 100644 index 00000000..14fb2122 --- /dev/null +++ b/HybridPong/Paddle.h @@ -0,0 +1,31 @@ +#pragma once +#include "Maths.h" + +class Paddle +{ +public: + Paddle(); + ~Paddle(); + Vector2 getPosition(); + void setPosition(Vector2 position); + int getDirection(); + void setDirection(int direction); +private: + Vector2 mPosition; + int mDirection; +}; + +//One thing I've noticed about music, is that music +//has a way of calming the mind. Music is the souls' +//pure expression. +//But music isn't about the noise, the sound. Music +//isn't about the harmony or the melody. It's about +//becoming as quiet as possible, between moments of +//intense volume, hearing the resonance, and +//adjusting accordingly. + +//The quieter you become the more you are able to hear. +//The quieter you become the more you are able to hear. +//The quieter you become the more you are able to hear. +//The quieter you become the more you are able to hear. +//The quieter you become the more you are able to hear. \ No newline at end of file