/**
 * \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);
    }
  }
}
Exemple #2
0
/*刷新一行屏幕*/
void RefreshOneLine(u8 x_start , u8 x_end , u8 y)
{
	u8 *pLCD;
	set_xy(x_start,y*2);
	for(pLCD = &LCDbuf[y*2][x_start] ; pLCD<&LCDbuf[y*2][64];)
	{
		WriteData(*pLCD++);
	}
	set_xy(x_start,y*2+1);
	for(pLCD = &LCDbuf[y*2+1][x_start] ; pLCD<&LCDbuf[y*2+1][64];)
	{
		WriteData(*pLCD++);
	}

	set_xy(64,y*2);
	for(pLCD = &LCDbuf[y*2][64] ; pLCD<&LCDbuf[y*2][x_end];)
	{
		WriteData(*pLCD++);
	}
	set_xy(64,y*2+1);
	for(pLCD = &LCDbuf[y*2+1][64] ; pLCD<&LCDbuf[y*2+1][x_end];)
	{
		WriteData(*pLCD++);
	}
	memset(LCDbuf[y*2] , 0 ,128);
	memset(LCDbuf[y*2+1] , 0 ,128);
}
Exemple #3
0
/***********************************************************
*   函数名称:
*   功能描述:   OLED显示单个字符
*   参数列表:
*   返回结果:
*   备    注:在指定位置显示一个字符,包括部分字符
***********************************************************/
void OLED_SSD1306::show_char(uint8_t x, uint8_t y, uint8_t chr)
{
    unsigned char c = 0, i = 0;
    c = chr - ' '; //得到偏移后的值
    if(x > Max_Column - 1)
    {
        x = 0;
        y = y + 2;
    }
    if(SIZE == 16)
    {
        set_xy(x, y);
        for(i = 0; i < 8; i++)
            write_data(font8x16[c * 16 + i]);
        set_xy(x, y + 1);
        for(i = 0; i < 8; i++)
            write_data(font8x16[c * 16 + i + 8]);
    }
    else
    {
        set_xy(x, y + 1);
        for(i = 0; i < 6; i++)
            write_data(font6x8[c][i]);
    }
}
Exemple #4
0
void add_body_force_xy(xy_t p0, xy_t p1, double mass, xy_t *acc)	// adds the force from p1's mass to p0's acceleration
{
	double dbb2, dbb;
	double fmag;

	dbb2 = hypot_xy2(p0, p1);
	dbb = sqrt(dbb2);
	fmag = mass / dbb2;
	*acc = add_xy( *acc, div_xy( mul_xy(set_xy(fmag), sub_xy(p1, p0)) , set_xy(dbb)) );
}
Exemple #5
0
/**
 * \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();
}
Exemple #6
0
/**
 * \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(
    const HeroPtr& hero,
    int max_distance,
    int speed,
    double angle,
    const std::string& sprite_name
):
  Entity("", 0, hero->get_layer(), Point(0, 0), Size(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;

  }

  std::shared_ptr<StraightMovement> movement =
      std::make_shared<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();
}
Exemple #7
0
/***********************************************************
*   函数名称:
*   功能描述:   OLED显示一个汉字
*   参数列表:
*   返回结果:
*   备    注:在指定位置显示一个汉字
***********************************************************/
void OLED_SSD1306::show_chinese(uint8_t x, uint8_t y, uint8_t no)
{
    u8 t, adder = 0;
    set_xy(x, y);
    for(t = 0; t < 16; t++)
    {
        write_data(Hzk[2 * no][t]);
        adder += 1;
    }
    set_xy(x, y + 1);
    for(t = 0; t < 16; t++)
    {
        write_data(Hzk[2 * no + 1][t]);
        adder += 1;
    }
}
Exemple #8
0
/**
 * \brief Creates an arrow.
 * \param hero The hero.
 */
