/
Leonidvgol
/
Arkanoid
Обзор
Документация
Войти
/
Leonidvgol
/
Arkanoid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
ball.cpp
43 строки
1 KB
Leonid_Golovyrin
Добавлена визуализация жизней и окно прохождения всех уровней
18 мар 2025, 21:51
18 мар 2025, 21:51
f714802
Код
Авторство
О чём код?
#include "ball.h" Ball::Ball(b2World* world, float x, float y) : GameObject(world) { b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(x / SCALE, y / SCALE); bodyDef.linearDamping = 0; bodyDef.angularDamping = 1.0; body = world->CreateBody(&bodyDef); setBody(body); b2CircleShape circle; circle.m_radius = radius / 2 / SCALE; b2FixtureDef fixtureDef; fixtureDef.shape = &circle; fixtureDef.friction = 1.0f; fixtureDef.density = 0.1f; fixtureDef.restitution = 1.0f; body->CreateFixture(&fixtureDef); setRect(-radius / 2, -radius / 2, radius, radius); } GoodBall::GoodBall(b2World* world, float x, float y) : Ball(world, x, y){ setBrush(QColor(255,255,255)); } BadBall::BadBall(b2World* world, float x, float y) : Ball(world, x, y){ setBrush(QColor(90,90,90)); } void Ball::updateGraphics() { setPos(body->GetPosition().x * SCALE, -body->GetPosition().y * SCALE); } void Ball::moveBallForPaddle(float x) { body->SetLinearVelocity(b2Vec2(x, 0.0f)); } void Ball::startGame() { body->SetLinearVelocity(b2Vec2(0.0f, 15.0f)); }