• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision695 (tree)
Zeit2011-02-12 20:20:53
Autorbiikame

Log Message

Nlgp1.Sprite.Sprite.UnloadおよびUpdateを作成

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Stages/Stage.cs (revision 694)
+++ trunk/Nlgp1/Nlgp1/Stages/Stage.cs (revision 695)
@@ -24,6 +24,7 @@
2424 Index = stageIndex;
2525 StageData stageData = StageData.Load( Program.CurrentDirectory , stageIndex );
2626 StageDrawer.LoadStage( stageData.ChipCount );
27+ Sprite.LoadStage( stageData.MapRowCount , stageData.MapColumnCount );
2728
2829 World = new World( new AABB { LowerBound = new Vec2( 0 , 0 ), UpperBound = new Vec2( stageData.MapColumnCount , stageData.MapRowCount ) * ChipImage.SizeSide } , new Vec2() , false );
2930
@@ -72,7 +73,10 @@
7273 }
7374
7475 public static void Update( Controller controller ) {
75- World.Step( 1.0f / 60.0f , 8 , 1 );
76+ World.Step( 1 , 8 , 1 );
77+ foreach ( Sprite sprite in Sprite.GetCollection() ) {
78+ sprite.Update();
79+ }
7680 }
7781
7882 /// <summary>
--- trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 694)
+++ trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 695)
@@ -21,6 +21,10 @@
2121 /// <param name="World">Worldオブジェクト</param>
2222 /// <param name="location">現在の座標</param>
2323 public Sprite( ChipId chipId , World world , Vec2 location ) {
24+ #region コレクション
25+ lock( spriteList )
26+ spriteList.Add( this );
27+ #endregion
2428 this.ChipId = chipId;
2529 this.World = world;
2630 this.Location = location;
@@ -28,6 +32,18 @@
2832 }
2933
3034 /// <summary>
35+ /// ゲームから削除される際に呼ばれます
36+ /// </summary>
37+ public void Unload() {
38+ }
39+
40+ /// <summary>
41+ /// 1フレーム毎に呼ばれます
42+ /// </summary>
43+ public void Update() {
44+ }
45+
46+ /// <summary>
3147 /// チップの種類を識別するIDを取得します。
3248 /// </summary>
3349 public ChipId ChipId {
@@ -68,5 +84,42 @@
6884 }
6985 }
7086 #endregion
87+
88+ #region コレクション
89+ /// <summary>
90+ /// ステージを読み込みます。
91+ /// </summary>
92+ /// <param name="mapHeight">シートの縦幅</param>
93+ /// <param name="mapWidth">シートの横幅</param>
94+ public static void LoadStage( int mapHeight , int mapWidth ) {
95+ spriteList = new List< Sprite >( mapHeight * mapWidth );
96+ }
97+ /// <summary>
98+ /// 生存するスプライトをコレクションで取得します。
99+ /// </summary>
100+ /// <returns></returns>
101+ public static IEnumerable<Sprite> GetCollection() {
102+ lock( spriteList ) {
103+ int count = spriteList.Count;
104+ foreach( Sprite sprite in spriteList ) {
105+ yield return sprite;
106+ if( spriteList.Count != count )
107+ yield break;
108+ }
109+ }
110+ }
111+ /// <summary>
112+ /// すべてのオブジェクトを削除します。
113+ /// </summary>
114+ public static void ClearCollection() {
115+ lock( spriteList ) {
116+ foreach( var sprite in spriteList )
117+ sprite.Unload();
118+ spriteList.Clear();
119+ }
120+ }
121+
122+ private static List< Sprite > spriteList;
123+ #endregion
71124 }
72125 }
\ No newline at end of file
Show on old repository browser