Пример #1
0
void Player::setup_physics()
{
	clan::PhysicsContext pc = m_physicsWorld.get_pc();

	clan::BodyDescription body_desc(m_physicsWorld);
	body_desc.set_type(clan::BodyType::body_dynamic);
	body_desc.set_angular_damping(5.0f);
	m_physicsBody = clan::Body(pc, body_desc);

	//clan::ChainShape outline_shape(m_physicsWorld);
	//outline_shape.create_loop(m_collisionOutline);

	/*
	clan::Vec2f vertices[] = { 
		clan::Vec2f(m_sprite.get_width()/4.0f, 0),
		clan::Vec2f(m_sprite.get_width()/2.0f, m_sprite.get_height()/2.0f),
		clan::Vec2f(0, m_sprite.get_height()/2.0f)
	};
	

	clan::Vec2f vertices[] = { 
		clan::Vec2f(-0.001f, 0),
		clan::Vec2f(0.001f, 0.002f),
		clan::Vec2f(0.001f, 0),
		clan::Vec2f(0, 0)
	};
	
	outline_shape.create_loop(vertices, 4);
	*/

	clan::PolygonShape outline_shape(m_physicsWorld);
	outline_shape.set_as_box(m_sprite.get_width()/2.0f, m_sprite.get_height()/2.0f);
	
	clan::FixtureDescription fix_desc(m_physicsWorld);
	fix_desc.set_shape(outline_shape);
	fix_desc.set_restitution(0.0f);
	fix_desc.set_friction(1.0f);
	fix_desc.set_density(m_mass);

	m_physicsBodyFixture = clan::Fixture(pc, m_physicsBody, fix_desc);
}
Пример #2
0
Player::Player(Game &game_)
{
	//Init static vars

	Player::player1 = this;
	Player::isPlayer1Playing = true;

	//
	game = &game_;
	Canvas canvas = game_.get_canvas();
	PhysicsContext pc = game_.get_pc();
	ResourceManager resources = game_.get_resources();

	vehicle	= Sprite::resource(canvas, "Car1", resources);

	vehicle.set_linear_filter(false);
	//________________________________________________________________________
	//															   T U R R E T	
	turret		= Sprite::resource(canvas, "Turret1", resources);
	turretBase	= Sprite::resource(canvas, "Turret1Base", resources);
	
	turret.set_linear_filter(false);
	turretBase.set_linear_filter(false);
	
	turret_angle = Angle(0,angle_degrees);
	time_since_last_shoot = 0.0f;

	missile.set_game(*game);
	missile.set_speed(500.0f);
	missile.set_type(MissileDesc::mt_bullet);
	
	//________________________________________________________________________
	//															   R E N D E R
	
	draw_slot = game_.get_draw_sig().connect(this,&Player::draw);
	update_slot = game_.get_update_sig().connect(this,&Player::update);
	
	//________________________________________________________________________
	//															 P H Y S I C S
	
	BodyDescription body_desc(pc);
	body_desc.set_position(0, game->get_height()-40);
	body_desc.set_type(body_dynamic);
	body_desc.set_angular_damping(100.0f);

	PolygonShape shape(pc);
	shape.set_as_box(vehicle.get_width()/2.5f, vehicle.get_height()/4.0f, Vec2f(0.0f, 5.0f), Angle(0, angle_degrees));

	FixtureDescription fixture_desc(pc);
	fixture_desc.set_density(1000.0f);
	fixture_desc.set_shape(shape);
	
	body = Body(pc, body_desc);
	body.set_data(this);
	Fixture(pc, body, fixture_desc);

	/*
	pos_x=0;
	pos_y=game->get_height()-40;
	*/
	xAcc = 1000.0f;
	yAcc = 600.0f;

	x_max_speed=80.0f;
	y_max_speed=40.0f;

	x_speed=0.0f;
	y_speed=0.0f;

	go_right = false;
	go_left = false;
	go_up = false;
	go_down = false;
	doShoot1 = false;
	doShoot2 = false;

	wobble_timer = 0;

	turretBasePos.x = 0.0f;
	turretBasePos.y = 0.0f;

	turretPos.x = 0.0f;
	turretPos.y = 0.0f;
	//__________________________________________________________________________
	//															 G A M E P L A Y
	type = go_player;

	life = max_life = 100.0f;
	is_dead= false;
	target_x_pos = 0.0f;
	target_y_pos = 0.0f;

}
Пример #3
0
Enemy::Enemy(Game &game_)
{
	ID = staticID;
	staticID++;
	add_enemy(this);

	game = &game_;
	Canvas &canvas = game_.get_canvas();
	PhysicsContext pc = game_.get_pc();
	ResourceManager &resources = game_.get_resources();

//________________________________________________________________________
//														   G A M E P L A Y
	type = go_enemy;
	eType = T_HOVERBOT;
	
	missile.set_game(*game);
	missile.set_speed(90.0f);
	missile.set_type(MissileDesc::mt_energy);
	missile.should_hurt_player(true);
	missile.should_hurt_enemy(false);
	turret_angle = Angle(0,angle_degrees);
	time_since_last_shoot = 0.0f;

//________________________________________________________________________
//															   R E N D E R
	enemy = Sprite::resource(canvas,"Enemy1", resources);
	enemy.set_play_loop(true);
	
	//int x,y;
	//Origin origin;
	//enemy->get_alignment(origin,x,y);

	update_callback = std::function<void(int)>(std::bind(&Enemy::update, this, std::placeholders::_1));
	cc.connect(game_.get_draw_sig(), clan::bind_member(this, &Enemy::draw));
    cc.connect(game_.get_update_sig(), update_callback);

//__________________________________________________________________________
//															   P H Y S I C S

	BodyDescription body_desc(pc);
	body_desc.set_position(0, game->get_height()-40);
	body_desc.set_type(body_dynamic);
	body_desc.set_angular_damping(100.0f);

	PolygonShape shape(pc);
	shape.set_as_box(enemy.get_width()/2.5f, enemy.get_height()/2.5f);

	FixtureDescription fixture_desc(pc);
	fixture_desc.set_density(1000.0f);
	fixture_desc.set_shape(shape);
	
	body = Body(pc, body_desc);
	body.set_data(this);
	Fixture(pc, body, fixture_desc);

	pos.x = 50;
	pos.y = 50;
	life = 100;
	is_dead = false;

	body.set_position(pos);

	speed = -35;

	body.set_linear_velocity(Vec2f(speed,0));

	target = Player::getPlayer1();
}
Пример #4
0
//________________________________________________________________________
//________________________________________________________________________
Missile::Missile(MissileDesc &desc)
{
	type = go_missile;

	game	= desc.game;
	speed	= desc.speed_;
	angle	= desc.angle_;
	pos		= desc.pos_;
	mType   = desc.mType_;
	does_hurt_player = desc.does_hurt_player_;
	does_hurt_enemy = desc.does_hurt_enemy_;

	GraphicContext &gc = game->get_gc();
	PhysicsContext pc = game->get_pc();
	ResourceManager &resources = game->get_resources();

	//___________________________________________________________________
	//																G F X

	switch(mType)
	{
	case MissileDesc::mt_bullet:
		bullet = Sprite::resource(gc, "Bullet1", resources);
		damage = 20;
		break;
	case MissileDesc::mt_energy:
		bullet = Sprite::resource(gc, "Bullet2", resources);
		damage = 10;
		break;
	case MissileDesc::mt_rocket:
		bullet = Sprite::resource(gc, "Rocket", resources);
		damage = 50;
		break;
	}

	bullet.set_linear_filter(false);
	bullet.set_angle(angle);

	//___________________________________________________________________
	//													    P H Y S I C S

	BodyDescription body_desc(pc);
	body_desc.set_position(0, game->get_height()-40);
	body_desc.set_type(body_dynamic);

	PolygonShape shape(pc);
	shape.set_as_box(bullet.get_width()/4, bullet.get_height()/4);

	FixtureDescription fixture_desc(pc);
	fixture_desc.set_density(50.0f);
	fixture_desc.set_shape(shape);
	
	body = Body(pc, body_desc);
	body.set_data(this);
	Fixture(pc, body, fixture_desc);

	body.set_position(pos);
	body.set_angle(angle);

	x_speed = speed*cos(angle.to_radians());
	y_speed = speed*sin(angle.to_radians());

	body.set_linear_velocity(Vec2f(x_speed, y_speed));

	lifeTime= 3000.0f;
	currentLifeTime=0.0f;

	//___________________________________________________________________
	//													          C O R E

	update_slot	= game->get_update_sig().connect(this,&Missile::update); 
	draw_slot	= game->get_draw_sig().connect(this,&Missile::draw); 
	should_die = false;
}