6.計分
計分概述:
分值計量直接反應玩家在遊戲中得到的成就感。所以,計分系統在遊戲中顯得尤其重要,有的反應在直接獲取的分數上,有的反應在殺敵數量上等。數組
計分原理:
原理圖,如圖6-1所示。函數
圖6-1
實現方法:
步驟1:網站
子彈擊中敵人。擊中敵人的條件參考4.碰撞檢測內容。ui
步驟2:spa
敵人死亡。相關代碼以下所示。3d
步驟3:
3.1計分器計分原理: code
(1)定義一個有九個格子的顯示器面板,面板從右到左用下角標標註爲0-8,每一個格子存放0-9十個數字。遊戲
(2)設定每消滅一個敵人,玩家獲取5分,將數值每次傳給一個變量var;將數值var傳給string數組。ip
(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> |