-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld.c
More file actions
65 lines (57 loc) · 1.97 KB
/
world.c
File metadata and controls
65 lines (57 loc) · 1.97 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "world.h"
#include "components.h"
#include "consts.h"
#include "raylib.h"
int CreateEntity(World *world) {
for (int i = 0; i < MAX_ENTITIES; ++i) {
if (world->mask[i] == MNONE) {
return i;
}
}
return -1;
}
void CreatePaddle(World *world, float x_pos, KeyboardKey Up, KeyboardKey Down,
int gamepad, GamepadButton GPUp, GamepadButton GPDown) {
int entity_id = CreateEntity(world);
if (entity_id == -1) {
return;
}
world->mask[entity_id] =
MTRANSFORM | MVELOCITY | MPLAYERIMP | MPADDLE | MCOLLIDER | MRECT;
world->transform[entity_id] =
(CTransform){.position = {x_pos, GetScreenHeight() / 2.0f},
.size = {PADLE_WIDTH, PADDLE_HEIGHT}};
world->velocity[entity_id] = (CVelocity){0.0f, 0.0f};
world->rects[entity_id] = (CRect){(Rectangle){
world->transform[entity_id].position.x,
world->transform[entity_id].position.y,
world->transform[entity_id].size.x,
world->transform[entity_id].size.y,
}};
world->p_input[entity_id] = (CPlayerInput){gamepad, Up, Down, GPUp, GPDown};
}
void CreateWall(World *world, float y_pos) {
int entity_id = CreateEntity(world);
if (entity_id == -1) {
return;
}
world->mask[entity_id] = MTRANSFORM | MWALL | MCOLLIDER | MRECT;
world->transform[entity_id] = (CTransform){
.position = {0, y_pos}, .size = {GetScreenWidth(), WALL_WIDTH}};
world->rects[entity_id] = (CRect){(Rectangle){
world->transform[entity_id].position.x,
world->transform[entity_id].position.y,
world->transform[entity_id].size.x,
world->transform[entity_id].size.y,
}};
}
void CreateBall(World *world) {
int entity_id = CreateEntity(world);
if (entity_id == -1) {
return;
}
world->mask[entity_id] = MTRANSFORM | MVELOCITY | MCOLLIDER | MBALL;
world->transform[entity_id] = (CTransform){
.position = {HALF_SCREEN_WIDTH, HALF_SCREEN_HEIGHT}, .size = {10, 10}};
world->velocity[entity_id] = (CVelocity){.speed = {0, 0}};
}