Arrow::Arrow(const Hero& hero):
  Entity("", 0, hero.get_layer(), Point(0, 0), Size(0, 0)),
  hero(hero) {

  // initialize the entity
  int direction = hero.get_animation_direction();
  create_sprite("entities/arrow", true);
  get_sprite().set_current_direction(direction);
  set_drawn_in_y_order(true);

  if (direction % 2 == 0) {
    // Horizontal.
    set_size(16, 8);
    set_origin(8, 4);
  }
  else {
    // Vertical.
    set_size(8, 16);
    set_origin(4, 8);
  }

  set_xy(hero.get_center_point());
  notify_position_changed();

  std::string path = " ";
  path[0] = '0' + (direction * 2);
  set_movement(std::make_shared<PathMovement>(
      path, 192, true, false, false
  ));

  disappear_date = System::now() + 10000;
  stop_now = false;
  entity_reached = nullptr;
}
Exemple #9
0
/**
 * \brief Creates an arrow.
 * \param hero The hero.
 */
Arrow::Arrow(const Hero& hero):
  MapEntity("", 0, hero.get_layer(), 0, 0, 0, 0),
  hero(hero) {

  // initialize the entity
  int direction = hero.get_animation_direction();
  create_sprite("entities/arrow", true);
  get_sprite().set_current_direction(direction);
  set_drawn_in_y_order(true);

  if (direction % 2 == 0) {
    // Horizontal.
    set_size(16, 8);
    set_origin(8, 4);
  }
  else {
    // Vertical.
    set_size(8, 16);
    set_origin(4, 8);
  }

  set_xy(hero.get_center_point());
  set_optimization_distance(0); // Make the arrow continue outside the screen until disappear_date.

  std::string path = " ";
  path[0] = '0' + (direction * 2);
  Movement* movement = new PathMovement(path, 192, true, false, false);
  set_movement(movement);

  disappear_date = System::now() + 10000;
  stop_now = false;
  entity_reached = NULL;
}
Exemple #10
0
/**
 * \brief Creates a carried item (i.e. an item carried by the hero).
 * \param hero the hero who is lifting the item to be created
 * \param original_entity the entity that will be replaced by this carried item
 * (its coordinates, size and origin will be copied)
 * \param animation_set_id name of the animation set for the sprite to create
 * \param destruction_sound_id Name of the sound to play when this item is destroyed
 * (or an empty string).
 * \param damage_on_enemies damage received by an enemy if the item is thrown on him
 * (possibly 0)
 * \param explosion_date date of the explosion if the item should explode,
 * or 0 if the item does not explode
 */
