void Animal::handleStimulus(Environment *environment, double dt) { voiceInterval -= dt; if (this == environment->getPlayer()) { Vector2D movement = environment->getMovement(); movement = movement.mult(dt); translate(movement); handleCollisions(environment); environment->updateObjectScreen(this); if (movement.distanceTo(Vector2D()) > 1.0e-5) { addEnergy(-dt); } for (int i = 0; i < sensors.size(); i++) { sensors[i]->handleStimulus(this, environment, dt); } } else { RandomNumberGenerator *rng = RandomNumberGenerator::getInstance(); if (curAIStateDuration > 0.0) { curAIStateDuration -= dt; } else { curAIStateDuration = ((double) rng->getInt(500, 3000)) / 1000.0; curAIDirection = Vector2D(rng->getInt(-1, 1), rng->getInt(-1, 1)); curAIDirection = curAIDirection.mult(speed); } Vector2D movement = curAIDirection; movement = movement.mult(dt); translate(movement); handleCollisions(environment); environment->updateObjectScreen(this); } }
Player::Player( const std::string& login, std::unique_ptr< const Home > home ): login( login ), mStore( new Store() ), mHome( std::move( home ) ), mEnergy( 0 ), mLastTimeAddEnergy( 0 ), mRoom(), mRestTime( 0 ), mFindItems( 0 ) { DASSERT( mHome ); DASSERT( !login.empty() ); mEnergy = mStore->loadLast< energy_t >( PLAYER_TABLE_STORE, "energy", login ); mLastTimeAddEnergy = mStore->loadLast< size_t >( PLAYER_TABLE_STORE, "lastTimeAddEnergy", login ); if (mLastTimeAddEnergy == 0) { mLastTimeAddEnergy = currentTime() / 1000; } // рассчитаем энергию исходя из последнего запуска игры под этим логином addEnergy(); // поможем игроку, предоставив запас энергии, если у него её нет if (mEnergy < MIN_ENERGY) { mEnergy = MIN_ENERGY; } }
void BarGraph::presentation_up(){ for (int i = 0; i < 10; i++) { addEnergy(1); updateBarGraph(); delay(400); } }
void PlayerUnit::update(){ move(); exchangeBoost(); boost ? boostShot() : normalShot(); if(cnt == 120){ EnemyBulletMng.setCreate(true); } cnt >= 180 ? collision = true : ++cnt; collideJudge(); PlayerMng.update(this); addEnergy(1.0f / 30.0f); if(device->input(KEY_SLOW)){ if(++m_bcnt > 20){ addEnergy(1.0f / 45.0f); } } else { m_bcnt = 0; } }
//agent interaction with resources Piece &Agent::interact(Resource *resource) { addEnergy(resource->consume()); return *this; }