bool GeoConnection::same_orientation(NeuronID i, NeuronID j) { double xi,yi,xj,yj; get_xy(i,xi,yi,true); get_xy(j,xj,yj,false); return same_orientation(xi,yi,xj,yj); }
/* Given a variable to bound, this checks it against the known ontology and returns: * 0 if everything's OK, * 1 if the category is known but doesn't have the feature * 2 if the category is known but the feature isn't. * 3 if the feature somehow is not known */ int varcheckt(list * l, list * ontology) { int i; int categoryfound = 0; int featurefound = 0; char * category = list_get_token(l, 1); char * feature = list_get_token(l, 2); if(!feature) return 3; /* Check all the lines in the CSV */ for(i = 2; i <= ontology->length; i++) { /* Look up the variable name */ char * varname = get_xy(ontology, 1, i); if(!varname) continue; if(!strcmp(varname, category)) { categoryfound = 1; char * varval = get_xy(ontology, 2, i); if(varval) if(!strcmp(feature, varval)) featurefound = 1; } if(categoryfound && featurefound) return 0; } if(categoryfound && featurefound) return 0; if(categoryfound && !featurefound) return 2; return 1; }
/* Given a variable to bound, this checks it against the known ontology and returns: * 0 if everything's OK, * 1 if the category is not known * 2 if the category is known but can't be bound bound negative. */ int varcheckb(char * c, list * ontology) { int i = 0; char * varname; /* Check all the lines in the CSV */ while(++i && (varname = get_xy(ontology, 1, i))) { char * nb = get_xy(ontology, 3, i); int negbind; if(nb) negbind = atoi(nb); else negbind = 0; /* If the variable name is being bound negative, then check that that's allowed * (that information is in column three; 0 for no and 1 for yes) */ if(c[0] == '-' && !strcmp(varname, c + 1) && negbind) return 0; if(c[0] == '-' && !strcmp(varname, c + 1) && !negbind) return 2; /* If the variable is being bound positive (but not to a value), then check that the variable name is recognised */ if(c[0] != '-') if(!strcmp(varname, c)) return 0; } return 1; }
void RenderContext::mouseposition(double x, double y) { if (mousedown) { auto new_center = glm::dvec2(cx, cy) + get_xy(dragstart_x, dragstart_y) - get_xy(x, y); cx = new_center.x; cy = new_center.y; dragstart_x = x; dragstart_y = y; } // auto pp = get_xy(x, y); // printf("\n %5f %5f\n", pp.x, pp.y); }
double GeoConnection::getProbability(NeuronID i, NeuronID j, double sigma) { double xi,yi,xj,yj; get_xy(i,xi,yi,true); get_xy(j,xj,yj,false); if (same_orientation(xi,yi,xj,yj)){ return this->oProb; } double x = pow(xj-xi,2); double y = pow(yj-yi,2); return exp(-1*(x+y) / sigma); }
/** * \brief Returns the coordinates where an object controlled by this movement * should be displayed. * \return the coordinates to use to display the object controlled by this movement */ Point RelativeMovement::get_displayed_xy() const { if (entity_followed == nullptr) { return get_xy(); } // if the followed entity is displayed at a different position than its real position, // we apply the same difference when displaying this entity const Point& followed_xy = entity_followed->get_xy(); const Point& followed_displayed_xy = entity_followed->get_displayed_xy(); Point dxy = followed_displayed_xy - followed_xy; return get_xy() + dxy; }
/** * \brief This function is called when this entity stops being moved by the * hero. */ void Block::stop_movement_by_hero() { clear_movement(); when_can_move = System::now() + moving_delay; // see if the block has moved if (get_xy() != last_position) { // the block has moved last_position = get_xy(); // save the new position for next time if (maximum_moves == 1) { // if the block could be moved only once, maximum_moves = 0; // then it cannot move anymore } } }
/** * \brief Returns the point located just outside the arrow's collision box, * in its current direction. */ const Rectangle Arrow::get_facing_point() const { Rectangle facing_point = get_xy(); switch (get_sprite().get_current_direction()) { // right case 0: facing_point.add_x(8); break; // up case 1: facing_point.add_y(-9); break; // left case 2: facing_point.add_x(-9); break; // down case 3: facing_point.add_y(8); break; default: Debug::die("Invalid direction for Arrow::get_facing_point()"); } return facing_point; }
void StraightMovement::set_speed_y(double speed_yy) { if(std::fabs(speed_yy) <= 1E-6) { speed_yy = 0; } this->speed_y = speed_yy; uint32_t now = System::now(); // compute delay_x, move_x, next_move_date_x. if(speed_y > 0) { this->delay_y = (uint32_t) (1000 / this->speed_y); move_y = 1; set_next_move_date_y(now + delay_y); } else if(speed_y < 0) { this->delay_y = (uint32_t) (-1000 / this->speed_y); move_y = -1; set_next_move_date_y(now + delay_y); } else { move_y = 0; } this->angle = Geometry::get_angle(0.f, 0.f, speed_x * 100, speed_y * 100); start_xy.set_xy(get_xy()); this->finished = false; if(get_entity() != NULL) { get_entity()->notify_movement_changed(); } }
int selectitem(const char **items, int n, int *i, int k) { int x, y; switch (k) { case 0: break; case MVLEFT: if (*i) *i -= 1; break; case MVRIGHT: if (*i < n-1) *i += 1; break; case STARTBTN: case A_BTN: get_xy(&x, &y); n = dropdownlist(items, n, *i, x, y); if (n) *i = n-1; setcurs(x, y); return 3; default: return 0; } putch('['); printstr(items[*i]); n = getdropdownwidth(items, n) - strlen(items[*i]); putnchars(' ', n); printstr("] "); return 1; }
/** * @brief Sets the x speed. * @param x_speed the x speed of the object in pixels per second */ void StraightMovement::set_x_speed(double x_speed) { if (std::fabs(x_speed) <= 1E-6) { x_speed = 0; } this->x_speed = x_speed; uint32_t now = System::now(); // compute x_delay, x_move and next_move_date_x if (x_speed == 0) { x_move = 0; } else { if (x_speed > 0) { x_delay = (uint32_t) (1000 / x_speed); x_move = 1; } else { x_delay = (uint32_t) (1000 / (-x_speed)); x_move = -1; } set_next_move_date_x(now + x_delay); } angle = Geometry::get_angle(0, 0, (int) (x_speed * 100), (int) (y_speed * 100)); initial_xy.set_xy(get_xy()); finished = false; notify_movement_changed(); }
/** * \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; }
/** * @brief Sets the y speed. * @param y_speed the y speed of the object in pixels per second */ void StraightMovement::set_y_speed(double y_speed) { if (std::fabs(y_speed) <= 1E-6) { y_speed = 0; } this->y_speed = y_speed; uint32_t now = System::now(); // compute y_delay, y_move and next_move_date_y if (y_speed == 0) { y_move = 0; } else { if (y_speed > 0) { y_delay = (uint32_t) (1000 / y_speed); y_move = 1; } else { y_delay = (uint32_t) (1000 / (-y_speed)); y_move = -1; } set_next_move_date_y(now + y_delay); } angle = Geometry::get_angle(0, 0, (int) (x_speed * 100), (int) (y_speed * 100)); initial_xy.set_xy(get_xy()); finished = false; if (get_entity() != NULL) { get_entity()->notify_movement_changed(); } }
/** * \brief Updates the position. */ void RelativeMovement::update() { if (entity_followed == nullptr) { finished = true; return; } if (entity_followed->is_being_removed()) { finished = true; entity_followed = nullptr; } else { Point next = entity_followed->get_xy() + entity_offset; Point dnext = next - get_xy(); if (!are_obstacles_ignored()) { if (!finished && (dnext.x != 0 || dnext.y != 0)) { if (!test_collision_with_obstacles(dnext)) { set_xy(next); } else { finished = true; notify_obstacle_reached(); } } } else { set_xy(next); } } }
/** * @brief This function is called when the entity has just moved. */ void CustomEnemy::notify_position_changed() { Enemy::notify_position_changed(); if (!is_being_hurt()) { script->event_position_changed(get_xy()); } }
/** * \brief Creates an explosion on this object. */ void Destructible::explode() { get_entities().add_entity(std::make_shared<Explosion>( "", get_layer(), get_xy(), true )); Sound::play("explosion"); get_lua_context().destructible_on_exploded(*this); }
/** * \brief Returns the coordinates where an object controlled by this movement * should be displayed. * \return the coordinates to use to display the object controlled by this movement */ const Rectangle FollowMovement::get_displayed_xy() { if (entity_followed == NULL) { return get_xy(); } // if the followed entity is displayed at a different position than its real position, // we apply the same difference when displaying this entity const Rectangle& followed_xy = entity_followed->get_xy(); const Rectangle& followed_displayed_xy = entity_followed->get_displayed_xy(); int dx = followed_displayed_xy.get_x() - followed_xy.get_x(); int dy = followed_displayed_xy.get_y() - followed_xy.get_y(); Rectangle displayed_xy = get_xy(); displayed_xy.add_xy(dx, dy); return displayed_xy; }
/** * @brief Sets the maximum distance of the movement. * @param max_distance if the object goes further than this distance, it will come back (0 means no limit) */ void RandomMovement::set_max_distance(int max_distance) { Debug::check_assertion(max_distance >= 0, StringConcat() << "Invalid value of max_distance: " << max_distance); this->max_distance = max_distance; // restrict the movement in a rectangle bounds.set_xy(get_xy()); bounds.add_xy(-max_distance, -max_distance); bounds.set_size(max_distance * 2, max_distance * 2); }
inline void compare_xy(DistanceField2D& partial_field, sdf_cell& cell, int64_t x, int64_t y, int64_t x_offset, int64_t y_offset) { sdf_cell other = get_xy(partial_field, x + x_offset, y + y_offset); other.d1 += x_offset; other.d2 += y_offset; if (distance_squared(other) < distance_squared(cell)) { cell = other; } }
static void unshade_cb(void *data) { get_xy(shade_win, &sw_x, &sw_y); D(("Shade win is at %hd, %hd\n", sw_x, sw_y)); Epplet_window_hide(shade_win); Epplet_window_show(main_win); return; data = NULL; }
/** * \brief Sets the maximum radius. * \param max_radius If the object goes further than this distance, * it will come back (0 means no limit). */ void RandomMovement::set_max_radius(int max_radius) { Debug::check_assertion(max_radius >= 0, StringConcat() << "Invalid value of max_radius: " << max_radius); this->max_radius = max_radius; // restrict the movement in a rectangle bounds.set_xy(get_xy()); bounds.add_xy(-max_radius, -max_radius); bounds.set_size(max_radius * 2, max_radius * 2); }
/** * \brief Adds to the map the pickable treasure (if any) hidden under this destructible item. */ void Destructible::create_treasure() { get_entities().add_entity(Pickable::create( get_game(), "", get_layer(), get_xy(), treasure, FALLING_MEDIUM, false )); }
static int op_handler(int k, int *pos) { const struct termopt opt = {ASCII, "CP437 ASCII", "drawing"}; int i = *pos-2; if (i < 0) { if (k) { clearbox(0, 16, 0, 4); inputsetup_box(k-1, 1, 7); } draw_options_box(); return 1; } if (!i) { if (k == MVLEFT) i = 0; else if (k == MVRIGHT) i = 1; else { i = !getopt_int("", "fullscreen"); if (k == A_BTN) i = !i; else if (k) return 0; } printmenuitem_options("yes no", i); if (k) { union val v; v.integ = !i; setoption("", "fullscreen", v, 0); } i = 1; } else if (i == 1) { if (!k) { get_xy(&k, &i); setcurs(2, i+5); putnchars(HLINE, 28); help_alt_enter(); setcurs(k, i); k = 0; } i = term_optionhandler(k, &opt); } #ifndef NO_BLOCKSTYLES else i = select_blockstyle(k); #endif if (i == 3) { draw_tetris_logo(0, 0); draw_options_box(); } return i; }
/** * \brief Notifies this movement that the coordinates controlled by it * have just been changed. */ void Movement::notify_position_changed() { LuaContext* lua_context = get_lua_context(); if (lua_context != nullptr && are_lua_notifications_enabled()) { lua_context->movement_on_position_changed(*this, get_xy()); } if (entity != nullptr) { if (!entity->is_being_removed()) { entity->notify_position_changed(); } } }
/** * \brief Sets the maximum radius. * \param max_radius If the object goes further than this distance, * it will come back (0 means no limit). */ void RandomMovement::set_max_radius(int max_radius) { if (max_radius < 0) { std::ostringstream oss; oss << "Invalid max radius: " << max_radius; Debug::die(oss.str()); } this->max_radius = max_radius; // restrict the movement in a rectangle bounds.set_xy(get_xy()); bounds.add_xy(-max_radius, -max_radius); bounds.set_size(max_radius * 2, max_radius * 2); }
/** * \brief Chooses a new direction for the movement. */ void RandomMovement::set_next_direction() { set_speed(normal_speed); double angle; if (get_entity() == nullptr || max_radius == 0 // means no limit || bounds.contains(get_xy())) { // we are inside the bounds (or there is no bound): pick a random direction angle = Geometry::degrees_to_radians(Random::get_number(8) * 45 + 22.5); } else { // we are outside the bounds: get back into the rectangle to avoid going too far angle = Geometry::get_angle(get_xy(), bounds.get_center()); } set_angle(angle); next_direction_change_date = System::now() + 500 + Random::get_number(1500); // change again in 0.5 to 2 seconds notify_movement_changed(); }
/** * \brief Creates a boomerang. * \param hero the hero * \param max_distance maximum distance of the movement in pixels * \param speed speed of the movement in pixels per second * \param angle the angle of the boomerang trajectory in radians * \param sprite_name animation set id representing the boomerang */ Boomerang::Boomerang( Hero& hero, int max_distance, int speed, double angle, const std::string& sprite_name): MapEntity("", 0, hero.get_layer(), 0, 0, 0, 0), hero(hero), has_to_go_back(false), going_back(false), speed(speed) { // initialize the entity create_sprite(sprite_name); set_size(16, 16); set_origin(8, 8); int hero_x = hero.get_top_left_x(); int hero_y = hero.get_top_left_y(); switch (hero.get_animation_direction()) { case 0: set_xy(hero_x + 24, hero_y + 8); break; case 1: set_xy(hero_x + 8, hero_y - 8); break; case 2: set_xy(hero_x - 8, hero_y + 8); break; case 3: set_xy(hero_x + 8, hero_y + 24); break; } initial_coords.set_xy(get_xy()); StraightMovement* movement = new StraightMovement(false, false); movement->set_speed(speed); movement->set_angle(angle); movement->set_max_distance(max_distance); set_movement(movement); next_sound_date = System::now(); }
void RenderContext::zoom(double yoffset) { auto old_scale = cur_scale; auto center = glm::dvec2(cx, cy); auto pos = get_xy(pos_x, pos_y); cur_scale *= (yoffset < 0 ? 1.1 : (1 / 1.1)); auto new_center = pos + (cur_scale / old_scale) * (center - pos); cx = new_center.x; cy = new_center.y; // printf("\n cx %6f cy %6f xpos %6f ypos %6f xsize %6i ysize %6i posx %6f // posy %6f \n", // cx, cy, xpos, ypos, xsize, ysize, pos.x, pos.y); }
static void shade_cb(void *data) { Epplet_window_hide(main_win); Epplet_window_show(shade_win); if (sw_x == (unsigned short)-1 && sw_y == (unsigned short)-1) { get_xy(main_win, &sw_x, &sw_y); sw_x += (16 * (w - 1)); sw_y += (16 * (h - 1)); } D(("Shade win moving to %hd, %hd\n", sw_x, sw_y)); XMoveWindow(Epplet_get_display(), shade_win, sw_x, sw_y); return; data = NULL; }
/** * \brief Notifies the block that it has just moved. */ void Block::notify_position_changed() { // now we know that the block moves at least of 1 pixel: // we can play the sound if (get_movement() != NULL && !sound_played) { Sound::play("hero_pushes"); sound_played = true; } check_collision_with_detectors(false); update_ground_below(); if (are_movement_notifications_enabled()) { get_lua_context().entity_on_position_changed(*this, get_xy(), get_layer()); } }