Example #1
0
 static inline
 void level3( T &p0, T &p1, T &p2 )
 {
     level2(p0, p1);
     level2(p1, p2);
     level2(p0, p1);
 }
Example #2
0
 static inline
 void level4( T &p0, T &p1, T &p2, T &p3 )
 {
     level2(p0, p1);
     level2(p2, p3);
     level2(p0, p2);
     level2(p1, p3);
     level2(p1, p2);
 }
Example #3
0
 static inline
 void level6( T &p0, T &p1, T &p2, T &p3, T &p4, T &p5)
 {
     level3(p0, p1, p2);
     level3(p3, p4, p5);
     level2(p0, p3);
     level2(p2, p5);
     level4(p1, p2, p3, p4);
 }
Example #4
0
float smallcalc::Parser::level1()
{
	float ans = level2();
	TOKEN_TYPE operator_id = token_type;
	while (operator_id == ADDITION_OP || operator_id == SUBSTRACTION_OP)
	{
		next_token();
		ans = eval_operator(operator_id, ans, level2());
		operator_id = token_type;
	}
	return ans;
}
Example #5
0
void CMPolynomial::level1(double& result)    // logical
{
	register int op;
	double hold;

	level2(result);
	while (islogical(token)) {
		op = token;
		get_token();
		level2(hold);
		logical(op,result,hold);
	}
}
Example #6
0
void mapseq()
{
	switch(next)
	{
		case 0:menu();sidemenu();break;
		case 98:levelskip();break;
		case 1:level1();break;
		case 2:level2();break;
		case 3:level3();break;
		case 4:level4();break;
		case 5:level5();break;
		case 101:levelskip();break;
		case 6:level6();break;
		case 7:level7();break;
		case 8:level8();break;
		case 9:level9();break;
		case 10:level10();break;
		case 102:levelskip();break;
		case 11:level11();break;
		case 12:level12();break;
		case 13:level13();break;
		case 14:level14();break;
		case 15:level15();break;
		case 103:levelskip();break;
		case 16:win();break;
		case 99:help();break;
		case 100:lose();elapsedTime=0;break;
	}
}
Example #7
0
//int tracking(ClientData clientData, Tcl_Interp* interp, int argc, const char** argv)
int tracking( int argc, const char** argv)
{
 level1();
 level2();
 level3();

 return 0;
}
Example #8
0
int
main(int argc, char ** argv)
{
    std::cout << "I'm such a _deep_ sample" << std::endl;
    level1();
    level2();    
    return 0;
}
Example #9
0
/* Entry point into parser. */
void get_exp(double* result){

  get_token();  
  //  printf("getexpparser: <%s> ...to level2 \n", bas_token );

  if(!*bas_token) {
    serror(2);
    return;
  }
  level2(result);
  //  printf("Parser: res=<%lf> \n", result );
  putback(); /* return last bas_token read to input stream */
}
Example #10
0
/* Process parenthesized expression. */
void level6(double* result){
  if((*bas_token == '(') && (bas_token_type == DELIMITER)) {
    get_token(); 
    //  printf("level6 <%s>, descending into level2\n", bas_token );
    level2(result); 
    //  printf("level6 <%s>, back       from level2\n", bas_token );
    if(*bas_token != ')')
      serror(1);
    get_token(); 
  }
  else
    primitive(result);
}
Example #11
0
void pacmanGame()
{
	lcdSetBackgroundColour(BACKGROUND_COLOUR);
	lcdSetFontColour(FOREGROUND_COLOUR);
	lcdSetCursor(0, 0);
	lcdPixelsDraw(240 * 320, BACKGROUND_COLOUR);
	lcdPrint(10, 10, "PACMAN");
	wait(1000000);
	lcdPrint(50, 10, "MOVE WITH 2,4,5,6");
	wait(1000000);
	lcdPrint(76, 10, "PRESS A TO START");
	while (kBuffer != 3)
		continue;
	kBuffer = 16;
	lcdFillWindow(0, 239, 0, 319, BACKGROUND_COLOUR);
	lcdPrint(112, 80, "LEVEL 1");
	wait(1000000);
	pacman::lifes = 3;
	while (1) {
		if (level1()) {
			pacman::lifes = 3;
			pacman::score = 0;
			continue;
		}
		if (level2()) {
			pacman::lifes = 3;
			pacman::score = 0;
			continue;
		}

		if (level3()) {
			pacman::lifes = 3;
			pacman::score = 0;
			continue;
		}

		if (level4()) {
			pacman::lifes = 3;
			pacman::score = 0;
			continue;
		}
	}

}
Example #12
0
void level1_5(double *hold)
{
	char op;

	op = 0;
	if (((token_type) == DELIMITER) && *(token) == '!')
	{
		op = *(token);
		get_token();
	}
	level2( hold);

	if (op)
	{
		if (*hold == 0.0)
			*hold = 1.0;
		else
			*hold = 0.0;
	}
}
Example #13
0
SeaScene::SeaScene(QObject *parent) :
    QGraphicsScene(parent)
{

    setItemPointersNull();

    paused_ = false;
    screenLitKeeper_.keepScreenLit(true);

    QSettings settings;

    //set background

    QPixmap waves (":/pix/meri.png");
    waves.scaled(20,20);
    setBackgroundBrush(QBrush(waves));

    //set random seed

    qsrand(QTime::currentTime().msec()+2);  //+2 to avoid setting it to 1



//Setup level sets

    QList<Level> levelList;
    Level level1(5,10);
    levelList.append(level1);
    Level level2(5,10,2,50);
    levelList.append(level2);
    Level level3(5,15,2,50);
    levelList.append(level3);
    Level level4(5,15,4,50);
    levelList.append(level4);
    Level level5(5,15,5,100);
    levelList.append(level5);

    Levelset set ("Original",levelList);
    availableLevelsets_.append(set);


    //Create another set of levels and place it in the available levelsets list
    levelList.clear();
    Level set2level1(8,15,4,50);
    levelList.append(set2level1);
    Level set2level2(8,20,4,50);
    levelList.append(set2level2);
    Level set2level3(8,20,5,80);
    levelList.append(set2level3);
    Level set2level4(8,20,6,120);
    levelList.append(set2level4);
    Level set2level5(8,25,8,150);
    levelList.append(set2level5);

    Levelset set2("Difficult",levelList);
    availableLevelsets_.append(set2);


    //Setup starting levelset

    QString levelname = settings.value("levelset","Original").toString();
    bool found = false;
    foreach (Levelset levelset, availableLevelsets_)
    {
        if (levelset.getName() == levelname)
        {
            levelset_ = levelset;
            found = true;
            break;
        }
    }

    if (!found)  //The last used level is not available
    {
        levelset_ = availableLevelsets_.value(0);
    }

    currentLevel_ = 0;

    totalScore_ = 0;



    connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));

    pVibrateAction_ = new QAction(tr("Vibration effects"),this);
    pVibrateAction_->setCheckable(true);
    connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool)));

    pVibrateAction_->setChecked(settings.value("vibration",false).toBool());


    pPauseAction_ = new QAction(tr("Pause"),this);
    pPauseAction_->setCheckable(true);
    connect(pPauseAction_,SIGNAL(toggled(bool)),this,SLOT(pause(bool)));


    deviceLockPollTimer_.setInterval(20*60);
    connect(&deviceLockPollTimer_,SIGNAL(timeout()),this,SLOT(pollDeviceLocked()));
    deviceLockPollTimer_.start();


    autopauseTimer.setSingleShot(true);
    autopauseTimer.setInterval(15*60*1000);
    connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn()));


}
Example #14
0
int main(int argc, char *argv[])
{
	SDL_Init(SDL_INIT_VIDEO);
	displayWindow = SDL_CreateWindow("Final Project", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL);
	SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
	SDL_GL_MakeCurrent(displayWindow, context);
#ifdef _WINDOWS
	glewInit();
#endif

	ShaderProgram* program = new ShaderProgram(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glViewport(0, 0, 640, 480);

	Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);

	Matrix modelMatrix;
	Matrix textMatrix;
	Matrix viewMatrix;
	Matrix projectionMatrix;
	projectionMatrix.setOrthoProjection(-10.0f, 10.0f, -7.5f, 7.5f, -1.0f, 1.0f);
	
	std::vector<Entity> entities;

	int lastWinner;

	// Load player sprites
	GLint paddleBlue = LoadTextureClamp(RESOURCE_FOLDER"assets\\paddleBlu.png");
	GLint paddleRed = LoadTextureClamp(RESOURCE_FOLDER"assets\\paddleRed.png");
	// Load item sprites
	GLint coinCopperSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\coinCopper.png");
	GLint coinSilverSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\coinSilver.png");
	GLint coinGoldSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\coinGold.png");
	GLint coinPlatinumSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\coinPlatinum.png");
	GLint starCopperSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\starCopper.png");
	GLint starSilverSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\starSilver.png");
	GLint starGoldSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\starGold.png");
	GLint starPlatinumSprite = LoadTextureClamp(RESOURCE_FOLDER"assets\\starPlatinum.png");
	// Load font
	GLuint fontSheet = LoadTextureClamp(RESOURCE_FOLDER"assets\\font1.png");
	// Load level bg
	GLint mainBG = LoadTextureRepeat(RESOURCE_FOLDER"assets\\bg_main.png");
	GLint levelBG = LoadTextureRepeat(RESOURCE_FOLDER"assets\\bg_level.png");
	GLint overBG = LoadTextureRepeat(RESOURCE_FOLDER"assets\\bg_over.png");

	// Load music
	Mix_Music *music1;
	music1 = Mix_LoadMUS(RESOURCE_FOLDER"assets\\Im Free.mp3");
	Mix_Music *music2;
	music2 = Mix_LoadMUS(RESOURCE_FOLDER"assets\\Lagrima.mp3");
	Mix_Music *music3;
	music3 = Mix_LoadMUS(RESOURCE_FOLDER"assets\\The Old Song.mp3");
	Mix_Music *music4;
	music4 = Mix_LoadMUS(RESOURCE_FOLDER"assets\\FASE.mp3");
	// Load sounds
	Mix_Chunk* itemHit;
	itemHit = Mix_LoadWAV(RESOURCE_FOLDER"hit.wav");
	Mix_Chunk* buttonPress;
	buttonPress = Mix_LoadWAV(RESOURCE_FOLDER"Menu Selection Click.wav");


	// Initialize players
	Entity playerBlue(ENTITY_PLAYER, paddleBlue, fontSheet, SDL_SCANCODE_A, SDL_SCANCODE_D, -5.0f);
	Entity playerRed(ENTITY_PLAYER, paddleRed, fontSheet, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, 5.0f);

	Entity coinCopper(ENTITY_ITEM, coinCopperSprite, fontSheet, 10, buttonPress);
	Entity coinSilver(ENTITY_ITEM, coinSilverSprite, fontSheet, 25, buttonPress);
	Entity coinGold(ENTITY_ITEM, coinGoldSprite, fontSheet, 50, buttonPress);
	Entity coinPlatinum(ENTITY_ITEM, coinPlatinumSprite, fontSheet, 100, buttonPress);
	Entity starCopper(ENTITY_ITEM, starCopperSprite, fontSheet, 100, buttonPress);
	Entity starSilver(ENTITY_ITEM, starSilverSprite, fontSheet, 250, buttonPress);
	Entity starGold(ENTITY_ITEM, starGoldSprite, fontSheet, 500, buttonPress);
	Entity starPlatinum(ENTITY_ITEM, starPlatinumSprite, fontSheet, 1000, buttonPress);

	entities.push_back(playerBlue);
	entities.push_back(playerRed);
	entities.push_back(coinCopper);
	entities.push_back(coinSilver);
	entities.push_back(coinGold);
	entities.push_back(coinPlatinum);
	entities.push_back(starCopper);
	entities.push_back(starSilver);
	entities.push_back(starGold);
	entities.push_back(starPlatinum);

	Level level1(LEVEL_FREEPLAY, fontSheet, levelBG, music3, entities);
	Level level2(LEVEL_CLOCKED, fontSheet, levelBG, music4, entities);
	Level level3(LEVEL_SCORED, fontSheet, levelBG, music1, entities);

	Mix_PlayMusic(music3, -1);

	SDL_Event event;
	bool done = false;
	while (!done) {
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
				done = true;
			}
		}
		glClear(GL_COLOR_BUFFER_BIT);

		program->setModelMatrix(modelMatrix);
		program->setViewMatrix(viewMatrix);
		program->setProjectionMatrix(projectionMatrix);
		glUseProgram(program->programID);

		switch (state)
		{
		case MAIN_MENU:
			RenderBG(program, mainBG);
			if (keys[SDL_SCANCODE_1]) { // Press 1 to get into game level
				state = GAME_LEVEL_1;
				Mix_PlayChannel(-1, buttonPress, 0);
				Mix_PlayMusic(level1.getBgm(), -1);
			}
			if (keys[SDL_SCANCODE_2]) { // Press 2 to get into game level
				state = GAME_LEVEL_2;
				Mix_PlayChannel(-1, buttonPress, 0);
				Mix_PlayMusic(level2.getBgm(), -1);
			}
			if (keys[SDL_SCANCODE_3]) { // Press 3 to get into game level
				state = GAME_LEVEL_3;
				Mix_PlayChannel(-1, buttonPress, 0);
				Mix_PlayMusic(level3.getBgm(), -1);
			}
			if (keys[SDL_SCANCODE_ESCAPE]){
				done = true;
			}
			break;
		case GAME_LEVEL_1:
			if (!level1.isComplete()){
				level1.Update();
				level1.FixedUpdate();
				level1.Render(program);
				level1.RenderText(program);
			}
			else {
				lastWinner = level1.getWinner();
				state = MAIN_MENU;
				level1.reset();
				Mix_PlayMusic(music3, -1);
			}
			break;
		case GAME_LEVEL_2:
			if (!level2.isComplete()){
				level2.Update();
				level2.FixedUpdate();
				level2.Render(program);
				level2.RenderText(program);
			}
			else {
				lastWinner = level2.getWinner();
				state = GAME_OVER;
				level2.reset();
				Mix_PlayMusic(music3, -1);
			}
			break;
		case GAME_LEVEL_3:
			if (!level3.isComplete()){
				level3.Update();
				level3.FixedUpdate();
				level3.Render(program);
				level3.RenderText(program);
			}
			else {
				lastWinner = level3.getWinner();
				state = GAME_OVER;
				level3.reset();
				Mix_PlayMusic(music3, -1);
			}
			break;
		case GAME_OVER:
			RenderBG(program, overBG);
			program->setModelMatrix(textMatrix);
			textMatrix.identity();
			textMatrix.Translate(-7.5f, 0.0f, 0.0f);
			if (lastWinner == 0)
				DrawText(program, fontSheet, "Blue Player wins!", 1.0f, 0.005f);
			else if (lastWinner == 1)
				DrawText(program, fontSheet, "Red Player wins!", 1.0f, 0.005f);
			if (keys[SDL_SCANCODE_RETURN]) {
				level1.reset();
				level2.reset();
				level3.reset();
				state = MAIN_MENU;
				Mix_PlayChannel(-1, buttonPress, 0);
			}
			else if (keys[SDL_SCANCODE_ESCAPE]) {
				done = true;
			}
			break;
		}

		SDL_GL_SwapWindow(displayWindow);
	}

	SDL_Quit();
	return 0;
}
Example #15
0
int
Tree_Test::execute (TAO_Naming_Client &root_context)
{
  try
    {
      // Create a tree of contexts: root->level1->level2.  Bind object
      // foo under context level2.

      // Bind level1 context under root.
      CosNaming::Name level1;
      level1.length (1);
      level1[0].id = CORBA::string_dup ("level1_context");
      CosNaming::NamingContext_var level1_context;
      level1_context = root_context->bind_new_context (level1);

      // Create a new context.
      CosNaming::NamingContext_var level2_context;
      level2_context = root_context->new_context ();

      // Instantiate a dummy object and bind it under the new context.
      My_Test_Object *impl1 =
        new My_Test_Object (CosNaming_Client::OBJ1_ID);
      Test_Object_var obj1 = impl1->_this ();
      impl1->_remove_ref ();

      CosNaming::Name obj_name;
      obj_name.length (1);
      obj_name[0].id = CORBA::string_dup ("foo");
      level2_context->bind (obj_name, obj1.in ());

      // Bind the context we just created under level1.
      CosNaming::Name level2 (level1);
      level2.length (2);
      level2[1].id = CORBA::string_dup ("level2_context");
      root_context->bind_context (level2,
                                  level2_context.in ());

      // Resolve and unbind level1/level2/foo, and bind it back.
      CosNaming::Name test_name (level2);
      test_name.length (3);
      test_name[2].id = obj_name[0].id;
      CORBA::Object_var result_obj_ref =
        root_context->resolve (test_name);
      Test_Object_var result_object =
        Test_Object::_narrow (result_obj_ref.in ());

      if (CORBA::is_nil (result_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Problems with resolving foo in Tree Test - nil object ref.\n"),
                          -1);

      CORBA::Short id = result_object->id ();

      if (id != CosNaming_Client::OBJ1_ID)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Problems with resolving foo in Tree Test - wrong id.\n"),
                          -1);

      // Unbind the object from the Naming Context and bind it back
      // in.
      root_context->unbind (test_name);
      root_context->bind (test_name,
                          obj1.in ());

      // Create new context and rebind under the name level1/level2.
      CosNaming::NamingContext_var new_level2_context;
      new_level2_context =
        root_context->new_context ();
      root_context->rebind_context (level2,
                                  new_level2_context.in ());

      // Bind, resolve, rebind, and resolve foo under level1/level2.
      root_context->bind (test_name,
                          obj1.in ());
      result_obj_ref = root_context->resolve (test_name);
      result_object = Test_Object::_narrow (result_obj_ref.in ());

      CORBA::Short obj_id = result_object->id ();

      if (CORBA::is_nil (result_object.in ())
          || !(obj_id == CosNaming_Client::OBJ1_ID))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Problems in the Tree Test\n"),
                          -1);

      My_Test_Object *impl2 =
        new My_Test_Object (CosNaming_Client::OBJ2_ID);
      Test_Object_var obj2 = impl2->_this ();

      impl2->_remove_ref ();

      root_context->rebind (test_name,
                            obj2.in ());
      result_obj_ref = root_context->resolve (test_name);
      result_object = Test_Object::_narrow (result_obj_ref.in ());

      obj_id = result_object->id ();

      if (CORBA::is_nil (result_object.in ())
          || !( obj_id == CosNaming_Client::OBJ2_ID))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Problems with rebind in Tree Test\n"),
                          -1);
    }

  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception in Tree test");
      return -1;
    }


  ACE_DEBUG ((LM_DEBUG,
              "All functions work properly\n"));
  return 0;
}
Example #16
0
 static inline
 void level2( T *p )
 {
     assert(p);
     level2(p[0],p[1]);
 }
