Esempio n. 1
0
void search(int x, int y, int d, int step)
{
    map[x][y] = 2;
    ans = step > ans ? step : ans;

    int dx = x + dir[d][0], dy = y + dir[d][1];
    if (dx < 0 || dx >= n) {
        move_y(x, y, step);

        map[x][y] = 0;
        return ;
    }
    if (dy < 0 || dy >= n) {
        move_x(x, y, step);

        map[x][y] = 0;
        return ;
    }

    if(map[dx][dy] == 1) {
        if (d == 0 || d == 2) move_y(x, y, step);
        else move_x(x, y, step);

        map[x][y] = 0;
        return ;
    }
    if (map[dx][dy] == 2) {
        map[x][y] = 0;
        return ;
    }

    search(dx, dy, d, step + 1);

    map[x][y] = 0;
}
Esempio n. 2
0
	void doRender()
	{
		printf("move_y=%d\r\n", move_y());
		if (vertical > 2)
		image::Render(&dark, 0, posy - move_y() - bright_ture_y, width, vertical / 2 * node_h, 0, 0);
		image::Render(&bright, bright_ture_x, posy - move_y(), bright_ture_w, bright_ture_h, bright_ture_x, bright_ture_y);
		image::Render(&dark, 0, posy - move_y() + bright_ture_h, width, vertical / 2 * node_h, bright_ture_x,
				bright_ture_y + bright_ture_h);
	}
Esempio n. 3
0
  void Roll::update(Spirit& spirit,
		    const stage::Zone& zone,
		    const enemy::EnemyVec& enemies,
		    const prop::PropVec& props)
  {
    if (spirit.orientation.h == common::Horizontal::LEFT) {
      spirit.force.add_x(-values[ctr.value()]);
      
    } else if (spirit.orientation.h == common::Horizontal::RIGHT) {
      spirit.force.add_x(values[ctr.value()]);
    }

    move_x(zone, props, spirit);

    move_y(zone, props, spirit);
  
    if (!check_ground(zone, props, spirit)) {
      if (spirit.orientation.h == common::Horizontal::LEFT) {
	spirit.force.set_vx(-speed);
	
      } else if (spirit.orientation.h == common::Horizontal::RIGHT) {
	spirit.force.set_vx(speed);
      }

      if (spirit.link != nullptr) {
	// Prevent stickiness when attached to a prop.
	spirit.mass.update_y(-1);
      }
      spirit.motion_flag.set(static_cast<int>(MotionState::FALL));
      
    } else if(spirit.controller->is_pressed(input::Glyph::A)) {
      spirit.force.reset();
      spirit.motion_flag.set(static_cast<int>(MotionState::JUMP));
      
    } else if (ctr.update()) {
      spirit.force.reset();
      
      if(spirit.controller->is_pressed(input::Glyph::A)) {
	spirit.motion_flag.set(static_cast<int>(MotionState::JUMP));
	
      } else if (spirit.controller->is_on(input::Glyph::LEFT) ||
		 spirit.controller->is_on(input::Glyph::RIGHT)) {
	spirit.motion_flag.set(static_cast<int>(MotionState::WALK));
	
      } else {
	spirit.motion_flag.set(static_cast<int>(MotionState::IDLE));
      }
    }
  }
Esempio n. 4
0
	void doTouchUp()
	{
		posy -= move_y();
		if (posy < dark.pos1)
		{
			posy = dark.pos2 - (dark.pos1 - posy);
			//printf("F to pos1 %d!!!!!\r\n",posy);
		}
		if (posy > dark.pos2)
		{
			posy = dark.pos1 + (posy - dark.pos2);
			//printf("F to pos2 %d!!!!!\r\n",posy);
		}
		posy = (posy + node_h / 2) / node_h * node_h;
		index = (posy - dark.pos1) / node_h;
		printf("index=%d\r\n", index);

		Flush();
	}
