Skip to content

Commit

Permalink
Complete chapter 11.6
Browse files Browse the repository at this point in the history
  • Loading branch information
DaikonNimono committed Mar 15, 2024
1 parent a907530 commit 3f40e9a
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 60 deletions.
6 changes: 5 additions & 1 deletion data/FirstPersonShooter.world
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,7 @@
<parameter name="hitPrefab">guid://8c628a2a1e96b3815d3476ec7c87055be14f7afe</parameter>
<parameter name="muzzleFlashPrefab">guid://dda131848d3d0f13356549567731f0bdb2587af8</parameter>
</property>
<property parent="96c240040ff7888aa3804c36b43a466e1b430b9e" guid="8f9065512eab9f295d4b71e700410ba2f3c00d69"/>
</properties>
<transform>-0.99999982 -8.7422492e-08 0 0.0 8.7422762e-08 -0.99999982 0 0.0 0 0 0.9999997 0.0 8 11.499999 0.99999994 1.0</transform>
<node type="PlayerDummy" id="1303834765" name="PlayerDummy">
Expand Down Expand Up @@ -2555,6 +2556,9 @@
<streaming_mode_ram>0</streaming_mode_ram>
<mesh_name>guid://89640b0d7ffa9f7f02a1a97753abc138ef6e3f24</mesh_name>
<surface name="box" intersection="1" shadow_mask="0x0" viewport_mask="0x0" intersection_mask="0x2" material="37b5258e98b7907a6fdfa8cc5256713c8ffef517"/>
<properties>
<property parent="51e877b3c29f323185bb02f9fb15bbc3f3022b4b" guid="32fbb6e3f511f228f0ff32a98500d9171aac507b"/>
</properties>
<transform>1 -7.1054274e-15 2.9611872e-16 0.0 7.1054274e-15 1 2.4335929e-08 0.0 -2.9611893e-16 -2.4335929e-08 1 0.0 5.5368699e-21 3.765877e-14 0 1.0</transform>
</node>
</node>
Expand All @@ -2575,7 +2579,7 @@
</node>
<node type="NodeReference" id="1735244756" name="robot_enemy">
<reference>guid://1052eb5f16b3c132e06baee99e58ab34533a5d03</reference>
<transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0.075533859 5.9413724 0.99999994 1.0</transform>
<transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0.075533859 5.9413724 1.5 1.0</transform>
</node>
</editor>
<console>
Expand Down
10 changes: 10 additions & 0 deletions data/csharp_template/FP_controller/components/EnemyLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class EnemyLogic : Component
// инициализируем состояние врага
private EnemyLogicState currentState = EnemyLogicState.Idle;

private Health health = null;

private bool targetIsVisible;
private Vec3 lastSeenPosition;
private vec3 lastSeenDirection;
Expand Down Expand Up @@ -80,6 +82,9 @@ private void Init()
targetIsVisible = false;
// берем компонент EnemyFireController
fireController = node.GetComponent<EnemyFireController>();

health = node.GetComponentInChildren<Health>();

shouldUpdateRoute = true;
lastCalculationTime = Game.Time;

Expand Down Expand Up @@ -108,6 +113,11 @@ private void Update()
case EnemyLogicState.Attack: color = vec4.RED; break;
}

// проверяем, выставлен ли флаг IsDead
if (health && health.IsDead)
// удаляем врага со сцены, если он убит (IsDead)
node.DeleteLater();

// визуализируем состояния врага
Visualizer.RenderPoint3D(node.WorldPosition + vec3.UP * 2.0f, 0.25f, color);
Visualizer.RenderPoint3D(node.WorldPosition + vec3.UP * 3.0f, 0.25f, IsTargetVisible() ? vec4.GREEN : vec4.RED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<asset version="2.18.0.1">
<guid>5158593f996ef01aae4f3a2a8ce7a21d539470f6</guid>
<type>component</type>
<hash>a3aaceda</hash>
<hash>0bbb0373</hash>
<runtimes>
<runtime id="5158593f996ef01aae4f3a2a8ce7a21d539470f6" name="EnemyLogic.cs" link="0"/>
<runtime id="5efec285bbcacbfd75d58238dff8fedd1ee54024" name="EnemyLogic.prop" link="1" type="4"/>
Expand Down
20 changes: 19 additions & 1 deletion data/csharp_template/FP_controller/components/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class HUD : Component
public AssetLink crosshairImage = null;
public int crosshairSize = 16;

private WidgetLabel label = null;

private WidgetSprite sprite = null;
private Gui screenGui = null;
private ivec2 prev_size = new ivec2(0, 0);
Expand All @@ -30,6 +32,16 @@ private void Init()
screenGui.AddChild(sprite, Gui.ALIGN_CENTER | Gui.ALIGN_OVERLAP);
// привязываем время жизни виджета к миру
sprite.Lifetime = Widget.LIFETIME.WORLD;

// добавляем виджет WidgetLabel для отображения здоровья игрока, устанавливаем его положение размер шрифта
label = new WidgetLabel(screenGui, "");
label.FontSize = 50;
label.SetPosition(10, 10);

// добавляем виджет к GUI
screenGui.AddChild(label, Gui.ALIGN_CENTER | Gui.ALIGN_OVERLAP);
// привязываем время жизни виджета к миру
label.Lifetime = Widget.LIFETIME.WORLD;
}

