Update to CMAKE and put version name in the main menu

It needed it really bad
This commit is contained in:
Pòsweg Blumenthal 2019-07-30 17:52:47 +02:00
parent a852169f7d
commit 68945d0e33
48 changed files with 938 additions and 331 deletions

62
CMakeLists.txt Normal file
View File

@ -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})

View File

@ -1,20 +0,0 @@
/*
SDL_image: An example image loading library for use with SDL
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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.
*/

View File

@ -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

View File

@ -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.

View File

@ -22,11 +22,19 @@ So far I have implemented a regular platformer, with its player, player physics,
## Compiling ## 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 <SDL.h> and <SDL_image.h> to <SDL2/SDL.h> and <SDL2/SDL_Image.h>. 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 ## References

BIN
SDL2.dll

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

255
cmake/FindSDL2.cmake Normal file
View File

@ -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 <SDL2/SDL.h>. 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)

158
cmake/FindSDL2_image.cmake Normal file
View File

@ -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 <SDL2/SDL.h>. 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)

100
cmake/FindSDL2_mixer.cmake Normal file
View File

@ -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)

157
cmake/FindSDL2_ttf.cmake Normal file
View File

@ -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 <SDL2/SDL.h>. 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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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;
}

BIN
src/.maps.cpp.swp Normal file

Binary file not shown.

View File

@ -12,17 +12,34 @@ Camera::Camera(int mapWidth, int mapHeight,int screenWidth, int screenHeight){
void Camera::update(int playerX, int playerY){ void Camera::update(int playerX, int playerY){
//Make the camera move when the player hits the middle of the screen //Make the camera move when the player hits the middle of the screen
if(mW != scW){ if(mW != scW){
if(playerX >= scW/2) posX = playerX - scW/2; if(playerX >= scW/2)
else posX = 0; posX = playerX - scW/2;
if(playerX >= mW - scW/2) posX = mW - scW;
else
posX = 0;
if(playerX >= mW - scW/2)
posX = mW - scW;
} }
else posX = 0; 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(){ int Camera::getPosX(){
return posX; return posX;
}; }
int Camera::getPosY(){ int Camera::getPosY(){
return posY; return posY;
}; }

View File

@ -35,4 +35,4 @@ int Core::coreInit(){
close(); close();
return 0; return 0;
}; }

View File

@ -4,7 +4,7 @@
DeltaTime::DeltaTime(){ DeltaTime::DeltaTime(){
now = SDL_GetPerformanceCounter(); now = SDL_GetPerformanceCounter();
}; }
float DeltaTime::getDt(){ float DeltaTime::getDt(){
last = now; last = now;
@ -14,4 +14,4 @@ float DeltaTime::getDt(){
if(dt > 0.15f) dt = 0.15f; if(dt > 0.15f) dt = 0.15f;
return dt; return dt;
}; }

View File

@ -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) type = 1; //Set the entity type (1 = block)
rect = {x,y,w,h}; rect = {x,y,w,h};
}; }
/*void Block::printAndCheck(int dimensions[], int cameraX){ /*void Block::printAndCheck(int dimensions[], int cameraX){
//Set the block's rect's dimensions and position //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 //Check if it collides with the player
player->check(rect,type); 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 //Set render color and render the rectangle
SDL_SetRenderDrawColor(renderer,169,145,73,0xFF); SDL_SetRenderDrawColor(renderer,169,145,73,0xFF);
SDL_RenderFillRect(renderer,&rect); SDL_RenderFillRect(renderer,&rect);
};*/ }*/
void Block::printAndCheck(int cameraX){ void Block::printAndCheck(int cameraX){
//Check if it collides with the player //Check if it collides with the player
@ -36,4 +36,4 @@ void Block::printAndCheck(int cameraX){
SDL_RenderDrawRect(renderer,&rect);*/ SDL_RenderDrawRect(renderer,&rect);*/
rect.x += cameraX; rect.x += cameraX;
}; }

View File

@ -4,4 +4,4 @@
SDL_Rect Entity::getRectangle(){ SDL_Rect Entity::getRectangle(){
return rect; return rect;
}; }

View File

@ -25,7 +25,7 @@ Player::Player(int x,int y, int lvlH, SDL_Renderer* render){
ply.setRenderer(renderer); ply.setRenderer(renderer);
loadMedia(); loadMedia();
}; }
int Player::print(int cameraX){ int Player::print(int cameraX){
oldPosX = posX; oldPosX = posX;
@ -53,7 +53,7 @@ int Player::print(int cameraX){
if(posY >= levelHeight) die(); if(posY >= levelHeight) die();
return 0; return 0;
}; }
void Player::die(){ void Player::die(){
posX = initPosX; posX = initPosX;
@ -82,11 +82,11 @@ void Player::loadMedia(){
plyRun.h = szH; plyRun.h = szH;
plyRun.x = szW*2; plyRun.x = szW*2;
plyRun.y = 0; plyRun.y = 0;
}; }
int Player::intVelX(){ int Player::intVelX(){
return static_cast<int>(velocityX); return static_cast<int>(velocityX);
}; }
void Player::move(){ void Player::move(){
//float dt = dTime.getDt(); //float dt = dTime.getDt();
@ -165,7 +165,7 @@ void Player::move(){
posY -= static_cast<int>(y+0.5); posY -= static_cast<int>(y+0.5);
}; }
int Player::check(SDL_Rect rectA, int type){ int Player::check(SDL_Rect rectA, int type){
//Initialize and reset collision 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<int>(movX); posX = static_cast<int>(movX);
posY = static_cast<int>(movY); posY = static_cast<int>(movY);
@ -276,4 +276,4 @@ int Player::check(SDL_Rect rectA, int type){
} }
} }
return power; return power;
}; }

