void ConnectFour::drop_token(int column) { if(!board[column][0].is_empty()) { return; } for(int i = ROWS-1; i >= 0; --i) { if(board[column][i].is_empty()) { board[column][i].set_color(current); auto& ptr = falling[column]; /* cancel animations in the same column so that if one column is quickly filled, the top won't stop at its goal while the first one is still falling through empty space */ if(ptr) { delete ptr; ptr = nullptr; } ptr = new Tile::Falling(board[column][i]); update_game_state(); return; } } }
/* Recieve Wireless Data */ void wireless_recieve(void) { m_rf_read(buffer,PACKET_LENGTH); // Read RF Signal state = buffer[0]; update_game_state(); }
int main( int argc, char *argv[] ) { GLFWwindow* window; /* Setting error callback to receive any errors during initialization */ glfwSetErrorCallback(error_callback); /* Initialize library */ if( !glfwInit() ) { return( -1 ); } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow( WINDOW_WIDTH, WINDOW_HEIGHT, "Hello World", NULL, NULL ); if( !window ) { glfwTerminate(); return( -1 ); } /* Make the window's context current */ glfwMakeContextCurrent( window ); /* Initialize game state */ init_game_state( &game_ctrl ); /* Set key callback to receive key events */ glfwSetKeyCallback(window, key_callback); /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /* Render here */ update_game_state( &game_ctrl ); render_game( &game_ctrl ); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return( 0 ); }
int Game::start(){ //TODO: folgenden Code auf Exceptions statt ERROR codes umschreiben if (!initialize()){ printf("Could not initialize => exit \n"); SDL_Quit(); return 1; } else { printf("Creating a Player...\n"); Vector2D player_pos; player_pos.x = 300; player_pos.y = 300; Player* player = new Player(renderer); player->set_position(player_pos); drawable_objects.push_back(player); active_player = player; //printf("Creating 1. object...\n"); //DrawableObject* first_test_object; //first_test_object = new DrawableObject(renderer); //drawable_objects.push_back(first_test_object); printf("Creating a chargeroid...\n"); Chargeroid* chargeroid_test_object = new Chargeroid(renderer); drawable_objects.push_back(chargeroid_test_object); printf("Creating a second chargeroid...\n"); Chargeroid* chargeroid_test_object2 = new Chargeroid(renderer); drawable_objects.push_back(chargeroid_test_object2); // MAIN GAME LOOP float time_passed = 0.; float last_time_in_s = get_current_time_in_s(); float current_time_in_s = get_current_time_in_s(); while (is_Running){ current_time_in_s = get_current_time_in_s(); time_passed = float(current_time_in_s - last_time_in_s); handle_input_events(); update_game_state(time_passed); render_current_frame(); last_time_in_s = current_time_in_s; } clean_up(); return 0; } }
int main () { lc4uint event; lc4_puts ((lc4uint*)"!!! Welcome to Frogger !!!\n"); lc4_puts ((lc4uint*)"Press j to go left\n"); lc4_puts ((lc4uint*)"Press k to go up\n"); lc4_puts ((lc4uint*)"Press l to go right\n"); lc4_puts ((lc4uint*)"Press m to go down\n"); reset_game_state(); redraw (); while (1) { event = lc4_get_event(); update_game_state(event); redraw (); } return 0; }
void update_state() { sample_buttons(); update_game_state(); if(has_button_changed(OPT1_BTN_INDEX) && is_button_pressed(OPT1_BTN_INDEX)) { toggle_pause_game(); } if(has_button_changed(DOWN_BUTTON_INDEX) && is_button_pressed(DOWN_BUTTON_INDEX)) { change_direction(DOWN); } if(has_button_changed(UP_BUTTON_INDEX) && is_button_pressed(UP_BUTTON_INDEX)) { change_direction(UP); } if(has_button_changed(LEFT_BUTTON_INDEX) && is_button_pressed(LEFT_BUTTON_INDEX)) { change_direction(LEFT); } if(has_button_changed(RIGHT_BUTTON_INDEX) && is_button_pressed(RIGHT_BUTTON_INDEX)) { change_direction(RIGHT); } }
void ai_best_move(SMove moves[4], SList_moves** poss_moves, int ln_moves, SGameState* gamestate, int lmax_moves, SToRegisterFileName* played_filename) { int i,j,k,l; SGameStateAndMoves* temp_psgm = NULL; int real_length = 0; if (lmax_moves > 0) { for (i = 0; i < ln_moves; i++) { SList_moves* plist_1 = ((*poss_moves) + i); if (lmax_moves > 1) { for (j = 0; j < (plist_1->l_nexts); j++) { SList_moves* plist_2 = (plist_1->nexts) + j; if (lmax_moves > 2) { for (k = 0; k < (plist_2->l_nexts); k++) { SList_moves* plist_3 = (plist_2->nexts) + k; if (lmax_moves > 3) { for (l = 0; l < (plist_3->l_nexts); l++) { SList_moves* plist_4 = (plist_3->nexts) + l; SGameStateAndMoves temp_gm; temp_gm.gamestate = update_game_state(*gamestate, (*plist_1)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_2)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_3)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_4)); temp_gm.real_length = lmax_moves; temp_gm.moves[0] = plist_1->head; temp_gm.moves[1] = plist_2->head; temp_gm.moves[2] = plist_3->head; temp_gm.moves[3] = plist_4->head; real_length = add_gm(&temp_psgm, real_length, temp_gm); } } else { SGameStateAndMoves temp_gm; temp_gm.gamestate = update_game_state(*gamestate, (*plist_1)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_2)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_3)); temp_gm.real_length = lmax_moves; temp_gm.moves[0] = plist_1->head; temp_gm.moves[1] = plist_2->head; temp_gm.moves[2] = plist_3->head; real_length = add_gm(&temp_psgm, real_length, temp_gm); } } } else { SGameStateAndMoves temp_gm; temp_gm.gamestate = update_game_state(*gamestate, (*plist_1)); temp_gm.gamestate = update_game_state(temp_gm.gamestate, (*plist_2)); temp_gm.real_length = lmax_moves; temp_gm.moves[0] = plist_1->head; temp_gm.moves[1] = plist_2->head; real_length = add_gm(&temp_psgm, real_length, temp_gm); } } } else { SGameStateAndMoves temp_gm; temp_gm.gamestate = update_game_state(*gamestate, (*plist_1)); temp_gm.real_length = lmax_moves; temp_gm.moves[0] = plist_1->head; real_length = add_gm(&temp_psgm, real_length, temp_gm); } } ai_best_moves(&temp_psgm, moves, real_length, played_filename, lmax_moves); } free(temp_psgm); }