Skip to content

Commit

Permalink
Finished version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthroy12 committed Sep 12, 2021
1 parent 78dc11b commit e9918c6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ file(GLOB_RECURSE APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.c)
add_executable(${CMAKE_PROJECT_NAME} ${APP_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} raylib)

target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC GAME_VERSION="1.0-DEV")
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC GAME_VERSION="1.0")

target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine
#target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="assets/") # Set the asset path macro in release more
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ static void change_scene(scene *scn) {
}

int main(void) {
SetTraceLogLevel(LOG_NONE);
SetWindowState(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Kosmos");
SetWindowState(FLAG_WINDOW_RESIZABLE);
InitAudioDevice();


SetExitKey(0); // Do not exit on ESC key

Expand Down
44 changes: 25 additions & 19 deletions src/scenes/game_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bullet bullet_buffer[BULLETS_BUFFER_SIZE] = { 0 };
int current_bullet_buffer = 0;

enemy enemy_buffer[ENEMIES_BUFFER_SIZE] = { 0 };
int enemies_left = ENEMIES_BUFFER_SIZE;

// Mouse
Vector2 virtual_mouse_pos = { 0 };
Expand Down Expand Up @@ -142,6 +143,7 @@ void reset_state(void) {
player_dir = (Vector2){ 0.0f, 0.0f };
player_speed = 0.0f;
player_health = PLAYER_MAX_HEALTH;
enemies_left = ENEMIES_BUFFER_SIZE;
game_over = false;
game_pause = false;

Expand Down Expand Up @@ -197,9 +199,11 @@ bool is_shoot(void) {
}

void set_game_over(void) {
player_health = 0;
game_over = true;
PlaySound(game_over_sound);
if (enemies_left) {
player_health = 0;
game_over = true;
PlaySound(game_over_sound);
}
}

void update_camera(void) {
Expand Down Expand Up @@ -250,6 +254,9 @@ void draw_and_update_enemies(float delta) {
if (bullet_buffer[j].visible && !bullet_buffer[j].enemy) {
PlaySound(enemy_damage_sound);
enemy_buffer[i].health--;
if (!enemy_buffer[i].health) {
enemies_left--;
}
bullet_buffer[j].visible = false;
}

Expand Down Expand Up @@ -446,14 +453,18 @@ void draw_window(Color color) {
DrawRectangleLinesEx(rec, 3, color);
}

void draw_game_over(void) {
void draw_game_over(bool win) {
draw_window(BLUE);

char *text = "GAME OVER";
int pos_x = (RENDER_WIDTH/2) - (MeasureTextEx(GetFontDefault(), text, 50, 20).x/2);
char *over_text = "GAME OVER";
char *win_text = "YOU WIN";

char *current_text = win ? win_text : over_text;

int pos_x = (RENDER_WIDTH/2) - (MeasureTextEx(GetFontDefault(), current_text, 50, 20).x/2);
int pos_y = (RENDER_HEIGHT/2) - 150;

DrawText(text, pos_x, pos_y, 70, RED);
DrawText(current_text, pos_x, pos_y, 70, RED);

update_and_draw_button(&buttons[0], virtual_mouse_pos, (Vector2){ RENDER_WIDTH, RENDER_HEIGHT });
update_and_draw_button(&buttons[1], virtual_mouse_pos, (Vector2){ RENDER_WIDTH, RENDER_HEIGHT });
Expand Down Expand Up @@ -485,19 +496,11 @@ void draw_health(void) {
}

void draw_enemies_left(void) {
int left = 0;

for (int i = 0; i < ENEMIES_BUFFER_SIZE; i++) {
if (enemy_buffer[i].health > 0) {
left++;
}
}

float left_offset = (RENDER_WIDTH/2) - ((left * 40.0f)/2);
float left_offset = (RENDER_WIDTH/2) - ((enemies_left * 40.0f)/2);

Vector2 pos = { 10.0f , 60.0f };

for (int i = 0; i < left; i++) {
for (int i = 0; i < enemies_left; i++) {
pos.x = (40.0f * i) + left_offset;
DrawRectangleV(pos, (Vector2){ 30.0f, 10.0f }, RED);
}
Expand Down Expand Up @@ -596,11 +599,15 @@ static void on_scene_update(void(*change_scene)(scene *scn), bool *should_exit,
if (game_over) {
char *game_over_message = "Man, You suck!";
DrawText(game_over_message, (RENDER_WIDTH/2) - (MeasureText(game_over_message, IN_GAME_FONT_SIZE)/2), 20, IN_GAME_FONT_SIZE, RED);
draw_game_over();
draw_game_over(false);
} else {
char *game_hint = "Destory enemies and avoid astroids";
DrawText(game_hint, (RENDER_WIDTH/2) - (MeasureText(game_hint, IN_GAME_FONT_SIZE)/2), 20, IN_GAME_FONT_SIZE, RED);
}

if (!enemies_left) {
draw_game_over(true);
}

if (!player_health && !game_over) {
set_game_over();
Expand Down Expand Up @@ -647,7 +654,6 @@ static void on_scene_update(void(*change_scene)(scene *scn), bool *should_exit,
}

static void on_scene_exit(void) {
printf("game Scene exit\n");
}

scene game_scene = {
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/main_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void event_handle(void) {

static void on_scene_update(void(*change_scene)(scene *scn), bool *should_exit, float delta) {
BeginDrawing();

ClearBackground((Color){18, 18, 18, 255});

draw_title((Vector2){ GetScreenWidth()/ 2, (GetScreenHeight()/2) - 100 }, "Kosmos");
Expand All @@ -98,7 +99,6 @@ static void on_scene_update(void(*change_scene)(scene *scn), bool *should_exit,


static void on_scene_exit(void) {
printf("Main exit\n");
}

const scene main_scene = {
Expand Down

0 comments on commit e9918c6

Please sign in to comment.