diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c40ee44 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 2.6) +project(platform-test) + + +### Set directories + +# Set include directory +include_directories(src) +# Set an output directory for our binaries +set(BIN_DIR ${platform-test_SOURCE_DIR}) +# Set sources dir +file(GLOB_RECURSE SRC_DIR RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp") + + + +# Bump up warning levels appropriately for clang, gcc & msvc +# Also set debug/optimization flags depending on the build type. +# IDE users choose this when selecting the build mode in their IDE +if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2") +elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +endif() + + + + + +### Find SFML stuff + +# Use our modified FindSDL2* modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${platform-test_SOURCE_DIR}/cmake") + +# Look up SDL2 and add the include directory to our include path +find_package(SDL2 REQUIRED) +include_directories(${SDL2_INCLUDE_DIR}) +# Look up SDL2_Image and add the include directory to our include path +find_package(SDL2_image REQUIRED) +include_directories(${SDL2_IMAGE_INCLUDE_DIR}) +# Look up SDL2_TTF and add the include directory to our include path +find_package(SDL2_ttf REQUIRED) +include_directories(${SDL2_TTF_INCLUDE_DIR}) +# Look up SDL2_mixer and add the include directory to our include path +find_package(SDL2_mixer REQUIRED) +include_directories(${SDL2_MIXER_INCLUDE_DIR}) + + + +#### Binaries + +# Make executable and indclude all the sources +add_executable(platform-test ${SRC_DIR}) + +#Link executable against SDL2 and its extensions +target_link_libraries(platform-test ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${SDL2_TTF_LIBRARY} ${SDL2_MIXER_LIBRARY}) +install(TARGETS platform-test RUNTIME DESTINATION ${BIN_DIR}) diff --git a/Licenses/COPYING.txt b/Licenses/COPYING.txt deleted file mode 100644 index 9234e91..0000000 --- a/Licenses/COPYING.txt +++ /dev/null @@ -1,20 +0,0 @@ -/* - SDL_image: An example image loading library for use with SDL - Copyright (C) 1997-2016 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ diff --git a/Licenses/LICENSE.png.txt b/Licenses/LICENSE.png.txt deleted file mode 100644 index 78d131c..0000000 --- a/Licenses/LICENSE.png.txt +++ /dev/null @@ -1,114 +0,0 @@ -The source code to this library used with SDL_image can be found here: -http://www.libsdl.org/projects/SDL_image/libs/ ---- - -This copy of the libpng notices is provided for your convenience. In case of -any discrepancy between this copy and the notices in the file png.h that is -included in the libpng distribution, the latter shall prevail. - -COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - -If you modify libpng you may insert additional notices immediately following -this sentence. - -This code is released under the libpng license. - -libpng versions 1.2.6, August 15, 2004, through 1.5.7, December 15, 2011, are -Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.2.5 -with the following individual added to the list of Contributing Authors - - Cosmin Truta - -libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are -Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.0.6 -with the following individuals added to the list of Contributing Authors - - Simon-Pierre Cadieux - Eric S. Raymond - Gilles Vollant - -and with the following additions to the disclaimer: - - There is no warranty against interference with your enjoyment of the - library or against infringement. There is no warranty that our - efforts or the library will fulfill any of your particular purposes - or needs. This library is provided with all faults, and the entire - risk of satisfactory quality, performance, accuracy, and effort is with - the user. - -libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are -Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-0.96, -with the following individuals added to the list of Contributing Authors: - - Tom Lane - Glenn Randers-Pehrson - Willem van Schaik - -libpng versions 0.89, June 1996, through 0.96, May 1997, are -Copyright (c) 1996, 1997 Andreas Dilger -Distributed according to the same disclaimer and license as libpng-0.88, -with the following individuals added to the list of Contributing Authors: - - John Bowler - Kevin Bracey - Sam Bushell - Magnus Holmgren - Greg Roelofs - Tom Tanner - -libpng versions 0.5, May 1995, through 0.88, January 1996, are -Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - -For the purposes of this copyright and license, "Contributing Authors" -is defined as the following set of individuals: - - Andreas Dilger - Dave Martindale - Guy Eric Schalnat - Paul Schmidt - Tim Wegner - -The PNG Reference Library is supplied "AS IS". The Contributing Authors -and Group 42, Inc. disclaim all warranties, expressed or implied, -including, without limitation, the warranties of merchantability and of -fitness for any purpose. The Contributing Authors and Group 42, Inc. -assume no liability for direct, indirect, incidental, special, exemplary, -or consequential damages, which may result from the use of the PNG -Reference Library, even if advised of the possibility of such damage. - -Permission is hereby granted to use, copy, modify, and distribute this -source code, or portions hereof, for any purpose, without fee, subject -to the following restrictions: - -1. The origin of this source code must not be misrepresented. - -2. Altered versions must be plainly marked as such and must not - be misrepresented as being the original source. - -3. This Copyright notice may not be removed or altered from any - source or altered source distribution. - -The Contributing Authors and Group 42, Inc. specifically permit, without -fee, and encourage the use of this source code as a component to -supporting the PNG file format in commercial products. If you use this -source code in a product, acknowledgment is not required but would be -appreciated. - - -A "png_get_copyright" function is available, for convenient use in "about" -boxes and the like: - - printf("%s",png_get_copyright(NULL)); - -Also, the PNG logo (in PNG format, of course) is supplied in the -files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). - -Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a -certification mark of the Open Source Initiative. - -Glenn Randers-Pehrson -glennrp at users.sourceforge.net -December 15, 2011 diff --git a/Licenses/LICENSE.zlib.txt b/Licenses/LICENSE.zlib.txt deleted file mode 100644 index ae89d83..0000000 --- a/Licenses/LICENSE.zlib.txt +++ /dev/null @@ -1,31 +0,0 @@ -The source code to this library used with SDL_image can be found here: -http://www.libsdl.org/projects/SDL_image/libs/ ---- - -Copyright notice: - - (C) 1995-2010 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - -If you use the zlib library in a product, we would appreciate *not* receiving -lengthy legal documents to sign. The sources are provided for free but without -warranty of any kind. The library has been entirely written by Jean-loup -Gailly and Mark Adler; it does not include third-party code. diff --git a/README.md b/README.md index d51b0cd..d4d8f8b 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,19 @@ So far I have implemented a regular platformer, with its player, player physics, ## Compiling -The Makefile it's very outdated and SDL2's header files path differs from windows so I would recommend to compile it on Windows. If you want to compile it in Linux you have to change the include path from and to and . +Dependencies: -This project uses the SDL2 and SDL2_Image libraries. You can find those here: https://www.libsdl.org/download-2.0.php +- SDL2 +- SDL2_ttf +- SDL2_image +- SDL2_mixer -After making sure that you have SDL2 and SDL_Image installed use your favorite IDE or compiler to compile it. Don't forget to include the C++11 (-std=c++11), SDL2 (-lSDL2main and -lSDL2) and SDL2_Image (-lSDL2_Image) flags. I found out that if you're using MinGW to compile it you have to add its flag (-lmingw32) or it will throw weird errors. +To compile it just follow the standard CMake procedure: + + mkdir build && cd build + cmake ../ + make + make install ## References diff --git a/SDL2.dll b/SDL2.dll deleted file mode 100644 index 2b7e319..0000000 Binary files a/SDL2.dll and /dev/null differ diff --git a/SDL2_image.dll b/SDL2_image.dll deleted file mode 100644 index cd35db0..0000000 Binary files a/SDL2_image.dll and /dev/null differ diff --git a/SDL2_mixer.dll b/SDL2_mixer.dll deleted file mode 100644 index 47adbc3..0000000 Binary files a/SDL2_mixer.dll and /dev/null differ diff --git a/SDL2_ttf.dll b/SDL2_ttf.dll deleted file mode 100644 index 2d8929e..0000000 Binary files a/SDL2_ttf.dll and /dev/null differ diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 0000000..872e3c4 --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,255 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2_main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDL2main.h and SDL2main.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2 is an environment variable that would +# correspond to the ./configure --prefix=$SDL2 +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. +# +# Note that on windows this will only search for the 32bit libraries, to search +# for 64bit change x86/i686-w64 to x64/x86_64-w64 + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + HINTS + ${SDL2} + $ENV{SDL2} + PATH_SUFFIXES include/SDL2 include SDL2 + i686-w64-mingw32/include/SDL2 + x86_64-w64-mingw32/include/SDL2 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Lookup the 64 bit libs on x64 +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_LIBRARY_TEMP SDL2 + HINTS + ${SDL2} + $ENV{SDL2} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +# On 32bit build find the 32bit libs +ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_LIBRARY_TEMP SDL2 + HINTS + ${SDL2} + $ENV{SDL2} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + # Lookup the 64 bit libs on x64 + IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + ${SDL2} + $ENV{SDL2} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) + # On 32bit build find the 32bit libs + ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + ${SDL2} + $ENV{SDL2} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) + ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +SET(SDL2_FOUND "NO") + IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") + + SET(SDL2_FOUND "YES") +ENDIF(SDL2_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) + diff --git a/cmake/FindSDL2_image.cmake b/cmake/FindSDL2_image.cmake new file mode 100644 index 0000000..78704cb --- /dev/null +++ b/cmake/FindSDL2_image.cmake @@ -0,0 +1,158 @@ +# Locate SDL2_image library +# This module defines +# SDL2_IMAGE_LIBRARY, the name of the library to link against +# SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image +# SDL2_IMAGE_INCLUDE_DIR, where to find SDL_image.h +# +# Additional Note: If you see an empty SDL2_IMAGE_LIBRARY_TEMP in your configuration +# and no SDL2_IMAGE_LIBRARY, it means CMake did not find your SDL2_Image library +# (SDL2_image.dll, libsdl2_image.so, SDL2_image.framework, etc). +# Set SDL2_IMAGE_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_IMAGE_LIBRARY +# variable, but when these values are unset, SDL2_IMAGE_LIBRARY does not get created. +# +# $SDL2 is an environment variable that would +# correspond to the ./configure --prefix=$SDL2 +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_IMAGE_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. +# +# Note that on windows this will only search for the 32bit libraries, to search +# for 64bit change x86/i686-w64 to x64/x86_64-w64 + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES include/SDL2 include SDL2 + i686-w64-mingw32/include/SDL2 + x86_64-w64-mingw32/include/SDL2 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Lookup the 64 bit libs on x64 +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP + NAMES SDL2_image + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +# On 32bit build find the 32bit libs +ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP + NAMES SDL2_image + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + +SET(SDL2_IMAGE_FOUND "NO") + IF(SDL2_IMAGE_LIBRARY_TEMP) + # Set the final string here so the GUI reflects the final state. + SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_image Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "") + SET(SDL2_IMAGE_FOUND "YES") +ENDIF(SDL2_IMAGE_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_IMAGE REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) + diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake new file mode 100644 index 0000000..1d9778c --- /dev/null +++ b/cmake/FindSDL2_mixer.cmake @@ -0,0 +1,100 @@ +# Locate SDL_MIXER library +# +# This module defines: +# +# :: +# +# SDL2_MIXER_LIBRARIES, the name of the library to link against +# SDL2_MIXER_INCLUDE_DIRS, where to find the headers +# SDL2_MIXER_FOUND, if false, do not try to link against +# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_MIXER +# +# +# +# For backward compatibility the following variables are also set: +# +# :: +# +# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) +# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) +# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND) +# +# +# +# $SDLDIR is an environment variable that would correspond to the +# ./configure --prefix=$SDLDIR used in building SDL. +# +# Created by Eric Wing. This was influenced by the FindSDL.cmake +# module, but with modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h + HINTS + ENV SDL2MIXERDIR + ENV SDL2DIR + PATH_SUFFIXES SDL2 + # path suffixes to search inside ENV{SDLDIR} + include/SDL2 include + PATHS ${SDL2_MIXER_PATH} + ) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(VC_LIB_PATH_SUFFIX lib/x64) +else() + set(VC_LIB_PATH_SUFFIX lib/x86) +endif() + +find_library(SDL2_MIXER_LIBRARY + NAMES SDL2_mixer + HINTS + ENV SDL2MIXERDIR + ENV SDL2DIR + PATH_SUFFIXES lib bin ${VC_LIB_PATH_SUFFIX} + PATHS ${SDL2_MIXER_PATH} + ) + +if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") + set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) + unset(SDL2_MIXER_VERSION_MAJOR_LINE) + unset(SDL2_MIXER_VERSION_MINOR_LINE) + unset(SDL2_MIXER_VERSION_PATCH_LINE) + unset(SDL2_MIXER_VERSION_MAJOR) + unset(SDL2_MIXER_VERSION_MINOR) + unset(SDL2_MIXER_VERSION_PATCH) +endif() + +set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) +set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer + REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS + VERSION_VAR SDL2_MIXER_VERSION_STRING) + +# for backward compatibility +set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) +set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) +set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND}) + +mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) diff --git a/cmake/FindSDL2_ttf.cmake b/cmake/FindSDL2_ttf.cmake new file mode 100644 index 0000000..9f38607 --- /dev/null +++ b/cmake/FindSDL2_ttf.cmake @@ -0,0 +1,157 @@ +# Locate SDL2_ttf library +# This module defines +# SDL2_TTF_LIBRARY, the name of the library to link against +# SDL2_TTF_FOUND, if false, do not try to link to SDL2_ttf +# SDL2_TTF_INCLUDE_DIR, where to find SDL_image.h +# +# Additional Note: If you see an empty SDL2_TTF_LIBRARY_TEMP in your configuration +# and no SDL2_TTF_LIBRARY, it means CMake did not find your SDL2_Image library +# (SDL2_ttf.dll, libsdl2_image.so, SDL2_ttf.framework, etc). +# Set SDL2_TTF_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_TTF_LIBRARY +# variable, but when these values are unset, SDL2_TTF_LIBRARY does not get created. +# +# $SDL2 is an environment variable that would +# correspond to the ./configure --prefix=$SDL2 +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_TTF_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. +# +# Note that on windows this will only search for the 32bit libraries, to search +# for 64bit change x86/i686-w64 to x64/x86_64-w64 + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_TTF_INCLUDE_DIR SDL_ttf.h + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES include/SDL2 include SDL2 + i686-w64-mingw32/include/SDL2 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Lookup the 64 bit libs on x64 +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP + NAMES SDL2_ttf + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +# On 32bit build find the 32bit libs +ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP + NAMES SDL2_ttf + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + +SET(SDL2_TTF_FOUND "NO") + IF(SDL2_TTF_LIBRARY_TEMP) + # Set the final string here so the GUI reflects the final state. + SET(SDL2_TTF_LIBRARY ${SDL2_TTF_LIBRARY_TEMP} CACHE STRING "Where the SDL2_ttf Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_TTF_LIBRARY_TEMP "${SDL2_TTF_LIBRARY_TEMP}" CACHE INTERNAL "") + SET(SDL2_TTF_FOUND "YES") +ENDIF(SDL2_TTF_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_TTF REQUIRED_VARS SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR) + diff --git a/libFLAC-8.dll b/libFLAC-8.dll deleted file mode 100644 index bcc6524..0000000 Binary files a/libFLAC-8.dll and /dev/null differ diff --git a/libfreetype-6.dll b/libfreetype-6.dll deleted file mode 100644 index 6b19b3c..0000000 Binary files a/libfreetype-6.dll and /dev/null differ diff --git a/libmodplug-1.dll b/libmodplug-1.dll deleted file mode 100644 index 69be1be..0000000 Binary files a/libmodplug-1.dll and /dev/null differ diff --git a/libogg-0.dll b/libogg-0.dll deleted file mode 100644 index 1b3a7bd..0000000 Binary files a/libogg-0.dll and /dev/null differ diff --git a/libpng16-16.dll b/libpng16-16.dll deleted file mode 100644 index 30833f0..0000000 Binary files a/libpng16-16.dll and /dev/null differ diff --git a/libvorbis-0.dll b/libvorbis-0.dll deleted file mode 100644 index 7f79a16..0000000 Binary files a/libvorbis-0.dll and /dev/null differ diff --git a/libvorbisfile-3.dll b/libvorbisfile-3.dll deleted file mode 100644 index 4e3a5ed..0000000 Binary files a/libvorbisfile-3.dll and /dev/null differ diff --git a/pangolin.ttf b/pangolin.ttf deleted file mode 100644 index e0031b0..0000000 Binary files a/pangolin.ttf and /dev/null differ diff --git a/platform-test.exe b/platform-test.exe deleted file mode 100644 index e4d09dc..0000000 Binary files a/platform-test.exe and /dev/null differ diff --git a/smpeg2.dll b/smpeg2.dll deleted file mode 100644 index 1cef588..0000000 Binary files a/smpeg2.dll and /dev/null differ diff --git a/source/menu.cpp b/source/menu.cpp deleted file mode 100644 index d7b6d43..0000000 --- a/source/menu.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "menu.h" - -class Button{ - public: - Button(int x,int y,int w,int h,SDL_Renderer* render,std::string buttonText); - void render(); - void hover(); - SDL_Rect getRect(); - private: - SDL_Rect buttonRect; - SDL_Rect textRect; - SDL_Renderer* renderer; - Texture text; - - bool isHover; -}; - -Button::Button(int x,int y,int w,int h,SDL_Renderer* render,std::string buttonText){ - renderer = render; - buttonRect = {x,y,w,h}; - isHover = false; - - text.setRenderer(renderer); - SDL_Color textColor = {0xFF,0xFF,0xFF}; - text.loadFromRendererText(buttonText,textColor); - - textRect = {x+(w/2)-text.getWidth()/2,y+(h/2)-text.getHeight()/2,text.getWidth(),text.getHeight()}; -}; - -void Button::render(){ - if(isHover) SDL_SetRenderDrawColor(renderer,80,80,80,0xFF); - else SDL_SetRenderDrawColor(renderer,128,128,128,0xFF); - - SDL_RenderFillRect(renderer,&buttonRect); - text.render(&textRect); - isHover = false; -}; - -void Button::hover(){ - isHover = true; -}; - -SDL_Rect Button::getRect(){ - return buttonRect; -}; - -int menu(SDL_Renderer* renderer){ - int SCREEN_WIDTH, SCREEN_HEIGHT; - SDL_GetRendererOutputSize(renderer,&SCREEN_WIDTH,&SCREEN_HEIGHT); - - bool quit = false; - SDL_Event e; - - Texture txLogo; - txLogo.setRenderer(renderer); - txLogo.loadTexture("textures/title.png"); - - int logoVmargin = 40; - - SDL_Rect logo = {(SCREEN_WIDTH/2)-txLogo.getWidth()/2,logoVmargin,txLogo.getWidth(),txLogo.getHeight()}; - - int btnSpc = SCREEN_HEIGHT - (logo.y + logo.h); - int buttonNum = 3; - int btnWidth = SCREEN_WIDTH/3; - int btnHeight = btnSpc/buttonNum/2; - int spc = (btnSpc-buttonNum*btnHeight)/(buttonNum+1); - - Button playBtn(SCREEN_WIDTH/2-btnWidth/2,(1*spc+0*btnHeight)+SCREEN_HEIGHT-btnSpc,btnWidth,btnHeight,renderer,"play"); - Button optionsBtn(SCREEN_WIDTH/2-btnWidth/2,(2*spc+1*btnHeight)+SCREEN_HEIGHT-btnSpc,btnWidth,btnHeight,renderer,"options"); - Button quitBtn(SCREEN_WIDTH/2-btnWidth/2,(3*spc+2*btnHeight)+SCREEN_HEIGHT-btnSpc,btnWidth,btnHeight,renderer,"quit"); - - int select = 0; - bool wait = 0; - const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL); - - while(!quit){ - while(SDL_PollEvent(&e)!=0){ - if(e.type == SDL_QUIT){ - quit = true; - } - } - SDL_SetRenderDrawColor(renderer,100,200,200,0xFF); - SDL_RenderClear(renderer); - - int dir = 0; - if(currentKeyStates[SDL_SCANCODE_UP]) dir--; - if(currentKeyStates[SDL_SCANCODE_DOWN])dir++; - - if(dir != 0){ - if(!wait) select += dir; - wait = true; - } - else wait = false; - - if(select >= buttonNum) select = 0; - if(select < 0) select = buttonNum-1; - - txLogo.render(&logo); - - if(currentKeyStates[SDL_SCANCODE_SPACE]){ - if(select == 0) return 1; - else if(select == 1) return 0; - else if(select == 2) break; - } - - if(select == 0) playBtn.hover(); - else if(select == 1) optionsBtn.hover(); - else quitBtn.hover(); - - playBtn.render(); - optionsBtn.render(); - quitBtn.render(); - - SDL_RenderPresent(renderer); - } - - return -1; -} diff --git a/src/.maps.cpp.swp b/src/.maps.cpp.swp new file mode 100644 index 0000000..4e4d604 Binary files /dev/null and b/src/.maps.cpp.swp differ diff --git a/source/camera.cpp b/src/camera.cpp similarity index 57% rename from source/camera.cpp rename to src/camera.cpp index ce0a986..618a234 100644 --- a/source/camera.cpp +++ b/src/camera.cpp @@ -12,17 +12,34 @@ Camera::Camera(int mapWidth, int mapHeight,int screenWidth, int screenHeight){ void Camera::update(int playerX, int playerY){ //Make the camera move when the player hits the middle of the screen if(mW != scW){ - if(playerX >= scW/2) posX = playerX - scW/2; - else posX = 0; - if(playerX >= mW - scW/2) posX = mW - scW; + if(playerX >= scW/2) + posX = playerX - scW/2; + + else + posX = 0; + + if(playerX >= mW - scW/2) + posX = mW - scW; } else posX = 0; -}; + + if(mH != scH){ + if(playerY >= scH/2) + posY = playerY - scH/2; + + else + posY = 0; + + if(playerY >= mH - scH/2) + posY = mH - scH; + } + else posY = 0; +} int Camera::getPosX(){ return posX; -}; +} int Camera::getPosY(){ return posY; -}; +} diff --git a/source/camera.h b/src/camera.h similarity index 100% rename from source/camera.h rename to src/camera.h diff --git a/source/core.cpp b/src/core.cpp similarity index 99% rename from source/core.cpp rename to src/core.cpp index effbb2a..a4c30bb 100644 --- a/source/core.cpp +++ b/src/core.cpp @@ -35,4 +35,4 @@ int Core::coreInit(){ close(); return 0; -}; +} diff --git a/source/core.h b/src/core.h similarity index 100% rename from source/core.h rename to src/core.h diff --git a/source/dt.cpp b/src/dt.cpp similarity index 97% rename from source/dt.cpp rename to src/dt.cpp index bddb6f1..51c1c1e 100644 --- a/source/dt.cpp +++ b/src/dt.cpp @@ -4,7 +4,7 @@ DeltaTime::DeltaTime(){ now = SDL_GetPerformanceCounter(); -}; +} float DeltaTime::getDt(){ last = now; @@ -14,4 +14,4 @@ float DeltaTime::getDt(){ if(dt > 0.15f) dt = 0.15f; return dt; -}; +} diff --git a/source/dt.h b/src/dt.h similarity index 100% rename from source/dt.h rename to src/dt.h diff --git a/source/entity/block.cpp b/src/entity/block.cpp similarity index 98% rename from source/entity/block.cpp rename to src/entity/block.cpp index 795f18c..489b029 100644 --- a/source/entity/block.cpp +++ b/src/entity/block.cpp @@ -7,11 +7,11 @@ Block::Block(int x,int y,int w,int h,SDL_Renderer* render, Player* ply){ type = 1; //Set the entity type (1 = block) rect = {x,y,w,h}; -}; +} /*void Block::printAndCheck(int dimensions[], int cameraX){ //Set the block's rect's dimensions and position - rect = {dimensions[0],dimensions[1],dimensions[2],dimensions[3]}; + rect = {dimensions[0],dimensions[1],dimensions[2],dimensions[3]} //Check if it collides with the player player->check(rect,type); @@ -22,7 +22,7 @@ Block::Block(int x,int y,int w,int h,SDL_Renderer* render, Player* ply){ //Set render color and render the rectangle SDL_SetRenderDrawColor(renderer,169,145,73,0xFF); SDL_RenderFillRect(renderer,&rect); -};*/ +}*/ void Block::printAndCheck(int cameraX){ //Check if it collides with the player @@ -36,4 +36,4 @@ void Block::printAndCheck(int cameraX){ SDL_RenderDrawRect(renderer,&rect);*/ rect.x += cameraX; -}; +} diff --git a/source/entity/block.h b/src/entity/block.h similarity index 100% rename from source/entity/block.h rename to src/entity/block.h diff --git a/source/entity/entity.cpp b/src/entity/entity.cpp similarity index 96% rename from source/entity/entity.cpp rename to src/entity/entity.cpp index e11f5f8..f3d26af 100644 --- a/source/entity/entity.cpp +++ b/src/entity/entity.cpp @@ -4,4 +4,4 @@ SDL_Rect Entity::getRectangle(){ return rect; -}; +} diff --git a/source/entity/entity.h b/src/entity/entity.h similarity index 100% rename from source/entity/entity.h rename to src/entity/entity.h diff --git a/source/entity/player.cpp b/src/entity/player.cpp similarity index 99% rename from source/entity/player.cpp rename to src/entity/player.cpp index 6d81fc8..112f57f 100644 --- a/source/entity/player.cpp +++ b/src/entity/player.cpp @@ -25,7 +25,7 @@ Player::Player(int x,int y, int lvlH, SDL_Renderer* render){ ply.setRenderer(renderer); loadMedia(); -}; +} int Player::print(int cameraX){ oldPosX = posX; @@ -53,7 +53,7 @@ int Player::print(int cameraX){ if(posY >= levelHeight) die(); return 0; -}; +} void Player::die(){ posX = initPosX; @@ -82,11 +82,11 @@ void Player::loadMedia(){ plyRun.h = szH; plyRun.x = szW*2; plyRun.y = 0; -}; +} int Player::intVelX(){ return static_cast(velocityX); -}; +} void Player::move(){ //float dt = dTime.getDt(); @@ -165,7 +165,7 @@ void Player::move(){ posY -= static_cast(y+0.5); -}; +} int Player::check(SDL_Rect rectA, int type){ //Initialize and reset collision type @@ -222,7 +222,7 @@ int Player::check(SDL_Rect rectA, int type){ } } - //Set and int-ize the position*/ + //Set and int-ize the position posX = static_cast(movX); posY = static_cast(movY); @@ -276,4 +276,4 @@ int Player::check(SDL_Rect rectA, int type){ } } return power; -}; +} diff --git a/source/entity/player.h b/src/entity/player.h similarity index 100% rename from source/entity/player.h rename to src/entity/player.h diff --git a/source/entity/powerup.cpp b/src/entity/powerup.cpp similarity index 99% rename from source/entity/powerup.cpp rename to src/entity/powerup.cpp index 619f31b..4bf04cc 100644 --- a/source/entity/powerup.cpp +++ b/src/entity/powerup.cpp @@ -19,7 +19,7 @@ SDL_RenderFillRect(*renderer,&cameraFix); } //posu->check(rect, type); -};*/ +}*/ Powerup::Powerup(int x,int y,SDL_Renderer* render, Player* ply){ renderer = render; //Set the renderer @@ -28,7 +28,7 @@ Powerup::Powerup(int x,int y,SDL_Renderer* render, Player* ply){ type = 2; //Set the entity type (2 = powerup) rect = {x,y,20,20};//Set the powerup's position and dimensions -}; +} void Powerup::printAndCheck(int cameraX){ //Check if it collides with the player @@ -44,4 +44,4 @@ void Powerup::printAndCheck(int cameraX){ //Change again the x position of rect rect.x += cameraX; } -}; +} diff --git a/source/entity/powerup.h b/src/entity/powerup.h similarity index 100% rename from source/entity/powerup.h rename to src/entity/powerup.h diff --git a/source/icon.rc b/src/icon.rc similarity index 100% rename from source/icon.rc rename to src/icon.rc diff --git a/source/main.cpp b/src/main.cpp similarity index 66% rename from source/main.cpp rename to src/main.cpp index 9380213..20ebb3e 100644 --- a/source/main.cpp +++ b/src/main.cpp @@ -5,7 +5,8 @@ Core core; -int main(int argc, char* args[]){ +//int main(int argc, char* args[]){ +int main(){ core.coreInit(); return 0; diff --git a/source/maps.cpp b/src/maps.cpp similarity index 96% rename from source/maps.cpp rename to src/maps.cpp index 5ee0ef1..06c4e48 100644 --- a/source/maps.cpp +++ b/src/maps.cpp @@ -25,7 +25,7 @@ Maps::Maps(SDL_Renderer* render){ blockTotal = 0; mapWidth = 0; mapHeight = 0; -}; +} Maps::~Maps(){ //Deallocate rows @@ -37,7 +37,7 @@ Maps::~Maps(){ //Free the music Mix_FreeMusic( gMusic ); gMusic = NULL; -}; +} int Maps::map(std::string mapName){ //Load map @@ -46,16 +46,17 @@ int Maps::map(std::string mapName){ mapWidth = sz*32; mapHeight = screenHeight; - +/* gMusic = Mix_LoadMUS( "assets/sapce-odyssey.ogg" ); if( gMusic == NULL ){ std::cout << "Failed to load beat music! SDL_mixer Error: " << Mix_GetError() << std::endl; } +*/ Texture level; level.setRenderer(renderer); - SDL_Color textColor = {0xFF,0xFF,0xFF}; - level.loadFromRendererText("level: dust3.map",textColor); + SDL_Color textColor = {0xFF,0xFF,0xFF,0xFF}; + level.loadFromRendererText("level: " + mapName,textColor); Texture sandCastle; sandCastle.setRenderer(renderer); @@ -93,7 +94,7 @@ int Maps::map(std::string mapName){ Block ground5(sz*31,0,sz*1,sz*8,renderer,&player); //Block ground(renderer,&player); - Mix_PlayMusic( gMusic, -1 ); + //Mix_PlayMusic( gMusic, -1 ); bool quit = false; SDL_Event e; @@ -142,11 +143,11 @@ int Maps::map(std::string mapName){ } musicQuit(); return -1; -}; +} void Maps::musicQuit(){ Mix_HaltMusic(); //Free the music Mix_FreeMusic( gMusic ); gMusic = NULL; -}; +} diff --git a/source/maps.h b/src/maps.h similarity index 100% rename from source/maps.h rename to src/maps.h diff --git a/src/menu.cpp b/src/menu.cpp new file mode 100644 index 0000000..ad5277f --- /dev/null +++ b/src/menu.cpp @@ -0,0 +1,131 @@ +#include "menu.h" + +class Button{ + public: + Button(int x,int y,int w,int h,SDL_Renderer* render,std::string buttonText); + void render(); + void hover(); + SDL_Rect getRect(); + private: + SDL_Rect buttonRect; + SDL_Rect textRect; + SDL_Renderer* renderer; + Texture text; + bool isHover; +}; + +Button::Button(int x,int y,int w,int h,SDL_Renderer* render,std::string buttonText){ + renderer = render; + buttonRect = {x,y,w,h}; + isHover = false; + + text.setRenderer(renderer); + SDL_Color textColor = {0xFF,0xFF,0xFF,0xFF}; + text.loadFromRendererText(buttonText,textColor); + + textRect = {x+(w/2)-text.getWidth()/2,y+(h/2)-text.getHeight()/2,text.getWidth(),text.getHeight()}; +} + +void Button::render(){ + if(isHover) SDL_SetRenderDrawColor(renderer,80,80,80,0xFF); + else SDL_SetRenderDrawColor(renderer,128,128,128,0xFF); + + SDL_RenderFillRect(renderer,&buttonRect); + text.render(&textRect); + isHover = false; +} + +void Button::hover(){ + isHover = true; +} + +SDL_Rect Button::getRect(){ + return buttonRect; +} + +int menu(SDL_Renderer* renderer){ + int SCREEN_WIDTH, SCREEN_HEIGHT; + SDL_GetRendererOutputSize(renderer,&SCREEN_WIDTH,&SCREEN_HEIGHT); + + bool quit = false; + SDL_Event e; + + Texture txLogo; + txLogo.setRenderer(renderer); + txLogo.loadTexture("textures/title.png"); + + int logoVmargin = 40; + + SDL_Rect logo = {(SCREEN_WIDTH/2)-txLogo.getWidth()/2,logoVmargin,txLogo.getWidth(),txLogo.getHeight()}; + + int btnSpc = SCREEN_HEIGHT - (logo.y + logo.h); + int buttonNum = 3; + int btnWidth = SCREEN_WIDTH/3; + int btnHeight = btnSpc/buttonNum/2; + int spc = (btnSpc-buttonNum*btnHeight)/(buttonNum+1); + + Button playBtn( + SCREEN_WIDTH/2 - btnWidth/2, + (1*spc + 0*btnHeight) + SCREEN_HEIGHT - btnSpc, + btnWidth, btnHeight, + renderer, + "play" + ); + Button optionsBtn(SCREEN_WIDTH/2-btnWidth/2,(2*spc+1*btnHeight)+SCREEN_HEIGHT-btnSpc,btnWidth,btnHeight,renderer,"options"); + Button quitBtn(SCREEN_WIDTH/2-btnWidth/2,(3*spc+2*btnHeight)+SCREEN_HEIGHT-btnSpc,btnWidth,btnHeight,renderer,"quit"); + + Texture txtVer; + txtVer.setRenderer(renderer); + SDL_Color txtVerColor = {0xFF,0xFF,0xFF,0xFF}; + txtVer.loadFromRendererText("Version 0.2",txtVerColor); + SDL_Rect txtVerRect = {10,SCREEN_HEIGHT-txtVer.getHeight()-10,txtVer.getWidth(),txtVer.getHeight()}; + + int select = 0; + bool wait = 0; + const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL); + + while(!quit){ + while(SDL_PollEvent(&e)!=0){ + if(e.type == SDL_QUIT){ + quit = true; + } + } + SDL_SetRenderDrawColor(renderer,100,200,200,0xFF); + SDL_RenderClear(renderer); + + int dir = 0; + if(currentKeyStates[SDL_SCANCODE_UP]) dir--; + if(currentKeyStates[SDL_SCANCODE_DOWN])dir++; + + if(dir != 0){ + if(!wait) select += dir; + wait = true; + } + else wait = false; + + if(select >= buttonNum) select = 0; + if(select < 0) select = buttonNum-1; + + txLogo.render(&logo); + + if(currentKeyStates[SDL_SCANCODE_SPACE]){ + if(select == 0) return 1; + else if(select == 1) return 0; + else if(select == 2) break; + } + + if(select == 0) playBtn.hover(); + else if(select == 1) optionsBtn.hover(); + else quitBtn.hover(); + + playBtn.render(); + optionsBtn.render(); + quitBtn.render(); + + txtVer.render(&txtVerRect); + + SDL_RenderPresent(renderer); + } + + return -1; +} diff --git a/source/menu.h b/src/menu.h similarity index 100% rename from source/menu.h rename to src/menu.h diff --git a/source/texture.cpp b/src/texture.cpp similarity index 98% rename from source/texture.cpp rename to src/texture.cpp index a469537..9ecbe72 100644 --- a/source/texture.cpp +++ b/src/texture.cpp @@ -13,12 +13,12 @@ Texture::Texture(){ if(TTF_Init() == -1) std::cout << TTF_GetError() << std::endl; font = TTF_OpenFont("cooper-hewitt-medium.otf",30); -}; +} void Texture::setRenderer(SDL_Renderer* render){ //Set renderer renderer = render; -}; +} Texture::~Texture(){ //Deallocate the texture when the class closes @@ -26,7 +26,7 @@ Texture::~Texture(){ IMG_Quit(); TTF_Quit(); -}; +} void Texture::loadTexture(std::string path){ //Get rid of preexisting texture @@ -54,7 +54,7 @@ void Texture::loadTexture(std::string path){ //Get rid of old loaded surface SDL_FreeSurface(loadedSurface); } -}; +} bool Texture::loadFromRendererText(std::string textureText, SDL_Color textColor){ //Get rid of preexisting texture @@ -97,19 +97,19 @@ void Texture::free(){ szW = 0; szH = 0; } -}; +} void Texture::render(SDL_Rect* quad,SDL_Rect* frame){ //Render the texture SDL_RenderCopy(renderer,texture,frame,quad); -}; +} void Texture::render(SDL_Rect* quad){ //Make a frame of the size of the quad SDL_Rect frame = {0,0,quad->w,quad->h}; //Render the texture SDL_RenderCopy(renderer,texture,&frame,quad); -}; +} void Texture::render(SDL_Rect* quad, int cameraX){ //Make a frame of the size of the quad @@ -121,7 +121,7 @@ void Texture::render(SDL_Rect* quad, int cameraX){ SDL_RenderCopy(renderer,texture,&frame,quad); quad->x = quad->x + cameraX; -}; +} void Texture::render(SDL_Rect* quad, int cameraX,float parallax){ //Make a frame of the size of the quad @@ -133,7 +133,7 @@ void Texture::render(SDL_Rect* quad, int cameraX,float parallax){ SDL_RenderCopy(renderer,texture,&frame,quad); quad->x = quad->x + cameraX * parallax; -}; +} /*void Texture::render(SDL_Rect* quad, int cameraX,int parallax, int vel){ //Make a frame of the size of the quad @@ -157,12 +157,12 @@ void Texture::render(SDL_Rect* quad, int cameraX,float parallax){ SDL_RenderCopy(renderer,texture,&frame,quad); quad->x += cameraX / parallax; -};*/ +}*/ int Texture::getWidth(){ return szW; -}; +} int Texture::getHeight(){ return szH; -}; +} diff --git a/source/texture.h b/src/texture.h similarity index 100% rename from source/texture.h rename to src/texture.h diff --git a/zlib1.dll b/zlib1.dll deleted file mode 100644 index 68a8bf7..0000000 Binary files a/zlib1.dll and /dev/null differ