Exemplo n.º 1
0
void update_screen(UART_instance_t * this_uart, int deg, float kp, float ki, float kd, float digit, k_value_t k_value)
{
	// Print the pendulum
	print_degrees(this_uart, deg);

	// Print the constants
	set_x(this_uart, 32);
	set_y(this_uart, 16);
	delay();
	char buffer[64];
	sprintf(buffer, "%07.3f\r\n%07.3f\r\n%07.3f", kp, ki, kd);
	UART_polled_tx_string( this_uart, (const uint8_t *)&buffer);

	// Clear the digit block
	erase_block(this_uart, 112, 16, 159, 56);

	// Print the digit increment/decrement
	set_x(this_uart, 112);
	delay();
	char digit_buffer[16];
	sprintf(digit_buffer, "%07.3f", digit);
	if (k_value == KP)
	{
		set_y(this_uart, 16);
	} else if (k_value == KI) {
		set_y(this_uart, 24);
	} else {
		set_y(this_uart, 32);
	}
	UART_polled_tx_string( this_uart, (const uint8_t *)&digit_buffer);
}
Exemplo n.º 2
0
void SceneGraph::link(TransformInstance child, TransformInstance parent)
{
	unlink(child);

	if (!is_valid(_data.first_child[parent.i]))
	{
		_data.first_child[parent.i] = child;
		_data.parent[child.i] = parent;
	}
	else
	{
		TransformInstance prev = { UINT32_MAX };
		TransformInstance node = _data.first_child[parent.i];
		while (is_valid(node))
		{
			prev = node;
			node = _data.next_sibling[node.i];
		}

		_data.next_sibling[prev.i] = child;

		_data.first_child[child.i].i = UINT32_MAX;
		_data.next_sibling[child.i].i = UINT32_MAX;
		_data.prev_sibling[child.i] = prev;
	}

	Matrix4x4 parent_tr = _data.world[parent.i];
	Matrix4x4 child_tr = _data.world[child.i];
	const Vector3 cs = scale(child_tr);

	Vector3 px = x(parent_tr);
	Vector3 py = y(parent_tr);
	Vector3 pz = z(parent_tr);
	Vector3 cx = x(child_tr);
	Vector3 cy = y(child_tr);
	Vector3 cz = z(child_tr);

	set_x(parent_tr, normalize(px));
	set_y(parent_tr, normalize(py));
	set_z(parent_tr, normalize(pz));
	set_x(child_tr, normalize(cx));
	set_y(child_tr, normalize(cy));
	set_z(child_tr, normalize(cz));

	const Matrix4x4 rel_tr = child_tr * get_inverted(parent_tr);

	_data.local[child.i].position = translation(rel_tr);
	_data.local[child.i].rotation = to_matrix3x3(rel_tr);
	_data.local[child.i].scale = cs;
	_data.parent[child.i] = parent;

	transform(parent_tr, child);
}
Exemplo n.º 3
0
void setup_screen(UART_instance_t * this_uart)
{
	set_x(this_uart, 128);
	set_y(this_uart, 8);
	delay();
	uint8_t header_buff[] = {"+/-\0"};
	UART_polled_tx_string( this_uart,(const uint8_t *)&header_buff);

	set_x(this_uart, 8);
	set_y(this_uart, 16);
	delay();
	uint8_t label_buff[] = {"Kp: \r\nKi: \r\nKd: \0"};
	UART_polled_tx_string( this_uart,(const uint8_t *)&label_buff);
}
Exemplo n.º 4
0
void placerBateaux(JOU joueur){
	int tailles_bateaux[5]={1,2,3,3,4};
	int i=0;
	for(i=0;i<5;i++){
		BAT bateau=creerBateau(tailles_bateaux[i]);
		int n_position=0;
		for(n_position=0;n_position<tailles_bateaux[i];n_position++){
				int abscisse=0;
				int ordonnee=0;
				printf("Entrez l'abscisse de la position %d du bateau %d:\n",i+1,n_position+1);
				scanf("%d",&abscisse);
				printf("Entrez l'abscisse de la position %d du bateau %d:\n",i+1,n_position+1);
				scanf("%d",&abscisse);
				POS position=creerPosition(abscisse, ordonnee);
				while(!coordonneeValide(position)){
					printf("Coordonnees invalide...");
					printf("Entrez l'abscisse de la position %d du bateau %d:\n",i+1,n_position+1);
					scanf("%d",&abscisse);
					printf("Entrez l'ordonnee de la position %d du bateau %d:\n",i+1,n_position+1);
					scanf("%d",&ordonnee);
					set_x(position,abscisse);
					set_y(position,ordonnee);
				}/*end while*/
				ajouterPosition(bateau,position);
		}/*end for*/
	ajouterBateau(joueur,bateau);
	}/*end for*/
}
Exemplo n.º 5
0
// Movimiento de la partida de caza hacia el patch destino
int move_hunters ()
{
	int x = get_x(), y = get_y(), guanacos;

	// Si estoy cazando no me muevo del patch
	if (get_start() == 1)
		return 0;

	// Change the patch
	// Avanzar en x
	if (x != DESTINY[0])
		x = (x>DESTINY[0]) ? x-1:x+1;
	// Avanzar en y
	else if (y != DESTINY[1])
		y = (y>DESTINY[1]) ? y-1:y+1;
	// Llegada al objetivo
	else
		set_arrive(1);
	// Asks guanacos number to the new patch
	add_numGuanacos_message (x,y);
/*	// Recive num of guanacos
	START_INFOGUANACOS_MESSAGE_LOOP
		guanacos = infoGuanacos_message->amount;
	FINISH_INFOGUANACOS_MESSAGE_LOOP
	// si hay guanacos comenzar la caza
	if (guanacos > 0)
		set_start(1);
	// Sino y se ha llegado al destino, acabar la caza
	else if (get_arrive() == 1 )
		set_end(1);*/
	set_x(x);
	set_y(y);
	printf("movido\n");
	return 0;
}
Exemplo n.º 6
0
 // reset vector from rectangular coordinates if form is
 // RECT (the default) or else from polar coordinates if
 // form is POL
 void Vector:: reset(double n1, double n2, Mode form)
 {
     mode = form;
     if (form == RECT)
      {
          x = n1;
          y = n2;
          //set_mag();
          //set_ang();
     }
     else if (form == POL)
     {
          double mag = n1;
          double ang = n2 / Rad_to_deg;
          set_x(mag,ang);
          set_y(mag,ang);
     }
     else
     {
          cout << "Incorrect 3rd argument to Vector() -- ";
          cout << "vector set to 0\n";
          x = y = 0.0;
          mode = RECT;
     }
 }
