Exemplo n.º 1
0
void Player::update(Game* game){
	if (Input::KeyUp.pressed && pos.y >= 0) pos.y -= 5;
	if (Input::KeyDown.pressed && pos.y < Game::stageSize.y)	pos.y += 5;
	if (Input::KeyRight.pressed && pos.x < Game::stageSize.x)	pos.x += 5;
	if (Input::KeyLeft.pressed && pos.x >= 0) pos.x -= 5;

	//fire
	auto bulletManager = game->getMyBulletManager();
	switch (fig){
	case Figure::TRIANGLE:
		for (int i : {-1, 1, 0}) {
			const double shotRad = Radians(5 * i);
			if (System::FrameCount() % 10 == 0) {
				auto shot = std::make_shared<Bullet>(pos, Palette::Aqua, shotRad - HalfPi, 1, 1);
				bulletManager->add(shot);
			}
		}
		break;
	case Figure::SQUARE:
		break;
	case Figure::TSQUARE:
		rad += 2;
		if (System::FrameCount() % 10 == 0){
			for (auto i : step_to(-4, 4, 1)){
				double shotRad = rad + TwoPi / 8 * i;
				auto bullet = std::make_shared<Bullet>(pos, Palette::Aqua, shotRad, 5.0, 0.0);
				bulletManager->add(bullet);
			}
		}
		break;
	case Figure::CIRCLE:
		if (System::FrameCount() % 70 == 0){
			for (int i : step(50)){
				rad = TwoPi / 100 * Random(1, 100);
				auto bullet = std::make_shared<Bullet>(pos, Palette::Aqua, rad, Random(1.0, 15.0), 0.0);
				bulletManager->add(bullet);
			}
		}
		break;
	};

	//catcher
	if (Input::KeyZ.clicked && fig == Figure::TRIANGLE){
		frameCount = System::FrameCount();
		state = State::CATCHER;
	}
	else if (state == State::CATCHER && (System::FrameCount() - frameCount) > 100){
		state = State::NORMAL;
	}

	checktHit(game);
}
Exemplo n.º 2
0
unsigned int CMob::think()
{
    int losx = x;
    int losy = y;
    if(los(losx, losy, PC->x, PC->y, get_fov_rad()))
    {
        last_seen_x = PC->x;
        last_seen_y = PC->y;
        chasing = true;
    }
    if (chasing)
    {
        if(tryattack(last_seen_x - x, last_seen_y - y))
            return get_attack_time();
        if(step_to(last_seen_x, last_seen_y))
            return get_move_time();
    }
    return get_move_time(); //idle
}