/** * @brief Creates a new chest with the specified treasure. * @param name Name identifying this chest. * @param layer Layer of the chest to create on the map. * @param x X coordinate of the chest to create. * @param y Y coordinate of the chest to create. * @param sprite_name Name of the animation set of the * sprite to create for the chest. It must have animations "open" and "closed". * @param treasure The treasure in the chest. */ Chest::Chest( const std::string& name, Layer layer, int x, int y, const std::string& sprite_name, const Treasure& treasure): Detector(COLLISION_FACING_POINT, name, layer, x, y, 16, 16), treasure(treasure), open(treasure.is_found()), treasure_given(open), treasure_date(0) { // Create the sprite. Sprite& sprite = create_sprite(sprite_name); std::string animation = is_open() ? "open" : "closed"; sprite.set_current_animation(animation); set_origin(get_width() / 2, get_height() - 3); }
/** * \brief Creates a new stairs entity. * \param name Name of the entity to create. * \param layer Layer of the entity to create on the map. * \param xy Coordinates of the entity to create. * \param direction Direction of the stairs (0 to 3). * \param subtype The subtype of stairs. */ Stairs::Stairs( const std::string& name, Layer layer, const Point& xy, int direction, Subtype subtype): Detector(COLLISION_TOUCHING | COLLISION_OVERLAPPING, name, layer, xy, Size(16, 16)), subtype(subtype) { Debug::check_assertion(!is_inside_floor() || layer != LAYER_HIGH, "Cannot put single floor stairs on the high layer"); set_direction(direction); if (!is_inside_floor()) { set_size(16, 8); if (direction == 3) { // Down. set_origin(0, -8); } } }
/** * \brief Creates a new stream. * \param name Name identifying the entity on the map or an empty string. * \param layer Layer of the entity to create. * \param x X coordinate of the entity to create. * \param y Y coordinate of the entity to create. * \param direction Direction of the stream (0 to 7). * \param sprite_name Animation set id of a sprite or an empty string. */ Stream::Stream( const std::string& name, Layer layer, int x, int y, int direction, const std::string& sprite_name ): Detector(COLLISION_OVERLAPPING, name, layer, x, y, 16, 16), speed(64), allow_movement(true), allow_attack(true), allow_item(true) { set_origin(8, 13); if (!sprite_name.empty()) { create_sprite(sprite_name); get_sprite().set_current_direction(direction); } set_direction(direction); }
/** * \brief Creates a new stairs entity. * \param name Name of the entity to create. * \param layer Layer of the entity to create on the map. * \param x X coordinate of the entity to create. * \param y Y coordinate of the entity to create. * \param direction Direction of the stairs (0 to 3). * \param subtype The subtype of stairs. */ Stairs::Stairs( const std::string& name, Layer layer, int x, int y, int direction, Subtype subtype): Detector(COLLISION_FACING_POINT_ANY | COLLISION_RECTANGLE, name, layer, x, y, 16, 16), subtype(subtype), enabled(true) { Debug::check_assertion(!is_inside_floor() || layer != LAYER_HIGH, "Cannot put single floor stairs on the high layer"); set_direction(direction); if (!is_inside_floor()) { set_size(16, 8); if (direction == 3) { // Down. set_origin(0, -8); } } }
/** * @brief Creates a hookshot. * @param hero the hero */ Hookshot::Hookshot(Hero &hero): next_sound_date(System::now()), has_to_go_back(false), going_back(false), entity_reached(NULL), link_sprite("entities/hookshot") { // initialize the entity int direction = hero.get_animation_direction(); set_layer(hero.get_layer()); create_sprite("entities/hookshot", true); get_sprite().set_current_direction(direction); link_sprite.set_current_animation("link"); set_size(16, 16); set_origin(8, 13); set_xy(hero.get_xy()); std::string path = " "; path[0] = '0' + (direction * 2); Movement *movement = new PathMovement(path, 192, true, false, false); set_movement(movement); }
/** * \brief Creates a hookshot. * \param hero the hero */ Hookshot::Hookshot(const Hero& hero): MapEntity("", 0, hero.get_layer(), 0, 0, 0, 0), next_sound_date(System::now()), has_to_go_back(false), going_back(false), entity_reached(nullptr), link_sprite(std::make_shared<Sprite>("entities/hookshot")) { // initialize the entity int direction = hero.get_animation_direction(); create_sprite("entities/hookshot", true); get_sprite().set_current_direction(direction); link_sprite->set_current_animation("link"); set_size(16, 16); set_origin(8, 13); set_drawn_in_y_order(true); set_xy(hero.get_xy()); std::string path = " "; path[0] = '0' + (direction * 2); set_movement(std::make_shared<PathMovement>(path, 192, true, false, false)); }
/** * \brief Creates the sprite of this pickable treasure. * * Pickable treasures are represented with two sprites: * the treasure itself and, for some items, a shadow. * * \return \c true in case of success, \c false if the animation corresponding * to the treasure is missing. */ bool Pickable::initialize_sprites() { // Shadow sprite. shadow_sprite = nullptr; EquipmentItem& item = treasure.get_item(); const std::string& animation = item.get_shadow(); bool has_shadow = false; if (!animation.empty()) { shadow_sprite = std::make_shared<Sprite>("entities/shadow"); has_shadow = shadow_sprite->has_animation(animation); } if (!has_shadow) { // No shadow or no such shadow animation. shadow_sprite = nullptr; } else { shadow_sprite->set_current_animation(animation); } // Main sprite. const std::string item_name = treasure.get_item_name(); create_sprite("entities/items"); Sprite& item_sprite = get_sprite(); if( !item_sprite.has_animation(item_name)) { std::ostringstream oss; oss << "Cannot create pickable treasure '" << item_name << "': Sprite 'entities/items' has no animation '" << item_name << "'"; Debug::error(oss.str()); return false; } item_sprite.set_current_animation(item_name); int direction = treasure.get_variant() - 1; if (direction < 0 || direction >= item_sprite.get_nb_directions()) { std::ostringstream oss; oss << "Pickable treasure '" << item_name << "' has variant " << treasure.get_variant() << " but sprite 'entities/items' only has " << item_sprite.get_nb_directions() << " variant(s) in animation '" << item_name << "'"; Debug::error(oss.str()); direction = 0; // Fallback. } item_sprite.set_current_direction(direction); item_sprite.enable_pixel_collisions(); // Set the origin point and the size of the entity. set_size(16, 16); set_origin(8, 13); uint32_t now = System::now(); if (falling_height != FALLING_NONE) { allow_pick_date = now + 700; // The player will be allowed to take the item after 0.7 seconds. can_be_picked = false; } else { can_be_picked = true; } // Initialize the item removal. if (will_disappear) { blink_date = now + 8000; // The item blinks after 8s. disappear_date = now + 10000; // The item disappears after 10s. } return true; }
void picture_rep::translate_origin (int dx, int dy) { set_origin (get_origin_x () + dx, get_origin_y () + dy); }
void MapEntity::set_bounding_box(Sprite& sprite) { set_size(sprite.get_size()); set_origin(sprite.get_origin()); }
void MapEntity::set_origin(const Rectangle &rec) { set_origin(rec.get_x(), rec.get_y()); }
int main() { connect_to_robot(); initialize_robot(); set_origin(); printf("Ghandy-Bot activated, destroy!!!\n"); //Set front IR sensors to to face left and right set_ir_angle(LEFT, -45); set_ir_angle(RIGHT, 45); init_map(); print_map(); robot.map[1][1].walls[0] = 1; robot.map[1][2].walls[2] = 1; robot.map[1][1].walls[1] = 1; robot.map[2][1].walls[3] = 1; robot.map[1][3].walls[2] = 1; robot.map[1][2].walls[0] = 1; robot.map[0][4].walls[2] = 1; robot.map[0][3].walls[0] = 1; robot.map[3][4].walls[3] = 1; robot.map[2][4].walls[1] = 1; robot.map[3][2].walls[2] = 1; robot.map[3][1].walls[0] = 1; robot.map[3][2].walls[3] = 1; robot.map[2][2].walls[1] = 1; int i; for(i=1;i<=4;i++) robot.map[0][i].walls[3] = 1; for(i=1;i<=4;i++) robot.map[i][1].walls[2] = 1; for(i=1;i<=4;i++) robot.map[3][i].walls[1] = 1; print_map(); /* Phase 1 */ //Perform depth first search on maze //dfs(0, 0, M_PI / 2); /* Phase 2 */ lee(0,1); //Update matrix with Lee costs from node [0,1] /* Generate shortest path to node [3,4] (finish line) */ generate_path(3,4); follow_path(); //Follow the generated path to finish //Phew, did we win??? printf("Ghandy-Bot deactivated!\n"); return 0; }
/* * find_by_Nth() : Find Nth record */ void find_by_Nth(List *list) { Boolean donef = FALSE; char s[80]; unsigned long num = 0L; while(!donef) { switch(find_by_Nth_menu()) { case 1: /* Choose search origin */ set_origin(list); continue; case 2: /* Choose search direction */ set_direction(list); continue; case 3: /* Enter number of records to skip */ input("Enter number of records to skip: ", s, sizeof(s)); if((num = atol(s)) <= 0 || num > DLL_GetNumberOfRecords(list)) { fputs("Invalid skip value.\n\n", stdout); continue; } fputs("\n", stdout); continue; case 4: /* Do the search */ if(num == 0L) { fputs( "No skip number has been set, please set a number.\n\n", stdout); continue; } if(verify_criteria(list, NULL, num) == FALSE) return; donef = TRUE; break; default: return; } fputs("\n", stdout); } switch(DLL_FindNthRecord(list, &get_addr, num)) { case DLL_NORMAL: display(&get_addr); #if DEBUG fprintf(stderr, "list->listsize: %ld, ", list->listsize); #endif fprintf(stdout, "Index of this record is: %ld\n\n", DLL_GetCurrentIndex(list)); break; case DLL_NULL_LIST: fputs("Warning: List is empty.\n\n", stderr); break; case DLL_NOT_FOUND: fputs("Warning: Bad index value.\n\n", stderr); break; default: fputs("Error: Unknown return type.\n\n", stderr); break; } }
/* * find_by_match() : Use DLL_FindRecord() */ void find_by_match(List *list) { int (*pfun)() = NULL; Boolean donef = FALSE; char *pField = NULL; while(!donef) { switch(find_by_match_menu()) { case 1: /* Choose search origin */ set_origin(list); continue; case 2: /* Choose search direction */ set_direction(list); continue; case 3: /* Choose search field */ pField = set_field(list, &pfun); fputs("\n", stdout); continue; case 4: /* Do the search */ if(pField == NULL) { fputs("No field has been set, please set a field.\n\n", stdout); continue; } if(verify_criteria(list, pField, 0L) == FALSE) return; donef = TRUE; break; default: return; } fputs("\n", stdout); } switch(DLL_FindRecord(list, &get_addr, &find_addr, (int (*)()) pfun)) { case DLL_NORMAL: display(&get_addr); #if DEBUG fprintf(stderr, "list->listsize: %ld, ", list->listsize); #endif fprintf(stdout, "Index of this record is: %ld\n\n", DLL_GetCurrentIndex(list)); break; case DLL_NULL_LIST: fputs("Warning: List is empty.\n\n", stderr); break; case DLL_NOT_FOUND: fputs("Warning: Record not found.\n\n", stderr); break; case DLL_NULL_FUNCTION: fputs("Error: Function pfun is NULL.\n\n", stderr); break; default: fputs("Error: Unknown return type.\n\n", stderr); break; } }
/** * @brief Constructor. * @param map The map containing the entity. * @param index Index of the entity in the map. */ Pickable::Pickable(MapModel& map, const EntityIndex& index) : EntityModel(map, index, EntityType::PICKABLE) { set_origin(QPoint(8, 13)); }
static int pcx_draw(video_adapter_t *adp) { u_char *vidmem; int swidth, sheight, sbpsl, sdepth, splanes; int banksize, origin; int c, i, j, pos, scan, x, y; u_char line[MAXSCANLINE]; if (pcx_info.zlen < 1) return 1; load_palette(adp, pcx_info.palette); vidmem = (u_char *)adp->va_window; swidth = adp->va_info.vi_width; sheight = adp->va_info.vi_height; sbpsl = adp->va_line_width; sdepth = adp->va_info.vi_depth; splanes = adp->va_info.vi_planes; banksize = adp->va_window_size; for (origin = 0; origin < sheight*sbpsl; origin += banksize) { set_origin(adp, origin); bzero(vidmem, banksize); } x = (swidth - pcx_info.width) / 2; y = (sheight - pcx_info.height) / 2; origin = 0; pos = y * sbpsl + x; while (pos > banksize) { pos -= banksize; origin += banksize; } set_origin(adp, origin); for (scan = i = 0; scan < pcx_info.height; ++scan, ++y, pos += sbpsl) { for (j = 0; j < pcx_info.bpsl && i < pcx_info.zlen; ++i) { if ((pcx_info.zdata[i] & 0xc0) == 0xc0) { c = pcx_info.zdata[i++] & 0x3f; if (i >= pcx_info.zlen) return 1; } else { c = 1; } if (j + c > pcx_info.bpsl) return 1; while (c--) line[j++] = pcx_info.zdata[i]; } if (pos > banksize) { origin += banksize; pos -= banksize; set_origin(adp, origin); } if (pos + pcx_info.width > banksize) { /* scanline crosses bank boundary */ j = banksize - pos; bcopy(line, vidmem + pos, j); origin += banksize; pos -= banksize; set_origin(adp, origin); bcopy(line + j, vidmem, pcx_info.width - j); } else { bcopy(line, vidmem + pos, pcx_info.width); } } return 0; }
void Deferred_lighting_renderer::render_point_light(const scene::Light& light, const scene::Scene& /*scene*/, const Rendering_context& context) { float4 energy_and_range = light.point_energy_and_range(); float range = energy_and_range.w; Sphere sphere(light.world_position(), range); const auto& camera = context.camera(); if (Intersection_type::Outside == camera.frustum().intersect(sphere)) { return; } Rendering_device& device = rendering_tool_.device(); device.set_framebuffer(context.framebuffer()); device.set_input_layout(volume_input_layout_); device.set_shader_resources(4, deferred_textures_); effect_->use(device); float4x4 world; set_scale(world, range, range, range); set_origin(world, light.world_position()); auto& change_per_light_data = change_per_light_.data(); change_per_light_data.world = world; change_per_light_data.energy_and_range = energy_and_range; change_per_light_data.position_vs = light.world_position() * camera.view(); change_per_light_.update(device); techniques_.point_light->use(); AABB light_AABB; light_AABB.position = light.world_position(); light_AABB.halfsize = float3(range, range, range); if (Intersection_type::Outside != Sphere(camera.world_position(), camera.greatest_distance_to_near_plane()).intersect(light_AABB)) { // camera is inside the light volume device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Front]); device.set_depth_stencil_state(inside_lighting_volume_ds_state_light_, 1); } else { // camera is outside the light volume device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Back]); device.set_depth_stencil_state(outside_lighting_volume_ds_state_prepare_, 1); device.set_blend_state(z_only_blend_state_); sphere_volume_.render(rendering_tool_); device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Front]); device.set_depth_stencil_state(outside_lighting_volume_ds_state_light_, 2); } device.set_blend_state(lighting_blend_state_); sphere_volume_.render(rendering_tool_); }