/
Leonidvgol
/
Arkanoid
Обзор
Документация
Войти
/
Leonidvgol
/
Arkanoid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
paddle.cpp
72 строки
2 KB
Leonid_Golovyrin
Добавлено окно выбора уровня, окно перехода к следующему уровню и окно окончания игры
14 мар 2025, 12:59
14 мар 2025, 12:59
1455e20
Код
Авторство
О чём код?
#include "paddle.h" Paddle::Paddle(b2World* world, float x, float y, float width, float height, QColor color, float speed) : GameObject(world), height (height), width (width), color (color), speed(speed) { b2BodyDef bodyDef; bodyDef.type = b2_kinematicBody; bodyDef.position.Set(x / SCALE, y / SCALE); bodyDef.linearDamping = 0; body = world->CreateBody(&bodyDef); setBody(body); b2PolygonShape box; box.SetAsBox(width / 2 / SCALE, height / 2 / SCALE); b2FixtureDef fixtureDef; fixtureDef.friction = 1.0f; fixtureDef.density = 10.0f; fixtureDef.shape = &box; body->CreateFixture(&fixtureDef); setRect(-width / 2, -height / 2, width, height); setBrush(color); } void Paddle::invertedControl() { invertedLinearVelocity = true; } void Paddle::resetInversion() { invertedLinearVelocity = false; } void Paddle::moveLeft() { if (getPositionX() > leftBound && !invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(-15.0f, 0.0f)); } if (getPositionX() < rightBound && invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(15.0f, 0.0f)); } } void Paddle::moveRight() { if (getPositionX() < rightBound && !invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(15.0f, 0.0f)); } if (getPositionX() > leftBound && invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(-15.0f, 0.0f)); } } void Paddle::clampPosition() { if (getPositionX() < leftBound && !invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(0.0f, 0.0f)); } else if (getPositionX() > rightBound && !invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(0.0f, 0.0f)); } if (getPositionX() > rightBound && invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(0.0f, 0.0f)); } else if (getPositionX() < leftBound && invertedLinearVelocity) { body->SetLinearVelocity(b2Vec2(0.0f, 0.0f)); } } void Paddle::moveStop() { body->SetLinearVelocity(b2Vec2(0.0f, 0.0f)); } void Paddle::updateGraphics() { setPos(body->GetPosition().x * SCALE, -body->GetPosition().y * SCALE); }