summaryrefslogtreecommitdiff
path: root/src/background.c
blob: 060ce6a4b1674ce2a2c3a3227e48db4dbc98d08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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 =
    GetMatchingAssetWithType(backgroundTextureName, Texture_Asset)->texture;

  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);
}