fix compile error
This commit is contained in:
17
.devcontainer/devcontainer.json
Normal file
17
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Linux Development",
|
||||
"dockerFile": "Dockerfile.linux",
|
||||
"context": "..",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"CMake.configureOnOpen": true
|
||||
},
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools",
|
||||
"ms-vscode.cpptools"
|
||||
]
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "cmake . && make"
|
||||
}
|
||||
@@ -2,25 +2,32 @@ cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(SDL_TD VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
# Find SDL2
|
||||
find_package(SDL2 QUIET)
|
||||
find_package(SDL2_mixer REQUIRED)
|
||||
|
||||
# Set SDL include directories and libraries
|
||||
set(SDL_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
|
||||
set(SDL_LIBRARIES ${SDL2_LIBRARIES})
|
||||
|
||||
# Find SDL2_mixer, SDL2_image, and SDL2_ttf
|
||||
find_library(SDL_MIXER_LIBRARY NAMES SDL2_mixer)
|
||||
find_library(SDL_IMAGE_LIBRARY NAMES SDL2_image)
|
||||
find_library(SDL_TTF_LIBRARY NAMES SDL2_ttf)
|
||||
|
||||
include_directories(${SDL_INCLUDE_DIRS})
|
||||
|
||||
# Gather source and header files
|
||||
file(GLOB_RECURSE PROJECT_SOURCES src/*.cpp)
|
||||
file(GLOB_RECURSE PROJECT_HEADERS src/*.hpp)
|
||||
|
||||
# Create executable
|
||||
add_executable(SDL_TD
|
||||
${PROJECT_SOURCES}
|
||||
${PROJECT_HEADERS}
|
||||
)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(SDL_TD
|
||||
${SDL_LIBRARIES}
|
||||
${SDL_MIXER_LIBRARY}
|
||||
@@ -29,10 +36,16 @@ target_link_libraries(SDL_TD
|
||||
fmt
|
||||
)
|
||||
|
||||
file(GLOB ASSETS
|
||||
"assets/*"
|
||||
)
|
||||
|
||||
file(GLOB ASSETS "assets/*")
|
||||
foreach(ASSET ${ASSETS})
|
||||
file(COPY ${ASSET} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/assets)
|
||||
endforeach()
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(SDL_TD PRIVATE
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
)
|
||||
|
||||
target_link_libraries(SDL_TD ws2_32)
|
||||
endif()
|
||||
|
||||
32
Dockerfile.linux
Normal file
32
Dockerfile.linux
Normal file
@@ -0,0 +1,32 @@
|
||||
FROM ubuntu:latest
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
ninja-build \
|
||||
libsdl2-dev \
|
||||
libsdl2-image-dev \
|
||||
libsdl2-mixer-dev \
|
||||
libsdl2-ttf-dev \
|
||||
libfmt-dev \
|
||||
libx11-dev \
|
||||
x11-xserver-utils \
|
||||
pulseaudio \
|
||||
mesa-utils \
|
||||
wget \
|
||||
unzip
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy your source code into the container
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN cmake . && make
|
||||
|
||||
# Command to run your application (optional)
|
||||
CMD ["./SDL_TD"]
|
||||
35
docker-compose.yml
Normal file
35
docker-compose.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
services:
|
||||
linux-build:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.linux
|
||||
volumes:
|
||||
- .:/project
|
||||
working_dir: /project
|
||||
command: >
|
||||
/bin/bash -c "cmake -B build && cmake --build build"
|
||||
|
||||
linux-run:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.linux
|
||||
depends_on:
|
||||
- linux-build
|
||||
volumes:
|
||||
- .:/project
|
||||
- /tmp/.X11-unix:/tmp/.X11-unix
|
||||
- ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native
|
||||
working_dir: /project/build
|
||||
environment:
|
||||
- DISPLAY=${DISPLAY}
|
||||
- QT_X11_NO_MITSHM=1
|
||||
- PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native
|
||||
devices:
|
||||
- /dev/snd:/dev/snd
|
||||
- /dev/dri:/dev/dri
|
||||
ipc: host
|
||||
shm_size: '512m'
|
||||
command: >
|
||||
/bin/bash -c "./SDL_TD"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ bool Game::init(const char* title, int w, int h) {
|
||||
title,
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
w, h,
|
||||
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN
|
||||
SDL_WINDOW_SHOWN
|
||||
));
|
||||
|
||||
if (!window) {
|
||||
@@ -74,8 +74,10 @@ void Game::run( ) {
|
||||
|
||||
while (gameState.gameover) {
|
||||
if (gameState.quit) return;
|
||||
SDL_SetRenderDrawColor(renderer.get( ), 248, 248, 248, 255);
|
||||
SDL_RenderClear(renderer.get( ));
|
||||
inputHandler( );
|
||||
gameRenderer->renderGameOver(gameBoard->getWidth( ), gameBoard->getHeight( ));
|
||||
gameRenderer->renderGameOver(gameBoard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ GameBoard::GameBoard( )
|
||||
}
|
||||
|
||||
bool GameBoard::tryMoveCurrentTetromino(int dx, int dy) {
|
||||
if (!currentTetromino) return;
|
||||
if (!currentTetromino) return false;
|
||||
currentTetromino->move(dx, dy);
|
||||
if (checkCollision(*currentTetromino)) {
|
||||
currentTetromino->move(-dx, -dy);
|
||||
|
||||
@@ -235,9 +235,10 @@ void Renderer::renderStartScreen( ) {
|
||||
SDL_RenderPresent(renderer.get( ));
|
||||
}
|
||||
|
||||
void Renderer::renderGameOver(int gbWidth, int gbHeight) {
|
||||
void Renderer::renderGameOver(const shared_ptr<GameBoard> gameBoard) {
|
||||
//Needed to draw the Walls again
|
||||
drawWall(gbWidth, gbHeight);
|
||||
drawWall(gameBoard->getWidth( ), gameBoard->getHeight( ));
|
||||
drawScoreboard(gameBoard->getScore( ), gameBoard->getLevel( ), gameBoard->getLines( ));
|
||||
|
||||
auto gameOver = unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)>(IMG_Load("assets/sprites/game_over.png"), SDL_FreeSurface);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
void renderBoard(const shared_ptr<GameBoard> gameBoard);
|
||||
|
||||
void renderStartScreen( );
|
||||
void renderGameOver(int gbWidth, int gbHeight);
|
||||
void renderGameOver(shared_ptr<GameBoard> gameBoard);
|
||||
const TextDimensions renderText(
|
||||
const string& text, int x, int y, int fontSize,
|
||||
SDL_Color color, HAlign textHAlign = HAlign::LEFT, VAlign textVAlign = VAlign::TOP
|
||||
|
||||
Reference in New Issue
Block a user