void Entity::die() { if(!dead) { dead = true; onDie(); } }
void LifeComponent::kill() { if (!m_spawning && !m_despawning) { int previousHealth = m_health; m_health = 0; healthChanged(previousHealth); onDie(); } }
void LifeComponent::dealDamage(int damage) { if (!m_spawning && !m_despawning && m_health > 0) { damage = std::min(damage, m_health); int previousHealth = m_health; m_health -= damage; healthChanged(previousHealth); if (m_health == 0) { onDie(); } } }
void EnemyBase::takeDamage(Damage & damage) { double finalDamage = damage.value; for(int i = 0;i < resistances.size();i++) { if(resistances[i].dmgType = damage.type) { finalDamage = resistances[i].getReducedDamageValue(damage.value); break; } } life -= finalDamage; if(life <= 0) { onDie(); } }
Game::Game(QObject *parent) : QObject(parent) { spoony_message = new SpoonyMessage(this); global_timer = new QTimer(this); global_speed = DEFAULT_SPEED; global_timer->start(1000 / global_speed); main_scene = new QGraphicsScene(0, 0, WIDTH, HEIGHT); main_view = new QGraphicsView(main_scene); main_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); main_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); main_view->setRenderHint(QPainter::Antialiasing); main_view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); main_view->setCacheMode(QGraphicsView::CacheBackground); current_level = 0; connect(spoony_message, SIGNAL(finish()), this, SLOT(playNextLevel())); connect(spoony_message, SIGNAL(reset()), this, SLOT(onDie())); qml_engine = new QDeclarativeEngine(this); qml_engine->rootContext()->setContextProperty("Game", this); qml_startscreen = new QDeclarativeComponent(qml_engine, QUrl("qrc:///startscreen.qml")); qml_startscreen->setObjectName("Startup"); sound_handler = new SoundHandler(this); global_lives = LIVES; emit ready(); }