View File

@ -19,7 +19,7 @@
SDL_RenderFillRect(*renderer,&cameraFix); SDL_RenderFillRect(*renderer,&cameraFix);
} }
//posu->check(rect, type); //posu->check(rect, type);
};*/ }*/
Powerup::Powerup(int x,int y,SDL_Renderer* render, Player* ply){ Powerup::Powerup(int x,int y,SDL_Renderer* render, Player* ply){
renderer = render; //Set the renderer 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) type = 2; //Set the entity type (2 = powerup)
rect = {x,y,20,20};//Set the powerup's position and dimensions rect = {x,y,20,20};//Set the powerup's position and dimensions
}; }
void Powerup::printAndCheck(int cameraX){ void Powerup::printAndCheck(int cameraX){
//Check if it collides with the player //Check if it collides with the player
@ -44,4 +44,4 @@ void Powerup::printAndCheck(int cameraX){
//Change again the x position of rect //Change again the x position of rect
rect.x += cameraX; rect.x += cameraX;
} }
}; }

View File

@ -5,7 +5,8 @@
Core core; Core core;
int main(int argc, char* args[]){ //int main(int argc, char* args[]){
int main(){
core.coreInit(); core.coreInit();
return 0; return 0;

View File

@ -25,7 +25,7 @@ Maps::Maps(SDL_Renderer* render){
blockTotal = 0; blockTotal = 0;
mapWidth = 0; mapWidth = 0;
mapHeight = 0; mapHeight = 0;
}; }
Maps::~Maps(){ Maps::~Maps(){
//Deallocate rows //Deallocate rows
@ -37,7 +37,7 @@ Maps::~Maps(){
//Free the music //Free the music
Mix_FreeMusic( gMusic ); Mix_FreeMusic( gMusic );
gMusic = NULL; gMusic = NULL;
}; }
int Maps::map(std::string mapName){ int Maps::map(std::string mapName){
//Load map //Load map
@ -46,16 +46,17 @@ int Maps::map(std::string mapName){
mapWidth = sz*32; mapWidth = sz*32;
mapHeight = screenHeight; mapHeight = screenHeight;
/*
gMusic = Mix_LoadMUS( "assets/sapce-odyssey.ogg" ); gMusic = Mix_LoadMUS( "assets/sapce-odyssey.ogg" );
if( gMusic == NULL ){ if( gMusic == NULL ){
std::cout << "Failed to load beat music! SDL_mixer Error: " << Mix_GetError() << std::endl; std::cout << "Failed to load beat music! SDL_mixer Error: " << Mix_GetError() << std::endl;
} }
*/
Texture level; Texture level;
level.setRenderer(renderer); level.setRenderer(renderer);
SDL_Color textColor = {0xFF,0xFF,0xFF}; SDL_Color textColor = {0xFF,0xFF,0xFF,0xFF};
level.loadFromRendererText("level: dust3.map",textColor); level.loadFromRendererText("level: " + mapName,textColor);
Texture sandCastle; Texture sandCastle;
sandCastle.setRenderer(renderer); 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 ground5(sz*31,0,sz*1,sz*8,renderer,&player);
//Block ground(renderer,&player); //Block ground(renderer,&player);
Mix_PlayMusic( gMusic, -1 ); //Mix_PlayMusic( gMusic, -1 );
bool quit = false; bool quit = false;
SDL_Event e; SDL_Event e;
@ -142,11 +143,11 @@ int Maps::map(std::string mapName){
} }
musicQuit(); musicQuit();
return -1; return -1;
}; }
void Maps::musicQuit(){ void Maps::musicQuit(){
Mix_HaltMusic(); Mix_HaltMusic();
//Free the music //Free the music
Mix_FreeMusic( gMusic ); Mix_FreeMusic( gMusic );
gMusic = NULL; gMusic = NULL;
}; }

131
src/menu.cpp Normal file
View File

@ -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;
}

View File

@ -13,12 +13,12 @@ Texture::Texture(){
if(TTF_Init() == -1) std::cout << TTF_GetError() << std::endl; if(TTF_Init() == -1) std::cout << TTF_GetError() << std::endl;
font = TTF_OpenFont("cooper-hewitt-medium.otf",30); font = TTF_OpenFont("cooper-hewitt-medium.otf",30);
}; }
void Texture::setRenderer(SDL_Renderer* render){ void Texture::setRenderer(SDL_Renderer* render){
//Set renderer //Set renderer
renderer = render; renderer = render;
}; }
Texture::~Texture(){ Texture::~Texture(){
//Deallocate the texture when the class closes //Deallocate the texture when the class closes
@ -26,7 +26,7 @@ Texture::~Texture(){
IMG_Quit(); IMG_Quit();
TTF_Quit(); TTF_Quit();
}; }
void Texture::loadTexture(std::string path){ void Texture::loadTexture(std::string path){
//Get rid of preexisting texture //Get rid of preexisting texture
@ -54,7 +54,7 @@ void Texture::loadTexture(std::string path){
//Get rid of old loaded surface //Get rid of old loaded surface
SDL_FreeSurface(loadedSurface); SDL_FreeSurface(loadedSurface);
} }
}; }
bool Texture::loadFromRendererText(std::string textureText, SDL_Color textColor){ bool Texture::loadFromRendererText(std::string textureText, SDL_Color textColor){
//Get rid of preexisting texture //Get rid of preexisting texture
@ -97,19 +97,19 @@ void Texture::free(){
szW = 0; szW = 0;
szH = 0; szH = 0;
} }
}; }
void Texture::render(SDL_Rect* quad,SDL_Rect* frame){ void Texture::render(SDL_Rect* quad,SDL_Rect* frame){
//Render the texture //Render the texture
SDL_RenderCopy(renderer,texture,frame,quad); SDL_RenderCopy(renderer,texture,frame,quad);
}; }
void Texture::render(SDL_Rect* quad){ void Texture::render(SDL_Rect* quad){
//Make a frame of the size of the quad //Make a frame of the size of the quad
SDL_Rect frame = {0,0,quad->w,quad->h}; SDL_Rect frame = {0,0,quad->w,quad->h};
//Render the texture //Render the texture
SDL_RenderCopy(renderer,texture,&frame,quad); SDL_RenderCopy(renderer,texture,&frame,quad);
}; }
void Texture::render(SDL_Rect* quad, int cameraX){ void Texture::render(SDL_Rect* quad, int cameraX){
//Make a frame of the size of the quad //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); SDL_RenderCopy(renderer,texture,&frame,quad);
quad->x = quad->x + cameraX; quad->x = quad->x + cameraX;
}; }
void Texture::render(SDL_Rect* quad, int cameraX,float parallax){ void Texture::render(SDL_Rect* quad, int cameraX,float parallax){
//Make a frame of the size of the quad //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); SDL_RenderCopy(renderer,texture,&frame,quad);
quad->x = quad->x + cameraX * parallax; quad->x = quad->x + cameraX * parallax;
}; }
/*void Texture::render(SDL_Rect* quad, int cameraX,int parallax, int vel){ /*void Texture::render(SDL_Rect* quad, int cameraX,int parallax, int vel){
//Make a frame of the size of the quad //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); SDL_RenderCopy(renderer,texture,&frame,quad);
quad->x += cameraX / parallax; quad->x += cameraX / parallax;
};*/ }*/
int Texture::getWidth(){ int Texture::getWidth(){
return szW; return szW;
}; }
int Texture::getHeight(){ int Texture::getHeight(){
return szH; return szH;
}; }

BIN
zlib1.dll

Binary file not shown.