int main(int argc, char* argv[]) { FILE *fp = fopen(argv[1], "r"); if (fp != NULL) { char direction = '|'; int prev = -1; char line[14]; while(fgets(line, sizeof(line), fp)) { int gate_index = find(line, '_'); if (prev == -1) prev = gate_index; int checkpoint_index = find(line, 'C'); if (checkpoint_index == -1) { direction = update_direction(prev, gate_index); line[gate_index] = direction; prev = gate_index; } else { direction = update_direction(prev, checkpoint_index); line[checkpoint_index] = direction; prev = checkpoint_index; } printf("%s", line); } fclose(fp); } return 0; }
/* Draws the current and previous position onto the screen */ void UpdatePlayerMovement( struct Player* Player1, struct Player* Player2 ) { //Detect which keyboard keys are being pressed detect_keys(); //Updates player's direction of motion update_direction(Player1, &player1_direction); //Player 1 update_direction(Player2, &player2_direction); //Player 2 //Set player's next position }
int tick() { // Handle user input Direction in = get_direction(); if (in != NO_DIRECTION) { push_move(move_list, in); } // Handle snake movement update_direction(snake, move_list); move_snake(snake); // Draw everything draw_frame(snake, food_list); Collision collision = find_collision(snake, food_list, screen); switch(collision){ case SNAKE: case SCREEN: return 0; case FOOD: grow_snake(); new_food(); break; case NONE: break; } snake_sleep(); return 1; }
Player::Player(uint32_t p) { vid = 0; pid = p; entity_class = EntityType::PLAYER; can_collide = true; can_rotate = false; // initialize things pos = fvec3(0.0f, 8.0f, 0.0f); //lower_bound = fvec3(-0.4f, -0.9f, 0.4f); //upper_bound = fvec3(0.4f, 0.9f, 0.4f); fvec3 lower_bound = fvec3(0.0f, 0.0f, 0.0f); fvec3 upper_bound = fvec3(0.9f, 0.9f, 0.9f); bounds = bounding_box(lower_bound, upper_bound); update_centerpos_smooth(); weight = 20; velocity_decay = 0.5f; update_direction(0.0, 0.0); id_assign = VID_UNIQUE_START; inventory = new PlayerInventory(); mount = 0; game_template = 0; }
void Active::force_direction(int value) { value &= 31; if (forced_direction == value) return; forced_direction = value; update_direction(); }
/* * void collision_check(); * * determines if any ball-wall or ball-ball collisions occur */ void collision_check() { int i, j; double d; for(i = 0; i < all_spheres.size(); i++) { wall_check(&all_spheres[i]); // ball-ball collisions if( i < all_spheres.size()-1 ){ for( j = i+1; j < all_spheres.size(); j++) { if(all_spheres[i].ghost + all_spheres[j].ghost >= 1) { continue; } d = distance(all_spheres[i], all_spheres[j]); // if a collision if( d <= all_spheres[i].radius + all_spheres[j].radius) { // COLLISION RESPONSE STARTS // two curves colliding, need to generate direction vectors if(all_spheres[i].path + all_spheres[j].path == 2){ { update_direction(&all_spheres[i]); update_direction(&all_spheres[j]); } // one curve and 1 ball collide, need to generate vector }else if(all_spheres[i].path + all_spheres[j].path == 1){ if(all_spheres[i].path == 1) { //[i] is the curved ball update_direction(&all_spheres[i]); }else{ //[j] is the curved ball update_direction(&all_spheres[j]); } // END BALL-CURVE } nudge_spheres(&all_spheres[i], &all_spheres[j], d); collision_response(&all_spheres[i], &all_spheres[j]); } } } // end ball-ball } }
void Active::restore_animation() { if (forced_animation == -1) return; forced_animation = -1; if (current_animation == animation) return; current_animation = animation; animation_frame = 0; update_direction(); }
void Active::set_animation(int value) { if (value == animation) return; value = get_animation(value); if (value == animation) return; animation = value; if (forced_animation >= 0) return; animation_frame = 0; current_animation = animation; update_direction(); }
static ClutterTranslateReturn clutter_keymap_x11_translate_event (ClutterEventTranslator *translator, gpointer native, ClutterEvent *event) { ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (translator); ClutterBackendX11 *backend_x11; ClutterTranslateReturn retval; XEvent *xevent; backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend); if (!backend_x11->use_xkb) return CLUTTER_TRANSLATE_CONTINUE; xevent = native; retval = CLUTTER_TRANSLATE_CONTINUE; #ifdef HAVE_XKB if (xevent->type == keymap_x11->xkb_event_base) { XkbEvent *xkb_event = (XkbEvent *) xevent; switch (xkb_event->any.xkb_type) { case XkbStateNotify: CLUTTER_NOTE (EVENT, "Updating keyboard state"); update_direction (keymap_x11, XkbStateGroup (&xkb_event->state)); update_locked_mods (keymap_x11, xkb_event->state.locked_mods); retval = CLUTTER_TRANSLATE_REMOVE; break; case XkbNewKeyboardNotify: case XkbMapNotify: CLUTTER_NOTE (EVENT, "Updating keyboard mapping"); XkbRefreshKeyboardMapping (&xkb_event->map); backend_x11->keymap_serial += 1; retval = CLUTTER_TRANSLATE_REMOVE; break; default: break; } } #endif /* HAVE_XKB */ return retval; }
AI::AI(Snake *snakes[], int player_num, Pellet *pellet, Collision_Table *collision_table, int difficulty, bool tron) { for (int i = 0; i < 4; i++) { m_snakes[i] = snakes[i]; } assert(pellet); m_pellet = pellet; m_collision_table = collision_table; m_player_num = player_num; if (difficulty == 0) { //EASY MAX_LOOK_AHEAD = EASY_MAX_LOOK_AHEAD; MAX_OFFENSIVE_MOVES = EASY_MAX_OFFENSIVE_MOVES; MAX_NOTICE_PELLET = EASY_MAX_NOTICE_PELLET; CHECK_FAIL = EASY_CHECK_FAIL; } else if (difficulty == 1) { //MEDIUM MAX_LOOK_AHEAD = MEDIUM_MAX_LOOK_AHEAD; MAX_OFFENSIVE_MOVES = MEDIUM_MAX_OFFENSIVE_MOVES; MAX_NOTICE_PELLET = MEDIUM_MAX_NOTICE_PELLET; if (tron) CHECK_FAIL = MEDIUM_CHECK_FAIL_TRON; else CHECK_FAIL = MEDIUM_CHECK_FAIL_SNAKE; } else { //HARD MAX_LOOK_AHEAD = HARD_MAX_LOOK_AHEAD; MAX_OFFENSIVE_MOVES = HARD_MAX_OFFENSIVE_MOVES; MAX_NOTICE_PELLET = HARD_MAX_NOTICE_PELLET; } m_ai_difficulty = difficulty; m_notice_pellet = MAX_NOTICE_PELLET; m_tron = tron; assert(snakes[m_player_num]); m_max_x = snakes[m_player_num]->get_max_x(); m_max_y = snakes[m_player_num]->get_max_y(); m_width = snakes[m_player_num]->get_width(); if (m_tron) m_offensive_count = rand() % MAX_OFFENSIVE_MOVES + (MAX_OFFENSIVE_MOVES/4) + 1; else m_offensive_count = 0; update_coordinates(); update_direction(); }
void Active::force_speed(int value) { value = std::max(0, std::min(100, value)); int delta = direction_data->max_speed - direction_data->min_speed; if (delta != 0) { value = (value * delta) / 100 + direction_data->min_speed; value = std::min<int>(direction_data->max_speed, value); } forced_speed = value; // XXX taken from Active::update, generalize maybe? if (forced_animation == -1 && animation != current_animation) { current_animation = animation; animation_frame = 0; update_direction(); } }
void Active::set_direction(int value, bool set_movement) { value &= 31; FrameObject::set_direction(value, set_movement); if (active_flags & AUTO_ROTATE) { set_angle((value * 360) / 32); value = 0; } if (value == animation_direction) return; animation_direction = value; Direction * old_dir = direction_data; Direction * new_dir = get_direction_data(); if (old_dir == new_dir) return; update_direction(new_dir); }
void Active::force_animation(int value) { if (value == forced_animation) return; value = get_animation(value); if (value == forced_animation) return; if (flags & FADEOUT) { FrameObject::destroy(); return; } forced_animation = value; if (value == current_animation) return; animation_frame = 0; current_animation = value; update_direction(); }
/** * @brief Set the camera position for the ModelView matrix. */ void RCamera::update() { update_direction(); if (third_person) { gluLookAt(pos.x, pos.y, pos.z, 0, 0, 0, up.x, up.y, up.z ); } else { gluLookAt(pos.x, pos.y, pos.z, pos.x + dir.x, pos.y + dir.y, pos.z + dir.z, up.x, up.y, up.z ); } update_frustum(); }
void Active::initialize_active(bool collision_box) { if (collision_box) { sprite_col.flags |= BOX_COLLISION; sprite_col.type = SPRITE_BOX; } update_direction(); int n = 1; if (current_animation == APPEARING || current_animation == DISAPPEARING) { // XXX figure out why this is needed #ifdef CHOWDREN_ACTIVE_LOOPING_APPEARING if (loop_count == -1 && current_animation == DISAPPEARING) loop_count = 1; #else if (loop_count == -1) loop_count = 1; #endif n++; } counter += int(direction_data->max_speed * manager.frame->timer_mul) * n; }
PangoDirection _clutter_keymap_x11_get_direction (ClutterKeymapX11 *keymap) { g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL); #ifdef HAVE_XKB if (CLUTTER_BACKEND_X11 (keymap->backend)->use_xkb) { if (!keymap->has_direction) { Display *xdisplay = CLUTTER_BACKEND_X11 (keymap->backend)->xdpy; XkbStateRec state_rec; XkbGetState (xdisplay, XkbUseCoreKbd, &state_rec); update_direction (keymap, XkbStateGroup (&state_rec)); } return keymap->current_direction; } else #endif return PANGO_DIRECTION_NEUTRAL; }
void AI::read_input() { update_coordinates(); update_direction(); if (try_move_to_pellet()) return; if (!m_tron) { if (rand() % SNAKE_TURN_CHANCE == 0) { if (ok_to_turn()) { go_safest_turn_direction(); return; } } } else if (m_offensive_count > 0) { offensive(); return; } defensive(); }
void Babar::update_state() { if (locked() ) m_lock--; if (m_lock == 0) { unlock(); } if (!Keyboard::GetInstance()->time_pressed (k_jump) ) m_jump = false; if (m_jump) { if ( Keyboard::GetInstance()->time_pressed (k_jump) > 1 ) { m_ready_double_jump = true; if ( Keyboard::GetInstance()->time_pressed (k_jump) > JUMP_TIME) { m_jump = false; Keyboard::GetInstance()->disable_key (k_jump); } } } update_direction(); if ( CollisionsManager::is_down_coll (gCollision->get_matrix()->down_collision_type (position() ) ) ) { interrupt_jump(); } if (can_fire() ) { m_fire = true; gProj->add_proj (fire_old(), PLAYER1); m_fire_phase = 0; } else { m_fire = false; m_fire_phase++; } if (can_crouch() ) { crouch(); } else { /* si on se releve */ if ( m_crouch_time ) { interrupt_crouch(); } } if (can_jump() ) jump(); if (can_double_jump() ) double_jump(); if (can_go_down() ) go_down(); if (m_invincible > 0) { m_invincible --; if (!locked() ) { if ( m_invincible % 2) { m_spriteGrid->no_pic(); } else { m_spriteGrid->set_pic(); } } } m_weapons_armory.update(); if (Keyboard::GetInstance()->time_pressed (k_prev_weapon) == 1) m_weapons_armory.previous_weapon(); if (Keyboard::GetInstance()->time_pressed (k_next_weapon) == 1) m_weapons_armory.next_weapon(); switch (get_state() ) { case STATIC: m_spriteGrid->setPictures (0); break; case WALK: m_spriteGrid->setPictures (1, 0, 2, 0); break; case JUMP: m_spriteGrid->setPictures (1); break; case CROUCH: m_spriteGrid->setPictures (12); break; case CROUCH_WALKING: m_spriteGrid->setPictures (13, 12, 14, 12); break; default: m_spriteGrid->setPictures (0); break; } //m_spriteGrid->change_anim(get_state(), m_dir, Keyboard::GetInstance()->key_down(k_fire)); m_spriteGrid->set_pos (position() ); set_h (m_spriteGrid->h() ); set_w (m_spriteGrid->w() ); }
void Active::update() { #ifdef CHOWDREN_DEFER_COLLISIONS flags |= DEFER_COLLISIONS; memcpy(old_aabb, sprite_col.aabb, sizeof(old_aabb)); #endif if (flags & FADEOUT) { if (fade_time > 0.0f) { fade_time -= manager.dt; if (fade_time <= 0.0f) { FrameObject::destroy(); } float p = fade_time / fade_duration; blend_color.set_alpha(p * 255.0f); return; } if (animation_finished == DISAPPEARING) { FrameObject::destroy(); return; } } update_flash(flash_interval, flash_time); animation_finished = -1; if (forced_animation == -1 && animation != current_animation) { current_animation = animation; animation_frame = 0; update_direction(); } if (forced_frame != -1 || (active_flags & ANIMATION_STOPPED) || loop_count == 0) { return; } int anim_speed; if (forced_speed != -1) anim_speed = forced_speed; else anim_speed = direction_data->max_speed; int counter = this->counter + int(anim_speed * frame->timer_mul); int old_frame = animation_frame; while (counter > 100) { counter -= 100; animation_frame++; if (animation_frame < direction_data->frame_count) continue; if (loop_count > 0) loop_count--; if (loop_count != 0) { animation_frame = direction_data->back_to; continue; } animation_finished = current_animation; animation_frame--; if (forced_animation != -1) { forced_animation = -1; forced_speed = -1; forced_direction = -1; } return; } this->counter = counter; if (animation_frame != old_frame) update_frame(); }
void Active::restore_direction() { forced_direction = -1; update_direction(); }