Personaje::Personaje(Mundo* mundo, Uint8 numero_jugador, char* nombre_client) { angulo_arma = 0; conectado = 1; arma_seleccionada =0; energia = ENERGIA_WORM; nombre_cliente = nombre_client; muerto = false; shape = NULL; radio = 0; dir_imagen = "TPTaller/imagenes/gusanitoderecha.png"; nro_jugador = numero_jugador; b2Vec2 escalas = mundo->GetEscalas(); alto = escalas.y / 50; ancho = escalas.x / 60; b2Vec2* vertices_tierra = mundo->GetVerticesTierra(); bool posicion_correcta = false; b2Vec2 posicion; //b2Vec2 aux=b2Vec2(10, 10); while (!posicion_correcta){ posicion.x+=10; //aux+=10; int indice = random( (mundo->GetCantVerticesTierra())); posicion = vertices_tierra[indice] - b2Vec2(0,alto/2); if (posicion.y < mundo->getAgua()->GetNivel()){ posicion_correcta=true; } } b2World* world = mundo->devolver_world(); b2BodyDef bodyDef = b2BodyDef(); // creo el body def bodyDef.position = posicion; // le asigno una posicion bodyDef.userData = this; // no se si funciona bien esto, bodyDef.type = b2_dynamicBody; body = world->CreateBody(&bodyDef); b2MassData massData = b2MassData(); massData.mass = 0.1; massData.center = b2Vec2(0, 0); massData.I = RECT_INERCIA_ROT; body->SetMassData(&massData); shape2 = new b2CircleShape(); shape2->m_radius = ancho/2; b2Filter filtro = b2Filter(); filtro.groupIndex = INDICE_GRUPO; b2FixtureDef fd; // creo un fixture fd.filter = filtro; fd.restitution = 0; fd.friction = 0.5; fd.shape = shape2; body->CreateFixture(&fd); // al body le pongo la fixture creada body->SetAwake(false); for (int i = 0 ; i<4; i++){ seleccionado[i] = false; } orientacion = 1; daniado_turno_actual = false; this->movio = 0; this->salto = 0; }
void CCollisionBox2D::_CreateFixture() { if(m_Body && !m_Fixture) { b2FixtureDef fixtureDef; b2PolygonShape shape; shape.SetAsBox((m_ScaleX * m_Width)/2.0f, (m_ScaleY * m_Height)/2.0f, b2Vec2(m_CenterX, m_CenterY), m_Rotation); fixtureDef.density = 1.0f; fixtureDef.filter = b2Filter(); fixtureDef.friction = 1.0f; fixtureDef.isSensor = true; fixtureDef.restitution = 0.0f; fixtureDef.shape = &shape; fixtureDef.userData = this; m_Fixture = m_Body->CreateFixture(&fixtureDef); } }