summaryrefslogtreecommitdiff
path: root/src/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/background.c')
-rw-r--r--src/background.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/background.c b/src/background.c
new file mode 100644
index 0000000..39e3c1e
--- /dev/null
+++ b/src/background.c
@@ -0,0 +1,30 @@
+#include "background.h"
+#include "constants.h"
+#include <raymath.h>
+
+void AddBackground(const char* backgroundTextureName) {
+ Entity e = {0};
+ e.type = Background_Entity;
+
+ e.flags |= ENTITY_VISIBLE;
+ e.drawLayer = Background_Layer;
+
+ e.position = (Vector2) {0.0f, 0.0f};
+ Texture2D backgroundTexture = GetTexture(backgroundTextureName);
+
+ const float backgroundSizeScale = (float)WINDOW_HEIGHT / backgroundTexture.height;
+ Vector2 backgroundBounds =
+ Vector2Scale((Vector2) {backgroundTexture.width, backgroundTexture.height}, backgroundSizeScale);
+
+ e.destRect = (Rectangle) {
+ .width = backgroundBounds.x,
+ .height = backgroundBounds.y
+ };
+ e.texture = backgroundTexture;
+
+ AddEntity(&e);
+}
+
+void UpdateBackground(Entity* background, float deltaTime) {
+ background->position.x -= 600 * deltaTime;
+}