Added sample game structure

This commit is contained in:
Maximilian Giller 2023-04-26 13:58:10 +02:00
parent d0f84d71cf
commit f5b36b01f0
5 changed files with 94 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build/

21
CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.12)
project(Holesome)
set(CMAKE_CXX_STANDARD 20)
# Find and include SFML
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
# Set up your project's source files
set(SOURCES
src/main.cpp
# src/game.cpp
# include/game.h
)
# Add an executable target
add_executable(Holesome ${SOURCES})
# Link SFML to your executable target
target_link_libraries(Holesome sfml-graphics sfml-audio)

10
include/game.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef SFML_SAMPLE_GAME_GAME_H
#define SFML_SAMPLE_GAME_GAME_H
class Game {
};
#endif //SFML_SAMPLE_GAME_GAME_H

1
src/game.cpp Normal file
View file

@ -0,0 +1 @@
#include "../include/game.h"

61
src/main.cpp Normal file
View file

@ -0,0 +1,61 @@
#include <SFML/Graphics.hpp>
#include <iostream>
int main() {
// Create a window with a resolution of 800x600 pixels
sf::RenderWindow window = sf::RenderWindow();
sf::VideoMode mode = sf::VideoMode::getDesktopMode();
std::cout << "Desktop Mode: "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl;
// Display the list of all the video modes available for fullscreen
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
for (std::size_t i = 0; i < modes.size(); ++i) {
sf::VideoMode mode = modes[i];
std::cout << "Mode #" << i << ": "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl;
}
window.create(sf::VideoMode::getDesktopMode(), "Sample Game", sf::Style::Fullscreen);
// Main loop that runs until the window is closed
while (window.isOpen()) {
// Process any events that have occurred since the last iteration
sf::Event event;
while (window.pollEvent(event)) {
// If the event is to close the window, then close it
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.key.code == sf::Keyboard::Escape || event.key.code == sf::Keyboard::Q) {
window.close();
}
}
// Clear the window to a solid color
window.clear(sf::Color::Black);
// Draw any objects that you want to display in the window
// Create a circle shape with a radius of 50 pixels
sf::CircleShape circle(50.f);
// Set the position of the circle shape to the center of the window
circle.setPosition(window.getSize().x / 2.f, window.getSize().y / 2.f);
// Set the color of the circle shape to red
circle.setFillColor(sf::Color::Red);
// Draw the circle shape on the window
window.draw(circle);
// Display the objects on the window
window.display();
}
return 0;
}