CarriedItem::CarriedItem(
    Hero& hero,
    const Entity& original_entity,
    const std::string& animation_set_id,
    const std::string& destruction_sound_id,
    int damage_on_enemies,
    uint32_t explosion_date
):
  Entity("", 0, hero.get_layer(), Point(0, 0), Size(0, 0)),
  hero(hero),
  is_lifting(true),
  is_throwing(false),
  is_breaking(false),
  break_one_layer_above(false),
  destruction_sound_id(destruction_sound_id),
  damage_on_enemies(damage_on_enemies),
  shadow_sprite(nullptr),
  throwing_direction(0),
  next_down_date(0),
  item_height(0),
  y_increment(0),
  explosion_date(explosion_date) {

  // align correctly the item with the hero
  int direction = hero.get_animation_direction();
  if (direction % 2 == 0) {
    set_xy(original_entity.get_x(), hero.get_y());
  }
  else {
    set_xy(hero.get_x(), original_entity.get_y());
  }
  set_origin(original_entity.get_origin());
  set_size(original_entity.get_size());
  set_drawn_in_y_order(true);

  // create the lift movement and the sprite
  std::shared_ptr<PixelMovement> movement = std::make_shared<PixelMovement>(
      lifting_trajectories[direction], 100, false, true
  );
  create_sprite(animation_set_id);
  get_sprite().set_current_animation("stopped");
  set_movement(movement);

  // create the shadow (not visible yet)
  shadow_sprite = std::make_shared<Sprite>("entities/shadow");
  shadow_sprite->set_current_animation("big");
}
Exemple #11
0
void main()
{

    unsigned image_in = input("image_in");
    unsigned image_out = output("image_out");

    unsigned image[SIZE];
    unsigned new_image[SIZE];

    int x, y, pixel;

    while(1){

        /* read in image */
        for(y=0; y<HEIGHT; y++){
            for(x=0; x<WIDTH; x++){
                set_xy(image, x, y, fgetc(image_in));
            }
            report(y);
        }

        /* apply edge detect */
        for(y=0; y<HEIGHT; y++){
            for(x=0; x<WIDTH; x++){

                pixel =  get_xy(image, x,   y  ) << 2;
                pixel -= get_xy(image, x-1, y+1);
                pixel -= get_xy(image, x+1, y-1);
                pixel -= get_xy(image, x-1, y-1);
                pixel -= get_xy(image, x+1, y+1);
                set_xy(new_image, x, y, pixel);
            }
            report(y);
        }

        /* write out image */
        for(y=0; y<HEIGHT; y++){
            for(x=0; x<WIDTH; x++){
                fputc(get_xy(new_image, x, y), image_out);
            }
            report(y);
        }

    }
}
Exemple #12
0
/**
 * @brief Creates a carried item (i.e. an item carried by the hero).
 * @param hero the hero who is lifting the item to be created
 * @param original_entity the entity that will be replaced by this carried item
 * (its coordinates, size and origin will be copied)
 * @param animation_set_id name of the animation set for the sprite to create
 * @param destruction_sound_id name of the sound to play when this item is destroyed
 * (or an empty string)
 * @param damage_on_enemies damage received by an enemy if the item is thrown on him
 * (possibly 0)
 * @param explosion_date date of the explosion if the item should explode,
 * or 0 if the item does not explode
 */
CarriedItem::CarriedItem(Hero& hero, MapEntity& original_entity,
    const std::string& animation_set_id,
    const std::string& destruction_sound_id,
    int damage_on_enemies, uint32_t explosion_date):

  MapEntity(),
  hero(hero),
  is_lifting(true),
  is_throwing(false),
  is_breaking(false),
  break_on_intermediate_layer(false) {

  // put the item on the hero's layer
  set_layer(hero.get_layer());

  // align correctly the item with the hero
  int direction = hero.get_animation_direction();
  if (direction % 2 == 0) {
    set_xy(original_entity.get_x(), hero.get_y());
  }
  else {
    set_xy(hero.get_x(), original_entity.get_y());
  }
  set_origin(original_entity.get_origin());
  set_size(original_entity.get_size());

  // create the lift movement and the sprite
  PixelMovement *movement = new PixelMovement(lifting_trajectories[direction], 100, false, true);
  create_sprite(animation_set_id);
  get_sprite().set_current_animation("stopped");
  set_movement(movement);

  // create the breaking sound
  this->destruction_sound_id = destruction_sound_id;

  // create the shadow (not visible yet)
  this->shadow_sprite = new Sprite("entities/shadow");
  this->shadow_sprite->set_current_animation("big");

  // damage on enemies
  this->damage_on_enemies = damage_on_enemies;

  // explosion
  this->explosion_date = explosion_date;
}
Exemple #13
0
/*-----------------------------------------------------------------------
LCD_write_english_String  : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置,x 0-83 ,y 0-5
-----------------------------------------------------------------------*/
void NOKIA5110::disp_string(unsigned char X,unsigned char Y,const char *s)
  {
    set_xy(X,Y);
    while (*s) 
      {
			 disp_char(*s);
			 s++;
      }
  }