Esempio n. 5
0
void move_home() {
    Slp_1_Write(1);
    Slp_2_Write(1);
    
    uint8 x = Lim_1_Read(), y = Lim_2_Read();
    
    while(!x || !y) {    
        if(!y){
            Dir_1_Write(1);
            Dir_2_Write(1);
            
            Stp_1_Write(0);
            Stp_1_Write(1);
            Stp_2_Write(0);
            Stp_2_Write(1);
            CyDelay(10);
        }      
        else if(!x){
            Dir_1_Write(0);
            Dir_2_Write(1);
            
            Stp_1_Write(0);
            Stp_1_Write(1);
            Stp_2_Write(0);
            Stp_2_Write(1);
            CyDelay(10);
        }
        x = Lim_1_Read();
        y = Lim_2_Read();
    }
    Slp_1_Write(0);
    Slp_2_Write(0);
    
    x_pos = 0;
    y_pos = 0;
    
    col_square = 11;
    row_square = 0;
    
    move_x(35);
    move_y(15);
}
Esempio n. 6
0
  void Cling::update(Spirit& spirit,
			  const stage::Zone& zone,
			  const enemy::EnemyVec& enemies,
			  const prop::PropVec& props)
  {
    bool x_collision = false;
    if (spirit.controller->is_on(input::Glyph::LEFT)) {
      spirit.orientation.h = common::Horizontal::LEFT;
      x_collision = spirit.mass.is_sidled_left(zone);
      
    } else if (spirit.controller->is_on(input::Glyph::RIGHT)) {
      spirit.orientation.h = common::Horizontal::RIGHT;
      x_collision = spirit.mass.is_sidled_right(zone);
    }

    spirit.mass.update_x(0);

    if (!x_collision) {
      ctr++;
    }

    // TODO : do not add like this
    spirit.force.add_y(-0.5);

    bool collision = move_y(zone, props, spirit);

    if (collision) {
      spirit.motion_flag.set(static_cast<int>(MotionState::IDLE));
      
    } else if (!spirit.mass.is_sidled(zone)) {
      spirit.motion_flag.set(static_cast<int>(MotionState::FALL));
      
    } else if (ctr >= 10) {
      spirit.motion_flag.set(static_cast<int>(MotionState::FALL));
    }
  }
Esempio n. 7
0
	void doRender()
	{
		image::Render(&img, move_x(), move_y());
	}
