コード例 #1
0
ファイル: meteor.cpp プロジェクト: plokre/Game_design
Meteor::Meteor(const std::string& name) :
  Drawable(name,
           Vector2f(getVariation(name,"/startLoc/x", 
                                 Gamedata::getInstance().getXmlInt(name+"/minDist"), 
                                 Gamedata::getInstance().getXmlInt(name+"/maxDist")
                                ),
                   Gamedata::getInstance().getXmlInt(name+"/startLoc/y") 
                   ), 
           Vector2f(Gamedata::getInstance().getXmlInt(name+"/speedX"),                    
                    Gamedata::getInstance().getXmlInt(name+"/speedY")
                   ) 
           ),
  explosion(NULL),
  zoom(Gamedata::getInstance().getRandFloat( 0.2, 1.0 )),
  frame( FrameFactory::getInstance().getFrame(name) ),
  frameWidth(frame->getWidth()),
  frameHeight(frame->getHeight()),
  worldWidth(Gamedata::getInstance().getXmlInt("world/width")),
  worldHeight(Gamedata::getInstance().getXmlInt("world/height")),
  hasExploded( false )
{ 
  Vector2f change = getVelocity()*zoom; //This step was done in the constructor as an assignment statement because the zoom factor which is a part of this class can
  setVelocity( change );                //only be initialized after the base class members are initialized thus preventing us from directly initializing the velocity 
                                        //according to the size of the meteor to produce the depth effect.
}
コード例 #2
0
// update nextEventTime and currentEnergy
void EnergyPlanInfinitePeriod::updateState() {
  int simulationTime = Simulation::getTime();

  int periodTime = (simulationTime - offset) % period;
  if(periodTime < highTime + highTimeVariation) {
    currentWattage = highWattage;
    nextEventTime = simulationTime + highTime + highTimeVariation;
  } else {
    currentWattage = lowWattage;
    nextEventTime = simulationTime + (period - highTime - highTimeVariation);
    highTimeVariation = getVariation(maxHighTimeVariation);
  }
}
コード例 #3
0
EnergyPlanInfinitePeriod::EnergyPlanInfinitePeriod(const char * caller, int period,
                int highTime, int lowWattage, int highWattage, int maxHighTimeVariation
                ) : EnergyPlan(caller, false), offset(helper::RandomNumbers::getRandom(0, period)) {

  // sanity check
  if(highTime + maxHighTimeVariation/2 > period || highTime - maxHighTimeVariation/2 < 0)
    throw exception::EnergyException((holderName + ": maxHighTimeVariation too large: check device").c_str());
  //... TODO: mehr

  // setup
  this->period = period;
  this->highTime = highTime;
  this->lowWattage = lowWattage;
  this->highWattage = highWattage;
  this->maxHighTimeVariation = maxHighTimeVariation;

  this->currentWattage = 0;
  this->highTimeVariation = getVariation(maxHighTimeVariation);
  this->nextEventTime = offset;
}