Added game map drawing.
This commit is contained in:
commit
692e9de011
16 changed files with 860 additions and 0 deletions
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
project(Bob CXX)
|
||||
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
|
||||
set(CMAKE_C_COMPILER /usr/bin/clang)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(SDL2_gfx REQUIRED)
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
include_directories(include ${SDL2_INCLUDE_DIR} ${SDL2GFX_INCLUDE_DIR} ${BOOST_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
9
LICENSE
Normal file
9
LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Tim Schubert
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
255
cmake/FindSDL2.cmake
Normal file
255
cmake/FindSDL2.cmake
Normal 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)
|
||||
|
163
cmake/FindSDL2_gfx.cmake
Normal file
163
cmake/FindSDL2_gfx.cmake
Normal file
|
@ -0,0 +1,163 @@
|
|||
# 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 SDL2main 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 SDLmain.h and SDLmain.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.
|
||||
#
|
||||
#
|
||||
# $SDL2DIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$SDL2DIR
|
||||
# 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" SDL 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" SDL 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).
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2003-2009 Kitware, Inc.
|
||||
#
|
||||
# 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.)
|
||||
|
||||
SET(SDL2GFX_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_PATH(SDL2GFX_INCLUDE_DIR SDL2_gfxPrimitives.h
|
||||
HINTS
|
||||
$ENV{SDL2GFXDIR}
|
||||
PATH_SUFFIXES include/SDL2 include
|
||||
PATHS ${SDL2GFX_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(SDL2GFX_LIBRARY_TEMP
|
||||
NAMES SDL2_gfx
|
||||
HINTS
|
||||
$ENV{SDL2GFXDIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS ${SDL2GFX_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF (NOT SDL2GFX_BUILDING_LIBRARY)
|
||||
IF (NOT ${SDL2GFX_INCLUDE_DIR} MATCHES ".framework")
|
||||
# Non-OS X framework versions expect you to also dynamically link to
|
||||
# SDL2GFXmain. This is mainly for Windows and OS X. Other (Unix) platforms
|
||||
# seem to provide SDL2GFXmain for compatibility even though they don't
|
||||
# necessarily need it.
|
||||
FIND_LIBRARY(SDL2GFXMAIN_LIBRARY
|
||||
NAMES SDL2_gfx
|
||||
HINTS
|
||||
$ENV{SDL2GFXDIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS ${SDL2GFX_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF (NOT ${SDL2GFX_INCLUDE_DIR} MATCHES ".framework")
|
||||
ENDIF (NOT SDL2GFX_BUILDING_LIBRARY)
|
||||
|
||||
# SDL2GFX 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 -lSDL2GFXmain -lSDL2GFX -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)
|
||||
|
||||
IF (SDL2GFX_LIBRARY_TEMP)
|
||||
# For SDL2GFXmain
|
||||
IF (NOT SDL2GFX_BUILDING_LIBRARY)
|
||||
IF (SDL2GFXMAIN_LIBRARY)
|
||||
SET(SDL2GFX_LIBRARY_TEMP ${SDL2GFXMAIN_LIBRARY} ${SDL2GFX_LIBRARY_TEMP})
|
||||
ENDIF (SDL2GFXMAIN_LIBRARY)
|
||||
ENDIF (NOT SDL2GFX_BUILDING_LIBRARY)
|
||||
|
||||
# For OS X, SDL2GFX 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(SDL2GFX_LIBRARY_TEMP ${SDL2GFX_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(SDL2GFX_LIBRARY_TEMP ${SDL2GFX_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
|
||||
ENDIF (NOT APPLE)
|
||||
|
||||
# For MinGW library
|
||||
IF (MINGW)
|
||||
SET(SDL2GFX_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2GFX_LIBRARY_TEMP})
|
||||
ENDIF (MINGW)
|
||||
|
||||
# Set the final string here so the GUI reflects the final state.
|
||||
SET(SDL2GFX_LIBRARY ${SDL2GFX_LIBRARY_TEMP} CACHE STRING "Where the SDL2GFX Library can be found")
|
||||
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
|
||||
SET(SDL2GFX_LIBRARY_TEMP "${SDL2GFX_LIBRARY_TEMP}" CACHE INTERNAL "")
|
||||
ENDIF (SDL2GFX_LIBRARY_TEMP)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2GFX REQUIRED_VARS SDL2GFX_LIBRARY SDL2GFX_INCLUDE_DIR)
|
3
include/Bob/CMakeLists.txt
Normal file
3
include/Bob/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
set(LIBRARY_NAME
|
||||
Bob
|
||||
)
|
1
include/CMakeLists.txt
Normal file
1
include/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
include_directories(Bob)
|
3
src/CMakeLists.txt
Normal file
3
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
add_executable(Bob Main.cpp)
|
||||
add_library(GameMap GameMap.cpp)
|
||||
target_link_libraries(Bob GameMap ${SDL2_LIBRARY} ${SDL2GFX_LIBRARY} ${Boost_LIBRARIES})
|
0
src/Field.cpp
Normal file
0
src/Field.cpp
Normal file
123
src/GameMap.cpp
Normal file
123
src/GameMap.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "GameMap.hpp"
|
||||
|
||||
bool operator==(Field left, Field right) {
|
||||
return left.x == right.x && left.y == right.y;
|
||||
}
|
||||
|
||||
bool operator!=(Field left, Field right) {
|
||||
return left == right;
|
||||
}
|
||||
|
||||
Field operator+(Field left, Field right) {
|
||||
return Field(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
}
|
||||
|
||||
Field operator-(Field left, Field right) {
|
||||
return Field(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
}
|
||||
|
||||
Field operator*(Field left, Field right) {
|
||||
return Field(left.x * right.x, left.y * right.y, left.z * right.z);
|
||||
}
|
||||
|
||||
Field operator/(Field left, Field right) {
|
||||
return cubic_round(left.x / right.x, left.y / right.y, right.z / left.z);
|
||||
}
|
||||
|
||||
Field cubic_round(double x, double y, double z) {
|
||||
int8_t round_x = (int8_t) std::round(x);
|
||||
int8_t round_y = (int8_t) std::round(y);
|
||||
int8_t round_z = (int8_t) std::round(z);
|
||||
double x_err = std::abs(round_x - x);
|
||||
double y_err = std::abs(round_y - y);
|
||||
double z_err = std::abs(round_z - z);
|
||||
if (x_err > y_err && x_err > z_err) {
|
||||
round_x = -round_y - round_z;
|
||||
} else if (y_err > z_err) {
|
||||
round_y = -round_x - round_z;
|
||||
} else {
|
||||
round_z = -round_x - round_y;
|
||||
}
|
||||
return Field(round_x, round_y, round_z);
|
||||
}
|
||||
|
||||
int cubic_distance(Field a, Field b) {
|
||||
return (abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z)) / 2;
|
||||
}
|
||||
|
||||
Field hex_direction(int direction) {
|
||||
assert (0 <= direction && direction <= 5);
|
||||
return hex_directions[direction];
|
||||
}
|
||||
|
||||
Field hex_neighbor(int8_t direction, Field f) {
|
||||
return hex_direction(direction) + f;
|
||||
}
|
||||
|
||||
Point field_to_point(const Field *f, const Layout *layout) {
|
||||
const Orientation m = layout->orientation;
|
||||
double x = (m.f0 * f->x + m.f1 * f->y) * layout->size;
|
||||
double y = (m.f2 * f->x + m.f3 * f->y) * layout->size;
|
||||
return Point(x + layout->origin.x, y + layout->origin.y);
|
||||
}
|
||||
|
||||
Field point_to_field(Point point, const Layout *layout) {
|
||||
const Orientation m = layout->orientation;
|
||||
double rel_x = (point.x - layout->origin.x) / layout->size;
|
||||
double rel_y = (point.y - layout->origin.y) / layout->size;
|
||||
double x = m.b0 * rel_x + m.b1 * rel_y;
|
||||
double y = m.b2 * rel_x + m.b3 * rel_y;
|
||||
return cubic_round(x, y, -x - y);
|
||||
}
|
||||
|
||||
Point field_corner_offset(uint8_t corner, const Layout *layout) {
|
||||
double angle = 2.0 * M_PI * (corner + layout->orientation.start_angle) / 6;
|
||||
return Point(layout->size * cos(angle), layout->size * sin(angle));
|
||||
|
||||
//uint8_t i = (uint8_t) ((corner + layout->orientation.start_corner) % 6);
|
||||
//return Point(layout->size * COS_ANGLES_HEX[i], layout->size * SIN_ANGLES_HEX[i]);
|
||||
}
|
||||
|
||||
std::vector<Point> field_to_polygon(const Field *field, const Layout *layout) {
|
||||
std::vector<Point> corners = {};
|
||||
Point center = field_to_point(field, layout);
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
Point offset = field_corner_offset(i, layout);
|
||||
corners.push_back(Point(center.x + offset.x, center.y + offset.y));
|
||||
}
|
||||
return corners;
|
||||
}
|
||||
|
||||
Grid::Grid() {
|
||||
this->fields = std::unordered_set<Field>();
|
||||
}
|
||||
|
||||
HexagonGrid::HexagonGrid(Sint16 grid_radius)
|
||||
: Grid() {
|
||||
// first lower half, then upper half
|
||||
for (Sint16 x = -grid_radius; x <= grid_radius; x++) {
|
||||
Sint16 y_l = (-grid_radius > -x - grid_radius) ? -grid_radius : -x - grid_radius;
|
||||
Sint16 y_u = (grid_radius < -x + grid_radius) ? grid_radius : -x + grid_radius;
|
||||
for (Sint16 y = y_l; y <= y_u; y++) {
|
||||
Sint16 z = -x - y;
|
||||
this->fields.insert({x, y, z});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HexagonGrid::render(SDL_Renderer *renderer, const SDL_Color color, const Layout *layout) {
|
||||
for (const Field &elem : this->fields) {
|
||||
std::vector<Point> polygon = field_to_polygon(&elem, layout);
|
||||
assert(polygon.size() > 5);
|
||||
Sint16 vx[6];
|
||||
Sint16 vy[6];
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
vx[i] = (Sint16) polygon[i].x;
|
||||
vy[i] = (Sint16) polygon[i].y;
|
||||
}
|
||||
const Sint16 x[6] = {vx[0], vx[1], vx[2], vx[3], vx[4], vx[5]};
|
||||
const Sint16 y[6] = {vy[0], vy[1], vy[2], vy[3], vy[4], vy[5]};
|
||||
aapolygonRGBA(renderer, x, y, 6, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
return true;
|
||||
}
|
133
src/GameMap.hpp
Normal file
133
src/GameMap.hpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <unordered_set>
|
||||
#include "Player.hpp"
|
||||
|
||||
#ifndef Point
|
||||
|
||||
struct Point {
|
||||
double x;
|
||||
double y;
|
||||
|
||||
Point(double x_, double y_) : x(x_), y(y_) { }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef Orientation
|
||||
|
||||
struct Orientation {
|
||||
// cubic to point
|
||||
const double f0, f1, f2, f3;
|
||||
// point to cubic
|
||||
const double b0, b1, b2, b3;
|
||||
// in multiples of 60 deg
|
||||
const double start_angle;
|
||||
|
||||
Orientation(double f0_, double f1_, double f2_, double f3_, double b0_, double b1_, double b2_, double b3_,
|
||||
double start_angle_)
|
||||
: f0(f0_), f1(f1_), f2(f2_), f3(f3_), b0(b0_), b1(b1_), b2(b2_), b3(b3_),
|
||||
start_angle(start_angle_) { }
|
||||
};
|
||||
|
||||
const Orientation pointy_orientation = Orientation(sqrt(3.0), sqrt(3.0) / 2.0, 0.0, 3.0 / 2.0,
|
||||
sqrt(3.0) / 3.0, -1.0 / 3.0, 0.0, 2.0 / 3.0,
|
||||
0.5);
|
||||
const Orientation flat_orientation = Orientation(3.0 / 2.0, 0.0, sqrt(3.0) / 2.0, sqrt(3.0),
|
||||
2.0 / 3.0, 0.0, -1.0 / 3.0, sqrt(3.0) / 3.0,
|
||||
0);
|
||||
#endif
|
||||
|
||||
#ifndef Layout
|
||||
|
||||
struct Layout {
|
||||
const Orientation orientation;
|
||||
const double size;
|
||||
const SDL_Point origin;
|
||||
|
||||
Layout(Orientation orientation_, double size_, SDL_Point origin_)
|
||||
: orientation(orientation_), size(size_), origin(origin_) { }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef Field
|
||||
|
||||
struct Field {
|
||||
const Sint16 x, y, z;
|
||||
|
||||
Field(Sint16 x_, Sint16 y_, Sint16 z_) : x(x_), y(y_), z(z_) {
|
||||
assert(x + y + z == 0);
|
||||
}
|
||||
};
|
||||
|
||||
// from upper right corner
|
||||
const std::vector<Field> hex_directions = {
|
||||
Field(1, 0, -1), Field(0, 1, -1), Field(-1, 1, 0), Field(-1, 0, 1), Field(-1, 1, 0)
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<Field> {
|
||||
size_t operator()(const Field &f) const {
|
||||
hash<Sint16> int_hash;
|
||||
size_t hx = int_hash(f.x);
|
||||
size_t hy = int_hash(f.y);
|
||||
// hz would be redundant, since f.z is redundant
|
||||
// combine hashes
|
||||
return hx ^ (hy + 0x9e3779b9 + (hx << 6) + (hx >> 2));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Field cubic_round(double x, double y, double z);
|
||||
|
||||
int cubic_distance(Field a, Field b);
|
||||
|
||||
bool operator==(Field left, Field right);
|
||||
|
||||
bool operator!=(Field left, Field right);
|
||||
|
||||
Field operator+(Field left, Field right);
|
||||
|
||||
Field operator-(Field left, Field right);
|
||||
|
||||
Field operator*(Field left, Field right);
|
||||
|
||||
Field operator/(Field left, Field right);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Point field_to_point(const Field *f, const Layout *layout);
|
||||
|
||||
Field point_to_field(Point point, const Layout *layout);
|
||||
|
||||
Point field_corner_offset(Uint8 corner, const Layout *layout);
|
||||
|
||||
std::vector<Point> field_to_polygon(const Field *field, const Layout *layout);
|
||||
|
||||
#ifndef Grid
|
||||
|
||||
class Grid {
|
||||
protected:
|
||||
std::unordered_set<Field> fields;
|
||||
public:
|
||||
Grid();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HexagonGrid
|
||||
|
||||
class HexagonGrid : public Grid {
|
||||
public:
|
||||
HexagonGrid(Sint16 grid_radius);
|
||||
|
||||
bool render(SDL_Renderer *renderer, const SDL_Color color, const Layout *layout);
|
||||
};
|
||||
|
||||
#endif
|
104
src/Main.cpp
Normal file
104
src/Main.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
#include <string>
|
||||
#include "Main.hpp"
|
||||
|
||||
void logSDLError(std::ostream &os, const std::string &msg) {
|
||||
os << msg << " error:" << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
SDL_Window *init_window() {
|
||||
SDL_Window *window = SDL_CreateWindow("Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
|
||||
if (window == NULL) {
|
||||
logSDLError(std::cout, "SDL_CreateWindow");
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
SDL_Renderer *init_renderer(SDL_Window *window) {
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (renderer == NULL) {
|
||||
logSDLError(std::cout, "SDL_CreateRenderer");
|
||||
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
SDL_Surface *init_surface(int width, int height) {
|
||||
|
||||
//SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32, rmask, gmask, bmask, amask);
|
||||
SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
|
||||
if (surface == NULL) {
|
||||
logSDLError(std::cout, "SDL_CreateSurface");
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
SDL_Texture *init_texture(SDL_Renderer *renderer, SDL_Surface *surface) {
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
if (texture == NULL) {
|
||||
logSDLError(std::cout, "SDL_CreateTexture");
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
int main(int, char **) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
logSDLError(std::cout, "SDL_init");
|
||||
return 1;
|
||||
}
|
||||
SDL_Window *window = init_window();
|
||||
if (!window) {
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
SDL_Renderer *renderer = init_renderer(window);
|
||||
if (!renderer) {
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
SDL_Surface *surface = init_surface(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
if (!surface) {
|
||||
SDL_FreeSurface(surface);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
SDL_Texture *texture = init_texture(renderer, surface);
|
||||
if (!texture) {
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_FreeSurface(surface);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
const SDL_Point center = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
|
||||
const Layout standard = Layout(pointy_orientation, 20.0, center);
|
||||
const SDL_Color color = {0, 255, 255, 255};
|
||||
HexagonGrid *grid = new HexagonGrid(4);
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
quit = true;
|
||||
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
|
||||
grid->render(renderer, color, &standard);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
delete grid;
|
||||
return 0;
|
||||
}
|
27
src/Main.hpp
Normal file
27
src/Main.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <SDL2/SDL.h>
|
||||
#include "GameMap.hpp"
|
||||
|
||||
#ifndef DATA_PATH
|
||||
#endif
|
||||
#ifndef SCREEN_WIDTH
|
||||
const int SCREEN_WIDTH = 800;
|
||||
#endif
|
||||
#ifndef SCREEN_HEIGHT
|
||||
const int SCREEN_HEIGHT = 800;
|
||||
#endif
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
Uint32 rmask = 0xff000000;
|
||||
Uint32 gmask = 0x00ff0000;
|
||||
Uint32 bmask = 0x0000ff00;
|
||||
Uint32 amask = 0x000000ff;
|
||||
#else
|
||||
Uint32 rmask = 0x000000ff;
|
||||
Uint32 gmask = 0x0000ff00;
|
||||
Uint32 bmask = 0x00ff0000;
|
||||
Uint32 amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
|
0
src/Player.cpp
Normal file
0
src/Player.cpp
Normal file
0
src/Player.hpp
Normal file
0
src/Player.hpp
Normal file
0
src/Upgrades.cpp
Normal file
0
src/Upgrades.cpp
Normal file
19
src/Upgrades.hpp
Normal file
19
src/Upgrades.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifndef Upgrade
|
||||
|
||||
class Upgrade {
|
||||
SDL_Color color;
|
||||
public:
|
||||
static Upgrade *Instance();
|
||||
|
||||
private:
|
||||
Upgrade() { };
|
||||
|
||||
Upgrade(Upgrade const &) { };
|
||||
|
||||
Upgrade &operator=(Upgrade const &) { };
|
||||
static Upgrade *m_pInstance;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue