6.计分
计分概述:
分值计量直接反应玩家在游戏中获得的成就感。因此,计分系统在游戏中显得尤为重要,有的反应在直接获取的分数上,有的反应在杀敌数量上等。
计分原理:
原理图,如图6-1所示。
图6-1
实现方法:
步骤1:
子弹击中敌人。击中敌人的条件参考4.碰撞检测内容。
步骤2:
敌人死亡。相关代码如下所示。
步骤3:
3.1计分器计分原理:
(1)定义一个有九个格子的显示器面板,面板从右到左用下角标标注为0-8,每个格子存放0-9十个数字。
(2)设定每消灭一个敌人,玩家获取5分,将数值每次传给一个变量var;将数值var传给string数组。
(3)数组中有数值的位数,对应显示器面板方格的下角标,使对应下角标方格的数字显示,并且设定数字为数组中对应的数值。
3.2代码的实现:
//定义存放数字的9个方格
_NumberSimulator = new UI_Number_Simulate(_windowName,
"JuanZhouNumber", 9);
//设置现有分数
_NumberSimulator.SetNumber(ScriptRuntime.MarkMgr.Instance.GetMark(),true);
01 |
public class UI_Number_Simulate
|
03 |
private class NumberSimulate
|
07 |
char _currentChar = ‘a‘ ;
|
08 |
public NumberSimulate(FString layoutname, string simulateID)
|
11 |
_layoutname = layoutname; |
12 |
_simulateID = simulateID; |
17 |
public void DoNumSimulate ( char var)
|
19 |
if (_layoutname == null || _simulateID == null )
|
23 |
if (_currentChar == var)
|
31 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_0" , true );
|
32 |
} else if (var == ‘1‘ ) {
|
33 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_1" , true );
|
34 |
} else if (var == ‘2‘ ) {
|
35 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_2" , true );
|
36 |
} else if (var == ‘3‘ ) {
|
37 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_3" , true );
|
38 |
} else if (var == ‘4‘ ) {
|
39 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_4" , true );
|
40 |
} else if (var == ‘5‘ ) {
|
41 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_5" , true );
|
42 |
} else if (var == ‘6‘ ) {
|
43 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_6" , true );
|
44 |
} else if (var == ‘7‘ ) {
|
45 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_7" , true );
|
46 |
} else if (var == ‘8‘ ) {
|
47 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_8" , true );
|
48 |
} else if (var == ‘9‘ ) {
|
49 |
GUI.UIWidget.SetVisible (_layoutname, _simulateID + "_9" , true );
|
54 |
public void SetAllInvisible()
|
56 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_0" , false );
|
57 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_1" , false );
|
58 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_2" , false );
|
59 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_3" , false );
|
60 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_4" , false );
|
61 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_5" , false );
|
62 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_6" , false );
|
63 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_7" , false );
|
64 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_8" , false );
|
65 |
GUI.UIWidget.SetVisible(_layoutname, _simulateID + "_9" , false );
|
68 |
private List<numbersimulate> _List = new List<numbersimulate>();
|
70 |
public UI_Number_Simulate (FString layoutname, string simulateID, int size)
|
73 |
for ( int i=0; i < size; i++)
|
75 |
NumberSimulate numSimulate = new NumberSimulate(layoutname, simulateID + i.ToString());
|
76 |
_List.Add(numSimulate); |
77 |
numSimulate.SetAllInvisible(); |
83 |
public void SetNumber ( int num, bool numFromLeftToRight)
|
86 |
string numString = num.ToString ();
|
87 |
if (numFromLeftToRight)
|
89 |
numString = numString.PadRight (_List.Count, ‘a‘ );
|
93 |
numString = numString.PadLeft (_List.Count, ‘a‘ );
|
95 |
for ( int i = 0; i < _List.Count; ++i)
|
97 |
_List[i].DoNumSimulate(numString[i]); |
99 |
}</numbersimulate></numbersimulate> |
《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇06:计分》