This commit is contained in:
patrick_pluto 2024-09-08 19:27:33 +02:00
parent 3719b1249b
commit e518e31fc7
6 changed files with 36 additions and 19 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
flappyBird
build/
*.kdev4

23
CMakeLists.txt Normal file
View file

@ -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})

View file

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 176 B

View file

Before

Width:  |  Height:  |  Size: 212 B

After

Width:  |  Height:  |  Size: 212 B

View file

@ -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 );

View file

@ -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)