Esempio n. 8
0
File: textbox.c Progetto: rodan/ampy
static void on_handle_key(int key)
{
	switch (key) {
	case 10:
	case 13:
	case 27:
	case KEY_CANCEL:
	case KEY_ENTER:
	case KEY_CLOSE:
	case KEY_EXIT:
		text_widget.close();
		break;
	case KEY_DOWN:
	case KEY_SF:
	case 'J':
	case 'j':
	case 'X':
	case 'x':
		move_y(1);
		break;
	case KEY_UP:
	case KEY_SR:
	case 'K':
	case 'k':
	case 'W':
	case 'w':
		move_y(-1);
		break;
	case KEY_LEFT:
	case 'H':
	case 'h':
	case 'P':
	case 'p':
		move_x(-1);
		break;
	case KEY_RIGHT:
	case 'L':
	case 'l':
	case 'N':
	case 'n':
		move_x(1);
		break;
	case KEY_NPAGE:
	case ' ':
		move_y(text_box_y);
		break;
	case KEY_PPAGE:
	case KEY_BACKSPACE:
	case 'B':
	case 'b':
		move_y(-text_box_y);
		break;
	case KEY_HOME:
	case KEY_BEG:
		move_x(-max_scroll_x);
		break;
	case KEY_LL:
	case KEY_END:
		move_x(max_scroll_x);
		break;
	case '\t':
		move_x(8);
		break;
	case KEY_BTAB:
		move_x(-8);
		break;
	}
}
Esempio n. 9
0
void movepiece(struct movement move) {
    
    moveRow(row_square - move.fromRow);
    moveCol(col_square - move.fromCol);
    
    row_square = move.toRow;
    col_square = move.toCol;
    
    CyDelay(5000);

    Em_Write(1);
    
    int rowdis = move.fromRow - move.toRow;
    int coldis = move.fromCol - move.toCol;
    
    //diagnal movement if clear path
    if (abs(rowdis) == abs(coldis)) {
        int temp = 0;
        for(int i = 1; i <= abs(coldis); i++) {
            if (board[move.fromRow + i * rowdis / abs(coldis)][move.fromCol + i * coldis / abs(coldis)] != 0) temp++;
        }
        if (temp == 0) {
            for(int i = 0; i < abs(coldis) * 51; i++) {
                move_x(coldis / abs(coldis));
                move_y(rowdis / abs(rowdis) * -1);
            }
        }
        return;
    }

    //col movement if clear path
    if (rowdis == 0) {
        int temp = 0;
        for(int i = 1; i <= abs(coldis); i++) {
            if (board[move.fromRow][move.fromCol + i * coldis / abs(coldis)] != 0) temp++;
        }
        moveCol(coldis);
        return;
    }

    //row movement if clear path
    if (coldis == 0) {
        int temp = 0;
        for(int i = 1; i <= abs(rowdis); i++) {
            if (board[move.fromRow + i * rowdis / abs(rowdis)][move.fromCol] != 0) temp++;
        }
        moveRow(rowdis);
        return;
    }

    //up or down indicator for end adjustment, where down is 1 and up -1
    //left or right indicator for end adjustment, where left is -1 and right is 1       
    int uod = 0, lor = 0;

    //determines the best path between spaces for cols

    if (move.fromCol < move.toCol) {
        lor = 1;
    } else if (move.fromCol > move.toCol) {
        lor = -1;
    } else if (move.fromCol < 6) {
        lor = 1;
    } else {
        lor = -1;
    }
    moveColHalf(lor * -1);

    //determines the best path between spaces for rows
    if (move.fromRow > move.toRow) {
        uod = -1;
    } else if (move.fromRow < move.toRow) {
        uod = 1;
    } else if (move.toRow < 4) {
        uod = -1;
    } else {
        uod = 1;
    }

    //moves across the rows with the adjustment
    if (rowdis == 0) {
        moveRowHalf(uod);
    } else if (rowdis > 0) {
        moveRowHalf(rowdis / abs(rowdis) * (rowdis * 2 - uod * -1));
    } else {
        moveRowHalf(rowdis / abs(rowdis) * (abs(rowdis) * 2 - uod));
    }
    //moves across the rows
    if (coldis == 0) {
        moveColHalf(lor);
    } else if (coldis > 0) {
        moveColHalf(coldis / abs(coldis) * (coldis * 2 - lor * -1));
    } else {
        moveColHalf(coldis / abs(coldis) * (abs(coldis) * 2 - lor));
    }

    //moves row adjustment
    moveRowHalf(-1 * uod);
    
    Em_Write(0);
    
}
Esempio n. 10
0
void moveRowHalf(int dis) {
    move_y(25 * dis * -1);
}
Esempio n. 11
0
void moveRow(int dis) {
    move_y(50 * dis * -1);
}
void main(void) {
     
   int8 recibe[5];                  //declaramos variables
   int8 send2[1];

   LED_OFF(LED_OK);                   //encendemos led rojo
   LED_ON(LED_FAIL);
            
   usb_init();                      //inicializamos el USB  
   
   setup_adc_ports(AN0);         //Configura canais analógico
   setup_adc(ADC_CLOCK_INTERNAL);    //De acordo com relógio interno.
   
   /*SETUP_TIMER_1 (T1_INTERNAL|T1_DIV_BY_2);       //Configurar timer1 para clock iterno/8
   enable_interrupts (INT_TIMER1);                //Habilitar Interrupções
   enable_interrupts (global);*/

   usb_task();                      //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host
   
   enable_interrupts (global);

   LED_OFF(LED_FAIL);                 //desligo o LED vermelho
   LED_ON(LED_OK);                    //acendo o LED verde
   
   move_x('S');
   move_y('S');
         
   while (true)
   {
      if(usb_enumerated())          //si el PicUSB está configurado
      {  
         if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
         {            
            LED_ON(LED_DATA);
            usb_get_packet(1, recibe, 5); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe            
            
            if(modo == 1)
            {               
                  if(dir_x == 1 && value_x == 1){
                     move_x('R');
                  }
                  if(dir_x == 2 && value_x == 1){
                     move_x('L');
                  }                  
                  if(dir_y == 1 && value_y == 1){
                     move_y('F');
                  }
                  if(dir_y == 2 && value_y == 1){
                     move_y('B');
                  }
                  
                  delay_ms(20);               
            }
            
            if (modo == 4)
            {
               status = 1;
               usb_put_packet(1, send2, 1, USB_DTS_TOGGLE); //enviada a informação para o PC com o status
            }    
            LED_OFF(LED_DATA);
         }
      }
   }
}