Exemplo n.º 7
0
void ObjectManager::create_ships(PlayerState& player_state)
{
    for (int i = 1; i <= NUM_OF_POSSIBLE_PLAYERS; i++) {
        if (player_state.energy_max(i)) {

            std::string name = "Player " + std::to_string(i);

            int s = player_state.score(i);
            int e = player_state.energy_max(i);
            player_state.set_energy(i, e);  // reset energy to max

            ObjIndex player_index = Object::parse_player_index(i);
            sdlc::Surface& gfx = obj[player_index];
            sdlc::Surface& hit_gfx = obj_hit[player_index];

            auto w1 = create_main_weapon(i, player_state);
            auto w2 = create_extra_weapon(i, player_state);

            KeySet keyset(i);   // For now we don't set custom keys

            auto new_ship = std::make_shared<Ship>(name, e, s, gfx, hit_gfx, w1, w2, keyset);

            new_ship->set_locked_to_screen(false);
            new_ship->set_x((float)(213 * i - new_ship->width()));
            new_ship->set_y(480);
            new_ship->set_vel(0, -200.0f);
            queue.push_back(new_ship);
        }
    }
}
Exemplo n.º 8
0
Surface& Surface::operator=(const Surface& rSurf)
{
    _pMaterialNext=0;
    _pMaterialPrev=0;

    set_type(rSurf.type());
    set_conic(rSurf.conic());
    set_radius_curvature(rSurf.radius_curvature());

    set_R4(rSurf.R4());
    set_R6(rSurf.R6());
    set_R8(rSurf.R8());
    set_R10(rSurf.R10());

    set_comment(rSurf.comment());

    set_x(rSurf.x());
    set_y(rSurf.y());
    set_z(rSurf.z());

    set_diameter(rSurf.diameter());
    set_auto_diameter(rSurf.get_auto_diameter());

    set_inner_diameter(rSurf.inner_diameter());
    set_auto_inner_diameter(rSurf.get_auto_inner_diameter());

    return *this;
}
Exemplo n.º 9
0
	void Vector::set(double n1, double n2, char form)
	{
		mode = form;
		if ( form == 'r')
		{
			x = n1;
			y = n2;
			set_mag();
			set_ang();
		}
		else if (form = 'p')
		{
			mag = n1;
			ang = n2 / Rad_to_deg;
			set_x();
			set_y();
		}
		else
		{
			cout << "Incorrect form\n";
			cout << "vector set to 0\n";
			x = y = mag = ang = 0.0;
			mode = 'r';
		}
	}
