summaryrefslogtreecommitdiff
path: root/src/star.c
blob: 6251e03305de6b4152c6754d3d4a583429c99ae1 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "star.h"

#include <math.h>
#include <stdlib.h>
#include <time.h>

#include "constants.h"
#include "raylib.h"

Vector3 Generate3DPosition() {
  srand(time(0));
  double random = (double)rand() / RAND_MAX;

  double angle = random * 2.0 * M_PI;
  double radius =
      (GetScreenHeight() / SPACE_SIZE) + (random * GetScreenHeight());

  float x = radius * sin(angle);
  float y = radius * cos(angle);

  Vector3 v = {x, y, STAR_START_POS_Z};
  return v;
}

Star StarCreate() {
  return (Star){Generate3DPosition(), {1, 1}, {0, 0}, 0.25f, BLACK};
}

void StarUpdate(Star *star) {
  float screen_center_x = GetScreenWidth() / 2.0;
  float screen_center_y = GetScreenHeight() / 2.0;

  float x = star->position.x / star->position.z + screen_center_x;
  float y = star->position.y / star->position.z + screen_center_y;

  star->renderPosition.x = x;
  star->renderPosition.y = y;

  float size = (STAR_START_POS_Z - star->position.z) / (0.2 * star->position.z);

  star->size.x = size;
  star->size.y = size;
}