本文整理汇总了C++中Sprite::GetY方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetY方法的具体用法?C++ Sprite::GetY怎么用?C++ Sprite::GetY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite::GetY方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawSprite
void BackBuffer::DrawSprite(Sprite& sprite)
{
SDL_Rect dest;
dest.x = sprite.GetX();
dest.y = sprite.GetY();
dest.w = sprite.GetWidth();
dest.h = sprite.GetHeight();
SDL_RenderCopy(m_pRenderer, sprite.GetTexture()->GetTexture(), 0, &dest);
}
示例2: CheckCollision
// check for collision between 'this' sprite and sprite
void Sprite::CheckCollision( Sprite &sprite ) {
int c;
c = CalculateCollision( GetBitmask(), sprite.GetBitmask(), (int)(sprite.GetX() - x), (int)(sprite.GetY() - y) );
if( c ) {
if(( &sprite != owner ) && (sprite.owner != this)) { // we can't collide with our owner
// a collision has occured
// modify the velocities
float avx, avy, bvx, bvy;
// the kinetic energies of the collision
float ke_him = .5 * sprite.GetMass() * (sprite.velocity.GetMagnitude() * sprite.velocity.GetMagnitude());
float ke_us = .5 * mass * (velocity.GetMagnitude() * velocity.GetMagnitude());
avx = sprite.velocity.GetX();
avy = sprite.velocity.GetY();
bvx = velocity.GetX();
bvy = velocity.GetY();
// calculate new velocities
avx = (velocity.GetX() * (( 2. * mass ) / ( sprite.GetMass() + mass ) )) - (sprite.velocity.GetX() * (( mass - sprite.GetMass() )/( sprite.GetMass() + mass )));
avy = (velocity.GetY() * (( 2. * mass ) / ( sprite.GetMass() + mass ) )) - (sprite.velocity.GetY() * (( mass - sprite.GetMass() )/( sprite.GetMass() + mass )));
bvx = (sprite.velocity.GetX() * (( 2. * sprite.GetMass() ) / ( sprite.GetMass() + mass ) )) - (velocity.GetX() * (( sprite.GetMass() - mass )/( sprite.GetMass() + mass )));
bvy = (sprite.velocity.GetY() * (( 2. * sprite.GetMass() ) / ( sprite.GetMass() + mass ) )) - (velocity.GetY() * (( sprite.GetMass() - mass )/( sprite.GetMass() + mass )));
velocity.Set( bvx, bvy );
sprite.velocity.Set( avx, avy );
// until debugged
ke_him = 1.;
ke_us = 1.;
// call the sprite-child's specific collision code
Collision( ke_him );
// and the other's collision code
sprite.Collision( ke_us );
}
}
}
示例3: main
int main(int argc, char* argv[]) {
Screen& screen = Screen::Instance();
ResourceManager& resManager = ResourceManager::Instance();
//screen.Open(screen.GetDesktopWidth(), screen.GetDesktopHeight(), true);
screen.Open(800, 600, false);
Image* characterImg = resManager.LoadImage("data/images/character.png", 16);
Image* backImg = resManager.LoadImage("data/images/clouds.png");
Map* map = resManager.LoadMap("data/maps/map.tmx");
characterImg->SetHandle(characterImg->GetWidth()/2, characterImg->GetHeight());
MapScene scene(map, backImg, backImg);
scene.SetBackgroundColor(0, 155, 255);
scene.SetRelativeBackSpeed(0.6, 0.6);
scene.SetRelativeFrontSpeed(0.8, 0.8);
scene.SetAutoBackSpeed(-4, 2);
scene.SetAutoFrontSpeed(-6, 3);
Sprite* character = scene.CreateSprite(characterImg);
character->SetFrameRange(0, 8);
character->SetPosition(192, 400);
character->SetCollision(Sprite::COLLISION_RECT);
Camera& cam = scene.GetCamera();
cam.SetBounds(0, 0, scene.GetMap()->GetWidth(), scene.GetMap()->GetHeight());
cam.FollowSprite(character);
double gravity = 10;
while (screen.IsOpened() && !screen.KeyPressed(GLFW_KEY_ESC)) {
// Actualizamos movimiento del jugador
double toX = character->GetX();
if ( screen.KeyPressed(GLFW_KEY_LEFT) ) {
toX = -10000;
character->SetScale(-1, 1);
} else if ( screen.KeyPressed(GLFW_KEY_RIGHT) ) {
toX = 10000;
character->SetScale(1, 1);
}
character->MoveTo(toX, character->GetY() + gravity, 256, 512);
// Calculamos distancia al suelo
double distanceToFloor = Distance(character->GetX(), character->GetY(), character->GetX(), scene.GetMap()->GetGroundY(character->GetX(), character->GetY()));
// Salto del jugador
if ( screen.KeyPressed(GLFW_KEY_SPACE) && distanceToFloor < 10 )
gravity = -48;
// Actualizamos gravedad
gravity += 128 * screen.ElapsedTime();
if ( gravity > 10 )
gravity = 10;
// Actualizamos escena
scene.Update(screen.ElapsedTime());
// Actualizamos animacion del jugador
if ( character->IsMoving() ) {
if ( distanceToFloor < 10 ) {
character->SetFPS(16);
} else {
character->SetFPS(0);
character->SetCurrentFrame(1);
}
} else {
character->SetFPS(0);
character->SetCurrentFrame(0);
}
// Dibujamos
scene.Render();
screen.Refresh();
}
resManager.FreeResources();
return 0;
}