Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CMake, Fixed Memory Leak, Fixed Score #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build/

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmake/sdl2"]
path = cmake/sdl2
url = https://gitlab.com/aminosbh/sdl2-cmake-modules.git
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"iosfwd": "cpp",
"string": "cpp"
}
}
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.19)

project(cursor-custodian VERSION 0.1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)

# Find SDL2, SDL2_image and SDL2_ttf libraries
if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(USE_FLAGS "-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=['png'] -s USE_SDL_TTF=2 -s USE_SDL_MIXER=2 -s USE_FREETYPE=1 --preload-file res")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXECUTABLE_SUFFIX .html)
else()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
set(SDL2_LIBRARIES SDL2::Main SDL2::Image SDL2::TTF SDL2::Mixer)
endif()

# Build game
add_compile_options(-Wall -Wextra)
include_directories(include)

FILE(GLOB_RECURSE SOURCES src/**.cpp)
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})

file(COPY res DESTINATION ${CMAKE_BINARY_DIR})

# Link SDL2::Main, SDL2::Image and SDL2::TTF to our project
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
31 changes: 0 additions & 31 deletions Makefile

This file was deleted.

1 change: 1 addition & 0 deletions cmake/sdl2
Submodule sdl2 added at ad006a
4 changes: 2 additions & 2 deletions include/entity.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>

class Entity
Expand Down
4 changes: 2 additions & 2 deletions include/ground.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>

#include "groundtile.h"
Expand Down
4 changes: 2 additions & 2 deletions include/groundtile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>

#include "entity.h"
Expand Down
7 changes: 4 additions & 3 deletions include/player.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>
#include <string>

Expand All @@ -17,7 +17,8 @@ class Player : public Entity {
const char* getScore();
const char* getHighscore();
int getScoreInt();
int isDead();
int getDeadType();
bool isDead();
void reset();
private:
float velocityX, velocityY;
Expand Down
6 changes: 3 additions & 3 deletions include/renderwindow.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>

#include "entity.h"

Expand Down
16 changes: 8 additions & 8 deletions src/entity.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>

#include "entity.h"

Entity::Entity(float p_x, float p_y, std::vector<SDL_Texture*> p_tex)
:x(p_x), y(p_y), tex(p_tex)
Entity::Entity(float p_x, float p_y, std::vector<SDL_Texture *> p_tex)
: x(p_x), y(p_y), tex(p_tex)
{
currentFrame.x = 0;
currentFrame.y = 0;
Expand All @@ -17,8 +17,8 @@ Entity::Entity(float p_x, float p_y, std::vector<SDL_Texture*> p_tex)
}
}

Entity::Entity(float p_x, float p_y, SDL_Texture* p_tex)
:x(p_x), y(p_y)
Entity::Entity(float p_x, float p_y, SDL_Texture *p_tex)
: x(p_x), y(p_y)
{
tex.push_back(p_tex);
currentFrame.x = 0;
Expand Down Expand Up @@ -86,7 +86,7 @@ void Entity::setAnimOffsetY(int p_index, int p_value)
animOffsetsY[p_index] = p_value;
}

SDL_Texture* Entity::getTex(int p_index)
SDL_Texture *Entity::getTex(int p_index)
{
return tex.at(p_index);
}
Expand All @@ -96,7 +96,7 @@ SDL_Rect Entity::getCurrentFrame()
return currentFrame;
}

void Entity::setTex(SDL_Texture* p_tex)
void Entity::setTex(SDL_Texture *p_tex)
{
tex[0] = p_tex;
}
4 changes: 2 additions & 2 deletions src/ground.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>
#include <iostream>
#include <stdlib.h>
Expand Down
Loading