void init_params(t_params *par) { par->config.oculus = 0; par->sound_toggle = 50; par->curr_opacity = 0; par->intro_volume = 100; par->intro_sound = bunny_load_music("assets/musics/menu_loop.wav"); par->menu_sound = bunny_load_music("assets/musics/menu.wav"); par->window = bunny_start(1920, 1080, 1, "Emmanuel can't, but {DOOM}inique Strauss can"); par->background = bunny_new_pixelarray(1920, 1080); par->game_bg = bunny_new_pixelarray(1920, 1080); par->option = bunny_new_pixelarray(500, 70); par->cur_pos = *bunny_get_mouse_position(); if (!(par->option) || !(par->background) || !(par->window) || !(par->game_bg)) err("Error: can't start Doom\n"); init_buttons(&par->menu_buttons); init_connect(&par->connect_buttons); par->again = GO_ON; par->current = &menu; par->fullscreen = 0; par->origin.x = (par->origin.y = 0); par->data = malloc(sizeof(t_data)); par->data->win = NULL; par->data->message.indice = 200; bunny_sound_play(par->intro_sound); bunny_sound_volume(par->intro_sound, 60); }
int main(void) { io_init(); init_buttons(); init_potis(); DDRPOTI_SEL_PORT = 0xFF; PORTPOTI_SEL_PORT = 0xFF; DDRA = 0x00; PORTA = 0xFF; ADMUX = 0; int i; for (i =0 ; i < 100; i++) { ask_buttons(); ask_potis(); } for (;;) { ask_buttons(); midi_buttons(); ask_potis(); midi_potis(); } }
void init() { srand ( (unsigned int)time(NULL) ); dbgoutf("Initialisation en cours..."); init_sdl(); init_buttons(); }
void bios(void) { uart_start(); pwm_setup(2); adc_start(1); twi_start(); //button code init_buttons(); //set the CPU_POW led pin to high to show we have power DDRD |= (1<<CPU_POW); PORTD |= (1<<CPU_POW); //set the status leds as outputs DDRD |= (1<<stat_led1); DDRD |= (1<<stat_led2); //if this is my dev board, pull them low because the leds are cathode #if DEV PORTD &= ~(1<<stat_led1) & ~(1<<stat_led2); #endif #if DEBUG uart_sendstr("0x01 - Hardware setup successful..."); uart_sendstr("Bios complete..."); uart_sendstr("Starting main code..."); #endif return; }
int main(void) { DDRC |= (1 << DDRC7); PORTC |= (1 << PORTC7); _delay_ms(2); PORTC &= ~(1 << PORTC7); init_power(); init_timeout_timer(); init_switch(); init_ref_clock(); init_spi(2); init_buttons(); init_serial(2400); init_adc(); init_i2c(); //Turn on interrupts sei(); play_sounds(); //Debug: Never Gets here while(1) { _delay_ms(1000); get_POT_set_TWIPOT(); } }
void init() { ResetReason = MCUSR; cli(); WDT_off(); // Turn off until initialization is done and we can pet the dog. init_leds (); init_buttons(); init_limit_switches(); init_motor(); float mBaseFrequencyHerz = 500.0; // 4khz pwm_init( mBaseFrequencyHerz, TRUE ); init_serial(); init_configuration(); // read_configuration_and_set(); // init_adc(); // start_sampling(); encoder_init(); // pot_init (); WDT_Prescaler_Change(); //delay(100000); // ~ 2 sec //read_cal(); // Read everything including motor stops. sei(); //OS_InitTask(); }
void main(void) { struct puzzleStruct puzzle; struct buttonStruct buttons; bool result = true; //init code here setup_int(); init_puzzle(&puzzle); init_buttons(&buttons); init_inputs(); //Enter main loop for(;;) { //Draw GUI build_gui(&puzzle); //Handle USB update_puzzle(&puzzle,&buttons); //Set output set_output(&puzzle); //Check inputs update_buttons(&buttons); //Read result result = check_result(&puzzle); } }
/** * \brief Main entry of example application */ int main(void) { /* Variable to store the last winner */ uint8_t winner; system_init(); delay_init(); gfx_mono_init(); init_buttons(); init_display(); /* Start game */ while (true) { winner = 0; /* Wait for button interaction */ while (get_button() == BUTTON_NONE) { } /* Draw empty board */ setup_board(); /* Start playing */ for (int i = 0; i < 5; i++) { /* User's turn */ user_turn(); /* Check if the game is over */ winner = we_have_a_winner(); if (winner || i == 4) { break; } /* Add a delay for the opponent to "think" */ delay_ms(500); /* Opponent's turn */ opponent_turn(); /* Check if the game is over */ winner = we_have_a_winner(); if (winner) { break; } } /* Game over, print winner and get ready for restart */ if (winner == 1) { /* User won */ gfx_mono_draw_string("You won!", STRING_X, 0, &sysfont); wins++; } else if (winner == 2) { gfx_mono_draw_string("You lost!", STRING_X, 0, &sysfont); } else { gfx_mono_draw_string("No winner!", STRING_X, 0, &sysfont); } gfx_mono_draw_string("Press a button", STRING_X, SQUARE3_Y, &sysfont); games++; } }
/* Initialisation */ void rcx_init (void) { init_timer(&async, &dispatch[0]); init_power(); systime_init(); init_sensors(); //init_motors init_buttons(); // Buttons & display pins init_serial(0, 0, 1, 1); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); LCDinit(); LCDclear(); unsigned char player = initPlayer(); init_timer(); init_buttons(); __enable_interrupt(); printPlayer(player); while(1) { player = movementCheck(player); if(LOSE == 1){ LCDclear(); print("GAME"); secondLine(); print("OVER"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(didPlayerWin(player)){ LCDclear(); print("YOU"); secondLine(); print("WON"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(GAMEOVER){ char buttonsToPoll[4] = {BIT1, BIT2, BIT3, BIT4}; while(!pollP1Buttons(buttonsToPoll, 4)){ //poll until something is pressed } TAR = 0; LOSE = 0; TIMER = 0; GAMEOVER = 0; LCDclear(); player = initPlayer(); printPlayer(player); } } return 0; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; player = initPlayer(); initSPI(); LCDinit(); LCDclear(); RenewGame(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if (player==0xC7) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gamedone = 1; _delay_cycles(1000000); } if (CountTimer >=4) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over"); gamedone = 1; _delay_cycles(1000000); } } return 0; }
interface_drawer* create_interface_drawer(void) { interface_drawer* i_drawer = (interface_drawer*) malloc(sizeof (interface_drawer)); i_drawer->num_buttons = 48; i_drawer->butt = (button*) malloc(i_drawer->num_buttons * sizeof (button)); init_buttons(i_drawer); return i_drawer; }
int main(void) { init_buttons(); init_leds(); init_display(intensity); init_uart(); uart_interrupt_enable(); sei(); // main loop while(1) { // while button 1 is pressed, increment display brightness (mod 16) uint8_t button_status = debounce(&BUTTON0_PIN, BUTTON0); if(button_status == 1) { intensity = (intensity + 1) % 16; set_register_b(REG_INTENSITY, intensity); } else if(button_status == 2) { LIGHT_PORT ^= (1<<LIGHT); } // if timer is stopped (but not yet resetted) ... if(state == 'S') { // ... and button 0 has been pressed (and released), // save the current time in the times array (only once!) if(debounce(&BUTTON1_PIN, BUTTON1) && !time_already_saved) { uart_interrupt_disable(); append(times, TIMES, last_correct_decoded_time); led_blink(2); time_already_saved = 1; uart_interrupt_enable(); } } // if timer has been stopped or reset ... if(state == 'I' || state == 'S') { // ... and button 0 is pressed, show the current average if(!(BUTTON2_PIN & (1<<BUTTON2))) { uart_interrupt_disable(); display_uint16_time(average()); my_delay_ms(1500); while(!(BUTTON2_PIN & (1<<BUTTON2))); uart_interrupt_enable(); } } } }
int main(void) { init_buttons(); init_LEDs(); while(1) { if (BUT1) setLED1; else clearLED1; if (BUT2) setLED2; else clearLED2; if (BUT3) setLED3; else clearLED3; if (BUT4) setLED4; else clearLED4; } }
/* Intializes the LED, sets the default value, and loops. */ void main(void) { init_buttons(); led_init(); led_display_text("Hello World from ZNEO"); //enable interrupts EI(); //run forever while(1) { //do nothing while responding to interrupts } }
int Menu::run(sf::RenderWindow &window) { if (!initialized) { initialized = true; if (!init_buttons()) return -1; } if (text[0] == "Easy") { cursor_loc = 1; blist[1].toggleHighlight(sf::Color::Yellow); } else { cursor_loc = 0; blist[0].toggleHighlight(sf::Color::Yellow); } bool selecting = true; while (selecting) { sf::Event e; while (window.pollEvent(e)) { if (e.type == sf::Event::Closed) { selecting = false; cursor_loc = -1; } else if (e.type == sf::Event::KeyPressed) { if (e.key.code == sf::Keyboard::Up) { if (cursor_loc > 0) { blist[cursor_loc--].toggleHighlight(sf::Color::Yellow); blist[cursor_loc].toggleHighlight(sf::Color::Yellow); } } else if (e.key.code == sf::Keyboard::Down) { if (cursor_loc < blist.size() - 1) { blist[cursor_loc++].toggleHighlight(sf::Color::Yellow); blist[cursor_loc].toggleHighlight(sf::Color::Yellow); } } else if (e.key.code == sf::Keyboard::Z) { blist[cursor_loc].toggleHighlight(sf::Color::Yellow); selecting = false; } else if (e.key.code == sf::Keyboard::X) { blist[cursor_loc].toggleHighlight(sf::Color::Yellow); selecting = false; cursor_loc = numbuttons - 1; } } } window.clear(sf::Color::White); for (int i = 0; i < blist.size(); i++) { blist[i].draw(window); } window.display(); } return ret_signal[cursor_loc]; }
/** * Initializes everything on the robot * @author Group B1 * @param oi The open interface of the robot * @date 12/4/2012 */ void init_all(oi_t *oi) { oi = oi_alloc(); oi_init(oi); init_buttons(); init_usart(); lcd_init(); timer3_init(); ADC_init(); init_printf(0,write_one_char); move_servo(0); wait_ms(1000); printf("\n"); printf("\n"); }
static void setupHardware(void) { // TODO: Put hardware configuration and initialisation in here disable_global_int(); clk_system_init(); init_leds(); //init_pot(); init_buttons(); init_spi(); init_lcd_write_task(); init_uart0(); init_joystick(); enable_global_int(); // Warning: If you do not initialize the hardware clock, the timings will be inaccurate }
/* Intializes the hardware and loop. */ void main(void) { DI(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); init_midi_out(); init_buttons(); //enable interrupts EI(); //loop infinitely while(1) { ; } }
int main() { init(); init_positions(); init_buttons(); while(1) { if(ButtonPressed(BUTTON3, PA2)) { change_mode(); } process_mode(currentMode); } return 0; }
/* Intializes the LED, sets the default value, and loops. */ void main(void) { //initialize the hardware init_buttons(); init_speaker(); init_leds(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); //enable interrupts EI(); //run forever while(1) { //do nothing while responding to interrupts } }
void init_game_state(GameState * state) { //stel de beginwaarden van eigenschappen in init_world_from_file(&state->world, "assets/worlds/world1.world"); state->game_over = 0; state->wave.wave_number = 0; state->spells.frost_wave_active = 0; state->spells.poison_gas_active = 0; state->spells.spell_duration = 0; init_wave(state); state->enemies = (Entity*) malloc(sizeof(Entity)); state->towers = (Entity**) malloc(sizeof(Entity*)); state->enemies_length = 0; state->towers_length = 0; state->world.castle->castle.health = CASTLE_HEALTH; state->mana = 1250; state->money = 10000; state->score = 0; state->play = 0; init_buttons(&state->hud); }
int main(int argc, char **argv) { t_gmine gmine; gl_gmine = &gmine; init_gtk(argc, argv, &gmine); init_main(&gmine); init_table(&gmine); if ((gmine.buttons = malloc(gmine.x * gmine.y * sizeof(t_button))) == NULL) exit(1); init_pixmap(&gmine); init_menu(&gmine); init_buttons(&gmine); init_mines(&gmine); init_text(&gmine); gtk_timeout_add(1000, (GtkFunction) m_timer, &gmine); gtk_widget_show_all(gmine.window); gtk_main(); return (0); }
int main(void){ init_serial(); init_ISR(); //initialize all functions, ports... init_led(); init_buttons(); init_temp(); get_temp(); ht=temp; lt=temp; init_lcd(); while(1){ get_temp(); //recieve the temp, convert and print led_on(); //turn the led functions on get_serial(); //recieve the temp through serial } return 0; }
int main(void) { WDTCTL = (WDTPW|WDTHOLD); player = initPlayer(); //debugging: had player defined twice, caused * to jump around alot initSPI(); LCDinit(); LCDclear(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if(player == 0xC7){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gameover = 1; _delay_cycles(100000); } if(timerCount >= 4){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over!"); gameover = 1; _delay_cycles(100000); } } return 0; }
/* Intializes the hardware, loop on the CLI. */ void main(void) { DI(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); init_midi_sensors(SENSOR_NOTES, SENSOR_CTRL_1); init_midi_out(); init_buttons(); init_leds(); //initialize the command line interface init_cli(); //enable interrupts EI(); cli_loop(); }
// TODO: remove init_core_sprites, put instead ini_base_images. // Game entry point, calls all initialization functions before calling main_loop int main(int argc, char** argv) { // Declare main struct containing the important data data = (GDATAPTR)malloc(sizeof(GDATA)); // Initialize Allegro 5 and addon routines al_init(); al_init_primitives_addon(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); PHYSFS_init(argv[0]); // Initialize the core game data structure if(!data_init()) exit(EXIT_FAILURE); // Creates a player sprite if(!init_core_sprites()) exit(EXIT_FAILURE); // Initializes the buttons if(!init_buttons()) exit(EXIT_FAILURE); // Initializes the physics and collision detection if(!init_chipmunk()) exit(EXIT_FAILURE); // Create the progress bar loader(); // Enters the main loop, where everything happens main_loop(); // Cleanup before exit cleanup(data); // Return 0 before exit return 0; }
// ************************************************************************************************* // @fn init_application // @brief Initialize the microcontroller. // @param none // @return none // ************************************************************************************************* void init_application(void) { volatile unsigned char *ptr; #ifndef EMU // --------------------------------------------------------------------- // Enable watchdog // Watchdog triggers after 16 seconds when not cleared #ifdef USE_WATCHDOG WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK; #else WDTCTL = WDTPW + WDTHOLD; #endif // --------------------------------------------------------------------- // Configure PMM SetVCore(3); // Set global high power request enable PMMCTL0_H = 0xA5; PMMCTL0_L |= PMMHPMRE; PMMCTL0_H = 0x00; // --------------------------------------------------------------------- // Enable 32kHz ACLK P5SEL |= 0x03; // Select XIN, XOUT on P5.0 and P5.1 UCSCTL6 &= ~XT1OFF; // XT1 On, Highest drive strength UCSCTL6 |= XCAP_3; // Internal load cap UCSCTL3 = SELA__XT1CLK; // Select XT1 as FLL reference UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV; // --------------------------------------------------------------------- // Configure CPU clock for 12MHz _BIS_SR(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = DCORSEL_5; // Select suitable range UCSCTL2 = FLLD_1 + 0x16E; // Set DCO Multiplier _BIC_SR(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle __delay_cycles(250000); // Loop until XT1 & DCO stabilizes, use do-while to insure that // body is executed at least once do { UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG); SFRIFG1 &= ~OFIFG; // Clear fault flags } while ((SFRIFG1 & OFIFG)); // --------------------------------------------------------------------- // Configure port mapping // Disable all interrupts __disable_interrupt(); // Get write-access to port mapping registers: PMAPPWD = 0x02D52; // Allow reconfiguration during runtime: PMAPCTL = PMAPRECFG; // P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output) ptr = &P2MAP0; *(ptr+7) = PM_TA1CCR0A; P2OUT &= ~BIT7; P2DIR |= BIT7; // P1.5 = SPI MISO input ptr = &P1MAP0; *(ptr+5) = PM_UCA0SOMI; // P1.6 = SPI MOSI output *(ptr+6) = PM_UCA0SIMO; // P1.7 = SPI CLK output *(ptr+7) = PM_UCA0CLK; // Disable write-access to port mapping registers: PMAPPWD = 0; // Re-enable all interrupts __enable_interrupt(); #endif // --------------------------------------------------------------------- // Configure ports // --------------------------------------------------------------------- // Reset radio core radio_reset(); radio_powerdown(); // --------------------------------------------------------------------- // Init acceleration sensor as_init(); // --------------------------------------------------------------------- // Init LCD lcd_init(); // --------------------------------------------------------------------- // Init buttons init_buttons(); // --------------------------------------------------------------------- // Configure Timer0 for use by the clock and delay functions Timer0_Init(); // --------------------------------------------------------------------- // Init pressure sensor ps_init(); }
int welcome_main() { int i,j; int mx,my; int welcome = true; int option_screen = false; int score_screen = false; int first_run = true; int credits_screen = false; SDL_Rect temp; TTF_Font *MyFont; SDL_Color GREEN = {0,255,0}; SDL_Color WHITE = {255,255,255}; SDL_Surface *message = NULL; int option = -1; init_buttons(); init_images(); draw_image(backk,screen,NULL,0,0); gameLog("Welcome screen initialized..."); //draw_image(message,screen,NULL,0,0); //Mix_PlayMusic(background_music,-1); while(welcome) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEMOTION: for(i=0;i<TOTAL_NO_BUTTON;++i) { handle_mouseover(&button[i],event.motion.x,event.motion.y); } break; case SDL_MOUSEBUTTONDOWN: mx = event.button.x; my = event.button.y; for( i = 0; i < TOTAL_NO_BUTTON; ++i) { if(check_click(button[i],mx,my)==true) { if(sound)Mix_PlayChannel(-1,click_sound,4); animate_button(button[i],i); first_run = true; switch(i) { case 0: option = 1; welcome = false; break; case 1: option_screen = true; break; case 2: score_screen = true; break; case 3: credits_screen = true; break; case 4: option = -1; welcome = false; break; } } } break; case SDL_QUIT: welcome = false; option = -1; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_p: animate_button(button[0],0); welcome = false; option = 1; break; case SDLK_x: animate_button(button[4],4); welcome = false; option = -1; break; case SDLK_1: if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(background_music,-1); } else { if(Mix_PausedMusic() == 1) { sound = true; Mix_ResumeMusic(); } else { sound = false; Mix_PauseMusic(); } } break; case SDLK_0: Mix_HaltMusic(); break; } } } //---=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- while(option_screen == true) { if(first_run) { draw_image(option_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } draw_image(sound_icon[sound],screen,NULL,sound_button.dimension.x,sound_button.dimension.y); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(sound_button,mx,my) == true) { if(sound == 0) sound = 1; else sound =0; } if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); option_screen = false; } } } SDL_Flip(screen); } //========================================================================================== while(score_screen == true) { if(first_run) { draw_image(score_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); show_scores(); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); score_screen = false; } } } SDL_Flip(screen); } //========================================================================================== //========================================================================================== while(credits_screen == true) { if(first_run) { temp.x = 0; temp.y = 0; temp.w = 1100; temp.h = 600; clear_image(temp); MyFont = TTF_OpenFont("fonts\\lfont.ttf",32); message = TTF_RenderText_Blended(MyFont,"Developed By:",WHITE); draw_image(message,screen,NULL,100,100); SDL_FreeSurface(message); message = NULL; TTF_CloseFont(MyFont); MyFont = TTF_OpenFont("fonts\\sfont.ttf",20); message = TTF_RenderText_Blended(MyFont,"-> Bishruti Siku",GREEN); draw_image(message,screen,NULL,100,150); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Nitish Dhaubhadel",GREEN); draw_image(message,screen,NULL,100,170); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Iksha Gurung",GREEN); draw_image(message,screen,NULL,100,190); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Pranaya Pradhananga",GREEN); draw_image(message,screen,NULL,100,210); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Sandip Sahani",GREEN); draw_image(message,screen,NULL,100,230); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Computer Engineering",WHITE); draw_image(message,screen,NULL,100,300); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Kathmandu University",WHITE); draw_image(message,screen,NULL,100,320); SDL_FreeSurface(message); message = NULL; draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); credits_screen = false; } } } SDL_Flip(screen); } //========================================================================================== for(i=0;i<TOTAL_NO_BUTTON;++i) { draw_image(button_image[i][button[i].state],screen,NULL,button[i].dimension.x,button[i].dimension.y); } SDL_Flip(screen); } SDL_FreeSurface(option_screen_image); SDL_FreeSurface(score_screen_image); SDL_FreeSurface(back_button_image); SDL_FreeSurface(sound_icon[0]); SDL_FreeSurface(sound_icon[1]); SDL_FreeSurface(message); message = NULL; SDL_FreeSurface(backk); for(i=0;i<TOTAL_NO_BUTTON;++i) { for(j=0;j<2;++j) { SDL_FreeSurface(button_image[i][j]); } } //TTF_CloseFont(font); gameLog("Welcome screen closed..."); return option; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Use seed to create a random number static const char seed = 1234; //Define all of the strings that will be used in the program char * you = "YOU "; char * win = "WIN! "; char * game = "GAME "; char * over = "OVER! "; char * boom = "BOOM! "; char * space = " "; //Initialize the timer init_timer(); //Initialize the buttons init_buttons(); //Enable the interrupt __enable_interrupt(); //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Place the player at the starting location printPlayer(location); //Create random mine placement char random = prand(seed); random = prand(random); char mine1Location = 0x81 + random % 7; random = prand(random); char mine2Location = 0xC0 + random % 7; //print the first mine, and check to make sure the second mine is printed in a place that the user can still win the game printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); //during the rest of the game while (1) { //This is the end of the level - player wins! if (location == 0xC7) { print2LineMessage(you, win); //Set flag and increment to a value above 4 so that 'game over' is not printed flag = 5; increment = 5; //Reset the game for the next level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); increment = 0; } //The game is over if the player hits a mine if (location == mine1Location || location == mine2Location) { flag = 4; print2LineMessage(boom, space); __delay_cycles(444444); } //If two seconds have passed, increment the mines to move in the opposite directions of each other if (increment == 4) { clearPlayer(mine1Location); clearPlayer(mine2Location); mine1Location--; mine2Location++; printMine(mine1Location); printMine(mine2Location); increment = 0; } //If the player loses, print 'game over' if (flag == 4) { print2LineMessage(game, over); flag = 5; increment = 5; //Reset the game for a new level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); flag = 0; increment = 0; mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); } } }