Exemplo n.º 1
0
void CVarPlatform::process()
{
    int xBlockPos = target.x - getXPosition();
    int yBlockPos = target.y - getYPosition();
    
    const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos;
    const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos;
    
    if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED )
    {
        const Uint16 object = mpMap->getPlaneDataAt(2, target.x, target.y);

        Vector2D<int> speed(xBlockPos, yBlockPos);
        movePlat(speed);

        readDirection(object, xDirection, yDirection );
        detectNextTarget(target, xDirection, yDirection);
    }
    
    if(yDirection == UP && blockedu)
        yDirection = DOWN;
    else if(yDirection == DOWN && blockedd)
        yDirection = UP;
    
    if(xDirection == RIGHT && blockedr)
        xDirection = LEFT;
    else if(xDirection == LEFT && blockedl)
        xDirection = RIGHT;
    
    Vector2D<int> speed;
    
    if(yDirection == UP)
    {
        speed.y = -MOVE_SPEED;
    }
    else if(yDirection == DOWN)
    {
        speed.y = MOVE_SPEED;
    }
    
    
    if(xDirection == RIGHT)
    {
        speed.x = MOVE_SPEED;
    }
    else if(xDirection == LEFT)
    {
        speed.x = -MOVE_SPEED;
    }
    
    movePlat(speed);
    
    CPlatform::process();
}
int main()
{
	int choice;
	char direction;
	int maze[ROWS][COLS];
	int end = 1;//Stores game continue true/false
	
	createMaze(maze);
	placeHag(maze);
	placeStart(maze);
	// don't remove the next line
	afterRedirect();
	// don't remove the above line

	// NOTE: stdout has been mangled from the redirection
	// so after you do a printf without a \n execute the command fflush(stdout);
	
	printf("\n \n");
	printf("Maze initialized, and ready to play!\n");
	printf("Starting position [%d][%d]\n",playerRow, playerCol);
	
	do
	{
		choice = menu();

		if(choice == 1)
		{
			direction = readDirection();
			move(maze, direction);
		}// end choice

		else if(choice ==2)
			displayMaze(maze);

		else if(choice ==3)
			peek(maze);
		else
		{
			printf("Game exit\n");
			end = 0;//Game end
		}
		moveHag(maze);//Moves hag every third turn

	}while(endGame(maze) && end);

	return 0;

}// end main
Exemplo n.º 3
0
void CRocket::processFlying()
{
    int xBlockPos = target.x - getXPosition();
    int yBlockPos = target.y - getYPosition();
    
    const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos;
    const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos;
    
    
    if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED )
    {
	const Uint16 object = mp_Map->getPlaneDataAt(2, target.x, target.y);
	
	Vector2D<int> speed(xBlockPos, yBlockPos);	    
	moveDir(speed);
	playSound(SOUND_ROCKET_DRIVE);
	
	// Happens when the rocket find a place where to stop
	if(object == 0x6A || object == 0x69)
	{
	    xDirection = CENTER;
	    yDirection = UP;
	    setAction(A_ROCKET_SIT);
	    detectNextTarget(target, xDirection, yDirection);
	    
	    Vector2D<int> newPlayerPos = m_Pos;
	    
	    newPlayerPos.y = getYDownPos();
	    newPlayerPos.x = getXRightPos();
	    
	    mpCarriedPlayer->moveToForce(newPlayerPos);
	    mpCarriedPlayer->solid = true;
	    mpCarriedPlayer->dontdraw = false;
	    mpCarriedPlayer = nullptr;
	    return;
	}

	readDirection(object, xDirection, yDirection );
	
	// If there is an object that changes the direction of the rocket, apply it!	
	detectNextTarget(target, xDirection, yDirection);		
    }
    
    Vector2D<int> speed;
    
    if(yDirection == UP)
    {
	speed.y = -MOVE_SPEED;
    }
    else if(yDirection == DOWN)
    {
	speed.y = MOVE_SPEED;
    }    
    
    if(xDirection == RIGHT)
    {
	speed.x = MOVE_SPEED;
    }
    else if(xDirection == LEFT)
    {
	speed.x = -MOVE_SPEED;
    }
    
    if(mpCarriedPlayer != nullptr)
    {
	mpCarriedPlayer->moveDir(speed);
    }
    moveDir(speed);
}