JAMSPOOK-27 - Added ghosts

This commit is contained in:
Fredrick Amnehagen 2020-08-30 23:58:49 +02:00
parent e55db1dd14
commit bf46723715
12 changed files with 143 additions and 13 deletions

BIN
assets/meshes/ghost.bcosm Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -42,6 +42,7 @@ JamSpookGame::JamSpookGame():
// Add physics related asset loaders
assetSystem->addLoader(make_shared<CollisionShapeLoader>(assetPath), "CollisionShapeLoader");
assetSystem->addLoader(make_shared<StaticCollisionShapeLoader>(assetPath), "StaticCollisionShapeLoader");
// Create animation system
addSystem(make_shared<AnimationSystem>());
@ -200,9 +201,9 @@ void JamSpookGame::set()
dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))));
lightingFactory->createSun(10.0f,
vec3(0,0,0),
vec3(45,-45,0),
vec3(1,1,1),
0.1f,
0.5f,
renderLayerGame);
lightingFactory.reset();
@ -234,8 +235,8 @@ void JamSpookGame::set()
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame);
jump180Factory->createJump180(vec3(0, 0, 0), vec3(0, 0, 0));
jump180Factory->createJump180(vec3(25,-15, 14), vec3(0, 180, 0));
jump180Factory->createJump180(vec3(0, -1, 0), vec3(0, 0, 0));
jump180Factory->createJump180(vec3(25,-16, 14), vec3(0, 180, 0));
jump180Factory.reset();
@ -246,7 +247,7 @@ void JamSpookGame::set()
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame);
goalFactory->createGoal(vec3(-1, -30, -12));
goalFactory->createGoal(vec3(-1, -31, -12));
// goalFactory->createGoal(vec3(0, 0, 0));
goalFactory.reset();
@ -261,6 +262,31 @@ void JamSpookGame::set()
// trackPieceFactory->createRoad();
// trackPieceFactory->createTunnel();
// trackPieceFactory->createMountain();
// trackPieceFactory->createStaticPlatform();
trackPieceFactory->createGhost("SadGhost",
"ghost-white-diffuse.png",
vec3(20, -15, 10),
quat(vec3(radians(0.0f), radians(45.0f), radians(0.0f))),
5.0f);
trackPieceFactory->createGhost("AngryGhost",
"ghost-red-diffuse.png",
vec3(-8, -25, -18),
quat(vec3(radians(0.0f), radians(15.0f), radians(0.0f))),
5.0f);
// End scene entities
trackPieceFactory->createGhost("SadGhost",
"ghost-white-diffuse.png",
vec3(1005, 4, 1001),
quat(vec3(radians(0.0f), radians(45.0f), radians(0.0f))));
trackPieceFactory->createSign("ThankYouSign",
"sign-thanks-diffuse.png",
vec3(994, 0, 1000),
@ -326,7 +352,7 @@ void JamSpookGame::set()
renderLayerGame);
shared_ptr<Entity> endGameEntity = resetTriggerFactory->
createResetTrigger(vec3(-1, -30, -12),
createResetTrigger(vec3(-1, -31, -12),
vec3(1));
// shared_ptr<Entity> endGameEntity = resetTriggerFactory->

View File

@ -36,6 +36,7 @@
#include <ecos/physics/PhysicsSystem.h>
#include <ecos/physics/loaders/CollisionShapeLoader.h>
#include <ecos/physics/loaders/StaticCollisionShapeLoader.h>
#include <ecos/animation/AnimationSystem.h>
@ -116,6 +117,7 @@ using ecos::asset::DataManagementMode;
using ecos::physics::PhysicsSystem;
using ecos::physics::CollisionShapeLoader;
using ecos::physics::StaticCollisionShapeLoader;
using ecos::animation::AnimationSystem;

View File

@ -76,7 +76,8 @@ void KartPhysicsComponent::onICCMessage(shared_ptr<Message> message)
void KartPhysicsComponent::onCollision(const string& tag)
{
if (tag == "goal")
if (tag == "goal"
|| tag == "jump180")
{
ICCBroadcast(make_shared<Message>(IDCache::get("GroundCollisionMessage")));
}
@ -92,7 +93,8 @@ void KartPhysicsComponent::onCollision(const string& tag)
void KartPhysicsComponent::onSeparation(const string& tag)
{
if (tag == "goal")
if (tag == "goal"
|| tag == "jump180")
{
ICCBroadcast(make_shared<Message>(IDCache::get("GroundSeparationMessage")));
}

View File

@ -218,4 +218,95 @@ shared_ptr<Entity> TrackPieceFactory::createSign(
return entity;
}
shared_ptr<Entity> TrackPieceFactory::createGhost(
const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation,
float scaling)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag(name + "_ghost");
SceneGraph::addEntity(entity);
// Create transform
mat4 translationMatrix = translate(mat4(1.0f), position);
mat4 rotationMatrix = glm::toMat4(orientation);
mat4 scalingMatrix = glm::scale(mat4(1), vec3(scaling));
mat4 transform = translationMatrix * rotationMatrix * scalingMatrix;// * rotateToCenter;
// Add graphics component
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
entity,
getShared(mGraphicsSystem),
mRenderLayer);
entity->addComponent(graphicsComponent);
// Add the ModelRenderable
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("ghost.bcosm",
diffuseTextureFilePath,
name + "-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
shared_ptr<Entity> TrackPieceFactory::createStaticPlatform()
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("staticPlatform");
SceneGraph::addEntity(entity);
// Create transform
mat4 transform = mat4(1);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem);
shared_ptr<TrackPiecePhysicsComponent> physicsComponent =
make_shared<TrackPiecePhysicsComponent>(
transform,
entity,
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
colliderFactory->createStaticMeshCollider(vec3(0),
quat_cast(mat4(1)),
"static-platform.bcosps", // filePath
"static-platform-shape", // name
100.0f, // mass
entity,
entity->getEntityTag()));
delete colliderFactory;
// Note: Editing of rigid body params, maybe only has effect is it has been added to the world.
physicsComponent->getCollider()->getRigidBody()->setLinearFactor(btVector3(0, 0, 0)); // deny positional movement movement in any axis
physicsComponent->getCollider()->getRigidBody()->setAngularFactor(btVector3(0, 0, 0)); // deny rotational movement movement in any axis
physicsComponent->getCollider()->getRigidBody()->setRestitution(1);
entity->addComponent(physicsComponent);
// Add graphics component
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
entity,
getShared(mGraphicsSystem),
mRenderLayer);
entity->addComponent(graphicsComponent);
// Add the ModelRenderable of a ball
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("static-platform.bcosm",
"static-platform-diffuse.png",
"static-platform-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -140,6 +140,15 @@ public:
const string diffuseTextureFilePath,
vec3 position,
quat orientation);
/// Compose a ghost entity
shared_ptr<Entity> createGhost(const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation,
float scaling = 1.0f);
shared_ptr<Entity> createStaticPlatform();
};
} // namespace JamSpook