From e2dfc5c083857f279b55e4845430ccfa1c503828 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 31 Oct 2022 22:29:41 +0100 Subject: Created basic skeleton for the game session and scenes --- .gitignore | 1 + CMakeLists.txt | 6 ++++++ kurator/CMakeLists.txt | 12 ++++++++++++ kurator/src/GameOver.cpp | 35 +++++++++++++++++++++++++++++++++++ kurator/src/GameOver.h | 24 ++++++++++++++++++++++++ kurator/src/Scene.h | 16 ++++++++++++++++ kurator/src/Session.cpp | 33 +++++++++++++++++++++++++++++++++ kurator/src/Session.h | 22 ++++++++++++++++++++++ kurator/src/Title.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ kurator/src/Title.h | 24 ++++++++++++++++++++++++ kurator/src/main.cpp | 19 +++++++++++++++++++ 11 files changed, 232 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 kurator/CMakeLists.txt create mode 100644 kurator/src/GameOver.cpp create mode 100644 kurator/src/GameOver.h create mode 100644 kurator/src/Scene.h create mode 100644 kurator/src/Session.cpp create mode 100644 kurator/src/Session.h create mode 100644 kurator/src/Title.cpp create mode 100644 kurator/src/Title.h create mode 100644 kurator/src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5309e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f6aef10 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.16) +project(kurator) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS No) +find_package(raylib 4 REQUIRED) +add_subdirectory(kurator) diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt new file mode 100644 index 0000000..75d00a4 --- /dev/null +++ b/kurator/CMakeLists.txt @@ -0,0 +1,12 @@ +project(kurator) +add_executable( + ${PROJECT_NAME} + src/main.cpp + src/GameOver.cpp + src/Session.cpp + src/Title.cpp +) +target_link_libraries( + ${PROJECT_NAME} + PRIVATE raylib +) diff --git a/kurator/src/GameOver.cpp b/kurator/src/GameOver.cpp new file mode 100644 index 0000000..9646c17 --- /dev/null +++ b/kurator/src/GameOver.cpp @@ -0,0 +1,35 @@ +#include "GameOver.h" + +#include +#include + +#include + +#include "Session.h" + + +namespace kurator +{ + + +GameOver::GameOver(std::shared_ptr _session) : + session {std::move(_session)} +{ +} + + +void +GameOver::update(const float) +{ +} + + +void +GameOver::draw() const +{ + ClearBackground(GRAY); + DrawText("Bye", 100, 100, 20, BLACK); +} + + +} // namespace kurator diff --git a/kurator/src/GameOver.h b/kurator/src/GameOver.h new file mode 100644 index 0000000..70b5c31 --- /dev/null +++ b/kurator/src/GameOver.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Session.h" +#include "Scene.h" + + +namespace kurator +{ + + +class GameOver : public Scene +{ +public: + explicit GameOver(std::shared_ptr _session); + void update(float dt) override; + void draw() const override; +private: + std::shared_ptr session; +}; + + +} // namespace kurator diff --git a/kurator/src/Scene.h b/kurator/src/Scene.h new file mode 100644 index 0000000..fbd2480 --- /dev/null +++ b/kurator/src/Scene.h @@ -0,0 +1,16 @@ +#pragma once + + +namespace kurator +{ + + +class Scene +{ +public: + virtual void update(float dt) = 0; + virtual void draw() const = 0; +}; + + +} // namespace kurator diff --git a/kurator/src/Session.cpp b/kurator/src/Session.cpp new file mode 100644 index 0000000..07b19f1 --- /dev/null +++ b/kurator/src/Session.cpp @@ -0,0 +1,33 @@ +#include "Session.h" + +#include + +#include + +#include "Scene.h" + + +namespace kurator +{ + + +void +Session::set(std::shared_ptr _scene) +{ + scene = _scene; +} + + +void +Session::loop() +{ + if (!scene) + return; + scene->update(GetFrameTime()); + BeginDrawing(); + scene->draw(); + EndDrawing(); +} + + +} // namespace kurator diff --git a/kurator/src/Session.h b/kurator/src/Session.h new file mode 100644 index 0000000..cc8a4ee --- /dev/null +++ b/kurator/src/Session.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#include "Scene.h" + + +namespace kurator +{ + + +class Session +{ +public: + void set(std::shared_ptr _scene); + void loop(); +private: + std::shared_ptr scene; +}; + + +} // namespace kurator diff --git a/kurator/src/Title.cpp b/kurator/src/Title.cpp new file mode 100644 index 0000000..56f52a8 --- /dev/null +++ b/kurator/src/Title.cpp @@ -0,0 +1,40 @@ +#include "Title.h" + +#include +#include + +#include + +#include "GameOver.h" +#include "Session.h" + + +namespace kurator +{ + + +Title::Title(std::shared_ptr _session) : + session {std::move(_session)} +{ +} + + +void +Title::update(const float) +{ + if (IsKeyPressed(KEY_SPACE)) { + auto next = std::make_shared(session); + session->set(next); + } +} + + +void +Title::draw() const +{ + ClearBackground(BLACK); + DrawText("Hey", 100, 100, 20, GRAY); +} + + +} // namespace kurator diff --git a/kurator/src/Title.h b/kurator/src/Title.h new file mode 100644 index 0000000..c29dc99 --- /dev/null +++ b/kurator/src/Title.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Session.h" +#include "Scene.h" + + +namespace kurator +{ + + +class Title : public Scene +{ +public: + explicit Title(std::shared_ptr _session); + void update(float dt) override; + void draw() const override; +private: + std::shared_ptr session; +}; + + +} // namespace kurator diff --git a/kurator/src/main.cpp b/kurator/src/main.cpp new file mode 100644 index 0000000..112be1a --- /dev/null +++ b/kurator/src/main.cpp @@ -0,0 +1,19 @@ +#include + +#include + +#include "Session.h" +#include "Title.h" + + +int +main(int, char*[]) +{ + InitWindow(800, 600, "Kurator"); + auto session = std::make_shared(); + auto title = std::make_shared(session); + session->set(title); + while (!WindowShouldClose()) + session->loop(); + CloseWindow(); +} -- cgit v1.1