• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision731 (tree)
Zeit2011-02-21 11:25:24
Autorbiikame

Log Message

SpriteをCharacterに継承させるように修正

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Characters/Character.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Characters/Character.cs (revision 731)
@@ -9,19 +9,13 @@
99 /// <summary>
1010 /// キャラクタクラス
1111 /// </summary>
12- public class Character : ISprite {
13- public Character( int typeID , SpriteType spriteType , Size characterSize , LocationF location ) {
14- Sprite = new Sprite( LayerType.Character , typeID , spriteType , this , "CharacterImages" , characterSize , string.Format( "Character-{0}" , typeID ) , location );
12+ public class Character : Sprite {
13+ public Character( int typeID , SpriteType spriteType , Size characterSize , LocationF location )
14+ : base( LayerType.Character , typeID , spriteType , "CharacterImages" , characterSize , string.Format( "Character-{0}" , typeID ) , location )
15+ {
1516 }
1617
1718 /// <summary>
18- /// Characterオブジェクトが所有するスプライトを取得します。
19- /// </summary>
20- public Sprite Sprite {
21- get;
22- private set;
23- }
24- /// <summary>
2519 /// 現在の攻撃モードを取得または、設定します。
2620 /// </summary>
2721 public AttackType AttackType {
@@ -28,20 +22,5 @@
2822 get;
2923 set;
3024 }
31-
32- #region IDisposable メンバー
33- public void Dispose() {
34- Sprite.Dispose();
35- }
36- #endregion
37-
38- #region IDisposableComponent メンバー
39-
40- /// <summary>
41- /// オブジェクトが破棄されたときに発生します。
42- /// </summary>
43- public event EventHandler Disposed;
44-
45- #endregion
4625 }
4726 }
--- trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 731)
@@ -11,7 +11,7 @@
1111 namespace Nlgp1.Characters {
1212 public static class SpriteFactory {
1313 private static Sprite create( int typeID , LocationF location , Size characterSize ){
14- var newSprite = new Character( typeID , SpriteType.Monster , characterSize , location ).Sprite;
14+ var newSprite = new Character( typeID , SpriteType.Monster , characterSize , location );
1515 newSprite.Bounds.BlankLeft = 2;
1616 newSprite.Bounds.BlankRight = 2;
1717 newSprite.Bounds.BlankTop = 0;
@@ -151,7 +151,7 @@
151151 case 14:
152152 #region 10秒アイテム
153153 newSprite.ActionEvent += new EventHandler<SpriteActionEventArgs>( ( sender , e ) => {
154- if( e.Target.Bounds.HitTest( PlayerStatus.PlayerSprite.Bounds ) ) {
154+ if( e.Target.Bounds.HitTest( PlayerStatus.Player.Bounds ) ) {
155155 PlayerStatus.TimerInitialize();
156156 e.Target.Dispose();
157157 }
@@ -162,10 +162,10 @@
162162 #region 乗ると強制的に右に移動する
163163 newSprite.CanDefaultAction = false;
164164 newSprite.ActionEvent += new EventHandler<SpriteActionEventArgs>( ( sender , e ) => {
165- if( SpriteAction.HitDirection( PlayerStatus.PlayerSprite , e.Target ) == DirectionType.Top ) {
166- SpriteAction.Physisorption( PlayerStatus.PlayerSprite , e.Target , DirectionType.Top );
165+ if( SpriteAction.HitDirection( PlayerStatus.Player , e.Target ) == DirectionType.Top ) {
166+ SpriteAction.Physisorption( PlayerStatus.Player , e.Target , DirectionType.Top );
167167 if( e.Target.LogicParameter.Count >= 6 ) {
168- PlayerStatus.PlayerSprite.TryMove( PlayerStatus.PlayerSprite.Bounds.Width + PlayerStatus.PlayerSprite.X + 2 , PlayerStatus.PlayerSprite.Y );
168+ PlayerStatus.Player.TryMove( PlayerStatus.Player.Bounds.Width + PlayerStatus.Player.X + 2 , PlayerStatus.Player.Y );
169169 e.Target.LogicParameter.Count = 0;
170170 }
171171 e.Target.LogicParameter.Count++;
@@ -177,10 +177,10 @@
177177 #region 乗ると強制的に左に移動する
178178 newSprite.CanDefaultAction = false;
179179 newSprite.ActionEvent += new EventHandler<SpriteActionEventArgs>( ( sender , e ) => {
180- if( SpriteAction.HitDirection( PlayerStatus.PlayerSprite , e.Target ) == DirectionType.Top ) {
181- SpriteAction.Physisorption( PlayerStatus.PlayerSprite , e.Target , DirectionType.Top );
180+ if( SpriteAction.HitDirection( PlayerStatus.Player , e.Target ) == DirectionType.Top ) {
181+ SpriteAction.Physisorption( PlayerStatus.Player , e.Target , DirectionType.Top );
182182 if( e.Target.LogicParameter.Count >= 6 ) {
183- PlayerStatus.PlayerSprite.TryMove( PlayerStatus.PlayerSprite.Bounds.Width + PlayerStatus.PlayerSprite.X - 2 , PlayerStatus.PlayerSprite.Y );
183+ PlayerStatus.Player.TryMove( PlayerStatus.Player.Bounds.Width + PlayerStatus.Player.X - 2 , PlayerStatus.Player.Y );
184184 e.Target.LogicParameter.Count = 0;
185185 }
186186 e.Target.LogicParameter.Count++;
--- trunk/Nlgp1/Nlgp1/Players/PlayerController.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Players/PlayerController.cs (revision 731)
@@ -97,26 +97,26 @@
9797
9898 #region 入力状態確認
9999 if( PlayerController.Left ) {
100- PlayerStatus.PlayerSprite.Speed.X = -0.5f;
100+ PlayerStatus.Player.Speed.X = -0.5f;
101101 } else if( PlayerController.Right ) {
102- PlayerStatus.PlayerSprite.Speed.X = +0.5f;
102+ PlayerStatus.Player.Speed.X = +0.5f;
103103 } else {
104- PlayerStatus.PlayerSprite.Speed.X = 0;
104+ PlayerStatus.Player.Speed.X = 0;
105105 }
106106
107107
108108 if( PlayerController.Jump ) {
109- PlayerStatus.PlayerSprite.JumpStart();
109+ PlayerStatus.Player.JumpStart();
110110 } else if( PlayerController.Jumping == false ) {
111- PlayerStatus.PlayerSprite.JumpStop();
111+ PlayerStatus.Player.JumpStop();
112112 }
113113
114- PlayerStatus.PlayerSprite.IsBoosting = PlayerController.Boost;
114+ PlayerStatus.Player.IsBoosting = PlayerController.Boost;
115115
116116 if( PlayerController.Fly )
117- PlayerStatus.PlayerSprite.FlyStart();
117+ PlayerStatus.Player.FlyStart();
118118 else
119- PlayerStatus.PlayerSprite.FlyStop();
119+ PlayerStatus.Player.FlyStop();
120120
121121 PlayerStatus.Player.AttackType = PlayerController.Attack ? AttackType.DivineBuster : AttackType.None;
122122 #endregion
--- trunk/Nlgp1/Nlgp1/Players/PlayerStatus.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Players/PlayerStatus.cs (revision 731)
@@ -52,20 +52,6 @@
5252 }
5353
5454 /// <summary>
55- /// 自分自身のキャラクタのスプライトを取得します。
56- /// </summary>
57- public static Sprite PlayerSprite {
58- get {
59- if ( PlayerStatus.Player != null ) {
60- return PlayerStatus.Player.Sprite;
61- }
62- else {
63- return null;
64- }
65- }
66- }
67-
68- /// <summary>
6955 /// 自分自身のキャラクタを初期化します。
7056 /// </summary>
7157 /// <param name="location">初期位置</param>
@@ -72,12 +58,12 @@
7258 public static Sprite LoadPlayer( LocationF location ) {
7359 TimerInitialize();
7460
75- if( PlayerSprite != null )
76- PlayerSprite.Dispose();
61+ if( Player != null )
62+ Player.Dispose();
7763
7864 // 自分自身のパラメータは、ここで設定する
7965 Player = new Character( 1 , SpriteType.Player , MapData.DefaultChipSize , location );
80- PlayerSprite.HitPoint = 100;
66+ Player.HitPoint = 100;
8167 // Player.GetRectangle.BlankLeft = -2;
8268 // Player.GetRectangle.BlankRight = -2;
8369 // Player.GetRectangle.BlankBottom = 32;
@@ -92,7 +78,7 @@
9278 */
9379
9480 #region プレーヤー自身に対するActionイベント
95- PlayerSprite.ActionEvent += new EventHandler<SpriteActionEventArgs>( ( sender , e ) => {
81+ Player.ActionEvent += new EventHandler<SpriteActionEventArgs>( ( sender , e ) => {
9682 if( ( e.Target.MovingDirection & DirectionFlags.Top ) != 0 &&
9783 e.Target.GetHittingSprites( AspectType.Vertical ).Any( ( sprite ) => ( sprite.IsDestroyable ) ) ) {
9884 // 上方向に移動しており、衝突したセルが破壊可能であれば、そのセルを置換します。
@@ -186,7 +172,7 @@
186172 return type;
187173 };
188174 */
189- return PlayerStatus.PlayerSprite;
175+ return PlayerStatus.Player;
190176 }
191177 }
192178 }
--- trunk/Nlgp1/Nlgp1/Stages/GameMap.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Stages/GameMap.cs (revision 731)
@@ -47,7 +47,7 @@
4747 }
4848 }
4949 else {
50- sprite = new Sprite( layerType , cell.CellTypeID , SpriteType.Monster , null , Path.Combine( @"Stages\Defines\Maps\Normal" , layerType.ToString() ) , MapData.DefaultChipSize , null , location );
50+ sprite = new Sprite( layerType , cell.CellTypeID , SpriteType.Monster , Path.Combine( @"Stages\Defines\Maps\Normal" , layerType.ToString() ) , MapData.DefaultChipSize , null , location );
5151 }
5252 sprite.UpGravity = 0;
5353 sprite.DownGravity = 0;
--- trunk/Nlgp1/Nlgp1/Sprites/ISprite.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Sprites/ISprite.cs (revision 731)
@@ -9,11 +9,5 @@
99 /// スプライトを表す
1010 /// </summary>
1111 public interface ISprite : IDisposableComponent {
12- /// <summary>
13- /// スプライトを取得します。
14- /// </summary>
15- Sprite Sprite {
16- get;
17- }
1812 }
1913 }
--- trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 731)
@@ -13,7 +13,7 @@
1313 /// <summary>
1414 /// スプライトを表す。
1515 /// </summary>
16- public class Sprite : IDisposableComponent , IDraw , IMotion {
16+ public class Sprite : IDraw , ISprite , IMotion {
1717 private static List<Sprite> objectList = new List<Sprite>();
1818 /// <summary>
1919 /// 生存するスプライトをコレクションで取得します。
@@ -52,17 +52,15 @@
5252 /// <param name="layerType">レイヤの種類</param>
5353 /// <param name="typeID">識別ID</param>
5454 /// <param name="spriteType">スプライトの属性</param>
55- /// <param name="owner">スプライトの作成元</param>
5655 /// <param name="imageTypeName">使用するグラフィックフォルダ名</param>
5756 /// <param name="chipSize">スプライトのサイズ(最小=32x32)</param>
5857 /// <param name="debugID">デバッグ用 識別子 (通常使わない)</param>
5958 /// <param name="location">初期位置</param>
60- public Sprite( LayerType layerType , int typeID , SpriteType spriteType , ISprite owner , string imageTypeName , Size chipSize , string debugID , LocationF location ) {
59+ public Sprite( LayerType layerType , int typeID , SpriteType spriteType , string imageTypeName , Size chipSize , string debugID , LocationF location ) {
6160 lock( objectList )
6261 objectList.Add( this );
6362
6463 this.Motion = SpriteMotion.Get( layerType , imageTypeName , typeID , chipSize );
65- this.Owner = owner;
6664 this.Speed = new Speed();
6765 this.LogicParameter = new ActionParameter();
6866 this.Bounds = new Parameters.Bounds( this , new LocationF() , chipSize );
@@ -102,14 +100,6 @@
102100 }
103101
104102 /// <summary>
105- /// このスプライトの作成元のスプライトを取得します。
106- /// </summary>
107- public ISprite Owner {
108- get;
109- private set;
110- }
111-
112- /// <summary>
113103 /// 攻撃スロットに関連付けられているIAttackオブジェクトを取得します。
114104 /// </summary>
115105 /// <param name="attackType">攻撃方法</param>
@@ -968,7 +958,7 @@
968958 return this.DebugID;
969959 }
970960 else {
971- return string.Format( "{0}-{1}" , this.Owner , this.TypeID );
961+ return string.Format( "{0}-{1}" , base.ToString() , this.TypeID );
972962 }
973963 }
974964 #endregion
--- trunk/Nlgp1/Nlgp1/Attacks/Shot.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Attacks/Shot.cs (revision 731)
@@ -10,7 +10,7 @@
1010 /// 弾丸を生成する。
1111 /// </summary>
1212 /// <typeparam name="T">弾丸クラスの型</typeparam>
13- public class Shot<T> : Attack , IAttack where T : IGun , new() {
13+ public class Shot<T> : Attack , IAttack where T : IGun {
1414 private List<T> gunList = new List<T>();
1515 private Sprite ownerObject;
1616
@@ -29,8 +29,7 @@
2929 this.CanMoveingAttack = false;
3030
3131 this.Attacking += new EventHandler( ( sender , e ) => {
32- T gun = new T();
33- gun.Initialize( this.GunTypeID , this , gunSize , null , new LocationF() );
32+ T gun = Utility.Construct< T >( this.GunTypeID , this , gunSize , null , new LocationF() );
3433
3534 if( InitializeEvent != null )
3635 InitializeEvent( this , new SpriteActionEventArgs<T>( gun ) );
--- trunk/Nlgp1/Nlgp1/Attacks/Guns/IGun.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Attacks/Guns/IGun.cs (revision 731)
@@ -6,14 +6,5 @@
66 /// 弾丸を表す
77 /// </summary>
88 public interface IGun : ISprite {
9- /// <summary>
10- /// 弾丸を初期化します。
11- /// </summary>
12- /// <param name="typeID">弾の種類を表すID</param>
13- /// <param name="source">弾の作成元のIShotオブジェクト</param>
14- /// <param name="gunSize">弾のサイズ</param>
15- /// <param name="debugID">デバッグ用 識別子 (通常使わない)</param>
16- /// <param name="location">初期位置</param>
17- void Initialize( int typeID , IAttack source , Size gunSize , string debugID , LocationF location );
189 }
1910 }
--- trunk/Nlgp1/Nlgp1/Attacks/Guns/Gun.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Attacks/Guns/Gun.cs (revision 731)
@@ -8,18 +8,10 @@
88 /// <summary>
99 /// 弾を表す
1010 /// </summary>
11- public class Gun : IGun {
11+ public class Gun : Sprite , IGun {
1212 private bool isCharRight = false;
1313
1414 /// <summary>
15- /// 弾のスプライトを取得します。
16- /// </summary>
17- public Sprite Sprite {
18- get;
19- private set;
20- }
21-
22- /// <summary>
2315 /// 弾を生成したIShotオブジェクトを取得します。
2416 /// </summary>
2517 public IAttack Owner {
@@ -28,27 +20,13 @@
2820 }
2921
3022 #region IGun メンバー
31- void IGun.Initialize( int typeID , IAttack source , Size gunSize , string debugID , LocationF location ) {
23+ Gun( int typeID , IAttack source , Size gunSize , string debugID , LocationF location )
24+ : base( LayerType.Character , typeID , source.Owner.SpriteType , "GunImages" , gunSize , debugID , location )
25+ {
3226 this.Owner = source;
33- this.Sprite = new Sprite( LayerType.Character , typeID , source.Owner.SpriteType , this , "GunImages" , gunSize , debugID , location );
3427
3528
3629 }
3730 #endregion
38-
39- #region IDisposable メンバー
40- public void Dispose() {
41- Sprite.Dispose();
42- }
43- #endregion
44-
45- #region IDisposableComponent メンバー
46-
47- /// <summary>
48- /// オブジェクトが破棄されたときに発生します。
49- /// </summary>
50- public event EventHandler Disposed;
51-
52- #endregion
5331 }
5432 }
--- trunk/Nlgp1/Nlgp1/Program.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1/Program.cs (revision 731)
@@ -56,7 +56,7 @@
5656
5757 // タイムアウト判定
5858 #region 描画
59- StageView.DisplayDraw( PlayerStatus.PlayerSprite , Sprite.SpriteCollection().Cast<IDraw>() );
59+ StageView.DisplayDraw( PlayerStatus.Player , Sprite.SpriteCollection().Cast<IDraw>() );
6060
6161 //----------- ここからデバッグ用表示 -------------------------
6262 Screen.DrawString( new Location( 12 , 9 ) , string.Format( "残り{0}秒 {1}" , PlayerStatus.TimeLimit / 1000 , PlayerStatus.TimeLimit < 0 ? "TimeOut!!" : string.Empty ) ,
@@ -63,7 +63,7 @@
6363 meiryoFont , new Color( 0x00 , 0xFF , 0xFF ) );
6464
6565 // if( message == null )
66- DebugSprite( PlayerStatus.PlayerSprite );
66+ DebugSprite( PlayerStatus.Player );
6767
6868 Screen.DrawString( new Location( 5 , 32 ), message , meiryoFont , new Color( 0x00 , 0xFF , 0x00 ) );
6969
--- trunk/Nlgp1/Nlgp1.Common/Utility.cs (revision 730)
+++ trunk/Nlgp1/Nlgp1.Common/Utility.cs (revision 731)
@@ -102,5 +102,9 @@
102102
103103
104104 }
105+
106+ public static T Construct<T>( params object[] args ) {
107+ return ( T )( typeof( T ).InvokeMember( null , BindingFlags.CreateInstance | BindingFlags.Public , null , null , args ) );
108+ }
105109 }
106110 }
Show on old repository browser