Exemple #14
0
int select_tty(int tty_index)
{ 
  int ret =0;
  
  if ( 0 <= cur_tty_index && cur_tty_index < TTY_NUM)
    cur_tty_index = tty_index;
  else
    ret = -1;

  //s32_print_int(tty_table[cur_tty_index].console->vm_start, (u8*)(0xb8000+160*1), 16);

  int org_x, org_y;
  get_xy(tty_table[cur_tty_index].console, &org_x, &org_y);

  set_xy(tty_table[cur_tty_index].console, 0, 0);
  s32_console_print_str(tty_table[cur_tty_index].console, "simple os tty ");

  switch (cur_tty_index)
  {
    case 0:
      s32_console_print_char(tty_table[cur_tty_index].console, '1');
      break;
    case 1:
      s32_console_print_char(tty_table[cur_tty_index].console, '2');
      break;
    case 2:
      s32_console_print_char(tty_table[cur_tty_index].console, '3');
      break;
    default:
      break;
  }
  s32_console_print_str(tty_table[cur_tty_index].console, "\r\nfake login: "******"\r\n\r\n");
  set_xy(tty_table[cur_tty_index].console, org_x, org_y);
  u16 cur_console_vm_start = (tty_table[cur_tty_index].console->vm_start-0xb8000)/2;
  set_video_start_addr(cur_console_vm_start);


  //set_cursor(cur_console_vm_start + tty_table[cur_tty_index].console->cur_x + tty_table[cur_tty_index].console->cur_y*80);
  set_cursor(cur_console_vm_start + org_x + org_y*80);
  return ret;
}
Exemple #15
0
/**
 * @brief Resets the block at its initial position.
 */
void Block::reset() {

  if (get_movement() != NULL) {
    // the block was being pushed or pulled by the hero
    clear_movement();
    when_can_move = System::now() + moving_delay;
  }

  set_xy(initial_position);
  last_position.set_xy(initial_position);
  this->maximum_moves = initial_maximum_moves;
}
Exemple #16
0
/**
 * \brief Resets the block at its initial position.
 */
