Skip to content

Commit

Permalink
ADD bases of aiming system
Browse files Browse the repository at this point in the history
  • Loading branch information
PoUpA committed May 29, 2009
1 parent 7b73c87 commit 8e2de2d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
3 changes: 1 addition & 2 deletions application/source/Ennemies/Bee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace Polukili
this->rotationCenter = level->world->CreateBody(&rotationCenterDef);

b2CircleDef rotationCenterShapeDef;
rotationCenterShapeDef.density= 0.0f;
rotationCenterShapeDef.radius = 0.2f;
rotationCenterShapeDef.localPosition.Set(0.0f, 0.0f);
// TO COMMENT ! perhaps creating an enum with categories
Expand Down Expand Up @@ -76,7 +75,7 @@ namespace Polukili
void Bee::nextStep()
{

this->body->ApplyForce(b2Vec2(0.0f, Constants::defaultGravity*this->body->GetMass()), this->basePosition);
//this->body->ApplyForce(b2Vec2(0.0f, Constants::defaultGravity*this->body->GetMass()), this->basePosition);

}
} /* End of namespace Polukili::Ennemies */
Expand Down
51 changes: 43 additions & 8 deletions application/source/Players/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,64 @@ namespace Polukili
playerShape.density = Constants::defaultDensity;
playerShape.friction = Constants::defaultFriction;
playerShape.restitution = Constants::defaultRestitution;

// TO COMMENT ! perhaps creating an enum with categories
// TO COMMENT ! perhaps creating an enum with categories
// deal with who collide and doesn't
playerShape.filter.categoryBits = 0x0002;
playerShape.filter.maskBits = 0x0005;


this->body->CreateShape(&playerShape);
this->body->SetMassFromShapes();
this->body->SetMassFromShapes();


b2BodyDef aimDef;
aimDef.position.x = position.x + 0.5f;
aimDef.position.y = position.y;
this->aimPoint = level->world->CreateBody(&aimDef);
b2CircleDef aimShape;
aimShape.density = Constants::defaultDensity;

aimShape.radius = 0.1f;
aimShape.localPosition.Set(0.0f, 0.0f);
// TO COMMENT ! perhaps creating an enum with categories
// deal with who collide and doesn't
aimShape.filter.categoryBits = 0x0008;
aimShape.filter.maskBits = 0x0006;
this->aimPoint->CreateShape(&aimShape);
this->aimPoint->SetMassFromShapes();

b2DistanceJointDef jointDef;
jointDef.Initialize(this->body, this->aimPoint, this->body->GetPosition(), this->aimPoint->GetPosition());
jointDef.collideConnected = false;

level->world->CreateJoint(&jointDef);





}

/*************************************************/
void Player::nextStep()
{
u16 btnsheld = WPAD_ButtonsHeld(WPAD_CHAN_0);

this->aimPoint->ApplyForce(b2Vec2(0.0f, Constants::defaultGravity*this->aimPoint->GetMass()), this->aimPoint->GetPosition());
if (btnsheld & WPAD_BUTTON_UP)
{
this->body->ApplyImpulse(b2Vec2(-Constants::defaultImpulseSpeed,0),this->body->GetPosition());

this->aimPoint->ApplyForce(b2Vec2(-20.0f,0),this->aimPoint->GetPosition());
}
if (btnsheld & WPAD_BUTTON_DOWN)
{
this->body->ApplyImpulse(b2Vec2(Constants::defaultImpulseSpeed,0),this->body->GetPosition());
this->aimPoint->ApplyForce(b2Vec2(20.0f,0),this->aimPoint->GetPosition());
}
if (btnsheld & WPAD_BUTTON_RIGHT)
{

this->aimPoint->ApplyForce(b2Vec2(0,20.0f),this->aimPoint->GetPosition());
}
if (btnsheld & WPAD_BUTTON_2)
this->body->ApplyImpulse(b2Vec2(0,-3*Constants::defaultImpulseSpeed),this->body->GetPosition());

Expand All @@ -68,9 +105,7 @@ namespace Polukili
Console::log(LOG_INFO, "will shoot");
Bullets::Bullet* bullet = new Bullets::Bullet(this->level);
bullet->loadGraphics();
b2Vec2 pos = body->GetPosition();
pos.x += 0.5;
bullet->initPhysic(pos);
bullet->initPhysic(this->aimPoint->GetPosition());

Console::log(LOG_INFO, "shot");
}
Expand Down
5 changes: 4 additions & 1 deletion application/source/Players/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ namespace Polukili
* Returns the height of the tile in the image (must be multiple of 4).
*/
virtual int getImageHeight() const;


protected:
b2Body* aimPoint;

//end of class Player

};

} /* End of namespace Polukili::Players */
Expand Down

0 comments on commit 8e2de2d

Please sign in to comment.