Skip to content

Commit

Permalink
Merge branch 'dhruv_scalm' into 'master'
Browse files Browse the repository at this point in the history
Dhruv scalm

See merge request cs3-24sp/game-radagast!5
  • Loading branch information
emayecs committed Jun 13, 2024
2 parents a61bb31 + 36814d2 commit bed7592
Show file tree
Hide file tree
Showing 69 changed files with 2,793 additions and 4,311 deletions.
Empty file removed .debug
Empty file.
14 changes: 13 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
"vector.h": "c",
"observer.h": "c",
"cmath": "c",
"stddef.h": "c"
"stddef.h": "c",
"achievement.h": "c",
"emscripten.h": "c",
"polygon.h": "c",
"color.h": "c",
"array": "c",
"bitset": "c",
"string_view": "c",
"initializer_list": "c",
"regex": "c",
"utility": "c",
"valarray": "c",
"collision.h": "c"
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# List of C files in "libraries" and "demo" that you have written. Any additional files
# should be added here.
GAMES = game home settings game_play game_over
STUDENT_LIBS = asset_cache asset body collision color emscripten forces list polygon scene sdl_wrapper vector constants asset_helper observer subject achievement
STUDENT_LIBS = asset_cache asset body collision color emscripten forces list polygon scene sdl_wrapper vector constants asset_helper observer subject achievement screen_helper game_play_helper

# find <dir> is the command to find files in a directory
# ! -name .gitignore tells find to ignore the .gitignore
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Please don't use incognito. Otherwise, the achievements won't be saved.
- Please try on Chrome for best results.
- Please run without asan when testing achievements. Since Asan is so slow, the events may not be received and acted upon before the game ends.
- There is an intentional 3 second delay for some powerups for activation

## Section 0: Summary
This section should tell the reader what to expect in the future sections. In particular, it should contain at least:
Expand Down
Binary file removed assets/BabyElephantWalk60.wav
Binary file not shown.
Binary file removed assets/avengers.mp3
Binary file not shown.
Binary file added assets/barry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/black_circle.png
Binary file not shown.
Binary file added assets/force_shield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/frogger-background.png
Binary file not shown.
Binary file removed assets/frogger.png
Binary file not shown.
Binary file added assets/gravity_swap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/laser.png
Binary file not shown.
Binary file removed assets/log.png
Binary file not shown.
Binary file added assets/magnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/money.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/output.mp3
Binary file not shown.
Binary file added assets/powerup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/powerup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 102 additions & 45 deletions demo/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "asset.h"
#include "asset_cache.h"
#include "sdl_wrapper.h"
#include "constants.h"

struct state {
struct state
{
state_type_t curr_state;
difficulty_type_t difficulty_level;
home_state_t *home_state;
Expand All @@ -21,82 +23,112 @@ struct state {
game_over_state_t *game_over_state;
};

void run_home(state_t *state) {
/**
* Running the home screen each tick
*/
static void run_home(state_t *state)
{
home_state_t *home_state = state->home_state;
if (!home_state) {
if (!home_state)
{
home_state = home_init();
state->home_state = home_state;
}
state_type_t next_state = home_main(home_state);
if (sdl_is_done((void *)home_state)) {
if (sdl_is_done((void *)home_state))
{
state->home_state = NULL;
home_free(home_state);
}
else if (next_state != HOME) {
else if (next_state != HOME)
{
state->home_state = NULL;
state->curr_state = next_state;
home_free(home_state);
}
}

void run_settings(state_t *state) {
/**
* Running the settings screen each tick
*/
static void run_settings(state_t *state)
{
settings_state_t *settings_state = state->settings_state;
if (!settings_state) {
if (!settings_state)
{
settings_state = settings_init();
state->settings_state = settings_state;
settings_state->difficulty_level = state->difficulty_level;
}
state_type_t next_state = settings_main(settings_state);
state->difficulty_level = settings_state->difficulty_level;
if (sdl_is_done((void *)settings_state)) {
if (sdl_is_done((void *)settings_state))
{
state->settings_state = NULL;
settings_free(settings_state);
}
else if (next_state != SETTINGS) {
else if (next_state != SETTINGS)
{
state->settings_state = NULL;
state->curr_state = next_state;
settings_free(settings_state);
}
}

void run_game_play(state_t *state) {
/**
* Running the game play each tick
*/
static void run_game_play(state_t *state)
{
game_play_state_t *game_play_state = state->game_play_state;
if (!game_play_state) {
if (!game_play_state)
{
game_play_state = game_play_init(state->difficulty_level);
state->game_play_state = game_play_state;
}
state_type_t next_state = game_play_main(game_play_state);
if (sdl_is_done((void *)game_play_state)) {
if (sdl_is_done((void *)game_play_state))
{
state->game_play_state = NULL;
game_play_free(game_play_state);
}
else if (next_state != GAME_PLAY) {
else if (next_state != GAME_PLAY)
{
state->game_play_state = NULL;
state->curr_state = next_state;
game_play_free(game_play_state);
}
}

void run_game_over(state_t *state) {
/**
* Running the game over screen each tick
*/
static void run_game_over(state_t *state)
{
game_over_state_t *game_over_state = state->game_over_state;
if (!game_over_state) {
if (!game_over_state)
{
game_over_state = game_over_init();
state->game_over_state = game_over_state;
}
state_type_t next_state = game_over_main(game_over_state);
if (sdl_is_done((void *)game_over_state)) {
if (sdl_is_done((void *)game_over_state))
{
state->game_over_state = NULL;
game_over_free(game_over_state);
}
else if (next_state != GAME_OVER) {
else if (next_state != GAME_OVER)
{
state->game_over_state = NULL;
state->curr_state = next_state;
game_over_free(game_over_state);
}
}

state_t *emscripten_init() {
state_t *emscripten_init()
{
state_t *state = malloc(sizeof(state_t));
assert(state);
state->curr_state = HOME;
state->difficulty_level = EASY;
state->home_state = NULL;
Expand All @@ -106,35 +138,60 @@ state_t *emscripten_init() {
return state;
}

bool emscripten_main(state_t *state) {
switch (state->curr_state) {
case HOME: {
run_home(state);
break;
}
case SETTINGS: {
run_settings(state);
break;
}
case GAME_PLAY: {
run_game_play(state);
break;
}
case GAME_OVER: {
run_game_over(state);
break;
}
case EXIT: {
return true;
}
default: {
printf("Unknown state!\n");
exit(1);
}
bool emscripten_main(state_t *state)
{
switch (state->curr_state)
{
case HOME:
{
run_home(state);
break;
}
case SETTINGS:
{
run_settings(state);
break;
}
case GAME_PLAY:
{
run_game_play(state);
break;
}
case GAME_OVER:
{
run_game_over(state);
break;
}
case EXIT:
{
return true;
}
default:
{
fprintf(stderr, "%s\n", ERROR_MESSAGE_STATE);
exit(1);
}
}
return false;
}

void emscripten_free(state_t *state) {
void emscripten_free(state_t *state)
{
if (state->home_state != NULL)
{
home_free(state->home_state);
}
if (state->settings_state != NULL)
{
settings_free(state->settings_state);
}
if (state->game_play_state != NULL)
{
game_play_free(state->game_play_state);
}
if (state->game_over_state != NULL)
{
game_over_free(state->game_over_state);
}
free(state);
}
}
Loading

0 comments on commit bed7592

Please sign in to comment.