예제 #1
0
파일: Control.cpp 프로젝트: dvduvix/cvl11
/**
  * Tracks the face. Keeps a fixed distance from the face and makes the quad to
  * face the face. Before sending the message it validates the postion, the
  * normal and the yaw
  *
  * @param msg const mavlink_message_t *
  * @param client PxSHMImageClient *
  * @param objectPosition The position of the face in meters
  * @param normal Normal of the face in meters
  * @param quad_point Location of the quad in meters
  * @param fixed_z A fixed z-coordinate of the set point
  * @param lcm lam_t *
  * @param compid int
  *
  * @return 0
  */
int Control::trackFace(const mavlink_message_t *msg, PxSHMImageClient *client,
                       Vec3f objectPosition, Vec3f normal, Vec3f quad_point,
                       float fixed_z, lcm_t *lcm, int compid) {
    float keep = 1.1f;

    float normalization = sqrt(normal[0] * normal[0] + normal[1] * normal[1]);

    float yaw = arcTan(normal[0], normal[1]);

    Vec3f destination;

    destination[0] = objectPosition[0] - keep * normal[0] / normalization;
    destination[1] = objectPosition[1] - keep * normal[1] / normalization;
    destination[2] = fixed_z;

// std::cout << "Normal: " << Mat(normal) << std::endl;

    if (validatePosition(destination, yaw, quad_point, objectPosition) &&
            validateNormal(normal)) {
        flyToPos(destination, yaw, lcm, compid);
        cur_yaw = yaw;
        cur_des = destination;
    }

    return 0;
}
예제 #2
0
int GameBoard::isEndState() {
    // check if larva has made it to line 1 (the fence)
    if(board[7][0] == 'L' || board[7][2] == 'L' || board[7][4] == 'L' || board[7][6] == 'L') {
        return 1;
    }

    // check is the larva is surrounded.
    bool is_surrounded = true;
    for(int i = -1; i < 2; i += 2) { // i checks down and up
        for(int j = -1; j < 2; j += 2) { //j check left and right
            if(validatePosition(larva_pos[0] + i, larva_pos[1] + j) && board[larva_pos[0] + i][larva_pos[1] + j] == '\0') {
                is_surrounded = false;
                break;
            }
        }
        if(!is_surrounded) {
            break;
        }
    }
    if(is_surrounded) {
        return -1;
    }

    // check that the birds can move. if not, larva wins.
    bool can_move_bird = false;
    for(int i = 0; i < 4; ++i) { // i iterates the array of birds.
        for(int j = -1; j < 2; j += 2) { // j checks left and right
            if(validatePosition(bird_pos[i][0] - 1, bird_pos[i][1] + j) && board[bird_pos[i][0] - 1][bird_pos[i][1] + j] == '\0') {
                can_move_bird = true;
                break;
            }
        }
        if(can_move_bird) {
            break;
        }
    }
    if(!can_move_bird) {
        return 1;
    }

    return 0;
}
예제 #3
0
void PlayerSlot::tick(const float dt) {
	if (!tooltips.empty()) {
		tooltips.front().first -= dt;
		if (tooltips.front().first < 0) {
			delete last_tooltip;
			last_tooltip = tooltips.front().second;
	
			if (!last_tooltip_used)
				GameMonitor->onTooltip("hide", PlayerManager->get_slot_id(id), last_tooltip->area, last_tooltip->message);
			last_tooltip_used = false;
			
			tooltips.pop();
			if (!tooltips.empty()) {
				GameMonitor->onTooltip("show", PlayerManager->get_slot_id(id), tooltips.front().second->area, tooltips.front().second->message);	
			}
		}
	}
	if (!visible) 
		return;

	if (RTConfig->game_type == GameTypeCTF || RTConfig->game_type == GameTypeTeamDeathMatch) {
		if (team == Team::None) {
			if (join_team == NULL)
				join_team = new JoinTeamControl;
			join_team->tick(dt);			
		} else {
			delete join_team;
			join_team = NULL;		
		}
	}
		
	const Object * p = getObject();
	if (p == NULL) {
		moving = 0;
		return;
	}
					
	v2<float> pos, vel;
	p->get_position(pos);
	p->get_velocity(vel);
	vel.normalize();
		
	//vel.fromDirection(p->get_direction(), p->get_directions_number());
	if (!vel.is0())
		moving += dt;
	
	if (moving >= 2)
		moving = 2;
	
	GET_CONFIG_VALUE("player.controls.immediate-camera-sliding", bool, ics, false);
	
	map_dst = ics?pos:pos + map_dpos.convert<float>();
	map_dst.x -= viewport.w / 2;
	map_dst.y -= viewport.h / 2;
	validatePosition(map_dst);
		
	//float look_forward = v2<float>(slot.viewport.w, slot.viewport.h, 0).length() / 4;
	//slot.map_dst += vel * moving / 2 * look_forward; 

	map_dst_vel = Map->distance(map_dst_pos, map_dst);

	//	if (slot.map_dst_vel.length() > max_speed * 4)
	//		slot.map_dst_vel.normalize(max_speed * 4);
	map_dst_pos += map_dst_vel * math::min<float>(math::abs(dt * 30), 1.0f) * math::sign(dt);
	validatePosition(map_dst_pos);

	//const float max_speed = 2.5 * p->speed;
		
	v2<float> dvel = Map->distance(map_pos, map_dst_pos);

	//const int gran = 50;
	//map_vel = (dvel / (gran / 8)).convert<int>().convert<float>() * gran;
	
	//if (dvel.length() > p->speed) 
	//	dvel.normalize(p->speed);
	map_vel = dvel;
		
	//if (map_vel.length() > max_speed)
	//	map_vel.normalize(max_speed);
		
	map_pos += map_vel * math::min<float>(math::abs(10 * dt), 1) * math::sign(dt);
	//map_pos = map_dst_pos;
	validatePosition(map_pos);
	//LOG_DEBUG(("pos: %g,%g, dst: %g,%g, vel: %g,%g", map_pos.x, map_pos.y, map_dst.x, map_dst.y, map_vel.x, map_vel.y));
}
예제 #4
0
bool GameBoard::movePiece(char fromPos[2], char toPos[2]) {

    int from_i = '8' - fromPos[1];
    int from_j = fromPos[0] - 'A';
    int to_i = '8' - toPos[1];
    int to_j = toPos[0] - 'A';

    if(!validatePosition(from_i, from_j) || !validatePosition(to_i, to_j)) {
        return false;
    }

    // check the positions based on who's turn it is.
    if(curr_turn == TurnType::P_ONE_TURN) {
        // make sure that the piece is the larva.
        if(board[from_i][from_j] != 'L') {
            return false;
        }
        if(!(													// not any of the following:
                    (from_i == (to_i + 1) && from_j == (to_j + 1))	// move up-left
                    ||	(from_i == (to_i + 1) && from_j == (to_j - 1))	// move up-right
                    ||	(from_i == (to_i - 1) && from_j == (to_j + 1))	// move down-left
                    ||	(from_i == (to_i - 1) && from_j == (to_j - 1))	// move down-right
                )) {
            return false;
        }
    } else { // curr_turn == TurnType::P_TWO_TURN
        // make sure that the piece is a bird
        if(board[from_i][from_j] != 'B') {
            return false;
        }

        if(!(														// not any of the following:
                    (from_i == (to_i + 1) && from_j == (to_j + 1))	// move up-left
                    ||	(from_i == (to_i + 1) && from_j == (to_j - 1))	// move up-right
                )) {
            return false;
        }
    }

    // in both scenarios, we check if the toPos is empty. Can't be stacking pieces.
    if(board[to_i][to_j] != '\0') {
        return false;
    }

    // now that all checking is out of the way, make the move and switch turns.
    board[from_i][from_j] = '\0';
    board[to_i][to_j] = (curr_turn == TurnType::P_ONE_TURN) ? 'L' : 'B';

    // update the larva/bird position.
    if(curr_turn == TurnType::P_ONE_TURN) {
        this->larva_pos[0] = to_i;
        this->larva_pos[1] = to_j;
    } else {
        for(int i = 0; i < 4; ++i) {
            if(bird_pos[i][0] == from_i && bird_pos[i][1] == from_j) {
                bird_pos[i][0] = to_i;
                bird_pos[i][1] = to_j;
                break;
            }
        }
    }

    curr_turn = (curr_turn == TurnType::P_ONE_TURN) ? TurnType::P_TWO_TURN : TurnType::P_ONE_TURN;

    return true;
}
예제 #5
0
파일: Tank.cpp 프로젝트: luissifu/tankcoder
void Tank::goForward() {
	int or_x = x;
	int or_y = y;

	switch(direction)
	{
		case TANK_DIRECTION_LEFT:
			x--;
			break;

		case TANK_DIRECTION_LEFT_DOWN:
			if (y % 2 == 0)
			{
				y++;
			}
			else
			{
				x--;
				y++;
			}
			break;

		case TANK_DIRECTION_RIGHT_DOWN:
			if (y % 2 == 0)
			{
				x++;
				y++;
			}
			else
			{
				y++;
			}
			break;

		case TANK_DIRECTION_RIGHT:
			x++;
			break;

		case TANK_DIRECTION_RIGHT_UP:
			if (y % 2 == 0)
			{
				x++;
				y--;
			}
			else
			{
				y--;
			}
			break;

		case TANK_DIRECTION_LEFT_UP:
			if (y % 2 == 0)
			{
				y--;
			}
			else
			{
				x--;
				y--;
			}
			break;

		default:
			break;
	}

	if (x >= grid->getWidth())
		x = grid->getWidth() -1;
	else if (x < 0)
		x = 0;

	if (y >= grid->getHeight())
		y = grid->getHeight() -1;
	else if (y < 0)
		y = 0;

	if (grid->is_obstacle(x, y))
	{
		x = or_x;
		y = or_y;
	}

	if (id == 0)
	{
		int ex, ey;
		grid->findEnemy(ex, ey);

		if (x == ex && y == ey)
		{
			x = or_x;
			y = or_y;
		}

		grid->update_player(x, y);
	}
	else
	{
		int px, py;
		grid->findPlayer(px, py);

		if (x == px && y == py)
		{
			x = or_x;
			y = or_y;
		}

		grid->update_enemy(x, y);
	}

	validatePosition();
}
예제 #6
0
파일: Tank.cpp 프로젝트: luissifu/tankcoder
void Tank::setPosition(int x, int y) {
	this->x = x;
	this->y = y;

	validatePosition();
}