本文整理汇总了C++中Hero类的典型用法代码示例。如果您正苦于以下问题:C++ Hero类的具体用法?C++ Hero怎么用?C++ Hero使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hero类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getRoom
void Powerup::update()
{
if (GameState::getInt(mKind) != 0)
{
return;
}
Hero *hero = getRoom()->getHero();
Entity::CollisionRect cr = hero->getCollisionRect();
if (Collides(getCollisionRect(), cr))
{
GameState::put(mKind, 1);
std::string explanation;
PowerUpScreen* screen;
if (mKind == GameState::POWERUP_HIJUMP) {
screen = new PowerUpScreen("HI JUMP SOCKS", "JUMP HIGHER");
} else if (mKind == GameState::POWERUP_GUN) {
screen = new PowerUpScreen("POWER GUN", "USE Z");
} else if (mKind == GameState::POWERUP_GRENADE) {
screen = new PowerUpScreen("GRAVITY GRANADE", "USE X");
}
ScreenManager::add(screen);
}
mFrame++;
}
示例2:
void CGE2Engine::pocFul() {
Hero *h = _heroTab[_sex]->_ptr;
h->park();
_commandHandler->addCommand(kCmdWait, -1, -1, h);
_commandHandler->addCommand(kCmdSound, -1, 2, h);
_commandHandler->addCommand(kCmdSay, -1, kPocketFull + _sex, h);
}
示例3: Rect
// on "init" you need to initialize your instance
bool BackgroundLayer::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
Sprite *pSprite = Sprite::create("background2.png");
//pSprite->setOpacity(0.0);
// position the sprite on the center of the screen
pSprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
//Create a "one by one" touch event listener (processes one touch at a time)
auto listener1 = EventListenerTouchOneByOne::create();
// When "swallow touches" is true, then returning 'true' from the onTouchBegan method will "swallow" the touch event, preventing other listeners from using it.
listener1->setSwallowTouches(true);
// Example of using a lambda expression to implement onTouchBegan event callback function
listener1->onTouchBegan = [](Touch* touch, Event* event)
{
// event->getCurrentTarget() returns the *listener's* sceneGraphPriority node.
auto target = static_cast<Sprite*>(event->getCurrentTarget());
//Get the position of the current point relative to the button
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
//Check the click area
if (rect.containsPoint(locationInNode))
{
/*
Color4B *buffer = (Color4B *)malloc(sizeof(Color4B));
Point location = Point(locationInNode.x * CC_CONTENT_SCALE_FACTOR(), locationInNode.y * CC_CONTENT_SCALE_FACTOR());
glReadPixels(location.x,location.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
Color4B color = buffer[0];
log("sprite began... x = %f, y = %f pColor=%d %d %d %d", locationInNode.x, locationInNode.y, color.r, color.g, color.b, color.a);
*/
Hero *hero = FirstScene::getInstance()->getGameObjectsLayer()->getHero();
hero->go(locationInNode);
return true;
}
return false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, pSprite);
return true;
}
示例4: UpdateHeroFollow
void Camera::UpdateHeroFollow( float dt )
{
//if hero hasn't moved this frame, return
Hero* hero = g_game->GetWorld()->GetHero();
if(hero->MovedLastFrame() == false)
{
return;
}
//try to focus on hero
Vec2f oldCenter = m_quad.Center();
Vec2f toHero = g_game->GetWorld()->GetHero()->GetMoveCenter() - m_quad.Center();
float oldDistance = toHero.Length();
toHero.Normalize();
m_quad.Offset(toHero * kCameraMoveSpeed * dt);
float distanceMoved = (m_quad.Center() - oldCenter).Length();
if(distanceMoved > oldDistance)
{
//overshoot
m_quad.SetCenter(g_game->GetWorld()->GetHero()->GetMoveCenter());
}
//constrain to room
m_quad.ClipInsideOtherQuad(m_room->RoomQuad());
}
示例5: hgeCreate
void Robot::UseSkill()
{
if (!startattack)
{
HGE *hge = hgeCreate(HGE_VERSION);
float x, y;
hge->Input_GetMousePos(&x, &y);
backx = GetX();
backy = GetY();
switch (coretype)
{
//攻击型
//开始攻击
case Attack:
if (x<ACT_START_X || x>ACT_END_X || y<ACT_START_Y || y>ACT_END_Y)
{
if (!tremble)
tremble = 20;
return;
}
else
{
SetCollisionRange(40);
SetPos(x, y);
}
break;
//触发技能型
//跟hero做intercation将自身赋给hero然后自杀
case Magic:
break;
//BUFF型
//施放技能
case Buff:
{
int count = 0;
Hero *a = dynamic_cast<Hero*>(ObjectPool::GetObjPool().GetOurHero(GetType()));
for (int i = 0; i < STD_CORES; i++)
{
Robot *b = dynamic_cast<Robot*>(a->GetCOREs(i));
if (b && b->IsActive())
{
if (b->GetInnerCode() == GetInnerCode())
{
b->Suicide();
a->Interaction(b);
}
else
if (b->GetCoreType() == Buff)
count++;
}
}
SetSpeed(1500);
SetAim(25 + count * 50, 175);
}
break;
}
startattack = true;
}
}
示例6: Entity
/**
* \brief Creates an arrow.
* \param hero The hero.
*/
Arrow::Arrow(const Hero& hero):
Entity("", 0, hero.get_layer(), Point(0, 0), Size(0, 0)),
hero(hero) {
// initialize the entity
int direction = hero.get_animation_direction();
create_sprite("entities/arrow", true);
get_sprite().set_current_direction(direction);
set_drawn_in_y_order(true);
if (direction % 2 == 0) {
// Horizontal.
set_size(16, 8);
set_origin(8, 4);
}
else {
// Vertical.
set_size(8, 16);
set_origin(4, 8);
}
set_xy(hero.get_center_point());
notify_position_changed();
std::string path = " ";
path[0] = '0' + (direction * 2);
set_movement(std::make_shared<PathMovement>(
path, 192, true, false, false
));
disappear_date = System::now() + 10000;
stop_now = false;
entity_reached = nullptr;
}
示例7: query
bool DataBase::_insertHero(const Hero &hero) {
QSqlQuery query(_db);
query.prepare("insert into Heroes (hero_id, name) values(?, ?)");
query.addBindValue(hero.getId());
query.addBindValue(hero.getName());
return query.exec();
}
示例8: MapEntity
/**
* \brief Creates an arrow.
* \param hero The hero.
*/
Arrow::Arrow(const Hero& hero):
MapEntity("", 0, hero.get_layer(), 0, 0, 0, 0),
hero(hero) {
// initialize the entity
int direction = hero.get_animation_direction();
create_sprite("entities/arrow", true);
get_sprite().set_current_direction(direction);
set_drawn_in_y_order(true);
if (direction % 2 == 0) {
// Horizontal.
set_size(16, 8);
set_origin(8, 4);
}
else {
// Vertical.
set_size(8, 16);
set_origin(4, 8);
}
set_xy(hero.get_center_point());
set_optimization_distance(0); // Make the arrow continue outside the screen until disappear_date.
std::string path = " ";
path[0] = '0' + (direction * 2);
Movement* movement = new PathMovement(path, 192, true, false, false);
set_movement(movement);
disappear_date = System::now() + 10000;
stop_now = false;
entity_reached = NULL;
}
示例9: getRoom
void Savepoint::update()
{
mFrame++;
if (mTextCounter > 0)
{
mTextCounter--;
}
Hero *hero = getRoom()->getHero();
Entity::CollisionRect cr= hero->getCollisionRect();
bool heroOn = Collides(getCollisionRect(), cr);
if (heroOn && !mHeroOn)
{
// SAVE
GameState::put(GameState::LOCATION_X, getRoom()->getWorldOffsetX() * getRoom()->getTileWidth() + this->getPosition().x);
GameState::put(GameState::LOCATION_Y, getRoom()->getWorldOffsetY() * getRoom()->getTileHeight() + this->getPosition().y + 10);
GameState::saveToFile();
Sound::playSample("data/sounds/coin.wav");
mTextCounter = 50;
}
mHeroOn = heroOn;
}
示例10: winHero
// let a hero win the game
int Script::winHero(lua_State* L){
short x = (short)luaL_checknumber(L, 1);
short y = (short)luaL_checknumber(L, 2);
Hero* h = dynamic_cast<Hero*>(wrld.getObject(Vector2D(x,y)));
h->win();
return 0;
}
示例11: JUDGE_PLAYER_NULL
int Scene_Server_Request::process_20410001(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
JUDGE_PLAYER_NULL(player, role_id);
MSG_50200032 res_msg;
res_msg.role_id = player->role_id();
res_msg.open_type = 1;
player->fighter_detail().property_list(res_msg.prop_value);
Hero *hero = SCENE_PUBLIC->find_fight_hero(player->role_id());
if (hero) {
int hero_init_morale_type = hero->fighter_detail().init_morale.type;
double hero_init_morale_val = hero->fighter_detail().init_morale.total();
for (uint16_t i = 0; i < res_msg.prop_value.size(); ++i) {
if (res_msg.prop_value[i].type == hero_init_morale_type) {
res_msg.prop_value[i].value += hero_init_morale_val;
}
}
}
res_msg.prop_value.push_back(Property(PT_CAREER, player->career()));
res_msg.role_name = player->role_name();/*人物姓名*/
res_msg.gang_name = player->base_detail().gang_name;/*人物id*/
res_msg.gender = player->base_detail().gender;/*性别(1男,2女)*/
res_msg.gang_id = player->base_detail().gang_id;/*职业*/
res_msg.headship = player->ganger_detail().headship;
res_msg.avatar_vec = player->base_detail().avatar_vec;
OBJ_SEND_TO_CLIENT(res_msg, (*player));
return 0;
}
示例12: battle
//conducts the battle between player and enemy also increments or decrements gold
void battle(KillCount& kMap, Hero<int> &hero, Enemy<int> &e, int &gold){
cout << endl;
//show enemy stats and players stats before player chooses weapon
cout << "Now battling " << e.getName() << " " << e.getID() << " carrying "
<< e.getEgold() << " gold" << endl;
cout << "Enemy has " << e.getAttk() << " attack" << endl;
cout << hero.getName() << " has " << hero.getAttack() << endl;
//player attack after the have chosen a weapon
int heroBattleAttk = hero.getAttack() + hero.boost();
//show player attack after they have chosen a weapon
cout << hero.getName() << " Attack become " << heroBattleAttk << endl;
if(e.getAttk() > heroBattleAttk){
//if enemy has more attack player loses gold equal to amount carried by enemy
cout << "You have lost battle " << e.getEgold() << " gold lost" << endl;
gold -= e.getEgold();
cout << "Gold count now: " << gold << endl;
}else if(e.getAttk() < heroBattleAttk){
//if player has more attack than enemy player gains gold gold carried by enemy
cout << "You have won battle " << e.getEgold() << " gold gained" << endl;
gold += e.getEgold();
kMap.incrementCount(e.getName());
cout << "Gold count now: " << gold << endl;
}else{
//if tie no gold won or lost
cout << "Battle is a tie no gold gained or lost" << endl;
gold +=0;
cout << "Gold count now: " << gold << endl;
}
}
示例13: onKeyRelease
//释放按键
void Keyboard::onKeyRelease(EventKeyboard::KeyCode keycode, Event* event){
Hero* hero = global->hero;
if (keycode == EventKeyboard::KeyCode::KEY_LEFT_ARROW){
m_bKeyState[KEY_STATE_LEFT_ARROW] = false;
hero->CheckKeyState();
}
else if (keycode == EventKeyboard::KeyCode::KEY_RIGHT_ARROW){
m_bKeyState[KEY_STATE_RIGHT_ARROW] = false;
hero->CheckKeyState();
}
else if (keycode == EventKeyboard::KeyCode::KEY_DOWN_ARROW){
hero->onStandup();
m_bKeyState[KEY_STATE_DOWN_ARROW] = false;
}
else if (keycode == EventKeyboard::KeyCode::KEY_UP_ARROW){
m_bKeyState[KEY_STATE_UP_ARROW] = false;
}
else if (keycode == EventKeyboard::KeyCode::KEY_SPACE){
m_bKeyState[KEY_STATE_SPACE] = false;
}
else if (keycode == EventKeyboard::KeyCode::KEY_LEFT_CTRL){
m_bKeyState[KEY_STATE_LEFT_CTRL] = false;
}
else if (keycode == EventKeyboard::KeyCode::KEY_Z){
m_bKeyState[KEY_STATE_Z] = false;
}
}
示例14: rotate
void Enemy::move(Mode::Engine *engine) {
Hero *hero = engine->getData<Actors>()->getHero(0);
rotate(hero);
_x += (_speed * cos(_theta + 3.1415/4))/engine->getInstFps();
_y -= (_speed * sin(_theta + 3.1415/4))/engine->getInstFps();
for(int i = 0; i < engine->getData<Actors>()->getHeroAmt(); ++i) {
if(!_dead && !engine->getData<Actors>()->getHeros()->empty()) {
hero = engine->getData<Actors>()->getHero(i);
std::vector<Bullet*> *bullet = hero->getBullet();
for(int i = (bullet->size() > 400) ? bullet->size() - 400 : 0; i < bullet->size(); ++i) {
if(bullet->at(i)->getX() > _x &&
bullet->at(i)->getX() < _x + _h &&
bullet->at(i)->getY() > _y &&
bullet->at(i)->getY() < _y + _h) {
if(_health > 0) {
_health-=guns[bullet->at(i)->getType()].damage;
} else {
_dead = true;
++engine->getData<Actors>()->heroKills;
++engine->getData<Actors>()->heroPoints;
_x = 0;
_y = 0;
_w = 0;
_h = 0;
}
bullet->at(i)->die();
}
}
}
}
}
示例15: attack_hero
/**
* \brief Attacks the hero if possible.
*
* This function is called when there is a collision between the enemy and the hero.
*
* \param hero the hero
* \param this_sprite the sprite of this enemy that detected the collision with the hero,
* or NULL if it was not a pixel-precise collision.
*/
void Enemy::attack_hero(Hero &hero, Sprite *this_sprite) {
if (!is_immobilized() && can_attack && hero.can_be_hurt(this)) {
bool hero_protected = false;
if (minimum_shield_needed != 0
&& get_equipment().has_ability("shield", minimum_shield_needed)) {
// compute the direction corresponding to the angle between the enemy and the hero
double angle = hero.get_angle(*this);
int protected_direction4 = (int) ((angle + Geometry::PI_OVER_2 / 2.0) * 4 / Geometry::TWO_PI);
protected_direction4 = (protected_direction4 + 4) % 4;
// also get the direction of the enemy's sprite
int sprite_opposite_direction4 = -1;
if (this_sprite != NULL) {
sprite_opposite_direction4 = (this_sprite->get_current_direction() + 2) % 4;
}
// the hero is protected if he is facing the opposite of one of these directions
hero_protected = hero.is_facing_direction4(protected_direction4) ||
hero.is_facing_direction4(sprite_opposite_direction4);
}
if (hero_protected) {
attack_stopped_by_hero_shield();
}
else {
hero.hurt(*this, damage_on_hero, magic_damage_on_hero);
}
}
}