コード例 #1
0
ファイル: Logic.cpp プロジェクト: henriquegemignani/jigsaw
void Logic::HandleEvent(const SDL_Event& event) {
    if( pieces_.get_matches() >= layout_.total()) {
        // do nothing
    }
    else if( event.type == SDL_MOUSEBUTTONDOWN ) {
        cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y);
        if(event.button.button == SDL_BUTTON_LEFT/* && !rightdrag*/) {
            leftDown();

        } else if(event.button.button == SDL_BUTTON_RIGHT) {
            rightDown();
        }

    } else if( event.type == SDL_MOUSEBUTTONUP ) {
        cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y);
        if(event.button.button == SDL_BUTTON_LEFT/* && rect_up*/) {
            leftUp();

        } else if(event.button.button == SDL_BUTTON_RIGHT) {
            rightUp();
        }
    }
    else if( event.type == SDL_MOUSEMOTION ) {
        // Keep track of the mouse position in a handy format.
        cursor_.position = layout_.ScreenToGame(event.motion.x, event.motion.y);
    }
}
コード例 #2
0
void individualMove(struct board_position pos, int i, int j, int turn, int *nc, char *child_ptr) 
{
	struct board_position p;
	
	if (pos.board[i][j] != WPAWN) {
		p = pos;
		if (leftDown(p.board, i, j)) {
			insert_into_array(p, *nc, child_ptr);
			(*nc)++;
		}
		p = pos;
		if (rightDown(p.board, i, j)) {
			insert_into_array(p, *nc, child_ptr);
			(*nc)++;
		}
	}

	if (pos.board[i][j] != BPAWN) {
		p = pos;
		if (leftUp(p.board, i, j)) {
			insert_into_array(p, *nc, child_ptr);
			(*nc)++;
		}
		p = pos;
		if (rightUp(p.board, i, j)) {
			insert_into_array(p, *nc, child_ptr);
			(*nc)++;
		}
	}

	stacks(pos, i, j, turn, nc, child_ptr);
}
コード例 #3
0
void Keyboard::checkKeys(System* system)
{
	if( system->action.type == SDL_KEYDOWN )
	{
		switch(system->action.key.keysym.sym)
		{
			case SDLK_UP:
				break;
			case SDLK_DOWN: 
				break;
			case SDLK_LEFT: 
				
				leftDown(system);
			    break;

			case SDLK_RIGHT:
				
				rightDown(system);
				break;

			case SDLK_LSHIFT: 
				
				{ // this is a stack frame variable, for use of local hero
					Hero* hero = system->sprite_director->getHero();
				
					if(!(hero->jumping) )
					{
						Mix_PlayChannel( -1, system->jukebox->jump, 0 ); 
						hero->jump_start_time = SDL_GetTicks();
						hero->jumping = true;				
					}
				}
				break;
		}			 
	} 
	else if( system->action.type == SDL_KEYUP )
    {
        //Adjust the velocity
        switch( system->action.key.keysym.sym )
        {
            case SDLK_DOWN: 
				break;
			case SDLK_LEFT: 
				
				leftUp(system);				
				break;

			case SDLK_RIGHT: 
			
				rightUp(system);
				break;

			case SDLK_LSHIFT: 
				break; 
        }        
    }
	
}
コード例 #4
0
ファイル: Octree.cpp プロジェクト: pigoblock/TFYP
void Octree::constructOctree(int depth)
{
	//1. bounding box generation
	Vec3f leftDown(MAX, MAX, MAX);
	Vec3f rightUp(MIN, MIN, MIN);
	Vec3f mid;

	for(int i=0;i<NbNode;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(leftDown[j]>(*Node)[i][j])
				leftDown[j]=(*Node)[i][j];
			if(rightUp[j]<(*Node)[i][j])
				rightUp[j]=(*Node)[i][j];
		}
	}
	mid=(rightUp+leftDown)/2.0;

	//2. Root node
	Root=new OctreeNode;
	Root->setBoundingBox(leftDown, rightUp);
	Root->Depth=0;

	//3. Descendant
	OctreeNode** descendant=new OctreeNode*[8];
	for(int i=0;i<8;i++)
	{
		descendant[i]=new OctreeNode;
		descendant[i]->Depth=Root->Depth+1;
		Root->Descendant[i]=descendant[i];
	}

	//4. Descendant generation
	std::vector<int> nodeIdx[8];
	for(int i=0;i<NbNode;i++)
	{
		if((*Node)[i][0]>mid[0])
		{
			if((*Node)[i][1]>mid[1])
			{
				if((*Node)[i][2]>mid[2])
				{
					//RightTopFront
					nodeIdx[0].push_back(i);
				}
				else
				{
					//RightTopBehind
					nodeIdx[1].push_back(i);
				}
			}
			else
			{
				if((*Node)[i][2]>mid[2])
				{
					//RightBottomFront
					nodeIdx[2].push_back(i);
				}
				else
				{
					//RightBottomBehind
					nodeIdx[3].push_back(i);
				}
			}
		}
		else
		{
			if((*Node)[i][1]>mid[1])
			{
				if((*Node)[i][2]>mid[2])
				{
					//LeftTopFront
					nodeIdx[4].push_back(i);
				}
				else
				{
					//LeftTopBehind
					nodeIdx[5].push_back(i);
				}
			}
			else
			{
				if((*Node)[i][2]>mid[2])
				{
					//LeftBottomFront
					nodeIdx[6].push_back(i);
				}
				else
				{
					//LeftBottomBehind
					nodeIdx[7].push_back(i);
				}
			}
		}
	}

	//RightTopFront
	Vec3f p1=mid;
	Vec3f p2=rightUp;
	genOctree(descendant[0], p1, p2, nodeIdx[0], depth);  

	//RightTopBehind
	p1=Vec3f(mid[0], mid[1], leftDown[2]);
	p2=Vec3f(rightUp[0], rightUp[1], mid[2]);
	genOctree(descendant[1], p1, p2, nodeIdx[1], depth);  

	//RightBottomFront
	p1=Vec3f(mid[0], leftDown[1], mid[2]);
	p2=Vec3f(rightUp[0], mid[1], rightUp[2]) ;
	genOctree(descendant[2], p1, p2, nodeIdx[2], depth);

	//RightBottomBehind
	p1=Vec3f(mid[0],leftDown[1],leftDown[2]);
	p2=Vec3f(rightUp[0], mid[1], mid[2]);
	genOctree(descendant[3], p1, p2, nodeIdx[3], depth);

	//LeftTopFront
	p1=Vec3d(leftDown[0], mid[1], mid[2]);
	p2=Vec3d(mid[0], rightUp[1], rightUp[2]);
	genOctree(descendant[4], p1, p2, nodeIdx[4], depth);

	//LeftTopBehind
	p1=Vec3f(leftDown[0], mid[1], leftDown[2]);
	p2=Vec3f(mid[0], rightUp[1], mid[2]);
	genOctree(descendant[5], p1, p2, nodeIdx[5], depth);

	//LeftBottomFront
	p1=Vec3f(leftDown[0], leftDown[1], mid[2]);
	p2=Vec3f(mid[0], mid[1], rightUp[2]);
	genOctree(descendant[6], p1, p2, nodeIdx[6], depth);

	//LeftBottomBehind
	p1=leftDown;
	p2=(leftDown+rightUp)/2.0;
	genOctree(descendant[7], p1, p2, nodeIdx[7], depth);

	delete [] descendant;
}