void PlayerCar::loadSpine()
{
  try {
    ifstream atlasFile("spineboy.atlas");
    atlas = new Atlas(atlasFile);

    SkeletonJson skeletonJson(atlas);
	skeletonJson.scale = 0.5;

    ifstream skeletonFile("spineboy-skeleton.json");
    skeletonData = skeletonJson.readSkeletonData(skeletonFile);

    ifstream animationFile("spineboy-walk.json");
    animation = skeletonJson.readAnimation(animationFile, skeletonData);

    skeleton = new Skeleton(skeletonData);
    skeleton->flipX = false;
    skeleton->flipY = false;
    skeleton->setToBindPose();
    skeleton->getRootBone()->x = 200;
    skeleton->getRootBone()->y = 500;
    skeleton->updateWorldTransform();
  } catch (exception &ex) {
    cout << ex.what() << endl << flush;
  }
}
Exemplo n.º 2
0
Player::Player(ObjectLayer* layer, b2Vec2 position, uint16_t location) : layer(location), Collider(Collider::Player), inPortal(false), portalDirection(Portal::Up){
	chdir("assets/player");

	this->map = layer->map;

	b2BodyDef bodyDef;

	bodyDef.type = b2_dynamicBody;
	bodyDef.position = position;
	bodyDef.fixedRotation = true;

	body = layer->world.CreateBody(&bodyDef);
	body->SetUserData((Collider*)this);

	b2PolygonShape dynamicBox;
	dynamicBox.SetAsBox(0.47f, 0.75f, b2Vec2(0.5, 0.75), 0);

	b2FixtureDef fixtureDef;
	fixtureDef.shape = &dynamicBox;
	fixtureDef.density = 0.1f;
	fixtureDef.friction = 0;
	fixtureDef.userData = (b2ContactListener*)this;

	body->CreateFixture(&fixtureDef);

	b2CircleShape circle;
	circle.m_p.Set(0.5f, 1.5f);
	circle.m_radius = 0.49f;

	fixtureDef.shape = &circle;
	fixtureDef.density = 0.1f;
	fixtureDef.friction = 0.f;
	fixtureDef.userData = (b2ContactListener*)this;

	body->CreateFixture(&fixtureDef);

	b2CircleShape circlef;
	circlef.m_p.Set(0.5f, 1.9f);
	circlef.m_radius = 0.1;

	fixtureDef.shape = &circlef;
	fixtureDef.density = 0.1f;
	fixtureDef.friction = 2.f;
	fixtureDef.userData = (b2ContactListener*)this;

	body->CreateFixture(&fixtureDef);

	b2PolygonShape sensorBox;
	sensorBox.SetAsBox(0.45f, 0.1f, b2Vec2(0.5f, 2.f), 0);

	fixtureDef.shape = &sensorBox;
	fixtureDef.isSensor = true;
	fixtureDef.userData = (b2ContactListener*)this;

	body->CreateFixture(&fixtureDef);

	state = PlayerStanding;
	impulse = ImpulseNone;
	direction = Right;

	time = 0;
	jumpStart = 0;
	grounded = 0;

	std::ifstream atlasFile("pack.atlas");
	atlas.reset(new spine::Atlas(atlasFile));

	spine::SkeletonJson skeletonJson(atlas.get());

	std::ifstream skeletonFile("skeleton.json");
	skeletonData.reset(skeletonJson.readSkeletonData(skeletonFile));

	std::ifstream animationFile("skeleton-run3.json");
	run.reset(skeletonJson.readAnimation(animationFile, skeletonData.get()));

	skeleton.reset(new spine::Skeleton(skeletonData.get()));

	skeleton->flipX = false;
	skeleton->flipY = false;
	skeleton->setToBindPose();
	skeleton->getRootBone()->x = X_OFFSET;
	skeleton->getRootBone()->y = Y_OFFSET;
	skeleton->updateWorldTransform();

	sync();

	chdir("../..");
}