Last active
December 16, 2015 12:18
-
-
Save cstrat/5433155 to your computer and use it in GitHub Desktop.
103:23: error: initialization makes integer from pointer without a cast [-Werror]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pebble_os.h" | |
#include "pebble_app.h" | |
#include "pebble_fonts.h" | |
#define MY_UUID { 0x7E, 0xAE, 0xA1, 0x05, 0x71, 0xC3, 0x4E, 0x4F, 0xAF, 0xF8, 0x19, 0x40, 0x88, 0xEA, 0x4A, 0xA4 } | |
PBL_APP_INFO(MY_UUID, "Squash Scorer V3", "Chris Stratford", 1, 1, DEFAULT_MENU_ICON, APP_INFO_STANDARD_APP); | |
#define SCREEN_HEIGHT 152 | |
#define SCREEN_WIDTH 144 | |
#define LEFT_PADDING 5 | |
#define TOP_PADDING 5 | |
#define RIGHT_PADDING 5 | |
#define BOTTOM_PADDING 5 | |
Window window; | |
BmpContainer background_container; | |
TextLayer layer_direction; | |
TextLayer layer_p1_games; | |
TextLayer layer_p1_score; | |
TextLayer layer_p2_games; | |
TextLayer layer_p2_score; | |
static int direction; | |
static int game_count; | |
static int p1_score; | |
static int p1_games; | |
static int p2_score; | |
static int p2_games; | |
void config_provider(ClickConfig **config, Window *window); | |
void update_screen(); | |
void swap_direction(); | |
void check_scores(); | |
void handle_init(AppContextRef ctx) { | |
(void)ctx; | |
window_init(&window, "SQUASH - VERSION 3"); | |
window_stack_push(&window, true); | |
// Load Resources | |
resource_init_current_app(&APP_RESOURCES); | |
// Set Background | |
bmp_init_container(RESOURCE_ID_BACKGROUND_IMAGE, &background_container); | |
layer_add_child(&window.layer, &background_container.layer.layer); | |
// Set Action List | |
window_set_click_config_provider(&window, (ClickConfigProvider) config_provider); | |
// Initialise Variables | |
p1_score = 0; | |
p2_score = 0; | |
p1_games = 0; | |
p2_games = 0; | |
game_count = 1; | |
// Set Text Layers | |
text_layer_init(&layer_direction, GRect(LEFT_PADDING, 65, SCREEN_WIDTH-LEFT_PADDING-RIGHT_PADDING, 20)); | |
text_layer_set_text_alignment(&layer_direction, GTextAlignmentCenter); | |
text_layer_set_text_color(&layer_direction, GColorBlack); | |
text_layer_set_text(&layer_direction, "RIGHT > > >"); | |
layer_add_child(&window.layer, &layer_direction.layer); | |
text_layer_init(&layer_p1_games, GRect(LEFT_PADDING, TOP_PADDING, (SCREEN_WIDTH/2)-LEFT_PADDING, 30)); | |
text_layer_set_text_alignment(&layer_p1_games, GTextAlignmentLeft); | |
text_layer_set_text_color(&layer_p1_games, GColorBlack); | |
text_layer_set_text(&layer_p1_games, "Games: 0/1"); | |
layer_add_child(&window.layer, &layer_p1_games.layer); | |
text_layer_init(&layer_p1_score, GRect(SCREEN_WIDTH/2, TOP_PADDING, (SCREEN_WIDTH/2)-RIGHT_PADDING, 30)); | |
text_layer_set_text_alignment(&layer_p1_score, GTextAlignmentRight); | |
text_layer_set_text_color(&layer_p1_score, GColorBlack); | |
text_layer_set_text(&layer_p1_score, "Player 1"); | |
layer_add_child(&window.layer, &layer_p1_score.layer); | |
text_layer_init(&layer_p2_games, GRect(LEFT_PADDING, 100, (SCREEN_WIDTH/2)-LEFT_PADDING, 30)); | |
text_layer_set_text_alignment(&layer_p2_games, GTextAlignmentLeft); | |
text_layer_set_text_color(&layer_p2_games, GColorBlack); | |
text_layer_set_text(&layer_p2_games, "Games: 0/1"); | |
layer_add_child(&window.layer, &layer_p2_games.layer); | |
text_layer_init(&layer_p2_score, GRect(SCREEN_WIDTH/2, 100, (SCREEN_WIDTH/2)-RIGHT_PADDING, 30)); | |
text_layer_set_text_alignment(&layer_p2_score, GTextAlignmentRight); | |
text_layer_set_text_color(&layer_p2_score, GColorBlack); | |
text_layer_set_text(&layer_p2_score, "Player 2"); | |
layer_add_child(&window.layer, &layer_p2_score.layer); | |
} | |
void pbl_main(void *params) { | |
PebbleAppHandlers handlers = { | |
.init_handler = &handle_init | |
}; | |
app_event_loop(params, &handlers); | |
} | |
void update_screen() { | |
const char str_p1_games = "Games: 0/1"; | |
const char str_p2_games = "Games: 0/1"; | |
const char str_p1_score = "0"; | |
const char str_p2_score = "0"; | |
// Set Player Games | |
text_layer_set_text(&layer_p1_games, str_p1_games); | |
text_layer_set_text(&layer_p2_games, str_p2_games); | |
// Set Player Scores | |
text_layer_set_text(&layer_p1_score, str_p1_score); | |
text_layer_set_text(&layer_p2_score, str_p2_score); | |
// Set Direction | |
if (direction == 0) { | |
text_layer_set_text(&layer_direction, "RIGHT > > >"); | |
}else{ | |
text_layer_set_text(&layer_direction, "< < < LEFT"); | |
} | |
} | |
void swap_direction() { | |
if (direction == 0) { | |
direction = 1; | |
}else{ | |
direction = 0; | |
} | |
} | |
void check_scores() { | |
// Make sure not less than 0 | |
if (p1_score < 0) { p1_score = 0; } | |
if (p2_score < 0) { p2_score = 0; } | |
// Check for winner | |
if (p1_score >= 11 && p2_score < (p1_score-2)) { | |
// Player 1 Winner | |
} | |
if (p2_score >= 11 && p1_score < (p2_score-2)) { | |
// Player 2 Winner | |
} | |
} | |
void click_player1(ClickRecognizerRef recognizer, Window *window) { | |
p1_score++; | |
check_scores(); | |
swap_direction(); | |
update_screen(); | |
} | |
void click_player2(ClickRecognizerRef recognizer, Window *window) { | |
p2_score++; | |
check_scores(); | |
swap_direction(); | |
update_screen(); | |
} | |
void hold_player1(ClickRecognizerRef recognizer, Window *window) { | |
p1_score--; | |
check_scores(); | |
swap_direction(); | |
update_screen(); | |
} | |
void hold_player2(ClickRecognizerRef recognizer, Window *window) { | |
p2_score--; | |
check_scores(); | |
swap_direction(); | |
update_screen(); | |
} | |
void config_provider(ClickConfig **config, Window *window) { | |
config[BUTTON_ID_UP]->click.handler = (ClickHandler)click_player1; | |
config[BUTTON_ID_UP]->long_click.handler = (ClickHandler)hold_player1; | |
config[BUTTON_ID_UP]->long_click.delay_ms = 1000; | |
config[BUTTON_ID_DOWN]->click.handler = (ClickHandler)click_player2; | |
config[BUTTON_ID_DOWN]->long_click.handler = (ClickHandler)hold_player1; | |
config[BUTTON_ID_DOWN]->long_click.delay_ms = 1000; | |
//config[BUTTON_ID_RESET]->click.handler = (ClickHandler)reset_handler; | |
//config[BUTTON_ID_RESET]->long_click.handler = (ClickHandler)reset_handler; | |
//config[BUTTON_ID_RESET]->long_click.delay_ms = 1000; | |
(void)window; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment