Skip to content

Commit

Permalink
port the game to linux
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurmoreno committed Nov 14, 2024
1 parent c5c9b27 commit f9eb3bc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# Compiler Flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g")

# Find SDL
find_package(SDL REQUIRED)

# Include Directories
include_directories(
${PROJECT_SOURCE_DIR}/src
C:/msys64/ucrt64/include/SDL
)

# Library Directories
link_directories(
C:/msys64/ucrt64/lib
${SDL_INCLUDE_DIR}
)

# Source Files (using .cpp files)
Expand All @@ -33,4 +31,10 @@ file(GLOB SRC_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
add_executable(campo_de_batalha ${SRC_FILES})

# Link Libraries
target_link_libraries(campo_de_batalha mingw32 SDLmain SDL ws2_32)
if(WIN32)
# Windows-specific libraries
target_link_libraries(campo_de_batalha ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} mingw32 ws2_32)
else()
# Linux or other systems
target_link_libraries(campo_de_batalha ${SDL_LIBRARY} ${SDLMAIN_LIBRARY})
endif()
35 changes: 22 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
# ==============================

# Project name
PROJECT := campo_de_batalha.exe
PROJECT := campo_de_batalha

# Build directory
BUILD_DIR := build

# CMake generator
CMAKE_GENERATOR := "MinGW Makefiles"
# CMake generator for Windows
CMAKE_GENERATOR_WIN := "MinGW Makefiles"

# CMake generator for Linux (usually not needed)
CMAKE_GENERATOR_LINUX :=

# CMake executable
CMAKE := cmake
Expand All @@ -21,27 +24,33 @@ MAKE_CMD := make
# RULES
# ==============================

.PHONY: all build clean
.PHONY: all build build-linux clean format

# Default target
all: build

# Build target
build:
@echo "Starting build process..."
@mkdir $(BUILD_DIR) 2> NUL || echo "Build directory already exists."
@cd $(BUILD_DIR) && $(CMAKE) -G $(CMAKE_GENERATOR) .. && $(MAKE_CMD) --always-make
# Build target for Windows
build-win:
@echo "Starting build process on Windows..."
@if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
@cd $(BUILD_DIR) && $(CMAKE) -G $(CMAKE_GENERATOR_WIN) .. && $(MAKE_CMD) --always-make

# Build target for Linux
build-linux:
@echo "Starting build process on Linux..."
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && $(CMAKE) $(CMAKE_GENERATOR_LINUX) .. && $(MAKE_CMD)

# Clean target
clean:
@echo "Cleaning project..."
@rmdir /s /q $(BUILD_DIR) 2> NUL || echo "Build directory does not exist."
@if exist $(PROJECT) del /f /q $(PROJECT)
@$(RM) -r $(BUILD_DIR)
@$(RM) $(PROJECT) $(PROJECT).exe

# Format target for Windows
format:
@echo "Formatting source files..."
@for /r %%f in (src\*.cpp src\*.hpp) do clang-format -i "%%f"
@for file in $(wildcard src/*.[ch]pp); do clang-format -i "$$file"; done

# Phony Targets
.PHONY: all build clean format
.PHONY: all build build-linux clean format
10 changes: 7 additions & 3 deletions src/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#ifndef PLAYER_H
#define PLAYER_H

#ifdef __APPLE__
#include <SDL/SDL.h>
#if defined(__APPLE__)
#include <SDL/SDL.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <SDL.h>
#elif defined(__linux__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif

#include "Constants.hpp"
Expand Down
10 changes: 7 additions & 3 deletions src/Projectile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#ifndef PROJECTILE_H
#define PROJECTILE_H

#ifdef __APPLE__
#include <SDL/SDL.h>
#if defined(__APPLE__)
#include <SDL/SDL.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <SDL.h>
#elif defined(__linux__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif

#include "Constants.hpp"
Expand Down
10 changes: 7 additions & 3 deletions src/SpriteSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#include <string>
#include <unordered_map>

#ifdef __APPLE__
#include <SDL/SDL.h>
#if defined(__APPLE__)
#include <SDL/SDL.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <SDL.h>
#elif defined(__linux__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif

class SpriteSet {
Expand Down
14 changes: 9 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include <stdlib.h>
#include <windows.h>
#include <winsock2.h>

#include <iostream>
#include <vector>

#define SDL_MAIN_HANDLED // Add this line

#ifdef __APPLE__
#include <SDL/SDL.h>
#if defined(__APPLE__)
#include <SDL/SDL.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include <winsock2.h>
#include <SDL.h>
#elif defined(__linux__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif

#include "Constants.hpp"
Expand Down

0 comments on commit f9eb3bc

Please sign in to comment.