void TrainingsController::load() { //movements std::ifstream confIn(rootPath + CONF_FILE); if (confIn.is_open()) { std::string name; while (std::getline(confIn, name)) { Properties prop(rootPath + name + ".txt"); Movement *movement = new Movement(prop.get("name"), prop.get("desc"), prop.getDouble("trans_x"), prop.getDouble("trans_y"), prop.getDouble("rotation"), prop.getDouble("compression")); addMovement(movement); } } else initDefault(); confIn.close(); //trainings confIn.open(rootPath + TRAININGS_FILE); int i = 0; if (confIn.is_open()) { std::string name; while (std::getline(confIn, name)) { std::ifstream in(rootPath + name + ".txt"); std::string mov; std::vector<Movement*> vec; while (std::getline(in, mov)) vec.push_back(getMovement(mov)); in.close(); trainings.push_back(new TrainingsProcedure(name, vec, i++)); } } confIn.close(); }
float getDrive(float drive) { int new_key = robot_keyboard_get_key(); if(new_key == (317-KEYB_OFF) && drive < MAX_FREQ) //arrow up { drive += DRIVE_STEP; robot_console_printf("drive : %f\n", drive); current_movement = getMovement(drive); } if(new_key == (319-KEYB_OFF) && drive > 0.0) //arrow down { drive -= DRIVE_STEP; robot_console_printf("drive : %f\n", drive); current_movement = getMovement(drive); } return drive; }
void BuddyPlayer::deathReset(){ setY(200); spawn_time = SPAWN_TIME; setMoving(true); setStatus(Status_Falling); setHealth(getMaxHealth()); setDeath(0); animation_current = getMovement("idle"); }
void SoldierLyzc::animationEvent( Armature *armature, MovementEventType movementType, const string& movementID ) { if (movementType == LOOP_COMPLETE || movementType == COMPLETE) { auto va = Value(movementID.substr(movementID.length() - 2,2).c_str()); _currentIndex = va.asInt(); if (_currentIndex != _degreeIndex) { getHead()->getAnimation()->play(getMovement(_currentIndex,_degreeIndex)); } else { setStatus(e_battle_status_attack); } } }
void BuddyPlayer::act( vector< Object * > * others, World * world, vector< Object * > * add ){ Character::act(others, world, add); if (show_life > getHealth()){ show_life--; } if (show_life < getHealth()){ show_life++; } vector<Object *> enemies; if (getStatus() != Status_Ground && getStatus() != Status_Jumping){ return; } filterEnemies(enemies, others); if (animation_current->Act()){ animation_current->reset(); // nextTicket(); // animation_current = movements[ "idle" ]; animation_current = getMovement("idle"); animation_current->reset(); } if (animation_current == getMovement("idle") || animation_current == getMovement("walk") ){ if (enemies.empty() && want_x == -1 && want_z == -1 && Util::rnd(15) == 0){ // want_x = Util::rnd( 100 ) - 50 + furthestFriend( others, getAlliance(), this ); want_x = Util::rnd(100) - 50 + (int) leader->getX(); want_z = Util::rnd(world->getMinimumZ(), world->getMaximumZ()); } else if (! enemies.empty()){ const Object * main_enemy = findClosest(enemies); if ( main_enemy->getX() > getX() ){ want_x = (int)(main_enemy->getX() - 20 - Util::rnd(20)); } else { want_x = (int)(main_enemy->getX() + 20 + Util::rnd(20)); } if (want_x < 1){ want_x = Util::rnd(100) - 50 + (int) leader->getX(); } want_z = (int)(Util::rnd(3) - 1 + main_enemy->getZ()); faceObject(main_enemy); if (Util::rnd(35) == 0){ vector<Util::ReferenceCount<Animation> > attacks; for (map<string, Util::ReferenceCount<Animation> >::const_iterator it = getMovements().begin(); it != getMovements().end(); it++){ Util::ReferenceCount<Animation> maybe = (*it).second; if (maybe->isAttack() && maybe->getStatus() == Status_Ground && maybe->getName() != "special"){ attacks.push_back(maybe); } } double attack_range = fabs( getX() - main_enemy->getX() ); double zdistance = ZDistance( main_enemy ); for (vector<Util::ReferenceCount<Animation> >::iterator it = attacks.begin(); it != attacks.end(); /**/){ Util::ReferenceCount<Animation> maybe = *it; if (attack_range > maybe->getRange() || zdistance > maybe->getMinZDistance()){ it = attacks.erase(it); } else { it++; } } if (!attacks.empty()){ animation_current = attacks[Util::rnd(attacks.size())]; world->addMessage(animationMessage()); nextTicket(); animation_current->reset(); return; } else { } } } if (want_x != -1 && want_z != -1){ bool walk = false; if (want_x < 1){ want_x = 1; } if (want_z < world->getMinimumZ()){ want_z = world->getMinimumZ() + 1; } if (want_z >= world->getMaximumZ()){ want_z = world->getMaximumZ() - 1; } if (getX() - want_x < -2){ moveX(getSpeed()); setFacing(FACING_RIGHT); walk = true; } else if (getX() - want_x > 2){ setFacing(FACING_LEFT); moveX(getSpeed()); walk = true; } if (getZ() < want_z){ moveZ(getSpeed()); walk = true; } else if (getZ() > want_z){ moveZ(-getSpeed()); walk = true; } if (walk){ animation_current = getMovement("walk"); } if (fabs(getX() - want_x) <= 2 && fabs(getZ() - want_z) <= 2){ want_x = -1; want_z = -1; animation_current = getMovement("idle"); } } } }
void Rectangle::onDisplay() { display(); move(getMovement()); }