void Block::reset() {

  if (get_movement() != nullptr) {
    // the block was being pushed or pulled by the hero
    clear_movement();
    when_can_move = System::now() + moving_delay;
  }

  last_position = initial_position;
  this->maximum_moves = initial_maximum_moves;
  set_xy(initial_position);
  notify_position_changed();
}
Exemple #17
0
void NOKIA5110::printf(uint8_t row,uint8_t col,const char *fmt,...)
{
	char buf[16];
	u8 i = 0;
	va_list va_params;   
	va_start(va_params,fmt);   
	vsprintf(buf,fmt,va_params);   
	va_end(va_params); 
	set_xy(row,col);
	while(buf[i] != '\0')
	{
	   disp_char(buf[i++]);
	}
}
Exemple #18
0
/*刷新屏幕*/
void RefreshLCD(void)
{
	u8 *pLCD;
	u8 i;

	for(i=0;i<8;i++)//刷新左半屏
	{
		set_xy(0,i);
		for(pLCD = &LCDbuf[i][0] ; pLCD<&LCDbuf[i][64];)
		{
			WriteData(*pLCD++);
		}
	}

	for(i=0;i<8;i++) //刷新右半屏
	{
		set_xy(64,i);
		for(pLCD = &LCDbuf[i][64] ; pLCD<=&LCDbuf[i][127];)
		{
			WriteData(*pLCD++);
		}
	}
	memset(LCDbuf , 0 , 1024);//刷屏后清映射区
}
Exemple #19
0
void calc_screen_limits(zoom_t *zc)
{
	int x, y;

	if (3*zc->fb->w > 3*zc->fb->h)				// if widescreen (more than 4:3 aka 12:9)
		zc->scrscale = (double) zc->fb->h / 18.;	// for 1920x1080 srcscale would be 60
	else
		zc->scrscale = (double) zc->fb->w / 18.;
	zc->scrscale_unzoomed = zc->scrscale;

	zc->limit_u = mul_xy(xy(zc->fb->w, zc->fb->h), set_xy(0.5/zc->scrscale));

	zc->scrscale *= zc->zoomscale;
	zc->iscrscale = 1. / zc->scrscale;

	zc->drawlim_u = set_xy(zc->iscrscale * GAUSSRAD_HQ * zc->drawing_thickness);

	zc->corners.p0 = sub_xy(zc->offset_u, mul_xy(xy(zc->fb->w, zc->fb->h), set_xy(0.5*zc->iscrscale)));
	zc->corners.p1 = add_xy(zc->offset_u, mul_xy(xy(zc->fb->w, zc->fb->h), set_xy(0.5*zc->iscrscale)));
	zc->corners_dl.p0 = sub_xy(zc->corners.p0, zc->drawlim_u);
	zc->corners_dl.p1 = add_xy(zc->corners.p1, zc->drawlim_u);
	zc->fb->window_dl.p0 = set_xy(-GAUSSRAD_HQ * zc->drawing_thickness);			// drawing limit in pixels
	zc->fb->window_dl.p1 = sub_xy( xy(zc->fb->w-1, zc->fb->h-1), zc->fb->window_dl.p0 );
}
Exemple #20
0
void Snake::render_tick()
{
  byte x = _head_x;
  byte y = _head_y;
  byte dir;

  // Draw head
  set_xy(x, y, 1);

  // Delete tail
  for (int i=0; i < _snake_len; i++)
 {
    dir = ~(get_element(i)) & 3;

    next_pos((direction)dir, &x, &y);
    if (i == _snake_len - 1) {
        set_xy(x, y, 0);
    }
  }

  // Draw food
  if (_food_x > 0 && _food_y > 0)
    set_xy(_food_x, _food_y, 1);
}
Exemple #21
0
/*-----------------------------------------------------------------------
LCD_write_chinese_string: 在LCD上显示汉字

输入参数:X、Y    :显示汉字的起始X、Y坐标;
          ch_with :汉字点阵的宽度
          num     :显示汉字的个数;  
          line    :汉字点阵数组中的起始行数
          row     :汉字显示的行间距
测试:
	LCD_write_chi(0,0,12,7,0,0);
	LCD_write_chi(0,2,12,7,0,0);
	LCD_write_chi(0,4,12,7,0,0);	
-----------------------------------------------------------------------*/                        
void NOKIA5110::write_chinese_string(unsigned char X, unsigned char Y, 
                   unsigned char ch_with,unsigned char num,
                   unsigned char line,unsigned char row)
  {
    unsigned char i,n;
    
    set_xy(X,Y);                             //设置初始位置
    
    for (i=0;i<num;)
      {
      	for (n=0; n<ch_with*2; n++)              //写一个汉字
      	  { 
      	    if (n==ch_with)                      //写汉字的下半部分
      	      {
      	        if (i==0) set_xy(X,Y+1);
      	        else
      	           set_xy((X+(ch_with+row)*i),Y+1);
              }
      	    write_data(write_chinese[line+i][n]);
      	  }
      	i++;
      	set_xy((X+(ch_with+row)*i),Y);
      }
  }
