summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--GameScreen.cpp26
-rw-r--r--GameScreen.h16
-rw-r--r--TitleScreen.cpp10
-rw-r--r--main.cpp8
5 files changed, 57 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5abb82d..3ae25bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,7 @@ find_package(raylib 3 REQUIRED)
add_executable(
${PROJECT_NAME}
Game.cpp
+ GameScreen.cpp
main.cpp
TitleScreen.cpp
)
diff --git a/GameScreen.cpp b/GameScreen.cpp
new file mode 100644
index 0000000..714ccf5
--- /dev/null
+++ b/GameScreen.cpp
@@ -0,0 +1,26 @@
+#include "GameScreen.h"
+
+#include <raylib.h>
+
+
+GameScreen::GameScreen() :
+ m_pos {400, 300}
+{
+}
+
+
+void
+GameScreen::update(const float dt)
+{
+ if (IsKeyDown(KEY_LEFT))
+ m_pos.x -= dt * 30;
+ if (IsKeyDown(KEY_RIGHT))
+ m_pos.x += dt * 30;
+}
+
+
+void
+GameScreen::draw()
+{
+ DrawCircle(m_pos.x, m_pos.y, 10, LIGHTGRAY);
+}
diff --git a/GameScreen.h b/GameScreen.h
new file mode 100644
index 0000000..47a80d1
--- /dev/null
+++ b/GameScreen.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <raylib.h>
+
+#include "Screen.h"
+
+
+class GameScreen : public Screen
+{
+public:
+ GameScreen();
+ void update(float dt) override;
+ void draw() override;
+private:
+ Vector2 m_pos;
+};
diff --git a/TitleScreen.cpp b/TitleScreen.cpp
index 3faf48f..d109003 100644
--- a/TitleScreen.cpp
+++ b/TitleScreen.cpp
@@ -1,11 +1,21 @@
#include "TitleScreen.h"
+#include <memory>
+
#include <raylib.h>
+#include "Game.h"
+#include "GameScreen.h"
+
+
+extern Game g_game;
+
void
TitleScreen::update(const float dt)
{
+ if (IsKeyPressed(KEY_SPACE))
+ g_game.set(std::make_unique<GameScreen>());
}
diff --git a/main.cpp b/main.cpp
index 9f216e5..e76f30a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,7 +10,7 @@
#include "TitleScreen.h"
-static Game s_game;
+Game g_game;
void Loop();
@@ -19,7 +19,7 @@ void Loop();
int main()
{
InitWindow(800, 600, "Bullet Hell 2022");
- s_game.set(std::make_unique<TitleScreen>());
+ g_game.set(std::make_unique<TitleScreen>());
#ifdef PLATFORM_WEB
emscripten_set_main_loop(Loop, 0, 1);
#else
@@ -33,8 +33,8 @@ int main()
void Loop()
{
- s_game.update(GetFrameTime());
+ g_game.update(GetFrameTime());
BeginDrawing();
- s_game.draw();
+ g_game.draw();
EndDrawing();
}