void GameEntity::hit( GameEntity * entity ) { m_pathFinder.clearPath(); LuaValue val; float atk = 0.0f; float hp = 1.0f; if (entity->getProperty("atk", val)) { atk = val.floatValue(); } if (this->getProperty("hp", val)) { hp = val.floatValue(); } if (atk > hp) { this->setProperty("hp", LuaValue::floatValue(0.0f)); } else { this->setProperty("hp", LuaValue::floatValue(hp-atk)); } this->updateHPBar(); }
void LuaStack::pushLuaValue(const LuaValue& value) { const LuaValueType type = value.getType(); if (type == LuaValueTypeInt) { return pushInt(value.intValue()); } else if (type == LuaValueTypeFloat) { return pushFloat(value.floatValue()); } else if (type == LuaValueTypeBoolean) { return pushBoolean(value.booleanValue()); } else if (type == LuaValueTypeString) { return pushString(value.stringValue().c_str()); } else if (type == LuaValueTypeDict) { pushLuaValueDict(value.dictValue()); } else if (type == LuaValueTypeArray) { pushLuaValueArray(value.arrayValue()); } else if (type == LuaValueTypeObject) { pushObject(value.ccobjectValue(), value.getObjectTypename().c_str()); } }
void GameEntity::updateHPBar() { float hp = 1.0f; float maxhp = 1.0f; LuaValue val; if (this->getProperty("hp", val)) { hp = val.floatValue(); } if (this->getProperty("maxhp", val)) { maxhp = val.floatValue(); } m_hpBar->drawSegment(Vec2(-20, 30), Vec2(20, 30), 5.0f, Color4F(1.0f, 1.0f, 1.0f, 1.0f)); m_hpBar->drawSegment(Vec2(-20, 30), Vec2(20, 30), 4.0f, Color4F(0.0f, 0.0f, 0.0f, 1.0f)); m_hpBar->drawSegment(Vec2(-20, 30), Vec2(-20+40*(hp/maxhp), 30), 4.0f, Color4F(1.0f, 0.0f, 0.0f, 1.0f)); }