private void Update()
Expand All @@ -38,8 +50,14 @@ private void Update()
if (prev_size != new_size)
{
screenGui.RemoveChild(sprite);
screenGui.AddChild(sprite, Gui.ALIGN_CENTER | Gui.ALIGN_OVERLAP);
screenGui.AddChild(sprite, Gui.ALIGN_OVERLAP | Gui.ALIGN_FIXED);
}
prev_size = new_size;
}

// обновление текущего уровня здоровья игрока
public void UpdateHealthInfo(int health)
{
label.Text = "Health: " + health.ToString();
}
}
2 changes: 1 addition & 1 deletion data/csharp_template/FP_controller/components/HUD.cs.meta
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<asset version="2.18.0.1">
<guid>5faca71f8446cfac3ee60b883c3368aef60d5fab</guid>
<type>component</type>
<hash>c4c7bfe4</hash>
<hash>3964a462</hash>
<runtimes>
<runtime id="5faca71f8446cfac3ee60b883c3368aef60d5fab" name="HUD.cs" link="0"/>
<runtime id="6b62a5653e3463f1423407e64c4abca756dadd51" name="HUD.prop" link="1" type="4"/>
Expand Down
19 changes: 19 additions & 0 deletions data/csharp_template/FP_controller/components/Health.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "51e877b3c29f323185bb02f9fb15bbc3f3022b4b")]
public class Health : Component
{
public int health = 5; // начальный уровень здоровья

// флаг, проверяющий, не достиг ли текущий уровень здоровья 0
public bool IsDead => health <= 0;

public void TakeDamage(int damage)
{
// применяем ущерб
health = MathLib.Max(health - damage, 0);
}
}
10 changes: 10 additions & 0 deletions data/csharp_template/FP_controller/components/Health.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<asset version="2.18.0.1">
<guid>6629c61dbcf5668c3f0966d3e2f41c71b0b5b1b5</guid>
<type>component</type>
<hash>a2f4f621</hash>
<runtimes>
<runtime id="6629c61dbcf5668c3f0966d3e2f41c71b0b5b1b5" name="Health.cs" link="0"/>
<runtime id="51e877b3c29f323185bb02f9fb15bbc3f3022b4b" name="Health.prop" link="1" type="4"/>
</runtimes>
</asset>
29 changes: 29 additions & 0 deletions data/csharp_template/FP_controller/components/PlayerLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "96c240040ff7888aa3804c36b43a466e1b430b9e")]
public class PlayerLogic : Component
{
private Health health = null;
private void Init()
{
// берем у ноды компонент Health
health = node.GetComponentInChildren<Health>();
// обновляем информацию об исходном здоровье игрока
ComponentSystem.FindComponentInWorld<HUD>().UpdateHealthInfo(health.health);
}

private void Update()
{
// проверяем выставлен ли флаг IsDead
if (health && health.IsDead)
{
// обездвиживаем игрока, отключая компоненты
node.GetComponent<FirstPersonController>().Enabled = false;
node.GetComponent<WeaponController>().Enabled = false;
node.GetComponent<ShootInput>().Enabled = false;
}
}
}
10 changes: 10 additions & 0 deletions data/csharp_template/FP_controller/components/PlayerLogic.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<asset version="2.18.0.1">
<guid>c70564d6d805b75f7c23b858d839b1091b4f9c80</guid>
<type>component</type>
<hash>8602d67f</hash>
<runtimes>
<runtime id="c70564d6d805b75f7c23b858d839b1091b4f9c80" name="PlayerLogic.cs" link="0"/>
<runtime id="96c240040ff7888aa3804c36b43a466e1b430b9e" name="PlayerLogic.prop" link="1" type="4"/>
</runtimes>
</asset>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void Shoot()

// визуализируем эффект попадания в точке пересечения
vfx.OnHit(hitInfo.Point, hitInfo.Normal, hitObject);