Exemplo n.º 10
0
// construct vector from rectangular coordinates if form is r
// (the default) or else from polar coordinates if form is p
Vector::Vector(double n1, double n2, Mode form)
{
    mode = form;
    if (form == RECT)
    {
        x = n1;
        y = n2;
        set_mag();
        set_ang();
    }
    else if (form == POL)
    {
        mag = n1;
        ang = n2 / Rad_to_deg;
        set_x();
        set_y();
    }
    else
    {
        cout << "Incorrect 3rd argument to Vector() -- ";
        cout << "vector set to 0\n";
        x = y = mag = ang = 0.0;
        mode = RECT;
    }
}
Exemplo n.º 11
0
/**
 * \brief Throws the item.
 * \param direction direction where the hero throws the item (0 to 3)
 */
void CarriedItem::throw_item(int direction) {

  this->throwing_direction = direction;
  this->is_lifting = false;
  this->is_throwing = true;

  // play the sound
  Sound::play("throw");

  // stop the sprite animation
  Sprite& sprite = get_sprite();
  sprite.set_current_animation("stopped");

  // set the movement of the item sprite
  set_y(hero.get_y());
  std::shared_ptr<StraightMovement> movement =
      std::make_shared<StraightMovement>(false, false);
  movement->set_speed(200);
  movement->set_angle(Geometry::degrees_to_radians(direction * 90));
  clear_movement();
  set_movement(movement);

  this->y_increment = -2;
  this->next_down_date = System::now() + 40;
  this->item_height = 18;
}
Exemplo n.º 12
0
/**
 * \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;
}
Exemplo n.º 13
0
void BolsaDinero::hit(Actor *who, int damage)
{
	switch (who->get_team())
	{
	    case TEAM_OSO:
	    	am->del(this);
	    	break;
	    case TEAM_COMIDA:
	    case TEAM_AGUA:
	    case TEAM_VENENO:
	    case TEAM_HORMIGAS_ROJAS:
		case TEAM_HORMIGAS_VERDES:
		case TEAM_RANA:
		case TEAM_SCORE:
		case TEAM_BOLSA_DINERO:
		case TEAM_HORMIGUERO:
			set_x(Game::rnd(0,Game::gfx_w-get_w()));
            set_y(Game::rnd(0,Game::gfx_h-get_h()));
		  	break;

		default:
			break;
	}

}
Exemplo n.º 14
0
bool GuiWindow::mousemove(int x, int y) {
    if (mouse_is_down && moving_valid) {
        set_x(x - distance_x);
        set_y(y - distance_y);
    }

    return true;
}
Exemplo n.º 15
0
vector::Vector::Vector(double n1, double n2, Mode form)
{
	Vector::mode = form;
	if (form == RECT) {
		set_x(n1);
		set_y(n2);
	} else if (form == POL) {
		int x_ = n1 * cos (n2);
		int y_ = n1 * sin (n2);
		set_x(x_);
		set_y(y_);
	} else {
		std::cout << "Incorrect 3d arg param" << std::endl;
		vector::Vector();
	}

}
Exemplo n.º 16
0
void Particle::update(const Timer& timer)
{
    // Update position
    set_x(x() + (x_vel()  * timer.frame_time()));
    set_y(y() + (y_vel()  * timer.frame_time()));

    // Update alpha
    set_alpha(alpha() - (fade_speed() * timer.frame_time()));
}
Exemplo n.º 17
0
void TMaps::SerialiseRespPoints(Epsilon5::World& world) {
    for (auto i = RespPoints.begin(); i != RespPoints.end(); i++) {
        auto point = world.add_resp_points();
        point->set_x(i->X);
        point->set_y(i->Y);
        point->set_is_main(i->IsMain);
        point->set_team(i->Team);
    }
}
Exemplo n.º 18
0
void CreateBuildingCommand::setParams()
{
    auto request = m_requestMessage->MutableExtension(CreateBuildingRequest::id);
    
    request->set_instanceid(m_instanceId);
    request->set_buildingid(m_buildingId);
    request->set_x(m_x);
    request->set_y(m_y);
}
Exemplo n.º 19
0
circle::circle(pos p, double radius, double radiussize, gradient grad, int bt)
    : shape(bt), gradient_(grad)
{
    set_x(p.get_x());
    set_y(p.get_y());
    set_z(p.get_z());
    set_radius(radius);
    set_radiussize(radiussize);
}
Exemplo n.º 20
0
Paleta::Paleta (Almacen &almacen)
{
  piel = new Suelo (this, almacen, 2);
  set_actor_graphic (piel);
  setCodigo (Nombres::paleta);
  set_x (0);
  set_y (SCREEN_H - 70);
  set_is_detected (true);
  set_collision_method (CollisionManager::PP_COLLISION);
};
Exemplo n.º 21
0
Loro::Loro (Almacen &almacen):
ControllableActor (),
kboard (new Keyboard())
{
    // ¡Cuidado! Esto falla si en el almacén no existe el bitmap que se pide.
    // Animación de la derecha.
    izquierda = new Sprite(this);
    izquierda->add_frame(almacen.get_bitmap("sprite_042"), 0, 13, 10);
    izquierda->add_frame(almacen.get_bitmap("sprite_043"), 0,  0, 10);
    izquierda->add_frame(almacen.get_bitmap("sprite_044"), 0,  3, 10);
    izquierda->setMirror(true);

    // Animación de la izquierda.
    derecha = new Sprite(this);
    derecha->add_frame(almacen.get_bitmap("sprite_042"), 0, 13, 10);
    derecha->add_frame(almacen.get_bitmap("sprite_043"), 0,  0, 10);
    derecha->add_frame(almacen.get_bitmap("sprite_044"), 0,  3, 10);
    derecha->setMirror(false);

    // Animación de giro.
    giro_der = new Sprite(this);
    giro_der->add_frame(almacen.get_bitmap("pre2_338"), 10, 0, 5);
    giro_der->setMirror (true);

    giro_izq = new Sprite(this);
    giro_izq->add_frame(almacen.get_bitmap("pre2_338"), 10, 0, 5);
    giro_izq->setMirror (false);

    setCodigo (Nombres::herny);
    set_x(SCREEN_W/2);
    set_y(SCREEN_H/2);
    set_is_detected (true);
    set_collision_method(CollisionManager::PP_COLLISION);
    set_wh (36,26);

    // Animación de inicio.
    estado = FLOTANDO_DER;
    set_actor_graphic (derecha);

    // Se crea el control necesario para las acciones del loro.
    control = new Control ();
    control->add_action_name (LEFT,  "Izquierda");
    control->add_action_name (RIGHT, "Derecha");
    control->add_action_name (UP,    "Arriba");
    control->add_action_name (DOWN,  "Abajo");
    control->add_action_name (JUMP,  "Saltar");
    control->set_owner(this);

    // Se va a usar el teclado como único periférico para el loro.
    control->set_actionperipheral (UP,    kboard,  KEY_UP,    Peripheral::ON_PRESSING);
    control->set_actionperipheral (DOWN,  kboard,  KEY_DOWN,  Peripheral::ON_PRESSING);
    control->set_actionperipheral (LEFT,  kboard,  KEY_LEFT,  Peripheral::ON_PRESSING);
    control->set_actionperipheral (RIGHT, kboard,  KEY_RIGHT, Peripheral::ON_PRESSING);
    control->set_actionperipheral (JUMP,  kboard,  KEY_A,     Peripheral::ON_PRESS);
};
Exemplo n.º 22
0
void CVector::set_item(int iIndex, float fValue)
{
	if (iIndex == 0)
		return set_x(fValue);
	else if (iIndex == 1)
		return set_y(fValue);
	else if (iIndex == 2)
		return set_z(fValue);

	BOOST_RAISE_EXCEPTION(PyExc_IndexError, "Index out of range.")
}
Exemplo n.º 23
0
line::line(pos p, pos p2, double size, gradient grad, int blending_type)
    : shape(blending_type)
{
    set_x(p.get_x());
    set_y(p.get_y());
    set_z(p.get_z());
    set_x2(p2.get_x());
    set_y2(p2.get_y());
    set_z2(p2.get_z());
    set_size(size);
    set_gradient(grad);
}
Exemplo n.º 24
0
/**
 * \brief Updates the position.
 */
