diff --git a/.gitignore b/.gitignore index 8b4bb23..35e189c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -flappyBird +build/ +*.kdev4 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6aa3dc5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) + +# Set the project name +project(FlappyBird) + +# Find the SDL2 and SDL2_image packages +find_package(SDL2 REQUIRED) +find_package(SDL2_image REQUIRED) + +# Specify the source files +set(SRCS main.cpp) + +# Create the executable +add_executable(${PROJECT_NAME} ${SRCS}) + +# Link the SDL2 and SDL2_image libraries +target_link_libraries(${PROJECT_NAME} SDL2::SDL2 SDL2_image::SDL2_image) + +# Specify the assets directory +set(ASSETS_DIR ${CMAKE_SOURCE_DIR}/assets) + +# Copy assets to the build directory +file(COPY ${ASSETS_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/bird.png b/assets/bird.png similarity index 100% rename from bird.png rename to assets/bird.png diff --git a/pipe.png b/assets/pipe.png similarity index 100% rename from pipe.png rename to assets/pipe.png diff --git a/main.cpp b/main.cpp index 8f60629..c571d3c 100644 --- a/main.cpp +++ b/main.cpp @@ -94,14 +94,14 @@ int main ( int argc, char* argv[] ) } // Load the sprite texture - SDL_Texture* flappyBird = IMG_LoadTexture ( renderer, "bird.png" ); + SDL_Texture* flappyBird = IMG_LoadTexture ( renderer, "assets/bird.png" ); if ( flappyBird == nullptr ) { std::cerr << "Failed to load texture! SDL_Error: " << SDL_GetError() << std::endl; // Handle error } - SDL_Texture* pipe = IMG_LoadTexture ( renderer, "pipe.png" ); + SDL_Texture* pipe = IMG_LoadTexture ( renderer, "assets/pipe.png" ); if ( pipe == nullptr ) { std::cerr << "Failed to load texture! SDL_Error: " << SDL_GetError() << std::endl; @@ -206,17 +206,20 @@ int main ( int argc, char* argv[] ) quit = sdlPipe ( &pipe1Rect, &birdRect, renderer, flappyBird, pipe ); - if (!quit) { + if ( !quit ) + { quit = sdlPipe ( &pipe2Rect, &birdRect, renderer, flappyBird, pipe ); - } + } - if (!quit) { + if ( !quit ) + { quit = sdlPipe ( &pipe3Rect, &birdRect, renderer, flappyBird, pipe ); - } + } - if (!quit) { + if ( !quit ) + { quit = sdlPipe ( &pipe4Rect, &birdRect, renderer, flappyBird, pipe ); - } + } // Present the renderer SDL_RenderPresent ( renderer ); diff --git a/makefile b/makefile deleted file mode 100644 index a218902..0000000 --- a/makefile +++ /dev/null @@ -1,10 +0,0 @@ -CXX = g++ -CXXFLAGS = -lSDL2 -lSDL2_image -SRCS = main.cpp -TARGET = flappyBird - -all: $(SRCS) - $(CXX) -o $(TARGET) $(SRCS) $(CXXFLAGS) - -clean: - rm -f $(TARGET)