Skip to content

Commit

Permalink
added game restart
Browse files Browse the repository at this point in the history
  • Loading branch information
b0ggyb33 committed Jan 27, 2016
1 parent 49f1ec3 commit 25e781a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"basalt"
],
"uuid": "773e4473-32ba-405b-82cb-4d00c89d3f9a",
"versionLabel": "1.2",
"versionLabel": "2.0",
"watchapp": {
"watchface": false
}
Expand Down
14 changes: 14 additions & 0 deletions src/Game.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,18 @@ void initialiseGameState(GameState* state)
state->highScore=0;
}

}

void printGameState(GameState* state)
{
APP_LOG(APP_LOG_LEVEL_INFO, "======\nCurrent game state:\n======");
APP_LOG(APP_LOG_LEVEL_INFO, "Game in play: %u", (unsigned int)state->gameInPlay);
APP_LOG(APP_LOG_LEVEL_INFO, "Game time: %d", state->game_time);
APP_LOG(APP_LOG_LEVEL_INFO, "Score: %u", (unsigned int)state->score);
APP_LOG(APP_LOG_LEVEL_INFO, "Speed: %d", (int)state->speed);
APP_LOG(APP_LOG_LEVEL_INFO, "Crash: %d", (int)state->crash);
APP_LOG(APP_LOG_LEVEL_INFO, "Time of Last Update: %d", state->timeOfLastUpdate);
APP_LOG(APP_LOG_LEVEL_INFO, "Time of Last Speed Increase: %d", state->timeOfLastSpeedIncrease);
APP_LOG(APP_LOG_LEVEL_INFO, "Delay: %d", (int)state->delay);
APP_LOG(APP_LOG_LEVEL_INFO, "Update Speed Frequency: %d", state->updateSpeedFrequency);
}
5 changes: 3 additions & 2 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

typedef struct
{
int8_t gameInPlay;
bool gameInPlay;
int game_time;
uint16_t score;
uint16_t highScore;
Expand All @@ -17,4 +17,5 @@ typedef struct

}GameState;

void initialiseGameState(GameState* state);
void initialiseGameState(GameState* state);
void printGameState(GameState* state);
6 changes: 4 additions & 2 deletions src/js/scorePusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function sendScore(score)
}

// Construct URL
var url = "http://86.12.100.145:5000/json";
//var url = "http://54.194.206.38:80/json";
var url = "http://54.194.206.38:80/json";

// Push request to url
xhrRequest(url, 'POST', scoreToPush,
Expand All @@ -83,7 +84,8 @@ function sendScore(score)
}
function getUserName()
{
var url = "http://86.12.100.145:5000/json";
//var url = "http://54.194.206.38:80/json";
var url = "http://54.194.206.38:80/json";
// Push request to url
xhrRequestForUsername(url, 'POST',
function(responseText)
Expand Down
26 changes: 21 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static MrGameAndWatch* mgw;
static TextLayer *scoreLayer;
static TextLayer *highScoreLayer;
static TextLayer *nameLayer;
static TextLayer *restartTextLayer;

static char scoreString[10];
static char highScoreString[10];
Expand Down Expand Up @@ -154,6 +155,8 @@ void triggerEndGame(Ball* object)
renderCrash(game->crash);
sendScore(game->score);
text_layer_set_text(nameLayer, friendlyNameString);
text_layer_set_text(restartTextLayer, "Press Up to Restart ->");

}

void updateWorld()
Expand Down Expand Up @@ -226,9 +229,19 @@ static void reset_game_handler(ClickRecognizerRef recognizer, void *context)
{
if (!game->gameInPlay)
{
handle_deinit();
handle_init();
updateWorld();
text_layer_set_text(restartTextLayer,"");
text_layer_set_text(nameLayer,"");

initialiseGameState(game);
initialise_MisterGameAndWatch(mgw);
initialise_Ball(ball0, (int8_t)0, (int8_t)7, DIRECTION_RIGHT, 0);
initialise_Ball(ball1, (int8_t)0, (int8_t)9, DIRECTION_LEFT, 1);
initialise_Ball(ball2, (int8_t)0, (int8_t)11, DIRECTION_RIGHT, 2);
layer_mark_dirty(s_ball_layer);

renderScores();

app_timer_register(game->delay, updateWorld, NULL);
}
}

Expand All @@ -255,7 +268,7 @@ static void click_config_provider(void *context)
// Register the ClickHandlers
window_single_click_subscribe(BUTTON_ID_SELECT, up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
//window_single_click_subscribe(BUTTON_ID_UP, reset_game_handler);
window_single_click_subscribe(BUTTON_ID_UP, reset_game_handler);
}

void handle_init(void)
Expand All @@ -272,10 +285,12 @@ void handle_init(void)
// initialise score layers
scoreLayer = text_layer_create(GRect(0,0,60,20));
highScoreLayer = text_layer_create(GRect(144-30,0,30,20));
nameLayer = text_layer_create(GRect(0,20,160,20));
nameLayer = text_layer_create(GRect(0,40,160,20));
restartTextLayer = text_layer_create(GRect(0,20,160,20));
text_layer_set_background_color(scoreLayer, GColorClear);
text_layer_set_background_color(highScoreLayer, GColorClear);
text_layer_set_background_color(nameLayer, GColorClear);
text_layer_set_background_color(restartTextLayer, GColorClear);

// Load the images
s_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG);
Expand Down Expand Up @@ -312,6 +327,7 @@ void handle_init(void)
layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(scoreLayer));
layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(highScoreLayer));
layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(nameLayer));
layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(restartTextLayer));
layer_set_update_proc(s_ball_layer, renderBalls);

window_stack_push(my_window, true);
Expand Down

0 comments on commit 25e781a

Please sign in to comment.