mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 15:53:42 +00:00
Added interface for game functions
This commit is contained in:
parent
efd8cc6616
commit
b6854c79ec
@ -1,13 +1,13 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
project(SDL_Minigame)
|
project(engine)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
set(ENGINE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
|
set(ENGINE_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
|
||||||
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
set(ENGINE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(BUILD_SHARED_LIBS FALSE)
|
set(BUILD_SHARED_LIBS FALSE)
|
||||||
@ -15,17 +15,19 @@ set(BUILD_SHARED_LIBS FALSE)
|
|||||||
set(SDL2MIXER_VENDORED ON)
|
set(SDL2MIXER_VENDORED ON)
|
||||||
set(SDL2TTF_VENDORED ON)
|
set(SDL2TTF_VENDORED ON)
|
||||||
|
|
||||||
|
set(SDL2_SOURCE_DIR “${ENGINE_SOURCE_DIR}/extern/SDL”)
|
||||||
|
|
||||||
add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
|
add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
|
add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL)
|
add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL)
|
add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp)
|
||||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
add_library(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR})
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL functionality has a wrapper
|
||||||
SDL2::SDL2main
|
SDL2::SDL2main
|
||||||
SDL2::SDL2-static
|
SDL2::SDL2-static
|
||||||
SDL2_image::SDL2_image-static
|
SDL2_image::SDL2_image-static
|
||||||
@ -37,6 +39,3 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE "-fsanitize=address")
|
target_link_libraries(${PROJECT_NAME} PRIVATE "-fsanitize=address")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
file(COPY ${PROJECT_SOURCE_DIR}/assets DESTINATION ${PROJECT_BINARY_DIR})
|
|
||||||
@ -3,18 +3,26 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <SDL_mixer.h>
|
#include <SDL_mixer.h>
|
||||||
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
|
typedef std::function<void()> gamefunction;
|
||||||
|
|
||||||
class AssetManager;
|
class AssetManager;
|
||||||
class CollisionHandler;
|
class CollisionHandler;
|
||||||
class TextureManager;
|
class TextureManager;
|
||||||
class SoundManager;
|
class SoundManager;
|
||||||
class Map;
|
class Map;
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
extern gamefunction init;
|
||||||
|
extern gamefunction update;
|
||||||
|
}
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -130,6 +130,8 @@ void Game::init(const char* title, int xpos, int ypos, int width, int height, bo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
engine::init();
|
||||||
|
|
||||||
// character selection
|
// character selection
|
||||||
const char* player1Sprite;
|
const char* player1Sprite;
|
||||||
const char* player2Sprite;
|
const char* player2Sprite;
|
||||||
@ -297,6 +299,8 @@ void Game::update()
|
|||||||
manager.refresh();
|
manager.refresh();
|
||||||
manager.update();
|
manager.update();
|
||||||
|
|
||||||
|
engine::update(); // TODO: this might have to be split up into two update functions, before and after manager...
|
||||||
|
|
||||||
if (powerupSpawn == 0)
|
if (powerupSpawn == 0)
|
||||||
{
|
{
|
||||||
assets->createPowerup(assets->calculateSpawnPosition(), assets->calculateType());
|
assets->createPowerup(assets->calculateSpawnPosition(), assets->calculateType());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user