Exemple #22
0
/***********************************************************
*   函数名称:
*   功能描述:显示BMP图片128×64起始点坐标(x,y),
*   参数列表:x的范围0~127,y为页的范围0~7
*   返回结果:
*   备    注:
***********************************************************/
void OLED_SSD1306::draw_bmp(u16 x0, u16 y0, u16 x1, u16 y1, const unsigned char BMP[])
{
    unsigned int j = 0;
    unsigned char x, y;

    if(y1 % 8 == 0) y = y1 / 8;
    else y = y1 / 8 + 1;
    for(y = y0; y < y1; y++)
    {
        set_xy(x0, y);
        for(x = x0; x < x1; x++)
        {
            write_data(BMP[j++]);
        }
    }
}
Exemple #23
0
void
QtUtil :: Grid3DView :: contextMenuEvent (QContextMenuEvent * e)
{
	QMenu m;

	QMenu set_plane (tr ("Plane"));
	{
		set_plane .addAction (tr ("XY (Front)"), this, SLOT (set_xy()));
		set_plane .addAction (tr ("XZ (Top)"),   this, SLOT (set_xz()));
		set_plane .addAction (tr ("YZ (Side)"),  this, SLOT (set_yz()));
	}
	
	m .addMenu (& set_plane);

	m .exec (mapToGlobal (e -> pos ()));
}
Exemple #24
0
void __panic(struct x86_registers regs, const char *func, const char *file, int line,  const char *fmt, ...)
{
    char buffer[BSIZE];
    const char *panic_str = CONFIG_PANIC_STRING; 
    size_t panic_str_len = strlen(panic_str);
    size_t buf_len = 0;
    va_list ap;
    int x, y, i, j;
    union x86_regs_u r;
    r.s_reg = regs;
    va_start(ap, fmt);
    /* Move the formatted message to the buffer[] */
    buf_len = vsnprintf(buffer, BSIZE, fmt, ap);
    va_end(ap);
    
    /* Set the console color to white on red (Red Screen of Death :) */
    set_console_attributes(BG_COLOR_RED | FG_COLOR_WHITE);
    clear_console(); 
    /* Write the 'AKOSIX KERNEL PANIC' or other 
                                 user-defined panic string centered */
    kxya_print(CENTERED(panic_str_len), 1, BG_COLOR_BLACK 
                    | LIGHT | FG_COLOR_WHITE | BLINK, panic_str); 

    /* The message with more ligher white, also centered */
    kxya_print(CENTERED(buf_len), 3, BG_COLOR_RED|LIGHT|FG_COLOR_WHITE, buffer);

    set_xy(0, 5);
    /* Register dump */
    for (i = 0; i <= X86_REG_EDI; i++) {
        kprintf("\t%s: %d [%x]\n", x86_register_name[i], r.a_reg[i], r.a_reg[i]);
    }
    kprintf("\n");
    /* Segment registers are 16 bit long. Split the 32 bit array 
      elements to high and low variables to overcome this. */
    for (j = i = X86_REG_SS; i <= X86_REG_GS-1; i++, j++) {
        uint16_t high, low;
        high = r.a_reg[j] & 0x0000FFFF;
        low = r.a_reg[j]  & 0xFFFF0000;
        kprintf("\t%s: %d [%x]\n", x86_register_name[i], high, high);
        kprintf("\t%s: %d [%x]\n", x86_register_name[++i], low, low);
    }
    
    // __backtrace(CONFIG_CONSOLE_WIDTH-LINE_LEN+5, 5, 5);
    /* Location of the panic file:function():line */
    kxy_printf(0, CONSOLE_LAST_ROW, "%s:%s():%d", file, func, line);
    hang();
}
Exemple #25
0
/**
 * \brief Computes the position of the object controlled by this movement.
 *
 * This function should be called whenever the angle, the radius or the center changes.
 */
void CircleMovement::recompute_position() {

  Point center = this->center_point;
  if (center_entity != nullptr) {
    center += center_entity->get_xy();
  }

  Point xy = Geometry::get_xy(center, Geometry::degrees_to_radians(current_angle), current_radius);
  if (get_entity() == nullptr
      || !test_collision_with_obstacles(xy - get_entity()->get_xy())) {
    set_xy(xy);
    notify_position_changed();
  }
  else {
    notify_obstacle_reached();
  }
}
Exemple #26
0
/**
 * @brief Computes the position of the object controlled by this movement.
 *
 * This function should be called whenever the angle, the radius or the center changes.
 */
void CircleMovement::recompute_position() {

  Rectangle center = this->center_point;
  if (center_entity != NULL) {
    center.add_xy(center_entity->get_xy());
  }

  const Rectangle &xy = Geometry::get_xy(center, Geometry::degrees_to_radians(current_angle), current_radius);
  if (get_entity() == NULL
      || !test_collision_with_obstacles(xy.get_x() - get_entity()->get_x(), xy.get_y() - get_entity()->get_y())) {
    set_xy(xy);
    notify_position_changed();
  }
  else {
    notify_obstacle_reached();
  }
}
Exemple #27
0
/**
 * \brief This function is called when a conveyor belt detects a collision with this entity.
 * \param conveyor_belt a conveyor belt
 * \param dx direction of the x move in pixels (0, 1 or -1)
 * \param dy direction of the y move in pixels (0, 1 or -1)
 */
