• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision846 (tree)
Zeit2011-03-23 16:28:32
Autorbiikame

Log Message

Nlgp1.Parametersを修正

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 846)
@@ -124,7 +124,7 @@
124124 case 14:
125125 #region 10秒アイテム
126126 sprite.Shape.Stepped += ( sender ,e ) => {
127- foreach( ISpriteContact contact in e.Shape.Contacts ) {
127+ foreach( ISpriteShapeContact contact in e.Shape.Contacts ) {
128128 //if( ( ( IPolygonSpriteContact )( contact.Other ) ).Shape == PlayerStatus.Player.Sprite.Shape ) {
129129 // PlayerStatus.TimerInitialize();
130130 //}
--- trunk/Nlgp1/Nlgp1/Stages/StageMap.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Stages/StageMap.cs (nonexistent)
@@ -1,215 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.IO;
4-using System.Linq;
5-using Box2DX.Collision;
6-using Box2DX.Dynamics;
7-using Nlgp1.Characters;
8-using Nlgp1.Common;
9-using Nlgp1.Motions;
10-using Nlgp1.Parameters;
11-using Nlgp1.Players;
12-using Nlgp1.Sprites;
13-using Nlgp1.Utilities;
14-using Nlgp1.Views;
15-using Nlgp1.Windows;
16-
17-namespace Nlgp1.Stages {
18- /// <summary>
19- /// マップ
20- /// </summary>
21- public static class StageMap {
22- /// <summary>
23- /// ステージ(マップ)を読み込みます。
24- /// </summary>
25- public static void LoadStage( string rootPath , int stageNo ) {
26- StageMap.rootPath = rootPath;
27- StageMap.stageNo = stageNo;
28- StageMap.tickCount = 0;
29- MapData data = MapData.Load( rootPath , stageNo );
30- List< SpriteDef > defList = new List< SpriteDef >();
31- int rowNum = 0;
32- int columnNum = 0;
33- foreach( LayerType layerType in Enum.GetValues( typeof( LayerType ) ) ) {
34- Cell[,] sheet = data.GetSheet( layerType );
35- int sheetRowNum = sheet.GetLength( 1 );
36- int sheetColumnNum = sheet.GetLength( 0 );
37- rowNum = System.Math.Max( rowNum , sheetRowNum );
38- columnNum = System.Math.Max( columnNum , sheetColumnNum );
39- for( int row = 0 ; row < sheetRowNum ; ++row ) {
40- for( int column = 0 ; column < sheetColumnNum ; ++column ) {
41- if( sheet[ column , row ].TypeID >= 1 ) {
42- SpriteDef def = new SpriteDef( layerType , new Vector( column + 0.5f , row + 0.5f ) * MapData.CellSize , sheet[ column , row ] );
43- defList.Add( def );
44- if( def.IsPlayer ) {
45- StageMap.playerDef = def;
46- }
47- }
48- }
49- }
50- }
51- StageMap.worldArea = Rectangle.FromLowerUpper( new Vector(), new Vector( columnNum , rowNum ) * MapData.CellSize );
52- StageMap.world = StageWorldFactory.CreateStageWorld( StageMap.worldArea , new StageDebugView() );
53- StageMap.defs = defList.ToArray();
54- StageMap.activeArea = StageMap.ToActiveArea( playerDef.Position );
55- SpriteContactListener listener = new SpriteContactListener();
56- // マップ上にキャラクタを配置する。
57- foreach( SpriteDef def in StageMap.defs ) {
58- if( StageMap.activeArea.IsContacting( def.Position ) ) {
59- def.LoadSprite();
60- }
61- }
62- }
63-
64- public static void UnloadStage() {
65- Sprite.ClearCollection();
66- SpriteMotion.ClearCollection();
67- ChipSet.ClearCollection();
68- }
69-
70- public static void UpdateStage() {
71- // キャラクタアクション
72- StageMap.tickCount++;
73- StageMap.world.Step( () => {
74- foreach( Sprite sprite in Sprite.GetCollection() ) {
75- sprite.Step();
76- }
77- Rectangle previousActiveArea = StageMap.activeArea;
78- Rectangle currentActiveArea = StageMap.ToActiveArea( playerDef.SpritePosition );
79- StageMap.activeArea = currentActiveArea;
80- foreach( Sprite sprite in Sprite.GetCollection().ToArray() ) {
81- if( previousActiveArea.IsContacting( sprite.Body.Position ) && !currentActiveArea.IsContacting( sprite.Body.Position ) ) {
82- sprite.Unload();
83- }
84- }
85- foreach( SpriteDef def in StageMap.defs ) {
86- if( !def.IsLoaded && currentActiveArea.IsContacting( def.Position ) && !previousActiveArea.IsContacting( def.Position ) ) {
87- def.LoadSprite();
88- }
89- }
90- StageView.DrawToDisplay( StageMap.activeArea.Center , Sprite.GetCollection().OrderBy( ( sprite ) => sprite.LayerType ).Cast< IDrawable >() );
91- });
92- }
93-
94- private static Rectangle ToActiveArea( Vector position ) {
95- return Rectangle.FromCenterRadius( global::Box2DX.Common.Math.Clamp( position , StageMap.VisibleRadius , StageMap.worldArea.Size - StageMap.VisibleRadius ) , StageMap.ActiveRadius );
96- }
97-
98- private sealed class SpriteDef {
99-
100- public SpriteDef( LayerType layerType , Vector position , Cell cell ) {
101- this.LayerType = layerType;
102- this.Position = position;
103- this.Cell = cell;
104- }
105-
106- public void LoadSprite() {
107- if( this.sprite == null ) {
108- if( this.LayerType == LayerType.Character ) {
109- if( this.Cell.TypeID == 1 ) {
110- this.sprite = PlayerStatus.LoadPlayer( this.Position ); // プレーヤー
111- }
112- else {
113- this.sprite = SpriteFactory.CreateSprite( this.Cell.TypeID , this.Position , MapData.DefaultChipSize ); // キャラクタ
114- }
115- this.sprite.Stepped += ( sender , e ) => {
116- this.sprite.Body.ApplyForce( new Vector( 0 , this.sprite.DownGravity ) );
117- };
118- }
119- else {
120- this.sprite = new Sprite( this.LayerType , this.Cell.TypeID , SpriteType.Monster , null , Path.Combine( @"Stages\Defines\Maps\Normal" , this.LayerType.ToString() ) , MapData.DefaultChipSize , null , null , this.Position );
121- this.sprite.UpGravity = 0;
122- this.sprite.DownGravity = 0;
123- }
124- this.sprite.IsBlock = ( this.Cell.Types & CellTypes.Wall ) != 0;
125- this.sprite.IsDestroyable = ( this.Cell.Types & CellTypes.Destroy ) != 0;
126- this.sprite.Friction = this.Cell.Friction;
127- this.sprite.Unloaded += ( sender , e ) => {
128- this.sprite = null;
129- };
130- }
131- }
132-
133- private void Stepped( object sender , EventArgs e ) {
134- this.sprite.Step();
135- }
136-
137- public bool IsPlayer {
138- get {
139- return this.LayerType == LayerType.Character && this.Cell.TypeID == 1;
140- }
141- }
142-
143- public bool IsLoaded {
144- get {
145- return this.sprite != null;
146- }
147- }
148-
149- public Vector SpritePosition {
150- get {
151- return this.sprite.Body.Position;
152- }
153- }
154-
155- public readonly LayerType LayerType;
156-
157- public readonly Vector Position;
158-
159- public readonly Cell Cell;
160-
161- private Sprite sprite;
162- }
163-
164- /// <summary>
165- /// 現在のステージ(マップ)番号を取得します。
166- /// </summary>
167- public static int StageNo {
168- get {
169- return StageMap.stageNo;
170- }
171- }
172-
173- private static int stageNo;
174-
175- /// <summary>
176- /// データディレクトリのパスを取得します。
177- /// </summary>
178- public static string RootPath {
179- get {
180- return StageMap.rootPath;
181- }
182- }
183-
184- private static string rootPath;
185-
186- public static int TickCount {
187- get {
188- return StageMap.tickCount;
189- }
190- }
191-
192- private static int tickCount;
193-
194- public static IStageWorld World {
195- get {
196- return StageMap.world;
197- }
198- }
199-
200- private static IStageWorld world;
201-
202- public static readonly Vector VisibleRadius = new Vector( 8 , 6 ) * MapData.CellSize;
203-
204- public static readonly Vector ActiveRadius = new Vector( 12 , 9 ) * MapData.CellSize;
205-
206- private static SpriteDef[] defs;
207-
208- private static SpriteDef playerDef;
209-
210- private static Rectangle worldArea;
211-
212- private static Rectangle activeArea;
213- }
214-}
215-
--- trunk/Nlgp1/Nlgp1/Stages/Stage.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Stages/Stage.cs (revision 846)
@@ -0,0 +1,215 @@
1+using System;
2+using System.Collections.Generic;
3+using System.IO;
4+using System.Linq;
5+using Box2DX.Collision;
6+using Box2DX.Dynamics;
7+using Nlgp1.Characters;
8+using Nlgp1.Common;
9+using Nlgp1.Motions;
10+using Nlgp1.Parameters;
11+using Nlgp1.Players;
12+using Nlgp1.Sprites;
13+using Nlgp1.Utilities;
14+using Nlgp1.Views;
15+using Nlgp1.Windows;
16+
17+namespace Nlgp1.Stages {
18+ /// <summary>
19+ /// マップ
20+ /// </summary>
21+ public static class Stage {
22+ /// <summary>
23+ /// ステージ(マップ)を読み込みます。
24+ /// </summary>
25+ public static void LoadStage( string rootPath , int stageNo ) {
26+ Stage.rootPath = rootPath;
27+ Stage.stageNo = stageNo;
28+ Stage.tickCount = 0;
29+ MapData data = MapData.Load( rootPath , stageNo );
30+ List< SpriteDef > defList = new List< SpriteDef >();
31+ int rowNum = 0;
32+ int columnNum = 0;
33+ foreach( LayerType layerType in Enum.GetValues( typeof( LayerType ) ) ) {
34+ Cell[,] sheet = data.GetSheet( layerType );
35+ int sheetRowNum = sheet.GetLength( 1 );
36+ int sheetColumnNum = sheet.GetLength( 0 );
37+ rowNum = System.Math.Max( rowNum , sheetRowNum );
38+ columnNum = System.Math.Max( columnNum , sheetColumnNum );
39+ for( int row = 0 ; row < sheetRowNum ; ++row ) {
40+ for( int column = 0 ; column < sheetColumnNum ; ++column ) {
41+ if( sheet[ column , row ].TypeID >= 1 ) {
42+ SpriteDef def = new SpriteDef( layerType , new Vector( column + 0.5f , row + 0.5f ) * MapData.CellSize , sheet[ column , row ] );
43+ defList.Add( def );
44+ if( def.IsPlayer ) {
45+ Stage.playerDef = def;
46+ }
47+ }
48+ }
49+ }
50+ }
51+ Stage.worldArea = Rectangle.FromLowerUpper( new Vector(), new Vector( columnNum , rowNum ) * MapData.CellSize );
52+ Stage.world = StageWorldFactory.CreateStageWorld( Stage.worldArea , new StageDebugView() );
53+ Stage.defs = defList.ToArray();
54+ Stage.activeArea = Stage.ToActiveArea( playerDef.Position );
55+ SpriteShapeContactListener listener = new SpriteShapeContactListener();
56+ // マップ上にキャラクタを配置する。
57+ foreach( SpriteDef def in Stage.defs ) {
58+ if( Stage.activeArea.IsContacting( def.Position ) ) {
59+ def.LoadSprite();
60+ }
61+ }
62+ }
63+
64+ public static void UnloadStage() {
65+ Sprite.ClearCollection();
66+ SpriteMotion.ClearCollection();
67+ ChipSet.ClearCollection();
68+ }
69+
70+ public static void UpdateStage() {
71+ // キャラクタアクション
72+ Stage.tickCount++;
73+ Stage.world.Step( () => {
74+ foreach( Sprite sprite in Sprite.GetCollection() ) {
75+ sprite.Step();
76+ }
77+ Rectangle previousActiveArea = Stage.activeArea;
78+ Rectangle currentActiveArea = Stage.ToActiveArea( playerDef.SpritePosition );
79+ Stage.activeArea = currentActiveArea;
80+ foreach( Sprite sprite in Sprite.GetCollection().ToArray() ) {
81+ if( previousActiveArea.IsContacting( sprite.Body.Position ) && !currentActiveArea.IsContacting( sprite.Body.Position ) ) {
82+ sprite.Unload();
83+ }
84+ }
85+ foreach( SpriteDef def in Stage.defs ) {
86+ if( !def.IsLoaded && currentActiveArea.IsContacting( def.Position ) && !previousActiveArea.IsContacting( def.Position ) ) {
87+ def.LoadSprite();
88+ }
89+ }
90+ StageView.DrawToDisplay( Stage.activeArea.Center , Sprite.GetCollection().OrderBy( ( sprite ) => sprite.LayerType ).Cast< IDrawable >() );
91+ });
92+ }
93+
94+ private static Rectangle ToActiveArea( Vector position ) {
95+ return Rectangle.FromCenterRadius( global::Box2DX.Common.Math.Clamp( position , Stage.VisibleRadius , Stage.worldArea.Size - Stage.VisibleRadius ) , Stage.ActiveRadius );
96+ }
97+
98+ private sealed class SpriteDef {
99+
100+ public SpriteDef( LayerType layerType , Vector position , Cell cell ) {
101+ this.LayerType = layerType;
102+ this.Position = position;
103+ this.Cell = cell;
104+ }
105+
106+ public void LoadSprite() {
107+ if( this.sprite == null ) {
108+ if( this.LayerType == LayerType.Character ) {
109+ if( this.Cell.TypeID == 1 ) {
110+ this.sprite = PlayerStatus.LoadPlayer( this.Position ); // プレーヤー
111+ }
112+ else {
113+ this.sprite = SpriteFactory.CreateSprite( this.Cell.TypeID , this.Position , MapData.DefaultChipSize ); // キャラクタ
114+ }
115+ this.sprite.Stepped += ( sender , e ) => {
116+ this.sprite.Body.ApplyForce( new Vector( 0 , this.sprite.DownGravity ) );
117+ };
118+ }
119+ else {
120+ this.sprite = new Sprite( this.LayerType , this.Cell.TypeID , SpriteType.Monster , null , Path.Combine( @"Stages\Defines\Maps\Normal" , this.LayerType.ToString() ) , MapData.DefaultChipSize , null , null , this.Position );
121+ this.sprite.UpGravity = 0;
122+ this.sprite.DownGravity = 0;
123+ }
124+ this.sprite.IsBlock = ( this.Cell.Types & CellTypes.Wall ) != 0;
125+ this.sprite.IsDestroyable = ( this.Cell.Types & CellTypes.Destroy ) != 0;
126+ this.sprite.Friction = this.Cell.Friction;
127+ this.sprite.Unloaded += ( sender , e ) => {
128+ this.sprite = null;
129+ };
130+ }
131+ }
132+
133+ private void Stepped( object sender , EventArgs e ) {
134+ this.sprite.Step();
135+ }
136+
137+ public bool IsPlayer {
138+ get {
139+ return this.LayerType == LayerType.Character && this.Cell.TypeID == 1;
140+ }
141+ }
142+
143+ public bool IsLoaded {
144+ get {
145+ return this.sprite != null;
146+ }
147+ }
148+
149+ public Vector SpritePosition {
150+ get {
151+ return this.sprite.Body.Position;
152+ }
153+ }
154+
155+ public readonly LayerType LayerType;
156+
157+ public readonly Vector Position;
158+
159+ public readonly Cell Cell;
160+
161+ private Sprite sprite;
162+ }
163+
164+ /// <summary>
165+ /// 現在のステージ(マップ)番号を取得します。
166+ /// </summary>
167+ public static int StageNo {
168+ get {
169+ return Stage.stageNo;
170+ }
171+ }
172+
173+ private static int stageNo;
174+
175+ /// <summary>
176+ /// データディレクトリのパスを取得します。
177+ /// </summary>
178+ public static string RootPath {
179+ get {
180+ return Stage.rootPath;
181+ }
182+ }
183+
184+ private static string rootPath;
185+
186+ public static int TickCount {
187+ get {
188+ return Stage.tickCount;
189+ }
190+ }
191+
192+ private static int tickCount;
193+
194+ public static IStageWorld World {
195+ get {
196+ return Stage.world;
197+ }
198+ }
199+
200+ private static IStageWorld world;
201+
202+ public static readonly Vector VisibleRadius = new Vector( 8 , 6 ) * MapData.CellSize;
203+
204+ public static readonly Vector ActiveRadius = new Vector( 12 , 9 ) * MapData.CellSize;
205+
206+ private static SpriteDef[] defs;
207+
208+ private static SpriteDef playerDef;
209+
210+ private static Rectangle worldArea;
211+
212+ private static Rectangle activeArea;
213+ }
214+}
215+
--- trunk/Nlgp1/Nlgp1/Common/ChipSet.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Common/ChipSet.cs (revision 846)
@@ -89,7 +89,7 @@
8989 }
9090
9191 private static Image CreateImage( string path ) {
92- return Image.Load( Path.Combine( StageMap.RootPath , path ) );
92+ return Image.Load( Path.Combine( Stage.RootPath , path ) );
9393 }
9494
9595 public static void ClearCollection() {
--- trunk/Nlgp1/Nlgp1/Motions/SpriteMotion.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Motions/SpriteMotion.cs (revision 846)
@@ -61,10 +61,10 @@
6161 frame.Add( (MotionType)item , new MotionFrame() );
6262
6363 #region インデックス定義ファイルを読み込む
64- string defPath = Path.Combine( StageMap.RootPath , string.Format( @"Data\{0}\{1:D3}.def" , imageTypeName , typeID ) );
64+ string defPath = Path.Combine( Stage.RootPath , string.Format( @"Data\{0}\{1:D3}.def" , imageTypeName , typeID ) );
6565
6666 if( File.Exists( defPath ) == false )
67- defPath = Path.Combine( StageMap.RootPath , string.Format( @"Data\{0}\Common.def" , imageTypeName ) );
67+ defPath = Path.Combine( Stage.RootPath , string.Format( @"Data\{0}\Common.def" , imageTypeName ) );
6868
6969 if( File.Exists( defPath ) ) {
7070 foreach( var line in File.ReadAllLines( defPath ) ) {
--- trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 846)
@@ -83,7 +83,7 @@
8383 IsBlock = true;
8484 ActiveCellCount = 2;
8585 CanActDefault = true;
86- startTick = StageMap.TickCount;
86+ startTick = Stage.TickCount;
8787 steppedEventArgs = new SpriteSteppedEventArgs( this.Owner );
8888
8989 //this.Body = StageMap.World.CreateSpriteBody( true , position );
@@ -283,7 +283,7 @@
283283 /// </summary>
284284 public int ContinuityTime {
285285 get {
286- return StageMap.TickCount - startTick;
286+ return Stage.TickCount - startTick;
287287 }
288288 }
289289 /// <summary>
--- trunk/Nlgp1/Nlgp1/Attacks/Attack.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Attacks/Attack.cs (revision 846)
@@ -27,20 +27,20 @@
2727 this.SpriteOwner.Sprite.Stepped += new EventHandler<SpriteSteppedEventArgs>( ( sender , e ) => {
2828 if( ActionType == ActionType.None )
2929 return;
30- else if( ActionType == ActionType.Starting && StageMap.TickCount - attackTick >= StartingWait && canAttack ) {
30+ else if( ActionType == ActionType.Starting && Stage.TickCount - attackTick >= StartingWait && canAttack ) {
3131 // 攻撃中になった
3232 ActionType = ActionType.Attacking;
33- attackTick = StageMap.TickCount;
33+ attackTick = Stage.TickCount;
3434 if( Attacking != null )
3535 Attacking( this , EventArgs.Empty );
36- lastAttackTick = StageMap.TickCount;
37- } else if( ActionType == ActionType.Attacking && StageMap.TickCount - attackTick >= AttackingWait && canAttack ) {
36+ lastAttackTick = Stage.TickCount;
37+ } else if( ActionType == ActionType.Attacking && Stage.TickCount - attackTick >= AttackingWait && canAttack ) {
3838 // 攻撃を完了した
3939 ActionType = ActionType.None;
40- attackTick = StageMap.TickCount;
40+ attackTick = Stage.TickCount;
4141 if( Attacked != null )
4242 Attacked( this , EventArgs.Empty );
43- lastAttackTick = StageMap.TickCount;
43+ lastAttackTick = Stage.TickCount;
4444 }
4545 } );
4646 #endregion
@@ -104,11 +104,11 @@
104104 /// 攻撃を発生させます。
105105 /// </summary>
106106 public void Start() {
107- if( StageMap.TickCount - lastAttackTick < CreateWait || ActionType != ActionType.None || canAttack == false )
107+ if( Stage.TickCount - lastAttackTick < CreateWait || ActionType != ActionType.None || canAttack == false )
108108 return;
109- attackTick = StageMap.TickCount;
109+ attackTick = Stage.TickCount;
110110 ActionType = ActionType.Starting;
111- lastAttackTick = StageMap.TickCount;
111+ lastAttackTick = Stage.TickCount;
112112 if( Starting != null )
113113 Starting( this , EventArgs.Empty );
114114 }
--- trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteContact.cs (nonexistent)
@@ -1,37 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-
6-namespace Nlgp1.Parameters
7-{
8- class CircleSpriteContact:SpriteContact,ICircleSpriteContact
9- {
10- public CircleSpriteContact(SpriteShape source, SpriteShape target,
11- Vector position,float angle)
12- : base(source, target)
13- {
14-
15- }
16-
17- #region ICircleSpriteContact メンバ
18-
19- public ICircleSpriteShape Shape
20- {
21- //todo 後で
22- get { throw new NotImplementedException(); }
23- }
24-
25- public Vector Position
26- {
27- get { throw new NotImplementedException(); }
28- }
29-
30- public float Angle
31- {
32- get { throw new NotImplementedException(); }
33- }
34-
35- #endregion
36- }
37-}
--- trunk/Nlgp1/Nlgp1/Parameters/PolygonShapeContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/PolygonShapeContact.cs (nonexistent)
@@ -1,43 +0,0 @@
1-
2-using System.Collections.Generic;
3-
4-namespace Nlgp1.Parameters
5-{
6- class PolygonSpriteContact : SpriteContact,IPolygonSpriteContact
7- {
8- public PolygonSpriteContact(SpriteShape source, SpriteShape target,
9- Vector position,int edgeIndice,int vertexIndice):base(source,target)
10- {
11- Position = position;
12- EdgeIndice = edgeIndice;
13- VertexIndice = vertexIndice;
14- }
15-
16- Vector position;
17- int edgeindice;
18- int vertexindice;
19-
20- #region IPolygonSpriteContact メンバ
21-
22- public Vector Position
23- {
24- get { return position; }
25- private set { position = value; }
26- }
27-
28- public int EdgeIndice
29- {
30- get { return edgeindice; }
31- private set { edgeindice = value; }
32- }
33-
34- public int VertexIndice
35- {
36- get { return vertexindice; }
37- private set { vertexindice = value; }
38- }
39-
40- #endregion
41- }
42-}
43-
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteContact.cs (nonexistent)
@@ -1,17 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using Nlgp1.Utilities;
4-
5-namespace Nlgp1.Parameters
6-{
7- /// <summary>
8- /// ISpriteShapeの衝突結果を表すインターフェイス
9- /// </summary>
10- public interface ISpriteContact
11- {
12- /// <summary>
13- /// 衝突先のISpriteContact
14- /// </summary>
15- ISpriteContact Other { get; }
16- }
17-}
--- trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteContact.cs (nonexistent)
@@ -1,27 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using Nlgp1.Utilities;
4-
5-namespace Nlgp1.Parameters
6-{
7- /// <summary>
8- /// ISquareSpriteShapeの衝突結果を表す
9- /// </summary>
10- public interface IPolygonSpriteContact : ISpriteContact
11- {
12- /// <summary>
13- /// Sourceからみた相対的な衝突位置
14- /// </summary>
15- Vector Position { get; }
16-
17- /// <summary>
18- /// 衝突辺のインデックス群
19- /// </summary>
20- int EdgeIndice { get; }
21-
22- /// <summary>
23- /// 衝突頂点のインデックス群
24- /// </summary>
25- int VertexIndice { get; }
26- }
27-}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteContact.cs (nonexistent)
@@ -1,31 +0,0 @@
1-
2-namespace Nlgp1.Parameters
3-{
4- class SpriteContact:ISpriteContact
5- {
6- public SpriteContact(SpriteShape source, SpriteShape target)
7- {
8- Source = source;
9- Target = target;
10- }
11-
12- public SpriteShape Source
13- {
14- get;
15- protected set;
16- }
17- public SpriteShape Target
18- {
19- get;
20- protected set;
21- }
22- #region ISpriteContact メンバ
23-
24- public ISpriteContact Other
25- {
26- get { return this; }
27- }
28-
29- #endregion
30- }
31-}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (nonexistent)
@@ -1,241 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using Nlgp1.Utilities;
4-using Nlgp1.Sprites;
5-using Nlgp1.Box2DX;
6-using Box2DX.Dynamics;
7-using Nlgp1.Stages;
8-using Box2DX.Collision;
9-using System.Linq;
10-
11-namespace Nlgp1.Parameters
12-{
13- class SpriteContactListener:ContactListener
14- {
15- List<Shape> shape1s=new List<Shape>();
16- List<Shape> shape2s=new List<Shape>();
17- List<int> vertexindexes = new List<int>();
18- List<int> seagmentindexes1 = new List<int>(), seagmentindexes2 = new List<int>();
19- List<ContactPoint> contactPoints = new List<ContactPoint>();
20-
21- int allcontacts = 0, eventcontacts = 0;
22-
23- public override void Add(ContactPoint point)
24- {
25- PointRaise(point);
26-
27- }
28- public override void Persist(ContactPoint point)
29- {
30- PointRaise(point);
31- }
32- public override void Remove(ContactPoint point)
33- {
34-
35- }
36- public override void Result(ContactResult point)
37- {
38-
39- }
40- void PointRaise(ContactPoint cp)
41- {
42- allcontacts++;
43-
44- Shape s1 = cp.Shape1, s2 = cp.Shape2;
45- Vector s1pos = s1.GetBody().GetPosition(), s2pos = s2.GetBody().GetPosition();
46-
47- if (DoubledCheck(s1, s2)) return;
48- shape1s.Add(s1); shape2s.Add(s2);
49- contactPoints.Add(cp);
50- SpriteUserData nud1 = cp.Shape1.GetBody().GetUserData() as SpriteUserData;
51- SpriteUserData nud2 = cp.Shape2.GetBody().GetUserData() as SpriteUserData;
52-
53- nud1.SpriteShape.PointRaise(cp.Shape1, cp.Position);
54- nud2.SpriteShape.PointRaise(cp.Shape2, cp.Position);
55- //else{return;}
56- // if(nud2.SpriteShape.Type==SpriteShapeType.Polygon)
57- // {
58- // p2=((PolygonSpriteShape)nud1.SpriteShape).Area;
59- // }
60-
61- // seagmentindexes1.Add(se
62-
63-
64- // float upper, lower;
65- // //if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
66- // {
67-
68- // if (s1pos.Y > s2pos.Y)
69- // {
70- // upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
71- // }
72- // else
73- // {
74- // upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
75- // }
76- // }
77- // //else
78- // {
79- // if (s1pos.X > s2pos.X)
80- // {
81- // upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
82- // }
83- // else
84- // {
85- // upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
86- // }
87- // }
88-
89-
90- // ////このフレームで今までのすべてのコンタクト数とワールドのコンタクト数を比べる
91- // //if (GameMap.World.GetContactCount() != allcontacts)
92- // //{
93-
94- // //}
95-
96- // //配列とかコレクションを渡す、まさにコンタクツ
97- // //nud1.SpriteShape.Contacts=
98- // ////衝突辺が水平なら各頂点のX座標、垂直ならY座標Upper,Lower
99- // //SpriteShapeHittedEventArgs e = new SpriteShapeHittedEventArgs(nud1.SpriteShape, nud2.SpriteShape, s1dirs[cont2], lower, upper);
100- // //nud1.SpriteShape.OnHitted(this, e);
101- // //SpriteShapeHittedEventArgs e2 = new SpriteShapeHittedEventArgs(nud2.SpriteShape, nud1.SpriteShape, s1dirs[cont2], lower, upper);
102- // //nud2.SpriteShape.OnHitted(this, e2);
103- // eventcontacts++;
104- }
105-
106- bool DoubledCheck(Shape s,Shape s2)
107- {
108- bool shape1flag = false;
109- bool shape2flag = false;
110-
111- foreach (Shape sh in shape1s)
112- {
113- if (sh == null) break;
114- if (sh.Equals(s) || (sh.Equals(s2))) shape1flag = true;
115- }
116- foreach (Shape sh in shape2s)
117- {
118- if (sh == null) break;
119- if (sh.Equals(s) || (sh.Equals(s2))) shape2flag = true;
120- }
121- return shape1flag && shape2flag;
122- }
123-
124- Direction dircheck(Shape shape, Vector pos)
125- {
126- Vector spos=shape.GetBody().GetPosition();
127- if ((int)pos.X == (int)CalcfromShape.GetRight(shape)) { return Direction.Left; }
128- if ((int)pos.Y == (int)CalcfromShape.GetUpper(shape)) { return Direction.Top; }
129- if ((int)pos.X == (int)CalcfromShape.GetLeft(shape)) { return Direction.Left; }
130- return Direction.Bottom;
131- }
132-
133-
134-
135- Vector getUpperLower(Shape s1, Shape s2, Direction dir)
136- {
137- float upper, lower;
138- if (dir == Direction.Left || dir == Direction.Right)
139- {
140- //s1pos.Y > s2pos.Y
141- if (s1.GetBody().GetPosition().Y > s2.GetBody().GetPosition().Y)
142- {
143- upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
144- }
145- else
146- {
147- upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
148- }
149- }
150- else
151- {
152- if (s1.GetBody().GetPosition().X > s2.GetBody().GetPosition().X)
153- {
154- upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
155- }
156- else
157- {
158- upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
159- }
160- }
161- return new Vector(upper, lower);
162- }
163-
164- //
165- public void Step()
166- {
167- Dictionary<Shape, Dictionary<Shape, ContactPoint>> contactShape =
168- new Dictionary<Shape, Dictionary<Shape, ContactPoint>>();
169-
170- //HashSet<Shape>とオーダーが同じ
171- //IEqualityComparerを実装してDictionaryを1重で済ませる
172- //あるいは
173- //LookUp,Dictionary<,List<>>
174- Dictionary<Shape, ContactPoint> contact;
175- for (int i = 0; i < shape1s.Count; i++)
176- {
177- Shape s1 = shape1s[i];
178- Shape s2 = shape2s[i];
179- //Shape1sのspriteshape
180- //初めて出た際はそれを記憶しておく
181-
182-
183- bool isContactAlready1 = contactShape.TryGetValue(s1, out contact);
184- if (!isContactAlready1)
185- {
186- contact = new Dictionary<Shape, ContactPoint>();
187- contact.Add(s2, contactPoints[i]);
188- contactShape.Add(s1, contact);
189- }
190- //contactShape[shape1s[i]]がshape2を持っていない
191- else
192- {
193- if (!contactShape[s1].ContainsKey(s2))
194- {
195- contact.Add(s2, contactPoints[i]);
196- contactShape[s1] = contact;
197- }
198- }
199- bool isContactAlready2 = contactShape.TryGetValue(s2, out contact);
200- if (!isContactAlready2)
201- {
202- contact = new Dictionary<Shape, ContactPoint>();
203- contact.Add(s1, contactPoints[i]);
204- contactShape.Add(s2, contact);
205- }
206- else
207- {
208- if (!contactShape[s2].ContainsKey(s1))
209- {
210- contact.Add(s1, contactPoints[i]);
211- contactShape[s2] = contact;
212- }
213- }
214-
215- //実行時間は配列>Dictionary
216-
217- }
218- //DicごとにForeach
219- foreach (Shape shape in contactShape.Keys)
220- {
221- //SpriteShape ss = ((SpriteUserData)shape.GetBody().GetUserData()).SpriteShape;
222- //List<SpriteContact> sc=new List<SpriteContact>();
223- //foreach (Shape shape2 in contactShape[shape].Keys)
224- //{
225- // Direction d = dircheck(shape, contactShape[shape][shape2].Position);
226- // sc.Add(new SpriteContact(((SpriteUserData)shape2.GetBody().GetUserData()).SpriteShape,
227- // d,
228- // getUpperLower(shape, shape2, d).Y,
229- // getUpperLower(shape, shape2, d).X));
230-
231- // //targetshape.Add(shape2);
232- // //cpoint.Add(contactShape[shape][shape2]);
233- //}
234- //ss.Contacts = sc;
235- }
236- shape1s.Clear(); shape2s.Clear();
237- //s1dirs.Clear(); s2dirs.Clear();
238- eventcontacts = 0; allcontacts = 0;
239- }
240- }
241-}
--- trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteContact.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteContact.cs (nonexistent)
@@ -1,26 +0,0 @@
1-using System;
2-using Box2DX.Common;
3-
4-namespace Nlgp1.Parameters
5-{
6- /// <summary>
7- /// ICircleSpriteShapeの衝突結果を表すISpriteContact
8- /// </summary>
9- public interface ICircleSpriteContact : ISpriteContact
10- {
11- /// <summary>
12- /// 衝突元のICircleSpriteShape
13- /// </summary>
14- ICircleSpriteShape Shape { get; }
15-
16- /// <summary>
17- /// 衝突位置
18- /// </summary>
19- Vector Position { get; }
20-
21- /// <summary>
22- /// 衝突角
23- /// </summary>
24- float Angle { get; }
25- }
26-}
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteShapeContact.cs (revision 846)
@@ -0,0 +1,17 @@
1+using System;
2+using System.Collections.Generic;
3+using Nlgp1.Utilities;
4+
5+namespace Nlgp1.Parameters
6+{
7+ /// <summary>
8+ /// ISpriteShapeの衝突結果を表すインターフェイス
9+ /// </summary>
10+ public interface ISpriteShapeContact
11+ {
12+ /// <summary>
13+ /// 衝突先のISpriteContact
14+ /// </summary>
15+ ISpriteShapeContact Other { get; }
16+ }
17+}
--- trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteShape.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteShape.cs (revision 846)
@@ -22,6 +22,6 @@
2222 /// <summary>
2323 /// 衝突結果
2424 /// </summary>
25- IEnumerable<ICircleSpriteContact> Contacts { get; }
25+ IEnumerable<ICircleSpriteShapeContact> Contacts { get; }
2626 }
2727 }
--- trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShapeContact.cs (revision 846)
@@ -0,0 +1,37 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace Nlgp1.Parameters
7+{
8+ class CircleSpriteShapeContact:SpriteShapeContact,ICircleSpriteShapeContact
9+ {
10+ public CircleSpriteShapeContact(SpriteShape source, SpriteShape target,
11+ Vector position,float angle)
12+ : base(source, target)
13+ {
14+
15+ }
16+
17+ #region ICircleSpriteContact メンバ
18+
19+ public ICircleSpriteShape Shape
20+ {
21+ //todo 後で
22+ get { throw new NotImplementedException(); }
23+ }
24+
25+ public Vector Position
26+ {
27+ get { throw new NotImplementedException(); }
28+ }
29+
30+ public float Angle
31+ {
32+ get { throw new NotImplementedException(); }
33+ }
34+
35+ #endregion
36+ }
37+}
--- trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShape.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShape.cs (revision 846)
@@ -49,7 +49,7 @@
4949
5050 public override void PointRaise(Shape shape, Vector contactpos)
5151 {
52- PolygonSpriteContact spritecontact;
52+ PolygonSpriteShapeContact spritecontact;
5353
5454
5555 for (int i = 0; i < Area.Vertices.Length; i++)
@@ -64,7 +64,7 @@
6464 {
6565 //allContactPos.Add(contactpos);
6666 //seagmentIndexes.Add(i);
67- spritecontact = new PolygonSpriteContact(
67+ spritecontact = new PolygonSpriteShapeContact(
6868 this, ((SpriteUserData)shape.GetBody().GetUserData()).SpriteShape, contactpos,seagmentIndex, vertexIndex);
6969 }
7070
@@ -114,7 +114,7 @@
114114
115115 public event EventHandler<PolygonSpriteShapeSteppedEventArgs> Stepped;
116116 //
117- public IEnumerable<IPolygonSpriteContact> Contacts
117+ public IEnumerable<IPolygonSpriteShapeContact> Contacts
118118 {
119119 get;
120120 private set;
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeContact.cs (revision 846)
@@ -0,0 +1,31 @@
1+
2+namespace Nlgp1.Parameters
3+{
4+ class SpriteShapeContact:ISpriteShapeContact
5+ {
6+ public SpriteShapeContact(SpriteShape source, SpriteShape target)
7+ {
8+ Source = source;
9+ Target = target;
10+ }
11+
12+ public SpriteShape Source
13+ {
14+ get;
15+ protected set;
16+ }
17+ public SpriteShape Target
18+ {
19+ get;
20+ protected set;
21+ }
22+ #region ISpriteContact メンバ
23+
24+ public ISpriteShapeContact Other
25+ {
26+ get { return this; }
27+ }
28+
29+ #endregion
30+ }
31+}
--- trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShapeContact.cs (revision 846)
@@ -0,0 +1,43 @@
1+
2+using System.Collections.Generic;
3+
4+namespace Nlgp1.Parameters
5+{
6+ class PolygonSpriteShapeContact : SpriteShapeContact,IPolygonSpriteShapeContact
7+ {
8+ public PolygonSpriteShapeContact(SpriteShape source, SpriteShape target,
9+ Vector position,int edgeIndice,int vertexIndice):base(source,target)
10+ {
11+ Position = position;
12+ EdgeIndice = edgeIndice;
13+ VertexIndice = vertexIndice;
14+ }
15+
16+ Vector position;
17+ int edgeindice;
18+ int vertexindice;
19+
20+ #region IPolygonSpriteContact メンバ
21+
22+ public Vector Position
23+ {
24+ get { return position; }
25+ private set { position = value; }
26+ }
27+
28+ public int EdgeIndice
29+ {
30+ get { return edgeindice; }
31+ private set { edgeindice = value; }
32+ }
33+
34+ public int VertexIndice
35+ {
36+ get { return vertexindice; }
37+ private set { vertexindice = value; }
38+ }
39+
40+ #endregion
41+ }
42+}
43+
--- trunk/Nlgp1/Nlgp1/Parameters/StageWorld.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/StageWorld.cs (revision 846)
@@ -11,7 +11,7 @@
1111 public StageWorld(Rectangle area, IStageDebugView debugView)
1212 {
1313 this.world = new World(area, new Vec2(), false);
14- this.listener = new SpriteContactListener();
14+ this.listener = new SpriteShapeContactListener();
1515 this.world.SetContactListener(this.listener);
1616 this.debugDraw = new StageDebugDraw(debugView);
1717 this.world.SetDebugDraw(this.debugDraw);
@@ -36,7 +36,7 @@
3636 }
3737
3838 private readonly World world;
39- private readonly SpriteContactListener listener;
39+ private readonly SpriteShapeContactListener listener;
4040 private readonly StageDebugDraw debugDraw;
4141 }
4242 }
--- trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShapeContact.cs (revision 846)
@@ -0,0 +1,27 @@
1+using System;
2+using System.Collections.Generic;
3+using Nlgp1.Utilities;
4+
5+namespace Nlgp1.Parameters
6+{
7+ /// <summary>
8+ /// ISquareSpriteShapeの衝突結果を表す
9+ /// </summary>
10+ public interface IPolygonSpriteShapeContact : ISpriteShapeContact
11+ {
12+ /// <summary>
13+ /// Sourceからみた相対的な衝突位置
14+ /// </summary>
15+ Vector Position { get; }
16+
17+ /// <summary>
18+ /// 衝突辺のインデックス群
19+ /// </summary>
20+ int EdgeIndice { get; }
21+
22+ /// <summary>
23+ /// 衝突頂点のインデックス群
24+ /// </summary>
25+ int VertexIndice { get; }
26+ }
27+}
--- trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/ICircleSpriteShapeContact.cs (revision 846)
@@ -0,0 +1,26 @@
1+using System;
2+using Box2DX.Common;
3+
4+namespace Nlgp1.Parameters
5+{
6+ /// <summary>
7+ /// ICircleSpriteShapeの衝突結果を表すISpriteContact
8+ /// </summary>
9+ public interface ICircleSpriteShapeContact : ISpriteShapeContact
10+ {
11+ /// <summary>
12+ /// 衝突元のICircleSpriteShape
13+ /// </summary>
14+ ICircleSpriteShape Shape { get; }
15+
16+ /// <summary>
17+ /// 衝突位置
18+ /// </summary>
19+ Vector Position { get; }
20+
21+ /// <summary>
22+ /// 衝突角
23+ /// </summary>
24+ float Angle { get; }
25+ }
26+}
--- trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShape.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShape.cs (revision 846)
@@ -24,6 +24,6 @@
2424 /// <summary>
2525 /// 衝突結果
2626 /// </summary>
27- IEnumerable<IPolygonSpriteContact> Contacts { get; }
27+ IEnumerable<IPolygonSpriteShapeContact> Contacts { get; }
2828 }
2929 }
--- trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShape.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShape.cs (revision 846)
@@ -29,7 +29,7 @@
2929
3030 public event EventHandler<CircleSpriteShapeSteppedEventArgs> Stepped;
3131
32- public IEnumerable<ICircleSpriteContact> Contacts
32+ public IEnumerable<ICircleSpriteShapeContact> Contacts
3333 {
3434 get;
3535 set;
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeContactListener.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeContactListener.cs (revision 846)
@@ -0,0 +1,241 @@
1+using System;
2+using System.Collections.Generic;
3+using Nlgp1.Utilities;
4+using Nlgp1.Sprites;
5+using Nlgp1.Box2DX;
6+using Box2DX.Dynamics;
7+using Nlgp1.Stages;
8+using Box2DX.Collision;
9+using System.Linq;
10+
11+namespace Nlgp1.Parameters
12+{
13+ class SpriteShapeContactListener:ContactListener
14+ {
15+ List<Shape> shape1s=new List<Shape>();
16+ List<Shape> shape2s=new List<Shape>();
17+ List<int> vertexindexes = new List<int>();
18+ List<int> seagmentindexes1 = new List<int>(), seagmentindexes2 = new List<int>();
19+ List<ContactPoint> contactPoints = new List<ContactPoint>();
20+
21+ int allcontacts = 0, eventcontacts = 0;
22+
23+ public override void Add(ContactPoint point)
24+ {
25+ PointRaise(point);
26+
27+ }
28+ public override void Persist(ContactPoint point)
29+ {
30+ PointRaise(point);
31+ }
32+ public override void Remove(ContactPoint point)
33+ {
34+
35+ }
36+ public override void Result(ContactResult point)
37+ {
38+
39+ }
40+ void PointRaise(ContactPoint cp)
41+ {
42+ allcontacts++;
43+
44+ Shape s1 = cp.Shape1, s2 = cp.Shape2;
45+ Vector s1pos = s1.GetBody().GetPosition(), s2pos = s2.GetBody().GetPosition();
46+
47+ if (DoubledCheck(s1, s2)) return;
48+ shape1s.Add(s1); shape2s.Add(s2);
49+ contactPoints.Add(cp);
50+ SpriteUserData nud1 = cp.Shape1.GetBody().GetUserData() as SpriteUserData;
51+ SpriteUserData nud2 = cp.Shape2.GetBody().GetUserData() as SpriteUserData;
52+
53+ nud1.SpriteShape.PointRaise(cp.Shape1, cp.Position);
54+ nud2.SpriteShape.PointRaise(cp.Shape2, cp.Position);
55+ //else{return;}
56+ // if(nud2.SpriteShape.Type==SpriteShapeType.Polygon)
57+ // {
58+ // p2=((PolygonSpriteShape)nud1.SpriteShape).Area;
59+ // }
60+
61+ // seagmentindexes1.Add(se
62+
63+
64+ // float upper, lower;
65+ // //if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
66+ // {
67+
68+ // if (s1pos.Y > s2pos.Y)
69+ // {
70+ // upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
71+ // }
72+ // else
73+ // {
74+ // upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
75+ // }
76+ // }
77+ // //else
78+ // {
79+ // if (s1pos.X > s2pos.X)
80+ // {
81+ // upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
82+ // }
83+ // else
84+ // {
85+ // upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
86+ // }
87+ // }
88+
89+
90+ // ////このフレームで今までのすべてのコンタクト数とワールドのコンタクト数を比べる
91+ // //if (GameMap.World.GetContactCount() != allcontacts)
92+ // //{
93+
94+ // //}
95+
96+ // //配列とかコレクションを渡す、まさにコンタクツ
97+ // //nud1.SpriteShape.Contacts=
98+ // ////衝突辺が水平なら各頂点のX座標、垂直ならY座標Upper,Lower
99+ // //SpriteShapeHittedEventArgs e = new SpriteShapeHittedEventArgs(nud1.SpriteShape, nud2.SpriteShape, s1dirs[cont2], lower, upper);
100+ // //nud1.SpriteShape.OnHitted(this, e);
101+ // //SpriteShapeHittedEventArgs e2 = new SpriteShapeHittedEventArgs(nud2.SpriteShape, nud1.SpriteShape, s1dirs[cont2], lower, upper);
102+ // //nud2.SpriteShape.OnHitted(this, e2);
103+ // eventcontacts++;
104+ }
105+
106+ bool DoubledCheck(Shape s,Shape s2)
107+ {
108+ bool shape1flag = false;
109+ bool shape2flag = false;
110+
111+ foreach (Shape sh in shape1s)
112+ {
113+ if (sh == null) break;
114+ if (sh.Equals(s) || (sh.Equals(s2))) shape1flag = true;
115+ }
116+ foreach (Shape sh in shape2s)
117+ {
118+ if (sh == null) break;
119+ if (sh.Equals(s) || (sh.Equals(s2))) shape2flag = true;
120+ }
121+ return shape1flag && shape2flag;
122+ }
123+
124+ Direction dircheck(Shape shape, Vector pos)
125+ {
126+ Vector spos=shape.GetBody().GetPosition();
127+ if ((int)pos.X == (int)CalcfromShape.GetRight(shape)) { return Direction.Left; }
128+ if ((int)pos.Y == (int)CalcfromShape.GetUpper(shape)) { return Direction.Top; }
129+ if ((int)pos.X == (int)CalcfromShape.GetLeft(shape)) { return Direction.Left; }
130+ return Direction.Bottom;
131+ }
132+
133+
134+
135+ Vector getUpperLower(Shape s1, Shape s2, Direction dir)
136+ {
137+ float upper, lower;
138+ if (dir == Direction.Left || dir == Direction.Right)
139+ {
140+ //s1pos.Y > s2pos.Y
141+ if (s1.GetBody().GetPosition().Y > s2.GetBody().GetPosition().Y)
142+ {
143+ upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
144+ }
145+ else
146+ {
147+ upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
148+ }
149+ }
150+ else
151+ {
152+ if (s1.GetBody().GetPosition().X > s2.GetBody().GetPosition().X)
153+ {
154+ upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
155+ }
156+ else
157+ {
158+ upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
159+ }
160+ }
161+ return new Vector(upper, lower);
162+ }
163+
164+ //
165+ public void Step()
166+ {
167+ Dictionary<Shape, Dictionary<Shape, ContactPoint>> contactShape =
168+ new Dictionary<Shape, Dictionary<Shape, ContactPoint>>();
169+
170+ //HashSet<Shape>とオーダーが同じ
171+ //IEqualityComparerを実装してDictionaryを1重で済ませる
172+ //あるいは
173+ //LookUp,Dictionary<,List<>>
174+ Dictionary<Shape, ContactPoint> contact;
175+ for (int i = 0; i < shape1s.Count; i++)
176+ {
177+ Shape s1 = shape1s[i];
178+ Shape s2 = shape2s[i];
179+ //Shape1sのspriteshape
180+ //初めて出た際はそれを記憶しておく
181+
182+
183+ bool isContactAlready1 = contactShape.TryGetValue(s1, out contact);
184+ if (!isContactAlready1)
185+ {
186+ contact = new Dictionary<Shape, ContactPoint>();
187+ contact.Add(s2, contactPoints[i]);
188+ contactShape.Add(s1, contact);
189+ }
190+ //contactShape[shape1s[i]]がshape2を持っていない
191+ else
192+ {
193+ if (!contactShape[s1].ContainsKey(s2))
194+ {
195+ contact.Add(s2, contactPoints[i]);
196+ contactShape[s1] = contact;
197+ }
198+ }
199+ bool isContactAlready2 = contactShape.TryGetValue(s2, out contact);
200+ if (!isContactAlready2)
201+ {
202+ contact = new Dictionary<Shape, ContactPoint>();
203+ contact.Add(s1, contactPoints[i]);
204+ contactShape.Add(s2, contact);
205+ }
206+ else
207+ {
208+ if (!contactShape[s2].ContainsKey(s1))
209+ {
210+ contact.Add(s1, contactPoints[i]);
211+ contactShape[s2] = contact;
212+ }
213+ }
214+
215+ //実行時間は配列>Dictionary
216+
217+ }
218+ //DicごとにForeach
219+ foreach (Shape shape in contactShape.Keys)
220+ {
221+ //SpriteShape ss = ((SpriteUserData)shape.GetBody().GetUserData()).SpriteShape;
222+ //List<SpriteContact> sc=new List<SpriteContact>();
223+ //foreach (Shape shape2 in contactShape[shape].Keys)
224+ //{
225+ // Direction d = dircheck(shape, contactShape[shape][shape2].Position);
226+ // sc.Add(new SpriteContact(((SpriteUserData)shape2.GetBody().GetUserData()).SpriteShape,
227+ // d,
228+ // getUpperLower(shape, shape2, d).Y,
229+ // getUpperLower(shape, shape2, d).X));
230+
231+ // //targetshape.Add(shape2);
232+ // //cpoint.Add(contactShape[shape][shape2]);
233+ //}
234+ //ss.Contacts = sc;
235+ }
236+ shape1s.Clear(); shape2s.Clear();
237+ //s1dirs.Clear(); s2dirs.Clear();
238+ eventcontacts = 0; allcontacts = 0;
239+ }
240+ }
241+}
--- trunk/Nlgp1/Nlgp1/Program.cs (revision 845)
+++ trunk/Nlgp1/Nlgp1/Program.cs (revision 846)
@@ -47,13 +47,13 @@
4747 string stageFile = Path.Combine( rootPath , "Data\\stagenumber.txt" );
4848 if( File.Exists( stageFile ) )
4949 stage = Nlgp1.Common.Utility.TryParse<int>( File.ReadAllText( stageFile ).Trim() );
50- StageMap.LoadStage( rootPath , stage );
50+ Stage.LoadStage( rootPath , stage );
5151 }, () => {
5252 rate.Update();
5353
5454 PlayerController.UpdateInput();
5555
56- StageMap.UpdateStage();
56+ Stage.UpdateStage();
5757
5858 // タイムアウト判定
5959 #region 描画
@@ -73,7 +73,7 @@
7373
7474 return true;
7575 }, () => {
76- StageMap.UnloadStage();
76+ Stage.UnloadStage();
7777 if( meiryoFont != null ) {
7878 meiryoFont.Dispose();
7979 meiryoFont = null;
Show on old repository browser