-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f40e9a
commit 7de38b7
Showing
11 changed files
with
163 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
data/csharp_template/FP_controller/components/GameController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Unigine; | ||
|
||
public enum GameState | ||
{ | ||
Gameplay, | ||
Win, | ||
Lose, | ||
} | ||
|
||
[Component(PropertyGuid = "aa9f1fea1e56f7a6da31878c2789e44171c877b4")] | ||
public class GameController : Component | ||
{ | ||
public GameState state; | ||
public Player EndCamera = null; // Камера для финала игры | ||
|
||
public NodeDummy SpawnPoint = null; | ||
|
||
[ParameterFile] | ||
public AssetLink enemyPrefab = null; | ||
public int NumEnemies = 10; | ||
|
||
private int spawned_enemy_counter = 0; | ||
public float spawnInterval = 2.0f; | ||
private float currentTime = 0.0f; | ||
|
||
private void Init() | ||
{ | ||
// Задаем начальное состояние игрового процесса | ||
state = GameState.Gameplay; | ||
} | ||
|
||
private void Update() | ||
{ | ||
// если игра окончена | ||
if (state != GameState.Gameplay) | ||
{ | ||
// переключаемся на камеру для финала игры | ||
Game.Player = EndCamera; | ||
// показываем сообщение об итоге игры в HUD | ||
ComponentSystem.FindComponentInWorld<HUD>().DisplayStateMessage(state); | ||
} | ||
else | ||
{ | ||
// если врагов больше не осталось, переходим в состояние “Победа” (Win) | ||
Log.MessageLine(spawned_enemy_counter + NumEnemies); | ||
if (!ComponentSystem.FindComponentInWorld<EnemyLogic>() && spawned_enemy_counter == NumEnemies) | ||
state = GameState.Win; | ||
// генерируем новых врагов (enemyPrefab) в заданной точке (SpawnPoint) | ||
// с заданным интервалом времени (spawnInterval) | ||
if (spawned_enemy_counter < NumEnemies) | ||
{ | ||
currentTime += Game.IFps; | ||
|
||
if (currentTime > spawnInterval) | ||
{ | ||
currentTime -= spawnInterval; | ||
spawned_enemy_counter++; | ||
Node enemy = World.LoadNode(enemyPrefab.AbsolutePath); | ||
enemy.WorldTransform = SpawnPoint.WorldTransform; | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/csharp_template/FP_controller/components/GameController.cs.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>15d59b2cd4cb06278395d79e61d6ece3cb0bdf06</guid> | ||
<type>component</type> | ||
<hash>344bfb97</hash> | ||
<runtimes> | ||
<runtime id="15d59b2cd4cb06278395d79e61d6ece3cb0bdf06" name="GameController.cs" link="0"/> | ||
<runtime id="aa9f1fea1e56f7a6da31878c2789e44171c877b4" name="GameController.prop" link="1" type="4"/> | ||
</runtimes> | ||
</asset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters