int ai_block_projectile(controller *ctrl, ctrl_event **ev) { ai *a = ctrl->data; object *o = ctrl->har; iterator it; object **o_tmp; vector_iter_begin(&a->active_projectiles, &it); while((o_tmp = iter_next(&it)) != NULL) { object *o_prj = *o_tmp; if(projectile_get_owner(o_prj) == o) { continue; } if(o_prj->cur_sprite && maybe(a->difficulty)) { vec2i pos_prj = vec2i_add(object_get_pos(o_prj), o_prj->cur_sprite->pos); vec2i size_prj = object_get_size(o_prj); if (object_get_direction(o_prj) == OBJECT_FACE_LEFT) { pos_prj.x = object_get_pos(o_prj).x + ((o_prj->cur_sprite->pos.x * -1) - size_prj.x); } if(fabsf(pos_prj.x - o->pos.x) < 120) { a->cur_act = (o->direction == OBJECT_FACE_RIGHT ? ACT_DOWN|ACT_LEFT : ACT_DOWN|ACT_RIGHT); controller_cmd(ctrl, a->cur_act, ev); return 1; } } } return 0; }
void object_dynamic_tick(object *obj) { obj->age++; if(obj->attached_to != NULL) { object_set_pos(obj, object_get_pos(obj->attached_to)); object_set_direction(obj, object_get_direction(obj->attached_to)); } // Check if object still needs to be halted if(obj->halt_ticks > 0) { obj->halt_ticks--; obj->halt = (obj->halt_ticks > 0); } // Run animation player if(obj->cur_animation != NULL && obj->halt == 0) { for(int i = 0; i < obj->stride; i++) player_run(obj); } // Tick object implementation if(obj->dynamic_tick != NULL) { obj->dynamic_tick(obj); } // Handle screen shakes, V & H if(obj->sprite_state.screen_shake_vertical > 0) { obj->gs->screen_shake_vertical = obj->sprite_state.screen_shake_vertical * 4; obj->sprite_state.screen_shake_vertical = 0; } if(obj->sprite_state.screen_shake_horizontal > 0) { obj->gs->screen_shake_horizontal = obj->sprite_state.screen_shake_horizontal * 4; obj->sprite_state.screen_shake_horizontal = 0; } }
int console_cmd_har(game_state *gs, int argc, char **argv) { // change har if(argc == 2) { int i; if(strtoint(argv[1], &i)) { if(i < 0 || i > 10) { return 1; } game_player *player = game_state_get_player(gs, 0); if (scene_load_har(game_state_get_scene(gs), 0, player->har_id)) { return 1; } object *har_obj = game_player_get_har(player); vec2i pos = object_get_pos(har_obj); int hd = object_get_direction(har_obj); object *obj = malloc(sizeof(object)); object_create(obj, gs, pos, vec2f_create(0,0)); player->har_id = i; if(har_create(obj, game_state_get_scene(gs)->af_data[0], hd, player->har_id, player->pilot_id, 0)) { object_free(obj); free(obj); return 1; } // Set HAR to controller and game_player game_state_add_object(gs, obj, RENDER_LAYER_MIDDLE, 0, 0); game_state_del_object(gs, har_obj); // Set HAR for player game_player_set_har(player, obj); game_player_get_ctrl(player)->har = obj; game_player_get_har(player)->animation_state.enemy = game_player_get_har(game_state_get_player(gs, 1)); game_player_get_har(game_state_get_player(gs, 1))->animation_state.enemy = game_player_get_har(player); maybe_install_har_hooks(game_state_get_scene(gs)); return 0; } } return 1; }
void io_display(dungeon_t *d) { uint32_t y, x; uint32_t illuminated; clear(); for (y = 0; y < DUNGEON_Y; y++) { for (x = 0; x < DUNGEON_X; x++) { if ((illuminated = is_illuminated(d->pc, y, x))) { attron(A_BOLD); } if (d->charmap[y][x] && can_see(d, character_get_pos(d->pc), character_get_pos(d->charmap[y][x]), 1)) { attron(COLOR_PAIR(character_get_color(d->charmap[y][x]))); mvaddch(y + 1, x, character_get_symbol(d->charmap[y][x])); attroff(COLOR_PAIR(character_get_color(d->charmap[y][x]))); } else if (d->objectmap[y][x] && can_see(d, character_get_pos(d->pc), object_get_pos(d->objectmap[y][x]), 1)){ attron(COLOR_PAIR(object_get_color(d->objectmap[y][x]))); mvaddch(y+1, x, object_get_symbol(d->objectmap[y][x])); attroff(COLOR_PAIR(object_get_color(d->objectmap[y][x]))); } else { switch (pc_learned_terrain(d->pc, y, x)) { case ter_wall: case ter_wall_immutable: case ter_unknown: mvaddch(y + 1, x, ' '); break; case ter_floor: case ter_floor_room: mvaddch(y + 1, x, '.'); break; case ter_floor_hall: mvaddch(y + 1, x, '#'); break; case ter_debug: mvaddch(y + 1, x, '*'); break; case ter_stairs_up: mvaddch(y + 1, x, '<'); break; case ter_stairs_down: mvaddch(y + 1, x, '>'); break; default: /* Use zero as an error symbol, since it stands out somewhat, and it's * * not otherwise used. */ mvaddch(y + 1, x, '0'); } } if (illuminated) { attroff(A_BOLD); } } } io_print_message_queue(0, 0); refresh(); }