void Player::draw(sf::RenderWindow* renderWindow) { if(hasShield) { shield().setPosition(spaceShip().getPosition()); renderWindow->draw(shield()); } renderWindow->draw(spaceShip()); }
/*! Reduce the ship's power level by \a delta, which should be a positive number. If the reduction makes the power level negative, reset it to 0; If the ship's power level becomes 0, set the shield strength to 0, but don't drop the shiled here if it is up. The shiled is only dropped in phase 1 of the scene animation. \internal */ void KShip::reducePowerLevel(int delta) { powerLevel_ -= delta; if (powerLevel_ < 0) { powerLevel_ = 0; stopEngine(); shield()->setStrength(0); } view_->markVitalsChanged(); }
void Strategy() { if (opponent_number) { if (!opponent[0].shield_time) { if (dist(me.pos, opponent[0].pos) - me.radius - opponent[0].radius < kShortAttackRange[me.skill_level[SHORT_ATTACK]]) short_attack(me); else if (dist(me.pos, opponent[0].pos) - me.radius - opponent[0].radius < kLongAttackRange[me.skill_level[LONG_ATTACK]]) long_attack(me, opponent[0]); } else shield(me); } dash(me); /*if (see_boss && dist(me.pos, boss.pos) - me.radius - boss_r < kShortAttackRange[me.skill_level[SHORT_ATTACK]]) short_attack(me);*///打boss update(); }
bool TestCharacter::testCopy() { Engine *prevEngine = Engine::getEngine(); Engine *eng = new Engine(); eng->addRace(new Race("human")); Engine::setEngine(eng); Handle<Game> game = new Game(); Handle<Character> testChar(new Character()); testChar->setAge(24); testChar->setName("Melli"); testChar->setCameraOffset(0.8f, 0.4f); DialogueComponent *comp = new DialogueComponent(testChar); comp->setDialogueAvailable("testSub1"); comp->setDialogueAvailable("testSub2"); comp->setSubjectLock("testSub1"); testChar->setDialogueComp(comp); testChar->setFixedToGrid(true); testChar->setGender(Gender::FEMALE); testChar->setGraphic(new Sprite("characters/mainChar/front"), false); testChar->setGridLocation(5, 4); testChar->setLevel(2); testChar->setMaxLevel(10); testChar->setPickupReach(1.4f); testChar->setRace(Engine::getEngine()->getRace("human")); Handle<Inventory> inv(testChar->getInventory()); Handle<Item> sword(new Item()); sword->setGraphic(new Sprite("items/sword")); sword->setGroundGraphic(new Sprite("items/swordGround")); sword->getStatModifiers().addStatModifier(Stat::MAX_DAMAGE, StatModifier(5.0f, MOD_ADD)); sword->getStatModifiers().addStatModifier(Stat::MIN_DAMAGE, StatModifier(3.0f, MOD_ADD)); sword->setItemFullname("Sword", "Wooden", "of Death"); sword->setItemType(ItemCommon::SWORD); sword->setInventorySize(2, 3); inv->addItem(sword, 0, 0); Handle<Item> shield(new Item()); shield->getStatModifiers().addStatModifier(Stat::ARMOUR, StatModifier(4.0f, MOD_MULTIPLY)); shield->getStatModifiers().addStatModifier(Stat::ARMOUR, StatModifier(2.0f, MOD_ADD)); shield->setItemFullname("Shield", "Padded", "of ASD"); shield->setItemType(ItemCommon::SHIELD); shield->setInventorySize(2, 2); inv->addItem(shield, 4, 2); testChar->getStats()->setBaseStat(Stat::HEALTH, 10.0f); testChar->getStats()->setBaseStat(Stat::STRENGTH, 5.5f); testChar->getStats()->setBaseStat(Stat::MAX_DAMAGE, 4.0f); testChar->getStats()->setBaseStat(Stat::MIN_DAMAGE, 4.0f); testChar->getStats()->setBaseStat(Stat::ARMOUR, 7.0f); Handle<Item> swordEquip(new Item(*sword)); swordEquip->setItemFullname("Sword", "Wooden", "of Hit"); testChar->addBodyPart(new BodyPart("arm", BodyPartType::ARM, swordEquip)); testChar->addBodyPart(new BodyPart("torso", BodyPartType::TORSO)); testChar->addBodyPart(new BodyPart("legs", BodyPartType::LEGS)); am_equalsDelta(10.0f, testChar->getStats()->getStat(Stat::HEALTH), 0.0001f); am_equalsDelta(5.5f, testChar->getStats()->getStat(Stat::STRENGTH), 0.0001f); am_equalsDelta(9.0f, testChar->getStats()->getStat(Stat::MAX_DAMAGE), 0.0001f); am_equalsDelta(7.0f, testChar->getStats()->getStat(Stat::MIN_DAMAGE), 0.0001f); am_equalsDelta(7.0f, testChar->getStats()->getStat(Stat::ARMOUR), 0.0001f); Handle<Character> copyChar(new Character(*testChar)); am_equalsDelta(24.0f, copyChar->getAge(), 0.0001f); am_equalsStr("Melli", copyChar->getName()); am_equalsDelta(0.8f, copyChar->getCameraOffsetX(), 0.0001f); am_equalsDelta(0.4f, copyChar->getCameraOffsetY(), 0.0001f); DialogueComponent *copyComp = copyChar->getDialogueComp(); assert(copyComp != comp); assert(copyComp->getAttachedTo() == copyChar); assert(copyComp->isDialogueAvailable("testSub1")); assert(copyComp->isDialogueAvailable("testSub2")); assert(!copyComp->isSubjectLocked("testSub1")); assert(copyComp->isSubjectLocked("testSub2")); assert(copyChar->isFixedToGrid()); assert(copyChar->getGender() == Gender::FEMALE); assert(copyChar->getGraphic() != testChar->getGraphic()); assert(copyChar->getGraphic()->getAsset() == testChar->getGraphic()->getAsset()); am_equals(5, copyChar->getGridLocationX()); am_equals(4, copyChar->getGridLocationY()); am_equals(2, copyChar->getLevel()); am_equals(10, copyChar->getMaxLevel()); am_equalsDelta(1.4f, copyChar->getPickupReach(), 0.0001f); assert(copyChar->getRace() == Engine::getEngine()->getRace("human")); Handle<Inventory> copyInv(copyChar->getInventory()); assert(copyInv.get() && copyInv != inv); Handle<Item> copySword(copyInv->getItemAt(0, 0)); assert(copySword.get() && copySword != sword); am_equals(1u, copySword->getStatModifiers().getModifiers()[Stat::MAX_DAMAGE].size()); am_equalsDelta(5.0f, copySword->getStatModifiers().getModifiers()[Stat::MAX_DAMAGE][0].getValue(), 0.0001f); assert(MOD_ADD == copySword->getStatModifiers().getModifiers()[Stat::MAX_DAMAGE][0].getType()); am_equals(1u, copySword->getStatModifiers().getModifiers()[Stat::MIN_DAMAGE].size()); assert(MOD_ADD == copySword->getStatModifiers().getModifiers()[Stat::MIN_DAMAGE][0].getType()); am_equalsDelta(3.0f, copySword->getStatModifiers().getModifiers()[Stat::MIN_DAMAGE][0].getValue(), 0.0001f); am_equalsStr("Sword", copySword->getItemName()); am_equalsStr("Wooden", copySword->getPrefix()); am_equalsStr("of Death", copySword->getPostfix()); am_equalsStr("Wooden Sword of Death", copySword->getFullItemName()); assert(ItemCommon::SWORD == copySword->getItemType()); am_equals(2, copySword->getInventorySizeX()); am_equals(3, copySword->getInventorySizeY()); assert(copySword->getGraphic() != sword->getGraphic()); assert(copySword->getGraphic()->getAsset() == sword->getGraphic()->getAsset()); assert(copySword->getGroundGraphic() != sword->getGroundGraphic()); assert(copySword->getGroundGraphic()->getAsset() == sword->getGroundGraphic()->getAsset()); Handle<Item> copyShield(copyInv->getItemAt(4, 2)); assert(copyShield.get() && copyShield != shield); am_equals(2u, copyShield->getStatModifiers().getModifiers()[Stat::ARMOUR].size()); am_equalsDelta(4.0f, copyShield->getStatModifiers().getModifiers()[Stat::ARMOUR][0].getValue(), 0.0001f); assert(MOD_MULTIPLY == copyShield->getStatModifiers().getModifiers()[Stat::ARMOUR][0].getType()); am_equalsDelta(2.0f, copyShield->getStatModifiers().getModifiers()[Stat::ARMOUR][1].getValue(), 0.0001f); assert(MOD_ADD == copyShield->getStatModifiers().getModifiers()[Stat::ARMOUR][1].getType()); am_equalsStr("Shield", copyShield->getItemName()); am_equalsStr("Padded", copyShield->getPrefix()); am_equalsStr("of ASD", copyShield->getPostfix()); am_equalsStr("Padded Shield of ASD", copyShield->getFullItemName()); assert(ItemCommon::SHIELD == copyShield->getItemType()); am_equals(2, copyShield->getInventorySizeX()); am_equals(2, copyShield->getInventorySizeY()); am_equalsDelta(10.0f, testChar->getStats()->getBaseStat(Stat::HEALTH), 0.0001f); am_equalsDelta(5.5f, testChar->getStats()->getBaseStat(Stat::STRENGTH), 0.0001f); am_equalsDelta(4.0f, testChar->getStats()->getBaseStat(Stat::MAX_DAMAGE), 0.0001f); am_equalsDelta(4.0f, testChar->getStats()->getBaseStat(Stat::MIN_DAMAGE), 0.0001f); am_equalsDelta(7.0f, testChar->getStats()->getBaseStat(Stat::ARMOUR), 0.0001f); const BodyParts &parts = copyChar->getBodyParts(); assert(parts.hasBodyPart("arm")); assert(parts.hasBodyPart("torso")); assert(parts.hasBodyPart("legs")); Handle<Item> swordEquipCopy(parts.getBodyPart("arm")->getEquippedItem()); assert(swordEquipCopy.get() && swordEquipCopy != swordEquip); am_equalsStr("Wooden Sword of Hit", swordEquipCopy->getFullItemName()); am_equalsDelta(10.0f, copyChar->getStats()->getStat(Stat::HEALTH), 0.0001f); am_equalsDelta(5.5f, copyChar->getStats()->getStat(Stat::STRENGTH), 0.0001f); am_equalsDelta(9.0f, copyChar->getStats()->getStat(Stat::MAX_DAMAGE), 0.0001f); am_equalsDelta(7.0f, copyChar->getStats()->getStat(Stat::MIN_DAMAGE), 0.0001f); am_equalsDelta(7.0f, copyChar->getStats()->getStat(Stat::ARMOUR), 0.0001f); Engine::setEngine(prevEngine); delete eng; return true; }
void Player::update(float dt) { static bool is_pressed = false; if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && is_pressed == false && ammo > 0) { Game.addProjectile(pos(), rotation, getName()); is_pressed = true; ammo--; } if(!sf::Mouse::isButtonPressed(sf::Mouse::Left) && is_pressed) { is_pressed = false; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && hasMagnet) { std::vector<std::shared_ptr<GameObject>> objs = Game.getNearObjects("Player", 300.0f); for(int i = 0; i < objs.size(); i++) { std::shared_ptr<GameObject> e = Game.getGameObject("Enemy"); // velocity to enemy Vec2 vte = Vec2::velocity(objs[i]->pos(), e->pos()).normalized(); objs[i]->vel().x = vte.x*1.4f; objs[i]->vel().y = vte.y*1.4f; } hasMagnet = false; } sf::Vector2i mousePos = sf::Mouse::getPosition(Game.getWindow()); sf::Vector2f convertedMP = Game.getWindow().mapPixelToCoords(mousePos); float _rot = atan2f(pos().y - convertedMP.y, pos().x - convertedMP.x); rotation = -90+(180.0f/3.14f)*_rot; if(velocity.x > max_speed) velocity.x = max_speed; if(velocity.y > max_speed) velocity.y = max_speed; velocity.x -= velocity.x * smooth; velocity.y -= velocity.y * smooth; position.move(velocity.x, velocity.y); spaceShip().setPosition(position.x, position.y); if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { velocity.x += speedApply; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { velocity.x += -speedApply; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { velocity.y += -speedApply; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { velocity.y += speedApply; } spaceShip().setRotation(rotation); shield().setRotation(rotation); spaceShip().setColor(sf::Color(255,255,255,health)); if(health < 10) { spaceShip().setColor(sf::Color(255,255,255,10)); loseSound.playAsSound(); health=1000; Game.setGameState(GS_MENU); } if(health >= 255) { health = 255; } }
void WallClock::paintBackground(QPainter & painter) { initCoordinateSystem(painter); // Malowanie obwiedni tarczy. //QColor ramka(17,50,214);// ³adny niebieski QColor ramka(215,0,0); // g³êboki czerwony // Gradient zewnêtrznego okrêgu QRadialGradient back1(QPointF(0,0),135, QPointF(-27.5,110.0)); back1.setColorAt(0.0,QColor(255,255,255)); back1.setColorAt(1.0,ramka); // Gradient wewnêtrznego okrêgu QRadialGradient back2(QPoint(0,0),170, QPointF(57.5,100)); back2.setColorAt(0.0,ramka); back2.setColorAt(1.0,QColor(255,255,255)); QRadialGradient shield(QPointF(0,0),122,QPointF(-12.0,-15.0)); shield.setColorAt(0.0,Qt::white); shield.setColorAt(0.5,QColor(240,240,240)); shield.setColorAt(1.0,QColor(215,215,215)); QPen Pen(Qt::black); Pen.setWidth(2); painter.setPen(Pen); // Koperta zegark painter.setBrush(QBrush(back1)); painter.drawEllipse(-116,-116,232,232); painter.setBrush(QBrush(back2)); painter.setPen(Qt::NoPen); painter.drawEllipse(-109,-109,218,218); painter.setPen(Pen); painter.setBrush(QBrush(shield)); painter.drawEllipse(-102,-102,204,204); painter.setBrush(Qt::black); // rysowanie kó³ek godzin i samych godzin for (int i = 0; i < 12; ++i) { painter.drawEllipse(94, -2, 4, 4); painter.rotate(30.0); } // rysowanie kresek minut painter.setPen(Qt::black); Pen.setWidth(2); painter.setPen(Pen); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(94, 0, 97, 0); painter.rotate(6.0); } QSize Size; QString Str; // Rysowanie cyfr na tarczy if (digitOffset()!=0.0) { painter.setFont(digitFont()); painter.setPen(digitColor()); for ( int z = 1; z <= 12; ++z) { QString hour = QString("%1").arg(z); Size = painter.fontMetrics().size(Qt::TextSingleLine, hour); painter.save(); painter.translate(digitOffset() * cos(PI*z/6.0-PI/2.0),digitOffset() * sin(PI*z/6.0-PI/2.0)); painter.setPen(digitColor()); painter.drawText( QPointF ( Size.width()/ -2.0, Size.height() / 4.0), hour); painter.restore(); } } }// paintBackground