void Bomb::notify_collision_with_conveyor_belt(ConveyorBelt& conveyor_belt, int dx, int dy) {

  if (get_movement() == NULL) {

    // check that a significant part of the bomb is on the conveyor belt
    Rectangle center = get_center_point();
    center.add_xy(-1, -1);
    center.set_size(2, 2);

    if (conveyor_belt.overlaps(center)) {
      set_xy(conveyor_belt.get_xy());

      std::string path = "  ";
      path[0] = path[1] = '0' + conveyor_belt.get_direction();
      clear_movement();
      set_movement(new PathMovement(path, 64, false, false, false));
    }
  }
}
Exemple #28
0
/**
 * @brief Updates the movement.
 */
void TargetMovement::update() {

  if (System::now() >= next_recomputation_date) {
    recompute_movement();
    next_recomputation_date += recomputation_delay;
  }

  // see if the target is reached
  int dx = target_x - get_x();
  int dy = target_y - get_y();
  if (dx * sign_x <= 0 && dy * sign_y <= 0) {
    if (!test_collision_with_obstacles(dx, dy)) {
      set_xy(target_x, target_y); // because the target movement may have not been very precise
      stop();
      finished = true;
    }
  }

  StraightMovement::update();
}
Exemple #29
0
/*-----------------------------------------------------------------------
LCD_draw_map      : 位图绘制函数

输入参数:X、Y    :位图绘制的起始X、Y坐标;
          *map    :位图点阵数据;
          Pix_x   :位图像素(长)
          Pix_y   :位图像素(宽)
-----------------------------------------------------------------------*/
void NOKIA5110::draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
                  unsigned char Pix_x,unsigned char Pix_y)
  {
    unsigned int i,n;
    unsigned char row;
    
    if (Pix_y%8==0) row=Pix_y/8;      //计算位图所占行数
      else
        row=Pix_y/8+1;
    
    for (n=0;n<row;n++)
      {
      	set_xy(X,Y);
        for(i=0; i<Pix_x; i++)
          {
            write_data(map[i+n*Pix_x]);
          }
        Y++;                         //换行
      }      
  }
Exemple #30
0
/***********************************************************
*   函数名称:
*   功能描述:   OLED_SSD1306初始化
*   参数列表:
*   返回结果:
*   备    注:
***********************************************************/
void OLED_SSD1306::init(void)
{
    res_pin->set();
    delay_ms(100);
    res_pin->reset();
    delay_ms(100);
    res_pin->set();

    write_cmd(0xae);//--turn off oled panel
    write_cmd(0x00);//---set low column address
    write_cmd(0x10);//---set high column address
    write_cmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
    write_cmd(0x81);//--set contrast control register
    write_cmd(0xcf); // Set SEG Output Current Brightness
    write_cmd(0xa1);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
    write_cmd(0xc8);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
    write_cmd(0xa6);//--set normal display
    write_cmd(0xa8);//--set multiplex ratio(1 to 64)
    write_cmd(0x3f);//--1/64 duty
    write_cmd(0xd3);//-set display offset	Shift Mapping RAM Counter (0x00~0x3F)
    write_cmd(0x00);//-not offset
    write_cmd(0xd5);//--set display clock divide ratio/oscillator frequency
    write_cmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
    write_cmd(0xd9);//--set pre-charge period
    write_cmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
    write_cmd(0xda);//--set com pins hardware configuration
    write_cmd(0x12);
    write_cmd(0xdb);//--set vcomh
    write_cmd(0x40);//Set VCOM Deselect Level
    write_cmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
    write_cmd(0x02);//
    write_cmd(0x8d);//--set Charge Pump enable/disable
    write_cmd(0x14);//--set(0x10) disable
    write_cmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
    write_cmd(0xa6);// Disable Inverse Display On (0xa6/a7)
    write_cmd(0xaf);//--turn on oled panel

    write_cmd(0xaf);	/*display ON*/
    clear();
    set_xy(0, 0);
}