summaryrefslogtreecommitdiff
path: root/src/wall.c
blob: b4a3653ff5e4030188ca7f74d300cdce55d932bf (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
44
45
46
47
#include <raylib.h>
#include "wall.h"

#define BLOCK_WIDTH 128
#define BLOCK_HEIGHT 128

extern struct Texture wall_texture;

void add_wall(float xpos, float ypos, int tile) {
  int tile_x = tile % 18;
  int tile_y = tile / 18;

  struct entity wall = {
    .type = Wall_Entity,
    .flags = (ENTITY_ACTIVE | ENTITY_COLLISION_ACTIVE | ENTITY_VISIBLE),

    .texture = wall_texture,
    .sprite_source_rect = (Rectangle) {
      .x = tile_x * 129,
      .y = tile_y * 129,
      .width = 128,
      .height = 128
    },
    .sprite_dest_rect = (Rectangle) {
      .x = -BLOCK_WIDTH / 2,
      .y = -BLOCK_HEIGHT / 2,
      .width = BLOCK_WIDTH,
      .height = BLOCK_HEIGHT
    },

    .position = {
      .x = xpos,
      .y = ypos
    },
    .velocity = (Vector2) {0},

    .collider = (Rectangle) {
      .x = -BLOCK_WIDTH / 2,
      .y = -BLOCK_HEIGHT / 2,
      .width = BLOCK_WIDTH,
      .height = BLOCK_HEIGHT
    },
  };


  add_entity(&wall);
}