summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorarngo <[email protected]>2022-11-02 14:28:51 -0400
committerarngo <[email protected]>2022-11-02 14:28:51 -0400
commitf8f6d0d2e3e2a21bf48e0ae131015e2542f0f840 (patch)
treee4145f1db8c6de2515c3c801b0ad70275e57c7dd
parentfde8ab552350217592ac77123e9fec394741727e (diff)
downloadorbital_game-f8f6d0d2e3e2a21bf48e0ae131015e2542f0f840.tar.gz
orbital_game-f8f6d0d2e3e2a21bf48e0ae131015e2542f0f840.zip
implement resource loader
-rw-r--r--assets/textures/spaceShooter2_spritesheet_2X.pngbin0 -> 769635 bytes
-rw-r--r--src/main.cpp46
-rw-r--r--src/resources.cpp27
-rw-r--r--src/resources.h7
4 files changed, 80 insertions, 0 deletions
diff --git a/assets/textures/spaceShooter2_spritesheet_2X.png b/assets/textures/spaceShooter2_spritesheet_2X.png
new file mode 100644
index 0000000..3c03400
--- /dev/null
+++ b/assets/textures/spaceShooter2_spritesheet_2X.png
Binary files differ
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..d4b1bc3
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,46 @@
+#include "raylib.h"
+#include "resources.h"
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
+ ;
+ DrawTexture(Resources::useTexture("ship"), 0, 0, WHITE);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/src/resources.cpp b/src/resources.cpp
new file mode 100644
index 0000000..141e4ca
--- /dev/null
+++ b/src/resources.cpp
@@ -0,0 +1,27 @@
+#include <unordered_map>
+#include <string>
+#include <stdexcept>
+#include "raylib.h"
+#include "resources.h"
+
+namespace Resources {
+ static std::unordered_map<std::string, std::string> textureFiles = {
+ {"ship", "./assets/textures/spaceShooter2_spritesheet_2X.png"}
+ };
+ static std::unordered_map<std::string, Texture> textures;
+ Texture useTexture(std::string id) {
+ Texture texture;
+ auto texSearch = textures.find(id);
+ if (texSearch != textures.end()) {
+ return texSearch->second;
+ }
+ auto texPathSearch = textureFiles.find(id);
+ if (texPathSearch != textureFiles.end()) {
+ texture = LoadTexture(texPathSearch->second.c_str());
+ textures.insert({id, texture});
+ } else {
+ throw std::invalid_argument("Texture id '" + id + "' has no assigned path.");
+ }
+ return texture;
+ }
+}
diff --git a/src/resources.h b/src/resources.h
new file mode 100644
index 0000000..eef1883
--- /dev/null
+++ b/src/resources.h
@@ -0,0 +1,7 @@
+#include <unordered_map>
+#include <string>
+#include "raylib.h"
+
+namespace Resources {
+ Texture useTexture(std::string id);
+}