Untitled
unknown
c_cpp
2 years ago
4.1 kB
6
Indexable
while (window.isOpen())
{
delay = clock.getElapsedTime().asSeconds();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
}
//take degrees
rectLeft = posPigeon.x - Width / 2;
rectTop = posPigeon.y - Height / 2;
rectLeft = std::max(sizeBlock, rectLeft);
rectTop = std::min(rectTop, 0.f);
view.reset(sf::FloatRect(rectLeft, rectTop, Width, Height));
window.setView(view);
Mx = sf::Mouse::getPosition(window).x;
My = sf::Mouse::getPosition(window).y;
b = Mx - Gun.getPosition().x;
a = My - Gun.getPosition().y;
currentPosition = Gun.getPosition() - sf::Vector2f(rectLeft,rectTop);
mousePosition = sf::Mouse::getPosition();
const float PI = 3.14159265;
float a = currentPosition.x - mousePosition.x;
float b = currentPosition.y - mousePosition.y;
//гипотенуза
float c = std::sqrt(a * a + b * b);
float rotation = (atan2(b, a)) * 180 / PI;
cosL = a / c * -1;
sinL = b / c * -1;
if ((rotation > 93 && rotation <= 180) || (rotation < -93 && rotation >= -180) && isRight == false) {
if (count % 2 == 0) {
Gun.setScale(-1.0f, 1.0f);
Body.setScale(-1.0f, 1.0f);
Head.setScale(-1.0f, 1.0f);
BulletS.setScale(-bulletCf, bulletCf);
count++;
isRight = true;
kSize *= -1;
}
}
else if (rotation > -86 && rotation < 88) {
if (count % 2 == 1) {
Gun.setScale(1.0f, 1.0f);
Body.setScale(1.0f, 1.0f);
Head.setScale(1.0f, 1.0f);
BulletS.setScale(bulletCf, bulletCf);
count++;
isRight = false;
kSize *= -1;
}
}
if (isRight) {
Gun.setScale(1.0f, -1.0f);
BulletS.setScale(bulletCf, -bulletCf);
}
BulletS.setRotation(rotation);
Gun.setRotation(rotation);
if ((view.getCenter().x + Width / 2) + sizeBlock > shapeMap[0].size() * sizeBlock) {
Expand(map);
ConvertMap(map, shapeMap, sizeBlock, Height, ladder);
}
differentHeadX = (sizeBody[0] / 2 - sizeHead[0] / 2) * kSize;
differentGunX = 10 * kSize;
Move(shapeMap, speedY, posPigeon, sizeBody, sizeBlock, sizeHead, Height, onGround);
//setPosition
Body.setPosition(posPigeon.x, posPigeon.y);
Head.setPosition(Body.getPosition().x - differentHeadX, Body.getPosition().y - sizeBody[1] / 2 - sizeHead[1] / 2);
Gun.setPosition(Body.getPosition().x - differentGunX, Body.getPosition().y - 10);
BulletS.setPosition(Gun.getPosition().x, Gun.getPosition().y);
//bullet delay
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if (delay > 0.5) {
clock.restart();
bullet.bulletSprite = BulletS;
bullet.size = bulletSize;
bullet.speed = sf::Vector2f(BulletSpeed * cosL,BulletSpeed * sinL);
bullet.position = sf::Vector2f(BulletS.getPosition().x, BulletS.getPosition().y);
bullets.push_back(bullet);
}
}
window.clear(sf::Color::White);
drawMap(window, shapeMap,view);
window.draw(Body);
window.draw(Head);
BulletsAction(bullets, shapeMap, sizeBlock, view);
window.draw(Gun);
window.display();
}
return 0;
}Editor is loading...
Leave a Comment