Skip to content

Commit

Permalink
Merge branch 'rocket-projectile'
Browse files Browse the repository at this point in the history
  • Loading branch information
loinesg committed Apr 30, 2018
2 parents 3e3de63 + 3ee9aa9 commit 08d2e6a
Show file tree
Hide file tree
Showing 18 changed files with 311 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
<ClInclude Include="Source\Scene\GameObject.h" />
<ClInclude Include="Source\Scene\Helicopter.h" />
<ClInclude Include="Source\Scene\HelicopterView.h" />
<ClInclude Include="Source\Scene\Rocket.h" />
<ClInclude Include="Source\Scene\Scene.h" />
<ClInclude Include="Source\Scene\Shield.h" />
<ClInclude Include="Source\Scene\TurretGun.h" />
<ClInclude Include="Source\Scene\StaticMesh.h" />
<ClInclude Include="Source\Scene\StaticTurret.h" />
<ClInclude Include="Source\Scene\Terrain.h" />
Expand Down Expand Up @@ -127,8 +129,10 @@
<ClCompile Include="Source\Scene\GameObject.cpp" />
<ClCompile Include="Source\Scene\Helicopter.cpp" />
<ClCompile Include="Source\Scene\HelicopterView.cpp" />
<ClCompile Include="Source\Scene\Rocket.cpp" />
<ClCompile Include="Source\Scene\Scene.cpp" />
<ClCompile Include="Source\Scene\Shield.cpp" />
<ClCompile Include="Source\Scene\TurretGun.cpp" />
<ClCompile Include="Source\Scene\StaticMesh.cpp" />
<ClCompile Include="Source\Scene\StaticTurret.cpp" />
<ClCompile Include="Source\Scene\Terrain.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions Engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@
<ClInclude Include="Source\Physics\TerrainCollider.h">
<Filter>Physics</Filter>
</ClInclude>
<ClInclude Include="Source\Scene\Rocket.h">
<Filter>Scene</Filter>
</ClInclude>
<ClInclude Include="Source\Scene\TurretGun.h">
<Filter>Scene</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\Math\Point2.cpp">
Expand Down Expand Up @@ -393,6 +399,12 @@
<ClCompile Include="Source\Physics\TerrainCollider.cpp">
<Filter>Physics</Filter>
</ClCompile>
<ClCompile Include="Source\Scene\Rocket.cpp">
<Filter>Scene</Filter>
</ClCompile>
<ClCompile Include="Source\Scene\TurretGun.cpp">
<Filter>Scene</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Shaders\SkyboxPass.shader">
Expand Down
3 changes: 3 additions & 0 deletions Resources/Meshes/rocket.obj
Git LFS file not shown
4 changes: 2 additions & 2 deletions Resources/Prefabs/Helicopter.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
Rotation = 0 -0.286003 0 -0.958229
}
BoxCollider {
size = 2.694 3.253 5.317
offset = 0 0.733 2.037
size = 2.694 5 8
offset = 0 0.733 0
}
StaticMesh {
mesh = Resources\Meshes\helicopter.obj
Expand Down
13 changes: 13 additions & 0 deletions Resources/Prefabs/ProjectileRocket.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
name = Rocket
Rigidbody {
}
Transform {
}
StaticMesh {
mesh = Resources\Meshes\rocket.obj
material = Resources\Materials\cardboard_enemy.material
}
Rocket {
}
}
10 changes: 6 additions & 4 deletions Resources/Prefabs/Turret.prefab
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
name = Neoturret
name = Turret
Transform {
Position = 341.2 -0.8 133.7
Scale = 2 2 2
Position = 0 0 0
}
StaticMesh {
mesh = Resources\Meshes\turret_base.obj
Expand All @@ -22,12 +21,15 @@
children::0 {
name = Cannon
Transform {
Position = 0.0 0.6 0.0
Position = 0 0.6 0
}
StaticMesh {
mesh = Resources\Meshes\turret_cannon.obj
material = Resources\Materials\cardboard_enemy.material
}
TurretGun {
prefab = Resources\Prefabs\ProjectileRocket.prefab
}
}
}
}
24 changes: 24 additions & 0 deletions Resources/Scenes/startup.scene
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@
gameobjects::1 {
prefab = Resources\Prefabs\Helicopter.prefab
}
gameobjects::2 {
name = Static Mesh
Transform {
Position = 0 9.4 0
}
StaticMesh {
mesh = Resources\Meshes\car.mesh
material = Resources\Materials\cardboard.material
}
children::0 {
name = Static Mesh
Transform {
Scale = 10 10 10
}
StaticMesh {
mesh = Resources\Meshes\rocket.obj
material = Resources\Materials\cardboard.material
}
Rocket {
}
Rigidbody {
}
}
}
ambient_intensity = 1.567
sun_intensity = 5.8
sun_rotation = 27 281
Expand Down
10 changes: 10 additions & 0 deletions Source/Scene/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Scene/Freecam.h"
#include "Scene/Terrain.h"
#include "Scene/StaticTurret.h"
#include "Scene/Rocket.h"
#include "Scene/TurretGun.h"

#include "Physics/SphereCollider.h"
#include "Physics/BoxCollider.h"
Expand Down Expand Up @@ -186,6 +188,8 @@ void GameObject::drawAddComponentSection()
if (ImGui::Selectable("Rigidbody")) createComponent<Rigidbody>();
if (ImGui::Selectable("Terrain Collider")) createComponent<TerrainCollider>();
if (ImGui::Selectable("Static Turret")) createComponent<StaticTurret>();
if (ImGui::Selectable("Rocket")) createComponent<Rocket>();
if (ImGui::Selectable("Turret Gun")) createComponent<TurretGun>();