Health health = hitObject.GetComponent<Health>();
if (health)
health.TakeDamage(damage);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<asset version="2.18.0.1">
<guid>1005e2b9f814eb840a73c08a2aabf58cc6fbbb65</guid>
<type>component</type>
<hash>fbeaac5a</hash>
<hash>9a8478aa</hash>
<runtimes>
<runtime id="1005e2b9f814eb840a73c08a2aabf58cc6fbbb65" name="WeaponController.cs" link="0"/>
<runtime id="f242c1ef0b63af70a079e9989c2f5f4b62a1c57b" name="WeaponController.prop" link="1" type="4"/>
Expand Down
48 changes: 25 additions & 23 deletions data/fps/robot/robot_enemy.node
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<nodes version="2.18.0.1">
<node type="ObjectDummy" id="19500806" name="robot_root">
<body type="BodyRigid" id="1982313634" frozen="0">
<node type="ObjectDummy" id="222931157" name="robot_root">
<body type="BodyRigid" id="1152047135" frozen="0">
<angular_scale>0 0 0</angular_scale>
<shape type="ShapeCapsule" id="967673276" transform="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.850000024 1">
<shape type="ShapeCapsule" id="2118638913" transform="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.850000024 1">
<radius>0.5</radius>
<height>0.699999988</height>
</shape>
</body>
<properties>
<property parent="7eb5cbfb6c98181a790c65d41fb95f354d95dfc7" guid="d01a6afd17bbe07670f96592bcf7e07b219901b2">
<parameter name="leftMuzzle">594287224</parameter>
<parameter name="rightMuzzle">359711338</parameter>
<property parent="7eb5cbfb6c98181a790c65d41fb95f354d95dfc7" guid="4d01e108b2ca522eb0fb5ada70567bb62c1b7742">
<parameter name="leftMuzzle">1513852383</parameter>
<parameter name="rightMuzzle">1365570921</parameter>
<parameter name="bulletPrefab">guid://ec33ae15d2782870bf95a10f4fab1b221b40e019</parameter>
</property>
<property parent="5efec285bbcacbfd75d58238dff8fedd1ee54024" guid="029bd1f973305c170860d2c8f400cb3b1242f569">
<property parent="5efec285bbcacbfd75d58238dff8fedd1ee54024" guid="5e8aa7a154399ddfc90707b7bb82752410ca4db9">
<parameter name="player">131174606</parameter>
<parameter name="intersectionSocket">30316844</parameter>
<parameter name="intersectionSocket">1763698563</parameter>
<parameter name="playerIntersectionMask">0x2</parameter>
<parameter name="navigationMesh">1177965118</parameter>
</property>
</properties>
<transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0 0 0 1.0</transform>
<node type="ObjectMeshSkinned" id="1377671853" name="visuals">
<node type="ObjectMeshSkinned" id="1061053488" name="visuals">
<mesh_name>guid://113ec57667d1fe5d0486ec1847b280978e7aa50a</mesh_name>
<fps_visible_camera>-1</fps_visible_camera>
<fps_visible_shadow>30</fps_visible_shadow>
Expand All @@ -33,55 +32,58 @@
<surface name="robot_glass_color" intersection="1" intersection_mask="0x3" physics_friction="1" physics_restitution="1" material="1ee39dfdeca5c738c2b26137b098cd2a1f0a1a81"/>
<surface name="robot_glass_reflections_mat" intersection="1" intersection_mask="0x3" physics_friction="1" physics_restitution="1" material="e2b3d14bd547762e14a447b5be05b590e4208baf"/>
<surface name="robot_mat" intersection="1" intersection_mask="0x3" physics_friction="1" physics_restitution="1" material="bc7eb378d117e07749b3c36aafc61bc1ce66422c"/>
<properties>
<property parent="51e877b3c29f323185bb02f9fb15bbc3f3022b4b" guid="6ef9c700db403f62460ca592b5eaaa57035ce5fa"/>
</properties>
<transform>0.49999994 -3.7865182e-29 4.2351652e-22 0.0 3.7865191e-29 0.5 -3.5527162e-15 0.0 -4.2351657e-22 3.5527162e-15 0.5 0.0 0 0 0 1.0</transform>
<node type="WorldTransformBone" id="1316338728" name="WorldTransformBone">
<node type="WorldTransformBone" id="389360079" name="WorldTransformBone">
<bone>joint_2</bone>
<transform>0.71341574 -0.69943857 0.042703133 0.0 0.55578786 0.60190356 0.57342124 0.0 -0.42677617 -0.38535389 0.818147 0.0 0.27450061 0.27222845 0.76832491 1.0</transform>
<node type="NodeReference" id="21590375" name="jet_3">
<node type="NodeReference" id="771853538" name="jet_3">
<reference>guid://0a134f9336798fd67bd0853d9e11057894320a77</reference>
<transform>2.0000455 4.5448542e-07 7.7486038e-07 0.0 -2.2940338e-05 2.0000837 4.7683716e-07 0.0 1.5363097e-05 1.3530254e-05 2.0000713 0.0 -1.9073486e-06 -1.6391277e-06 -0.23828951 1.0</transform>
</node>
</node>
<node type="WorldTransformBone" id="794361308" name="WorldTransformBone_1">
<node type="WorldTransformBone" id="1386662515" name="WorldTransformBone_1">
<bone>joint_3</bone>
<transform>-0.69019872 -0.71501589 -0.11125735 0.0 0.64177847 -0.67588562 0.36235246 0.0 -0.33428502 0.17869264 0.92537683 0.0 0.27457523 -0.2628285 0.76287109 1.0</transform>
<node type="NodeReference" id="1670741899" name="jet_2">
<node type="NodeReference" id="684461366" name="jet_2">
<reference>guid://0a134f9336798fd67bd0853d9e11057894320a77</reference>
<transform>2.0000529 7.1525574e-07 -2.8312206e-07 0.0 2.5868416e-05 2.0000694 0 0.0 -6.1839819e-06 5.0067902e-06 2.0000868 0.0 8.3446503e-07 -7.1525574e-07 -0.24650681 1.0</transform>
</node>
</node>
<node type="WorldTransformBone" id="40804560" name="WorldTransformBone_2">
<node type="WorldTransformBone" id="930792279" name="WorldTransformBone_2">
<bone>joint_4</bone>
<transform>-0.66923231 0.73246187 -0.12501162 0.0 -0.695288 -0.55793941 0.45307654 0.0 0.26211244 0.39013252 0.88266277 0.0 -0.25062135 -0.26249185 0.72265375 1.0</transform>
<node type="NodeReference" id="611319279" name="jet_1">
<node type="NodeReference" id="184453322" name="jet_1">
<reference>guid://0a134f9336798fd67bd0853d9e11057894320a77</reference>
<transform>2.0000427 -6.92904e-07 2.9802322e-07 0.0 -2.2009015e-05 2.0000668 -2.3841858e-07 0.0 1.4021993e-05 1.5318394e-05 2.0000677 0.0 -1.3113022e-06 -2.0861626e-06 -0.23225865 1.0</transform>
</node>
</node>
<node type="WorldTransformBone" id="823007492" name="WorldTransformBone_3">
<node type="WorldTransformBone" id="1088714875" name="WorldTransformBone_3">
<bone>joint_5</bone>
<transform>0.73238534 0.6773814 0.069038153 0.0 -0.6677205 0.69467193 0.26754504 0.0 0.13327116 -0.24204428 0.96106887 0.0 -0.250696 0.2725651 0.72810757 1.0</transform>
<node type="NodeReference" id="1233244307" name="jet">
<node type="NodeReference" id="1410143134" name="jet">
<reference>guid://0a134f9336798fd67bd0853d9e11057894320a77</reference>
<transform>2.0000515 -1.0430813e-07 4.4703484e-08 0.0 2.669543e-05 2.000087 0 0.0 -7.0631504e-06 6.0796738e-06 2.0000861 0.0 1.0430813e-06 -9.5367432e-07 -0.2365478 1.0</transform>
</node>
</node>
<node type="WorldTransformBone" id="594287224" name="LeftGunBone">
<node type="WorldTransformBone" id="1513852383" name="LeftGunBone">
<bone>joint_8</bone>
<transform>0.99988168 -1.7359685e-05 0.015381269 0.0 -0.00013943078 0.99994802 0.010192467 0.0 -0.015380647 -0.010193406 0.99982971 0.0 -0.63721955 0.39293978 1.4175342 1.0</transform>
<node type="NodeDummy" id="825236343" name="LeftGunMuzzle">
<node type="NodeDummy" id="1724055986" name="LeftGunMuzzle">
<transform>0.99999994 0 0 0.0 0 0.99999994 0 0.0 0 0 0.99999988 0.0 0 0.80000001 -1.1920929e-07 1.0</transform>
</node>
</node>
<node type="WorldTransformBone" id="359711338" name="RightGunBone">
<node type="WorldTransformBone" id="1365570921" name="RightGunBone">
<bone>joint_11</bone>
<transform>0.99988168 -1.7359685e-05 0.015381269 0.0 -0.00013943078 0.99994802 0.010192467 0.0 -0.015380647 -0.010193406 0.99982971 0.0 0.62459785 0.39291796 1.4369448 1.0</transform>
<node type="NodeDummy" id="1022955201" name="RightGunMuzzle">
<node type="NodeDummy" id="261636020" name="RightGunMuzzle">
<transform>1 1.4551915e-11 0 0.0 0 1 -9.3132257e-10 0.0 9.3132257e-10 0 0.99999994 0.0 0 0.80000001 0 1.0</transform>
</node>
</node>
</node>
<node type="NodeDummy" id="30316844" name="robot_intersection_socket">
<node type="NodeDummy" id="1763698563" name="robot_intersection_socket">
<transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0 0 0.90023208 1.0</transform>
</node>
</node>
Expand Down
Loading

0 comments on commit 3f40e9a

Please sign in to comment.