Skip to content

Commit 729594d

Browse files
committed
Format and minor refactor entire source code
1 parent 3b6b786 commit 729594d

File tree

5 files changed

+155
-91
lines changed

5 files changed

+155
-91
lines changed

.clang-format

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ AlignConsecutiveAssignments: None
1010
AlignOperands: Align
1111
AllowAllArgumentsOnNextLine: false
1212
AllowAllParametersOfDeclarationOnNextLine: false
13-
AllowAllParametersOfDeclarationOnNextLine: false
1413
AllowShortBlocksOnASingleLine: Never
1514
AllowShortEnumsOnASingleLine: false
1615
AllowShortFunctionsOnASingleLine: Empty

headers/screens.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool DrawTauntScreen(void);
3939
void UnloadTauntScreen(void);
4040
int FinishTauntScreen(void);
4141

42-
void healthChangeNPC(int deltaHealth);
42+
void HealthChangeNPC(int deltaHealth);
4343

4444
bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rectangle texSource);
4545
bool GuiImageButtonExTint(
@@ -54,4 +54,4 @@ uint64_t rng_u64(uint64_t seed);
5454

5555
/// Generate a random double in range [0, 1].
5656
double rng_f64(uint64_t seed);
57-
#endif
57+
#endif

screens/chappal.c

+28-26
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,70 @@
44
#include <rlgl.h>
55
#include <stdlib.h>
66

7-
// Creates a new chappal at a random location with a random rotation speed.
87
// Speed will increase with time.
9-
108
static float speed = 6.0f;
119

10+
// Creates a new chappal at a random location with a random rotation speed.
1211
Chappal* CreateChappal(Texture2D textures[], Vector2 target) {
13-
// Texture2D textures
1412
Chappal* chappal = malloc(sizeof(Chappal));
13+
1514
int x = 0;
1615
int y = 0;
17-
const int WIDTH = GetScreenWidth();
18-
const int HEIGHT = GetScreenHeight();
16+
17+
const int halfWidth = GetScreenWidth() / 2;
18+
const int halfHeight = GetScreenHeight() / 2;
19+
1920
if (GetRandomValue(0, 1)) {
2021
x = GetRandomValue(
21-
target.x - (WIDTH / 2) - SPAWN_OFFSET,
22-
target.x + (WIDTH / 2) + SPAWN_OFFSET);
22+
target.x - halfWidth - SPAWN_OFFSET,
23+
target.x + halfWidth + SPAWN_OFFSET);
2324
if (GetRandomValue(0, 1)) {
24-
y = target.y + (HEIGHT / 2) + SPAWN_OFFSET;
25+
y = target.y + halfHeight + SPAWN_OFFSET;
2526
} else {
26-
y = target.y - (HEIGHT / 2) - SPAWN_OFFSET;
27+
y = target.y - halfHeight - SPAWN_OFFSET;
2728
}
2829
} else {
2930
y = GetRandomValue(
30-
target.y - (HEIGHT / 2) - SPAWN_OFFSET,
31-
target.y + (HEIGHT / 2) + SPAWN_OFFSET);
31+
target.y - halfHeight - SPAWN_OFFSET,
32+
target.y + halfHeight + SPAWN_OFFSET);
3233
if (GetRandomValue(0, 1)) {
33-
x = target.x + (WIDTH / 2) + SPAWN_OFFSET;
34+
x = target.x + halfWidth + SPAWN_OFFSET;
3435
} else {
35-
x = target.x - (WIDTH / 2) - SPAWN_OFFSET;
36+
x = target.x - halfWidth - SPAWN_OFFSET;
3637
}
3738
}
39+
3840
Vector2 position = {x, y};
3941
chappal->position = position;
4042
Vector2 direction = Vector2Subtract(target, chappal->position);
4143
direction = Vector2Normalize(direction);
4244
chappal->rotation = 0.0f;
4345
chappal->rotationSpeed = (float)GetRandomValue(ROTATION_SPEED_MIN, ROTATION_SPEED_MAX) / 10.0f;
4446
chappal->direction = direction;
45-
// chappal->texture = texture;
46-
// chappal->type = random type between 1 to n
47-
48-
// int randNum = rng_u64(rng_u64(time(NULL))) % 100;
4947

50-
int randNum = GetRandomValue(1, 100);
48+
// Choose a weapon randomly.
49+
int weaponChoice = GetRandomValue(1, 100);
5150

52-
if (randNum < 5)
51+
if (weaponChoice < 5)
5352
chappal->type = KHANA;
54-
else if (randNum < 20)
53+
else if (weaponChoice < 20)
5554
chappal->type = DANDA;
56-
else if (randNum < 40)
55+
else if (weaponChoice < 40)
5756
chappal->type = JUTA;
5857
else
5958
chappal->type = CHAPPAL;
59+
60+
// Set weapon texture.
6061
chappal->texture = textures[chappal->type];
62+
6163
return chappal;
6264
}
6365

6466
void UpdateChappal(Chappal* chappal) {
6567
Vector2 velocity = Vector2Scale(chappal->direction, speed);
6668
chappal->position = Vector2Add(chappal->position, velocity);
6769
chappal->rotation += chappal->rotationSpeed;
68-
};
70+
}
6971

7072
void DrawChappal(Chappal* chappal) {
7173
DrawTexturePro(
@@ -79,16 +81,16 @@ void DrawChappal(Chappal* chappal) {
7981
(Vector2){(float)chappal->texture.width / 2, (float)chappal->texture.height / 2},
8082
chappal->rotation,
8183
WHITE);
82-
};
84+
}
8385

8486
void IncreaseSpeed() {
8587
speed += 4.0f;
86-
};
88+
}
8789

8890
void SetSpeed(float newSpeed) {
8991
speed = newSpeed;
90-
};
92+
}
9193

9294
void DestroyChappal(Chappal* chappal) {
9395
free(chappal);
94-
};
96+
}

screens/screen_game.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void InitGameScreen(void) {
395395

396396
// Initializing the camera
397397
camera.zoom = 1.0f;
398-
};
398+
}
399399

400400
Node* createNode(Chappal* chappal) {
401401
Node* node = (Node*)malloc(sizeof(Node));
@@ -444,7 +444,7 @@ int gRows = 0, gCols = 0;
444444
int gTerrain[100 * 100];
445445
int gObstacles[100 * 100];
446446

447-
void healthChangeNPC(int deltaHealth) {
447+
void HealthChangeNPC(int deltaHealth) {
448448
lives += deltaHealth;
449449
if (lives > MAX_LIVES) {
450450
lives = MAX_LIVES;

0 commit comments

Comments
 (0)