Lifebuoy updated, now dies after 4 hits

This commit is contained in:
viktorljung
2015-10-08 21:51:43 +02:00
parent d5e7481866
commit 9fe2324913
22 changed files with 12146 additions and 10 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 124 B

@@ -9,4 +9,4 @@ Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd LifebuoyTexture.png
map_Kd LifebuoyTexture1.png
@@ -1,6 +1,6 @@
# Blender v2.75 (sub 0) OBJ File: 'Lifebuoy.blend'
# www.blender.org
mtllib Lifebuoy.mtl
mtllib Lifebuoy1.mtl
o Torus
v 0.428934 0.000000 0.162495
v 0.425944 0.009662 0.167205
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Lifebuoy.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd LifebuoyTexture2.png
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Lifebuoy.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd LifebuoyTexture3.png
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Lifebuoy.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd LifebuoyTexture4.png
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Lifebuoy.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd LifebuoyTexture5.png
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

+2 -1
View File
@@ -28,7 +28,8 @@
#include "Game/EHitPad.h"
#include "Game/EHitLag.h"
#include "Game/EActionButton.h"
#include "Game/CLifebuoy.h"
#include "Game/CLifebuoy.h"
#include "Game/ELifebuoyHit.h"
namespace dd
{
+1 -1
View File
@@ -15,7 +15,7 @@ namespace Components
struct Lifebuoy : Component
{
int Hits = 4;
};
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-09-29.
//
#ifndef DAYDREAM_ELIFEBUOYHIT_H
#define DAYDREAM_ELIFEBUOYHIT_H
#include "Core/Entity.h"
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct LifebuoyHit : Event
{
EntityID Lifebuoy;
};
}
}
#endif //DAYDREAM_ELIFEBUOYHIT_H
+5 -1
View File
@@ -16,6 +16,7 @@
#include "Physics/CRectangleShape.h"
#include "Game/EPause.h"
#include "Game/ELifebuoy.h"
#include "Game/ELifebuoyHit.h"
#include "Game/CLifebuoy.h"
#include <fstream>
#include <iostream>
@@ -48,19 +49,22 @@ private:
dd::EventRelay<LifebuoySystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LifebuoySystem, dd::Events::Pause> m_EPause;
dd::EventRelay<LifebuoySystem, dd::Events::Lifebuoy> m_ELifebuoy;
dd::EventRelay<LifebuoySystem, dd::Events::LifebuoyHit> m_ELifebuoyHit;
bool OnContact(const dd::Events::Contact &event);
bool OnPause(const dd::Events::Pause &event);
bool OnLifebuoy(const dd::Events::Lifebuoy &event);
bool OnLifebuoyHit(const dd::Events::LifebuoyHit &event);
struct LifebuoyInfo
{
EntityID Entity;
float TimeToLive = 15.f;
//int Hits = 4;
};
float m_LeftEdge = -3.8f;
float m_RightEdge = 3.8f;
float m_DownLimit = -5.3f;
float m_DownEdge = -9.2f;
std::list<LifebuoyInfo> m_Lifebuoys;
};
+3 -1
View File
@@ -297,7 +297,9 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
} // Lifebuoy should always reflect the ball upwards
else if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Lifebuoy"){
ballTransform->Velocity = glm::vec3(ballTransform->Velocity.x, abs(ballTransform->Velocity.y), ballTransform->Velocity.z);
Events::LifebuoyHit e;
e.Lifebuoy = otherEntitiy;
EventBroker->Publish(e);
} else {
auto it = m_Contacts.find(ballEntity);
if (it == m_Contacts.end()) {
+21 -4
View File
@@ -12,6 +12,7 @@ void dd::Systems::LifebuoySystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EContact, &LifebuoySystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LifebuoySystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_ELifebuoy, &LifebuoySystem::OnLifebuoy);
EVENT_SUBSCRIBE_MEMBER(m_ELifebuoyHit, &LifebuoySystem::OnLifebuoyHit);
//Lifebuoy
{
@@ -30,7 +31,7 @@ void dd::Systems::LifebuoySystem::Initialize()
physics->GravityScale = 1;
ctransform->Sticky = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Lifebuoy/Lifebuoy.obj";
cModel->ModelFile = "Models/Lifebuoy/Lifebuoy1.obj";
auto lifebuoy = m_World->AddComponent<Components::Lifebuoy>(ent);
m_World->CommitEntity(ent);
@@ -44,8 +45,9 @@ void dd::Systems::LifebuoySystem::Initialize()
void dd::Systems::LifebuoySystem::Update(double dt)
{
for (auto it = m_Lifebuoys.begin(); it != m_Lifebuoys.end();) {
it->TimeToLive -= dt;
auto transformComponent = m_World->GetComponent<Components::Transform>(it->Entity);
auto lifebuoyComponent = m_World->GetComponent<Components::Lifebuoy>(it->Entity);
if (transformComponent->Position.y < m_DownEdge) {
m_World->RemoveEntity(it->Entity);
@@ -57,14 +59,20 @@ void dd::Systems::LifebuoySystem::Update(double dt)
transformComponent->Position = glm::vec3(m_LeftEdge + 0.1f, transformComponent->Position.y, transformComponent->Position.z);
} else if (transformComponent->Position.x < m_LeftEdge) {
transformComponent->Position = glm::vec3(m_RightEdge - 0.1f, transformComponent->Position.y, transformComponent->Position.z);
} else if (it->TimeToLive < 0.f) {
}
if (lifebuoyComponent->Hits <= 0) {
auto physicsComponent = m_World->GetComponent<Components::Physics>(it->Entity);
physicsComponent->Mask = CollisionLayer::Type::LifeBuoy;
physicsComponent->GravityScale = 10.f;
auto modelComponent = m_World->GetComponent<Components::Model>(it->Entity);
modelComponent->Color = glm::vec4(0.5f, 0.5f, 0.5f, 0.f);
}
if (transformComponent->Position.y < m_DownLimit && lifebuoyComponent->Hits > 0) {
transformComponent->Position.y = m_DownLimit;
}
++it;
}
}
@@ -116,3 +124,12 @@ bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event)
return true;
}
bool dd::Systems::LifebuoySystem::OnLifebuoyHit(const dd::Events::LifebuoyHit &event)
{
auto lifebuoyComponent = m_World->GetComponent<Components::Lifebuoy>(event.Lifebuoy);
lifebuoyComponent->Hits -= 1;
auto modelComponent = m_World->GetComponent<Components::Model>(event.Lifebuoy);
modelComponent->ModelFile = "Models/Lifebuoy/Lifebuoy" + std::to_string(5 - lifebuoyComponent->Hits) + ".obj";
return true;
}