void FollowMovement::update() {

  if (entity_followed == NULL) {
    finished = true;
    return;
  }

  if (entity_followed->is_being_removed()) {
    finished = true;
    RefCountable::unref(entity_followed);
    entity_followed = NULL;
  }
  else {

    int next_x = entity_followed->get_x() + x;
    int next_y = entity_followed->get_y() + y;

    int dx = next_x - get_x();
    int dy = next_y - get_y();

    if (!are_obstacles_ignored()) {

      if (!finished && (dx != 0 || dy != 0)) {

        if (!test_collision_with_obstacles(dx, dy)) {
          set_x(next_x);
          set_y(next_y);
        }
        else {
          finished = true;
          notify_obstacle_reached();
        }
      }
    }
    else {
      set_x(next_x);
      set_y(next_y);
    }
  }
}
Exemplo n.º 25
0
void Point_3D::move(Point_3D* origin)
{
	//Mise à jour de l'abcisse
	set_x(get_x()-origin->get_x());
	//Mise à jour de l'ordonnée
	set_y(get_y()-origin->get_y());
	//Mise à jour de la profondeur
	set_z(get_z()-origin->get_z());
	//Mise à jour de l'abcisse d'origine
	dbl_x_origin-=origin->get_x();
	//Mise à jour de l'ordonnée d'origine
	dbl_y_origin-=origin->get_y();
	//Mise à jour de la profondeur d'origin
	dbl_z_origin-=origin->get_z();
}
Exemplo n.º 26
0
void Point_3D::scale(int coef)
{
	//Mise à jour de l'abcisse
	set_x(coef*get_x());
	//Mise à jour de l'ordonnée
	set_y(coef*get_y());
	//Mise à jour de la profondeur
	set_z(coef*get_z());
	//Mise à jour de l'abcisse d'origine
	dbl_x_origin=dbl_x_origin*coef;
	//Mise à jour de l'ordonnée d'origine
	dbl_y_origin=dbl_y_origin*coef;
	//Mise à jour de la profondeur d'origin
	dbl_z_origin=dbl_z_origin*coef;
}
Exemplo n.º 27
0
void vector::Vector::reset(double n1, double n2, Mode form)
{
	mode = form;
	if (form == RECT) {
		x = n1;
		y = n2;
	} else if (form == POL){
		int x_ = n1 * cos (n2);
		int y_ = n1 * sin (n2);
		set_x(x_);
		set_y(y_);
	} else {
		std::cout << "Incorrect 3d arg" << std::endl;
		x = y = 0.0;
		mode = RECT;
	}
}
GuiFPSWidget::GuiFPSWidget() : GuiContext(0,0)
{
    label = new GuiLabel(FontManager::font("small"),"100 FPS",0,0,1.0,true);
    background = new GuiColorRect(0,0,label->get_width()+10,label->get_height()+10);
    background->set_rgba(0.0,0.0,0.0,0.6);

    add(background);
    add(label);

    set_width(background->get_width());
    set_height(background->get_height());

    set_x(SCREEN_WIDTH/2-width/2);
    set_y(-SCREEN_HEIGHT/2+height/2);

    this->ticksTillUpdate = 0;
    this->className = "GuiFPSWidget";
}
Exemplo n.º 29
0
    Draw_Vector(double const x, double const y, double const z, double const ux, double const uy, double const uz)
    {
        set_x(x);
        set_y(y);
        set_z(z);

        set_ux(ux);
        set_uy(uy);
        set_uz(uz);

        set_arrow_len(5);
        set_arrow_angle(20);
        set_arrow_ratio(10);

        set_width(1);

        set_variable_len(false);

        set_color("BLACK");
    }
