float get_angle (int p1, int p2) { int delta_x, delta_y; /* Calculate (x2 - x1) and (y2 - y1). The points are passed in the * form x1y1 and x2y2. get_x() and get_y() are passed these points * and return the x and y values respectively. For example, * get_x(1020) returns 10. */ delta_x = get_x(p2) - get_x(p1); delta_y = get_y(p2) - get_y(p1); if (delta_x == 0) { if (delta_y > 0) return(PI/2); else if (delta_y < 0) return(-PI/2); } else if (delta_y == 0) { if (delta_x > 0) return(0.0); else if (delta_x < 0) return(PI); } return((float) atan2((double) delta_y,(double) delta_x)); }
void GUI::on_draw() { GUI * parent = get_parent(); if(parent != nullptr) { // keep object within parent bounds (keep from moving outside parent) if(get_x() <= parent->get_x()) {set_position(parent->get_x(), get_y());} if(get_y() <= parent->get_y()) {set_position(get_x(), parent->get_y());} if(get_x() >= parent->get_x() + (parent->get_width() - get_width())) {set_position(parent->get_x() + (parent->get_width() - get_width()), get_y());} if(get_y() >= parent->get_y() + (parent->get_height() - get_height())) {set_position(get_x(), parent->get_y() + (parent->get_height() - get_height()));} // keep object from exceeding parent size (width and height) UPDATED: 9-7-2018 if(get_width () > parent->get_width ()) set_size(parent->get_width(), get_height()); // if object is wider than parent, make width equal to parent's width if(get_height() > parent->get_height()) set_size(get_width(), parent->get_height()); // if object is taller than parent, make height equal to parent's height } if(is_visible()) { for(int i = 0; i < Factory::get_gui_factory()->get_size(); i++) { GUI * gui = static_cast<GUI*>(Factory::get_gui_factory()->get_object(i)); // draw all children if visible (child ui can also have their own visibility) if(is_parent_of(*gui)) { gui->draw(); } // set focus to the gui that is pressed if(gui->is_pressed()) { gui->set_focused(true); } } } // if mouse is over ui and mouse is pressed, set as current focus }
int infoClansInPatch() { int pt=get_tpatch(),pID=get_patchID(); int px=get_x(),py=get_y(); if(px==0){ set_tpatch(HM); set_repows(HMRWS); set_repods(HMRDS); } else if(px==1){ set_tpatch(LM); set_repows(LMRWS); set_repods(LMRDS); } else if ((py==0)||(py==GRIDSIZE-1)||(px==GRIDSIZE-1)){ set_tpatch(C); set_repows(CRWS); set_repods(CRDS); } else if ((px<=GRIDSIZE-1)/2){ set_tpatch(DP); set_repows(DPRWS); set_repods(DPRDS); } else{ set_tpatch(WP); set_repows(WPRWS); set_repods(WPRDS); } set_repo( get_repows() ); add_clanspatch_message(get_x(), get_y(), get_pclans()); return 0; }
/** * @brief Calculates the direction and the speed of the movement * depending on the target. */ void TargetMovement::recompute_movement() { if (target_entity != NULL) { // the target may be a moving entity target_x = target_entity->get_x(); target_y = target_entity->get_y(); } if (get_x() != target_x || get_y() != target_y) { finished = false; double angle = Geometry::get_angle(get_x(), get_y(), target_x, target_y); int dx = target_x - get_x(); int dy = target_y - get_y(); sign_x = (dx >= 0) ? 1 : -1; sign_y = (dy >= 0) ? 1 : -1; if (std::fabs(angle - get_angle()) > 1E-6 || get_speed() < 1E-6) { set_speed(speed); set_angle(angle); set_max_distance((int) Geometry::get_distance( get_x(), get_y(), target_x, target_y)); } } }
bool Unit::is_within_range(Unit *target) { switch(type) { case FIGHTER: if(abs(get_x() - target->get_x()) + abs(get_y() - target->get_y()) == 1) { return true; } break; case ARCHER: if(abs(get_x() - target->get_x()) + abs(get_y() - target->get_y()) == 2) { return true; } break; case MAGE: case HEALER: if(abs(get_x() - target->get_x()) <= 1 && abs(get_y() - target->get_y()) <= 1) { return true; } break; } return false; }
Complex1 Complex1::operator*(const Complex1 &a) const { double a_ = get_x() * a.get_x() - get_y() * a.get_y(); double b_ = get_x() * a.get_y() + get_y() * a.get_x(); Complex1 tmp(a_, b_); return tmp; }
/** * Percorre o labirinto */ void percorre() { int nova_posicao = verifica_adjacentes(pos_atual); int atual_x = get_x(pos_atual); int atual_y = get_y(pos_atual); if (nova_posicao != 0) { int novo_x = get_x(nova_posicao); int novo_y = get_y(nova_posicao); // Posicao atual é modificada como visitada labirinto[atual_x][atual_y] = VISITADA; // Muda visualmente o local do rato labirinto[novo_x][novo_y] = ATUAL; // Muda a atual para a nova posicao pos_atual = nova_posicao; // // ARMAZENAR NA PILHA // } }
bool test_copy() { piece p = new_piece_rh(0, 0, true, true); bool result = true; //the first one (set_up_1()) is with new_piece_rh (int x, int y, bool small, bool horizontal) set_up_1(); for (int i = 0; i < NB_PIECES; i++) { copy_piece(pieces[i], p); result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height"); result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width"); result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x"); result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y"); result = result && test_equality_bool(is_horizontal(pieces[i]), is_horizontal(p), "copy is_horizontal"); result = result && test_equality_bool(can_move_x(pieces[i]), can_move_x(p), "copy can_move_x"); result = result && test_equality_bool(can_move_y(pieces[i]), can_move_y(p), "copy can_move_y"); } tear_down(); //the second one (set_up_2()) is with new_piece(int x, int y, int width, int height, bool move_x, bool move_y) set_up_2(); for (int i = 0; i < NB_PIECES; i++) { copy_piece(pieces[i], p); result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height"); result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width"); result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x"); result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y"); result = result && test_equality_bool(is_horizontal(pieces[i]), is_horizontal(p), "copy is_horizontal"); result = result && test_equality_bool(can_move_x(pieces[i]), can_move_x(p), "copy can_move_x"); result = result && test_equality_bool(can_move_y(pieces[i]), can_move_y(p), "copy can_move_y"); } tear_down(); delete_piece(p); return result; }
//--------------------------------------------------------------------------- void uv_image::draw(vector<GLuint> * clist) { if(!get_visible()) return; if(retranslate) { glNewList(stranslation, GL_COMPILE); glTranslatef(get_x(), get_y(), 0); glEndList(); glNewList(etranslation, GL_COMPILE); glTranslatef(-1*get_x(), -1*get_y(), 0); glEndList(); retranslate = false; } if(redraw) { glNewList(drawing, GL_COMPILE); glColor3f(1, 1, 1); if(picx == -1) draw_size(0, 0, get_w(), get_h()); else draw_size(0, 0, get_w(), get_h(), picx, picy, picw, pich); glEndList(); redraw = false; } clist->push_back(stranslation); clist->push_back(drawing); clist->push_back(etranslation); };
void dijsktra(int source,int target) { int dist[302], prev[302], finished[302], path[302]; int next, x1, y1, x2, y2, min, start, i, d; int no_of_path = 0; for(i=0;i<pixel_count;i++) { dist[i] = 9999; prev[i] = -1; finished[i]=0; } start = source; finished[start]=1; dist[start] = 0; while(finished[target] ==0) { min = 9999; next = 0; for(i=0;i < pixel_count;i++) { d = dist[start] + cost[start][i]; if(d < dist[i] && finished[i]==0) { dist[i] = d; prev[i] = start; } if(min > dist[i] && finished[i]==0) { min = dist[i]; next = i; } } start = next; finished[start] = 1; } start = target; while(start != -1) { path[no_of_path] = start; no_of_path++; start = prev[start]; } printf("Distance : %d\n" , dist[target]); for(i=0;i<no_of_path-1;i++) { x1 = get_x(path[i]); y1 = get_y(path[i]); x2 = get_x(path[i+1]); y2 = get_y(path[i+1]); XDrawLine(display_ptr, win, gc_white, x1, y1, x2, y2); XDrawLine(display_ptr, win, gc_blue, x1, y1, x2, y2); } for(i=1;i<no_of_path-1;i++) { x1 = get_x(path[i]); y1 = get_y(path[i]); XFillArc( display_ptr, win, gc_red, x1- win_height/200, y1 - win_height/200, win_height/100, win_height/100, 0, 360*64); } }
Entity *Exit::collision(Player *player) { if (get_x() > player->get_x() && get_x() < player->get_x() + player->get_w() && get_y() > player->get_y() && get_y() < player->get_y() + player->get_h()) return (this); else return (Entity *)0; }
bool test_equality_piece(cpiece expected, cpiece value, char *msg) { if ((get_x(expected) != get_x(value)) || (get_y(expected) != get_y(value)) || (is_horizontal(expected) != is_horizontal(value)) || (is_small(expected) != is_small(value))) { fprintf(stderr, "%s expected piece is not equal to value piece\n", msg); return false; } return true; }
bool piece_equals(cpiece P1, cpiece P2){ bool res = true; res = res && get_x(P1) == get_x(P2); res = res && get_y(P1) == get_y(P2); res = res && get_height(P1) == get_height(P2); res = res && get_width(P1) == get_width(P2); res = res && is_horizontal(P1) == is_horizontal(P2); return res; }
void GraphicBG::draw() { drawn = true; x_drawn = get_x(); y_drawn = get_y(); // Hintergrund sichern blit(get_ground().get_al_bitmap(), bg, get_x(), get_y(), 0, 0, bg->w, bg->h); Graphic::draw(); }
bool sup(cpiece p1, cpiece p2) { if (get_x(p1) > get_x(p2)) { return true; } if (get_x(p1) == get_x(p2)) if (get_y(p1) > get_y(p2)) return true; return false; }
/* * Returns a Rectangle representing the union between * this Rectangle and the given Rectangle rect */ Rectangle Rectangle::get_union(Rectangle rect) { int x1, y1, x2, y2; x1 = rect.get_x() < get_x() ? rect.get_x() : get_x(); y1 = rect.get_y() < get_x() ? rect.get_y() : get_y(); x2 = rect.get_x() + rect.width < get_x() + width ? get_x() + width : rect.get_x() + rect.width; y2 = rect.get_y() + rect.height < get_y() + height ? get_y() + height : rect.get_y() + rect.height; return Rectangle(x1, y1, x2-x1, y2-y1); }
void Shelf::align(GuiPosition horizontal, GuiPosition vertical) { if (dimension == GUI_HORIZONTAL) { alignOnDimension(GUI_HORIZONTAL,horizontal); Vector2fSet((&outPosition),horizontal == GUI_LEFT ? get_x()-width+edgeVisible : get_x()+width-edgeVisible,get_y()); } else { alignOnDimension(GUI_VERTICAL,vertical); Vector2fSet((&outPosition),get_x(),vertical == GUI_BOTTOM ? get_y()-height+edgeVisible : get_y()+height-edgeVisible); } Vector2fSet((&inPosition),get_x(),get_y()); }
int VFrame::copy_from(VFrame *frame) { int w = MIN(this->w, frame->get_w()); int h = MIN(this->h, frame->get_h()); timestamp = frame->timestamp; switch(frame->color_model) { case BC_COMPRESSED: allocate_compressed_data(frame->compressed_size); memcpy(data, frame->data, frame->compressed_size); this->compressed_size = frame->compressed_size; break; case BC_YUV410P: memcpy(get_y(), frame->get_y(), w * h); memcpy(get_u(), frame->get_u(), w / 4 * h / 4); memcpy(get_v(), frame->get_v(), w / 4 * h / 4); break; case BC_YUV420P: case BC_YUV411P: //printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v()); memcpy(get_y(), frame->get_y(), w * h); memcpy(get_u(), frame->get_u(), w * h / 4); memcpy(get_v(), frame->get_v(), w * h / 4); break; case BC_YUV422P: //printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v()); memcpy(get_y(), frame->get_y(), w * h); memcpy(get_u(), frame->get_u(), w * h / 2); memcpy(get_v(), frame->get_v(), w * h / 2); break; case BC_YUV444P: //printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v()); memcpy(get_y(), frame->get_y(), w * h); memcpy(get_u(), frame->get_u(), w * h); memcpy(get_v(), frame->get_v(), w * h); break; default: // printf("VFrame::copy_from %d\n", calculate_data_size(w, // h, // -1, // frame->color_model)); // Copy without extra 4 bytes in case the source is a hardware device memmove(data, frame->data, get_data_size()); break; } return 0; }
/** * @brief Displays the carried item on the map. * * This is a redefinition of MapEntity::display_on_map() * to display the shadow independently of the item movement. */ void CarriedItem::display_on_map() { if (!is_throwing) { // display the sprite normally MapEntity::display_on_map(); } else { // when the item is being thrown, display the shadow and the item separately // TODO: this could probably be simplified by using a JumpMovement get_map().display_sprite(*shadow_sprite, get_x(), get_y()); get_map().display_sprite(get_sprite(), get_x(), get_y() - item_height); } }
void StraightMovement::update() { Movement::update(); if(!is_suspended()) { uint32_t now = System::now(); bool current_move_y = move_y != 0 && now >= next_move_date_y; bool current_move_x = move_x != 0 && now >= next_move_date_x; while(current_move_x || current_move_y) { // save current coordinates. Rectangle old_xy(get_x(), get_y()); if(current_move_x) { // time to move in x direction. if(current_move_y) { // time to move in y direction. if(next_move_date_x <= next_move_date_y) { // we first move in x direction. update_x(); if(now >= next_move_date_y) { update_y(); } } else { update_y(); // we first move in y direciton. if(now >= next_move_date_x) { update_x(); } } } else { // we only move in x direction. update_x(); } } else { // we only move in y direction. update_y(); } if(get_entity() != NULL && !finished) { // movement is successful old coordinates have changed. bool success = (get_x() != old_xy.get_x() || get_y() != old_xy.get_y() && (move_x != 0 || move_y != 0)); // no movement notify obstacle. if(!success) { notify_obstacle_reached(); set_finished(); } } // check if we continue wit movement. now = System::now(); current_move_x = move_x != 0 && now >= next_move_date_x; current_move_y = move_y != 0 && now >= next_move_date_y; } } }
static void train_display_add(int index, DisplayData *display, int train) { display->id = train; char command[256]; char *pos = &command[0]; pos += sprintf(pos, "\0337"); // Draw Trin Id. pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_ID_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, "Train: %d", train); // Draw Orientation. pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_ORIENTATION_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, ORIENTATION_STRING); // Draw Train Position pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_LANDMARK_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, LANDMARK_STRING); // Draw Train Distance pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_DISTANCE_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, DISTANCE_STRING); // Draw Calibrated Train Velocity pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_ESTIMATED_VELOCITY_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, ESTIMATED_SPEED_STRING); // Draw Calibrated Train Stopping Distance pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_STOPPING_DISTANCE_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, STOPPING_DISTANCE_STRING); // Draw Train Speed pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_MEASURED_VELOCITY_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, MEASURED_VELOCITY_STRING); // Draw Train Error. pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_ERROR_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, ERROR_STRING); // Draw Train Reservations. pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_RESERVED_NODES_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, RESERVED_NODES_STRING); // Draw Train Destination pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_DESTINATION_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1); pos += sprintf(pos, DESTINATION_STRING); pos += sprintf(pos, "\0338"); Write(COM2, command, pos - command); }
/* * Returns a Rectangle representing the intersection between * this Rectangle and the given Rectangle rect */ Rectangle Rectangle::get_intersection(Rectangle rect) { if(!intersects(rect)) return Rectangle(0, 0, 0, 0); int x1, y1, x2, y2; x1 = rect.get_x() >= get_x() ? rect.get_x() : get_x(); y1 = rect.get_y() >= get_x() ? rect.get_y() : get_y(); x2 = rect.get_x() + rect.width >= get_x() + width ? get_x() + width : rect.get_x() + rect.width; y2 = rect.get_y() + rect.height >= get_y() + height ? get_y() + height : rect.get_y() + rect.height; return Rectangle(x1, y1, x2-x1, y2-y1); }
bool test_move() { bool result = true; piece p = new_piece_rh(0, 0, true, true); set_up(); for (int dist = 1; dist < NB_PIECES; dist++) for (int i=0; i < NB_PIECES; i++) { copy_piece(pieces[i],p); move_piece(p, LEFT, dist); if (is_horizontal(pieces[i])) result = result && test_equality_int(get_x(pieces[i])-dist,get_x(p),"move LEFT"); else result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move LEFT"); copy_piece(pieces[i],p); move_piece(p, RIGHT, dist); if (is_horizontal(pieces[i])) result = result && test_equality_int(get_x(pieces[i])+dist,get_x(p),"move RIGHT"); else result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move RIGHT"); copy_piece(pieces[i],p); move_piece(p, UP, dist); if (!is_horizontal(pieces[i])) result = result && test_equality_int(get_y(pieces[i])+dist,get_y(p),"move UP"); else result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move UP"); copy_piece(pieces[i],p); move_piece(p, DOWN, dist); if (!is_horizontal(pieces[i])) result = result && test_equality_int(get_y(pieces[i])-dist,get_y(p),"move DOWN"); else result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move DOWN"); } tear_down(); delete_piece(p); return result; }
//NOTE Player3d Entity* Entity3d::collision3d(Player3d const& player) { //NOTE1 if (const_cast<Player3d *>(&player)->get_x() < get_x() && const_cast<Player3d *>(&player)->get_x() > get_x() + get_w() && const_cast<Player3d *>(&player)->get_y() < get_y() && const_cast<Player3d *>(&player)->get_y() > get_y() + get_h() && const_cast<Player3d *>(&player)->get_z() < get_z() && const_cast<Player3d *>(&player)->get_z() > get_z() + get_d() ) return this; else return (Entity *)0; }
void Bear::drawSprite(SDL_Surface *screen) { int eye_y = get_y() + eye_y_diff; int eye_x = get_x() + eye_x_diff; int x = get_x(); int y = get_y(); //body boxRGBA(screen, x - width/2, y - height/2, x + width/2, y + height/2, 255, 0, 0, 150); //left eye boxRGBA(screen, eye_x - eye_dist/2 - eye_width , eye_y, x - eye_dist/2, eye_y - eye_height, 255, 255, 0, 255); //right eye boxRGBA(screen, eye_x + eye_dist/2 , eye_y, x + eye_dist/2 + eye_width, eye_y - eye_height, 255, 255, 0, 255); }
bool intersect(cpiece p1, cpiece p2) { if (!p1 || !p2) { failure("intersect p1 or p2 are NULL"); return false; } if (get_x(p1) < get_x(p2) + get_width(p2) && get_x(p1) + get_width(p1) > get_x(p2) && get_y(p1) < get_y(p2) + get_height(p2) && get_height(p1) + get_y(p1) > get_y(p2)) { return true; } return false; }
ClientConnection::ClientConnection(TCPsocket sock, ClientManager *manager) : socket(sock), status(0), manager(manager) { printf("ClientConnection()\n"); bindings[SDLK_LEFT] = bindings[SDLK_a] = Binding(&Entity::left, 200); bindings[SDLK_RIGHT] = bindings[SDLK_d] = Binding(&Entity::right, 200); bindings[SDLK_UP] = bindings[SDLK_w] = Binding(&Entity::up, 200); bindings[SDLK_DOWN] = bindings[SDLK_s] = Binding(&Entity::down, 200); bindings[SDLK_SPACE] = bindings[SDLK_e] = Binding(&Entity::prepare_action, &Entity::action); bindings[SDLK_LSHIFT]= bindings[SDLK_f] = Binding(&Entity::prepare_grab, &Entity::grab); bindings[SDLK_LCTRL] = bindings[SDLK_g] = Binding(&Entity::prepare_drop, &Entity::drop); bindings[SDLK_LALT] = bindings[SDLK_q] = Binding(&Entity::prepare_swap, &Entity::swap); name = SDLNet_ResolveIP(SDLNet_TCP_GetPeerAddress(socket)); update_entity_connection(); old_x = get_x(); old_y = get_y(); send_mutex = SDL_CreateMutex(); messages_mutex = SDL_CreateMutex(); send_thread = SDL_CreateThread(send_thread_func, this); recieve_thread = SDL_CreateThread(recieve_thread_func, this); char data[] = { 'b', 151, 130, 42 }; // set background int len = sizeof(data); send(data, len); }
void ClientConnection::send_scroll() { int x = get_x(); int y = get_y(); int dx = World::difference(x, old_x); int dy = World::difference(y, old_y); old_x = x; old_y = y; for (typeof(client_entities.begin()) it = client_entities.begin(); it != client_entities.end(); ++it) { it->second.x -= dx; it->second.y -= dy; } static const int len = 5; DataPacket packet = { len, new char[len] }; packet.data[0] = 'S'; SDLNet_Write16(dx, packet.data + 1); SDLNet_Write16(dy, packet.data + 3); SDL_LockMutex(send_mutex); data_to_send.push_back(packet); SDL_UnlockMutex(send_mutex); }
int get_car_with_mouse(int x, int y, game tmpGame) { int miny, minx, maxx, maxy; for (int i = 0; i < game_nb_pieces(tmpGame); i++) { cpiece tmp = game_piece(tmpGame, i); minx = get_x(tmp) * RATIO; miny = (game_height(tmpGame) - get_y(tmp) - get_height(tmp)) * RATIO; maxx = (get_x(tmp) + get_width(tmp)) * RATIO; maxy = (game_height(tmpGame) - get_y(tmp)) * RATIO; if (x >= minx && x <= maxx && y >= miny && y <= maxy) { return i; } } return -1; }
/** * \brief Destroys the item while it is being thrown. */ void CarriedItem::break_item() { if (is_throwing && throwing_direction != 3) { // destroy the item where it is actually drawn set_y(get_y() - item_height); } get_movement()->stop(); if (!can_explode()) { if (!destruction_sound_id.empty()) { Sound::play(destruction_sound_id); } if (get_sprite().has_animation("destroy")) { get_sprite().set_current_animation("destroy"); } else { remove_from_map(); } } else { get_entities().add_entity(std::make_shared<Explosion>( "", get_layer(), get_xy(), true )); Sound::play("explosion"); if (is_throwing) { remove_from_map(); // because if the item was still carried by the hero, then the hero class will destroy it } } is_throwing = false; is_breaking = true; }