/**
Inputs: 
none

Returns: the initialized World object ready to be played
*/
world makeGame(short int level, short int numPlayers,int score){
    
    world gameWorld;
    gameWorld.nProj = 0;
    gameWorld.projList = (projectile*)calloc(MAX_PROJECTILES,sizeof(projectile));
    gameWorld.currentTime = 0; 
    
    gameWorld.player1 = (ship*)malloc(sizeof(ship));
    gameWorld.player1->AI_routine = NULL;
    gameWorld.player1->x_pos = (WORLD_X_SIZE/8)*3;
    gameWorld.player1->y_pos = WORLD_Y_SIZE-15;    
    gameWorld.player1->x_accel = 0; 
    gameWorld.player1->y_accel = UP;   
    gameWorld.player1->isAlive = 1;
    gameWorld.player1->last_x = 0;
    gameWorld.player1->last_y = 0;
    gameWorld.player1->dimensionID = 8;
    gameWorld.player1->startTime = 0;
    gameWorld.player1->ID = RESERVED_PLAYER1_ID;
    gameWorld.player1->drawPixels =  drawDIM8;
    gameWorld.player1->erase = eraseDIM8;
    gameWorld.player1->drawID = collideDIM8;    
    gameWorld.player1->AI_routine = NULL;
    gameWorld.player1->health = MAX_HEALTH;
    gameWorld.player1->lastHit = 0;
    
    gameWorld.score = score;
    
    if(numPlayers == 1){
        gameWorld.player2 = NULL; 
    }
    else{
    gameWorld.player2 = (ship*)malloc(sizeof(ship));
    gameWorld.player2->AI_routine = NULL;
    gameWorld.player2->x_pos = (WORLD_X_SIZE/8)*5;
    gameWorld.player2->y_pos = WORLD_Y_SIZE-15;    
    gameWorld.player2->x_accel = 0; 
    gameWorld.player2->y_accel = UP;   
    gameWorld.player2->isAlive = 1;
    gameWorld.player2->last_x = 0;
    gameWorld.player2->last_y = 0;
    gameWorld.player2->dimensionID = 8;
    gameWorld.player2->startTime = 0;
    gameWorld.player2->ID = RESERVED_PLAYER2_ID;
    gameWorld.player2->drawPixels =  drawDIM7;
    gameWorld.player2->erase = eraseDIM7;
    gameWorld.player2->drawID = collideDIM7;    
    gameWorld.player2->AI_routine = NULL;
    gameWorld.player2->health = MAX_HEALTH;
    gameWorld.player2->lastHit = 0;
    }
    
    if(level == 1){
        return level1(gameWorld);
    }
    else if(level == 2){
        return level2(gameWorld);
    }
    else if(level == 3){
        return level3(gameWorld);
    }
    else{
        return level1(gameWorld);
    }
}
Example #18
0
void level1(int t)
{
  level2(t);
}
//Returns a full matrix containing the density matrix at the final time
inline matrix<std::complex<double> > RobustGrape::GetPopulations (const size_t point, size_t initial_level){
	//the measure implemented, phi (PHI_0) is phi = trace[rho_desired* UN-1....U_0 rho_initial U_0\dg ... U_N-1\dg]
	char outfile[50];
	//Some flags to make sure all parameters are set
	size_t test=0;
	for(size_t k = 0; k < num_controls_; ++k)
	{
		test+=controlsetflag_[k];
		if(verbose==yes)
		{
		 	std::cout << k << "th control flag is " << controlsetflag_[k] << std::endl;
		}
	}
	if(test != 0)
		UFs::MyError("Grape::StateTransfer(): you have not set the drift and all control hamiltonians:\n");
		
	
	//Set the counters to zero
	count_ =0;
	pos_count_ =0;
	//the power scale for epsilot (epsilon = base_a^power_)
	power_ =0;
	// fidelity ranges from 0 to 1 with 0 be orthogonal and 1 being the same time
	double current_fidelity=0.0, current_delta_fidelity=1.0, last_fidelity=-1.0;
		
	// the propagators and the foraward evolution
	for(size_t j = 0; j < num_time_; ++j){
		Htemp_ = H_drift_[point];
		for(size_t k = 0; k < num_controls_; ++k){
			Htemp_ += controls_[k][j]*H_controls_[point][k];
		}
		// std::cout << Htemp_ << std::endl;
		Unitaries_[point][j]=ExpM::EigenMethod(Htemp_,-i*h_);
		if(j==0){
			rho_[point][0] = Unitaries_[point][0]*rho_initial_*MOs::Dagger(Unitaries_[point][0]);
		}
		else{
			rho_[point][j] = Unitaries_[point][j]*rho_[point][j-1]*MOs::Dagger(Unitaries_[point][j]);
		}
	}
		
	//Initialize the matrices used to compute the populations
	matrix<std::complex<double> > populations;
	populations.initialize(num_time_,dim_);

	matrix<std::complex<double> > level, propagator, currentLevel, level2, step, tempMatrix, tempMatrix2;
	level.initialize(dim_,dim_);
	MOs::Null(level);
	
	propagator.initialize(dim_,dim_);
	MOs::Null(propagator);
	
	currentLevel.initialize(dim_, 1);
	MOs::Null(currentLevel);
	
	level2.initialize(dim_, 1);
	MOs::Null(level2);
	
	step.initialize(dim_, 1);
	MOs::Null(step);
	
	tempMatrix.initialize(1, 1);
	MOs::Null(tempMatrix);
	
	tempMatrix2.initialize(1, dim_);
	MOs::Null(tempMatrix2);

	
	for (int i=0; i < dim_; i++)
	{
		level(i, dim_-i-1)=1;
	}
	//Create the initial state selection vector 
	level2(dim_ - initial_level -1, 0)=1;
	
	for (int k=0; k < num_time_; k++)	//Go through each time step
	{
		step=propagator*level2;
		
		for (int j=0; j < dim_; j++)	//Go through each quantum level
		{
			MOs::Null(currentLevel);		
			currentLevel(dim_ -j -1, 0)=1;
			tempMatrix2=MOs::Dagger(currentLevel * step);
			tempMatrix=MOs::Dagger(currentLevel * step)*(currentLevel * step);
			populations(k,j)=tempMatrix(0,0);	//Time=row, Level=col			//This is the occupancy of each level
			//populations[j](0,k)=tempMatrix(0,0);	//Time=Columns, Level=row 
		}
	
		if (k!=num_time_) propagator = rho_[point][k] * propagator;
		if (verbose==yes)
		{
			std::cout << "--------------------Propogator------------------------------" << std::endl;
			USs::OutputMatrix(propagator);
			std::cout << "------------------------------------------------------------" << std::endl;
		}
	} 
	
	return populations;
	//Output the populations to file
//	string line;
//	ofstream moredataout (outfile, ios::app);
//	for(size_t j = 0; j < num_time_; ++j)	//Go through each time step
//	{
//		line=j*h_;
//		for (size_t i=0; i < dim_; i++)			//Go through each dimension of the Hilbert space
//		{
//			line=line "\t" + populations[i](0,j);
//		}
//		//Output line to file
//		moredataout << line << '\n';
//	}
	
//	dataout.close();
}
Example #20
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Player cat("cat.png", lvl, player.rect.left, player.rect.top, 60, 120, 55, 25);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf;
	buf.loadFromFile("music/steklo.ogg");
	Sound glass;
	glass.setBuffer(buf); glass.setVolume(100);

	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187);
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450);
	 int cntMeow = 0;
	 Object ob = lvl.GetObject("catPlace");
	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

			if (event.type == Event::MouseButtonPressed){
					if (event.key.code == Mouse::Left)
					{
						int cntMeow = meow(meow1, meow2, cat, pos);
						//>>>>>>BALL<<<<<<<<<<<<<<
						if(cat.sprite.getGlobalBounds().intersects(ob.rect))
						{
							if(cntMeow == -1)
							{
								ball.falling(event, window, pos, lvl, time);
								glass.play();
								ball.moving(event, window, pos, "ball", lvl);
							}
						}
						cat.clickedThings(window, light);
						//BOOKS>>>>----<<<<<<
						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}

					}
			}		
					
					toys.moving(event, window, pos, "toys", lvl);
					if(light.isPlayed == false)
						light.moving(event, window, pos, "light", lvl);
					

	
        }
		
		

		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(light.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
			window.draw(brokenBall.sprite);
		window.draw(books.sprite);



		if(cat.room == 2){
			window.draw(bath.sprite);
			window.draw(mirror.sprite);
			window.draw(sink.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		

		window.draw(cat.sprite);
		
		window.display();
    }

}
Example #21
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 Music skyrim, muse, bathMus;
	 bathMus.openFromFile("music/bath.ogg");
	 Object mus = lvl.GetObject("muse");
	 muse.openFromFile("music/synd.ogg"); muse.setVolume(100);
	 skyrim.openFromFile("music/skyrim.ogg"); skyrim.setVolume(100);
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Object fish = lvl.GetObject("fish");
	 Object mo = lvl.GetObject("mouse");
	 Object ob = lvl.GetObject("catPlace");


	 Player cat("cat.png", lvl, 68, 429, 60, 120, player.rect.left,  player.rect.top, ELSE);
	 
	 Clock clock;
	 Clock gameTimeClock;
	 int sinkCnt = 0;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf, buf3;
	buf.loadFromFile("music/steklo.ogg");
	buf3.loadFromFile("music/mouse.ogg");
	Sound glass; Sound mouseS;
	glass.setBuffer(buf); glass.setVolume(100);
	mouseS.setBuffer(buf3);
	
	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215, POSTERS);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440, ELSE); 
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545, TOYS);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83, SHELF);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305, CABINET); 
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385, MOP); 
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285, ELSE);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190, BALL); 
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187, BOOKS); 
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430, ELSE); 
	 Furniture key("tayles1.png", 1, 1, 25, 25, 430, 425, KEY);
	 Furniture cabinetEnd("cabinet.png", 20, 50, 270, 350, 590, 290, ELSE); 
	 Furniture girl("girlHair.png", 1,1, 96, 45, 1075, 350, ELSE);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350, ELSE);
	 Furniture puddle("tayles1.png",789, 1000, 204, 75, 1057, 559, ELSE);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430, ELSE);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565, ELSE);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330, BATH);
	 Furniture openBath("bathr.png", 264, 79, 339, 369, 1015, 315, ELSE);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530, ELSE);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300, ELSE);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450, SINK);
	 Furniture sinkWater("bathr.png", 22, 180, 197, 427, 1200, 540, ELSE);
	 Furniture mou("mouse.png",  2, 21, 32, 25, mo.rect.left, mo.rect.top, ELSE);
	 
	 
	 std::list<Furniture> fList;
	 std::list<Furniture>::iterator it;
	 fList.push_back(posters);
	 fList.push_back(toys);
	 fList.push_back(upShelf);
	 fList.push_back(cabinet);
	 fList.push_back(mop);
	 fList.push_back(ball);
	 fList.push_back(books);
	 fList.push_back(key);
	 fList.push_back(puddle);
	 fList.push_back(brokenLight);
	 fList.push_back(bath);
	 fList.push_back(sink);
	 for(it = fList.begin(); it != fList.end(); it++){
		 it->setSub((void *)&it, writeMess);
	 }

	 int cntMeow = 1, cntGame = 0, click = 0, clickBath = 1, clickSink = 1;
	 bath.isPlayed = true;
	 sink.isPlayed = true;


	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		float sinkTime = gameTimeClock.getElapsedTime().asSeconds();
		if(clickSink < 2)
			gameTimeClock.restart();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);
		
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();

			if (event.type == Event::MouseButtonPressed)
				if (event.key.code == Mouse::Left){

					if (fish.rect.contains(pos.x, pos.y) && key.isPlayed == true){
						mainSong.stop();
						finish();
						window.close();
					}
					if (cat.sprite.getGlobalBounds().contains(pos.x, pos.y))
					{
						cntMeow++;
						if(cntMeow == 5)
						{
							meow2.play();
							cntMeow = 0;
						}
						else
							meow1.play();
					}
					 
					toys.trueMove(pos);
					if(light.isPlayed == false) light.trueMove(pos);
					if(ball.isPlayed == true && books.isPlayed == true) key.trueMove(pos);
					if(puddle.isPlayed == true) mop.trueMove(pos);
					click = light.clickedThings(pos);
					clickBath = bath.clickedThings(pos);
					clickSink = sink.clickedThings(pos);


					if (upShelf.sprite.getGlobalBounds().contains(pos.x, pos.y)){
						skyrim.play();
					}
					if (mus.rect.contains(pos.x, pos.y)){
						muse.play();
					}
					if (girl.sprite.getGlobalBounds().contains(pos.x, pos.y) && cat.room == 2){
						mainSong.pause();
						gameOver();
						mainSong.play();
					}
					if(mou.isPlayed == false)
						{
							if (mou.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								mouseS.play();
								//gameRunning();
								mou.isPlayed = true;
								mainSong.play();
							}
						}

						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}
				}
					
			if (event.type == Event::MouseButtonReleased)
				if (event.key.code == Mouse::Left){
					toys.isMove = false;
					key.isMove = false;
					if(light.isPlayed == false) light.isMove = false;
					 mop.isMove = false;
				}
		}
		if(sinkTime > 5 && clickSink == 2) puddle.isPlayed = true;

		if(clickBath == 2 && cat.room == 2)
			bathMus.play();

		if(click == -1){}
		else if(click == 1 || click == 2)
			cat.room = click;
		toys.intersect("toys",lvl); toys.move(pos); 
		if(mop.isPlayed == false)
		{
			mop.intersect("mop", lvl);
			mop.move(pos);
		}
		if(light.isPlayed == false) 
		{
			light.intersect("light", lvl);
			light.move(pos);
		}
		if(ball.isPlayed == true && books.isPlayed == true){
			if(mop.isPlayed == true)
				key.intersect("key", lvl);
			if(key.isPlayed == false)
				key.move(pos);
		}
		if(ball.isPlayed == false && books.isPlayed == true){
			if(cat.sprite.getGlobalBounds().intersects(ob.rect))
			{
				if(cntMeow == 0)
				{
					ball.falling(event, window, pos, lvl, time);
					glass.play();
					ball.isPlayed = true;
					ball.intersect("ball", lvl);
				}
			}
		}
        
      
		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		if(key.isPlayed == true)
			window.draw(cabinetEnd.sprite);
		else
			window.draw(cabinet.sprite);
		window.draw(upShelf.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
		{
			window.draw(brokenBall.sprite);
			window.draw(key.sprite);
		}
		window.draw(books.sprite);

		
		if(mou.isPlayed == false){
			window.draw(mou.sprite);
		}
		else
			window.draw(light.sprite);
		window.draw(toys.sprite);


		if(cat.room == 2){
				
			 if(clickBath == 2){
				window.draw(girl.sprite);
				window.draw(openBath.sprite);
			 }
			 else
				 window.draw(bath.sprite);
			window.draw(mirror.sprite);

			 if(clickSink == 2)
				window.draw(sinkWater.sprite);
			 else
				 window.draw(sink.sprite);

			 if(puddle.isPlayed == true && mop.isPlayed == false)
				window.draw(puddle.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		if(mop.isPlayed == false)
			window.draw(mop.sprite);
		window.draw(cat.sprite);

		for(it = fList.begin(); it != fList.end(); it++)
			{
				if(it->sprite.getGlobalBounds().contains(pos.x, pos.y))
				{
					if(it->f.cb_fn != NULL)
					{
						cb_fn fn;
						fn = (cb_fn)it->f.cb_fn;
						fn(&window, it->type, &pos);
					}
				}
			}
		
		window.display();
    }

}