Exemplo n.º 30
0
void print_degrees(UART_instance_t * this_uart, int deg)
{
	static uint8_t old_x_pixel = 0;
	static uint8_t old_y_pixel = 0;

	if (old_x_pixel > 80) {
		erase_block(this_uart, 75, 127, old_x_pixel+5, old_y_pixel-5);
	}
	else if (old_x_pixel < 80) {
		erase_block(this_uart, 85, 127, old_x_pixel-5, old_y_pixel-5);
	}
	else {
		erase_block(this_uart, 75, 127, 85, old_y_pixel-10);
	}

	deg += 90.0;				//Convert to range 0 to 180 degrees

	//Set location of degree printout
	set_x(this_uart, 64);
	set_y(this_uart, 64);
	delay();

	//Convert int to char array
	char buffer[4];
	sprintf(buffer, "%03d", deg);

	//Print degrees
	UART_send( this_uart, (const uint8_t *)&buffer, sizeof(buffer) );

	//Get locations of x and y pixels for head of the pendulum
	uint8_t x_pixel = 80 - cos(deg * PI / 180) * 50;
	uint8_t y_pixel = 127 - sin(deg * PI / 180) * 50;

	//Draw pendulum
	draw_line(this_uart, 80, 127, x_pixel, y_pixel);
	draw_circle(this_uart, x_pixel, y_pixel, 5);

	old_x_pixel = x_pixel;
	old_y_pixel = y_pixel;
}