ImGui::EndPopup();
}
Expand Down Expand Up @@ -437,6 +441,12 @@ Component* GameObject::createComponent(const std::string &typeName)
if (typeName == "TerrainCollider")
return createComponent<TerrainCollider>();

if (typeName == "Rocket")
return createComponent<Rocket>();

if (typeName == "TurretGun")
return createComponent<TurretGun>();

return nullptr;
}

Expand Down
27 changes: 27 additions & 0 deletions Source/Scene/Helicopter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "InputManager.h"

#include "Scene/Transform.h"
#include "Scene/StaticMesh.h"
#include "Utils/Clock.h"

#include "imgui.h"

#include <algorithm>
Expand All @@ -11,6 +14,7 @@ Helicopter::Helicopter(GameObject* gameObject)
transform_(gameObject->createComponent<Transform>()),
worldVelocity_(Vector3::zero()),
worldRotation_(Quaternion::identity()),
HP(100.0f),
horizontalMaxSpeed_(60.0f),
upMaxSpeed_(25.0f),
downMaxSpeed_(80.0f),
Expand All @@ -33,6 +37,14 @@ void Helicopter::drawProperties()
ImGui::DragFloat("Yaw rotation factor", &turnFactor_, 0.1f);
}

void Helicopter::handleCollision(Collider* collider)
{
if (collider->gameObject()->findComponent<Terrain>() != nullptr)
{
die();
}
}

void Helicopter::serialize(PropertyTable &table)
{
table.serialize("horizontal_max_speed", horizontalMaxSpeed_, 60.0f);
Expand Down Expand Up @@ -118,3 +130,18 @@ void Helicopter::handleInput(const InputCmd& inputs)
remainingPitch_ -= remainingPitch_ * decelerationFactor_;
}

void Helicopter::takeDamage(float damage)
{
HP -= damage;

if (HP <= 0.0f)
{
die();
}
}

void Helicopter::die()
{
gameObject()->findComponent<StaticMesh>()->setMaterial(ResourceManager::instance()->load<Material>("Resources/Materials/cardboard_enemy.material"));
Clock::instance()->setPaused(true);
}
11 changes: 11 additions & 0 deletions Source/Scene/Helicopter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Scene/Component.h"
#include "Physics/Collider.h"
#include "Math/Vector3.h"
#include "Math/Quaternion.h"

Expand All @@ -14,19 +15,29 @@ class Helicopter : public Component

void drawProperties() override;

void handleCollision(Collider* collider) override;

// Serialisation method
void serialize(PropertyTable &table) override;

void handleInput(const InputCmd& inputs) override;

Transform* transform() { return transform_; };

Vector3 velocity() { return worldVelocity_; }

void takeDamage(float damage);

void die();

private:

Transform* transform_;
Vector3 worldVelocity_;
Quaternion worldRotation_;

float HP;

float currentTilt_;

float horizontalMaxSpeed_;
Expand Down
54 changes: 54 additions & 0 deletions Source/Scene/Rocket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "Rocket.h"

#include "Scene/Transform.h"
#include "Scene/Helicopter.h"
#include "Physics/Rigidbody.h"

#include "SceneManager.h"

#include "imgui.h"

Rocket::Rocket(GameObject* gameObject)
: Component(gameObject),
transform_(gameObject->createComponent<Transform>()),
speed_(100.0f),
damage_(15.0f)
{
// Initialise rotation
transform_->setRotationLocal(Quaternion::identity());
}

void Rocket::drawProperties()
{
ImGui::DragFloat("Rocket speed", &speed_, 0.1f);
}

void Rocket::handleCollision(Collider* collider)
{
Helicopter* chopper = collider->gameObject()->findComponent<Helicopter>();
if (chopper != nullptr)
{
chopper->takeDamage(damage_);
}

// Delete gameObject on collision
delete gameObject();
}

void Rocket::setRocketSpeed(float speed)
{
speed_ = speed;
}
void Rocket::initRocket(const Point3& pos, const Quaternion& rot)
{
transform_->setPositionLocal(pos);
transform_->setRotationLocal(rot);

// Create rigidbody for collisions
gameObject()->createComponent<Rigidbody>();
Rigidbody* collider = gameObject()->findComponent<Rigidbody>();

// Calculate velocity and send to rigidbody component
Vector3 velocity = transform_->forwards() * speed_;
collider->setVelocity(velocity);
}
27 changes: 27 additions & 0 deletions Source/Scene/Rocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "Scene/Component.h"
#include "Math/Vector3.h"

class Transform;
class Quaternion;

class Rocket : public Component
{
public:
Rocket(GameObject* gameObject);

void drawProperties() override;
void handleCollision(Collider* collider) override;

void setRocketSpeed(float speed);
void initRocket(const Point3& pos, const Quaternion& rot);

private:
Transform* transform_;

float speed_;
float damage_;

bool initialised_ = false;
};
5 changes: 5 additions & 0 deletions Source/Scene/StaticMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ void StaticMesh::serialize(PropertyTable &table)
{
table.serialize("mesh", mesh_);
table.serialize("material", material_);
}

void StaticMesh::setMaterial(Material* material)
{
material_ = material;
}
2 changes: 2 additions & 0 deletions Source/Scene/StaticMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class StaticMesh : public Component
// Handles component serialization
void serialize(PropertyTable &table) override;

void setMaterial(Material* material);

Material* material() const { return material_; }
Mesh* mesh() const { return mesh_; }

Expand Down
Loading

0 comments on commit 08d2e6a

Please sign in to comment.