• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision833 (tree)
Zeit2011-03-02 05:05:05
Autorbiikame

Log Message

ISpriteShapeの形状を多角形に修正

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 833)
@@ -71,14 +71,6 @@
7171 // newSprite.LogicParameter.InitY = cellY * MapData.CellSize;
7272 character.Sprite.Body.ApplyForce( new Vector( 1 , 0 ) );
7373 character.Sprite.Shape.Stepped += ( sender , e ) => {
74- foreach( ISpriteContact contact in e.Shape.Contacts ) {
75- if( ( contact.Directions & Directions.Left ) != 0 ) {
76- contact.Target.Body.Sprite.Body.ApplyForce( new Vector( 0.3f , 0 ) );
77- }
78- else if( ( contact.Directions & Directions.Right ) != 0 ) {
79- contact.Target.Body.Sprite.Body.ApplyForce( new Vector( -0.3f , 0 ) );
80- }
81- }
8274 };
8375 #endregion
8476 break;
@@ -85,24 +77,6 @@
8577 case 9:
8678 #region 床から落下しないように左右に移動する。
8779 character.Sprite.Shape.Stepped += ( sender , e ) => {
88- bool isHittingLower = false;
89- bool isHittingUpper = true;
90- foreach( ISpriteContact contact in e.Shape.Contacts ) {
91- if( ( contact.Directions & Directions.Bottom ) != 0 ) {
92- if( System.Math.Max( contact.Position.Lower.Y , contact.Position.Upper.Y ) <= 0 ) {
93- isHittingLower = true;
94- }
95- if( System.Math.Min( contact.Position.Lower.Y , contact.Position.Upper.Y ) >= 0 ) {
96- isHittingUpper = true;
97- }
98- }
99- if( !isHittingLower ) {
100- e.Shape.Body.Sprite.Body.ApplyForce( new Vector( -0.05f , 0 ) );
101- }
102- else if( !isHittingUpper ) {
103- e.Shape.Body.Sprite.Body.ApplyForce( new Vector( +0.05f , 0 ) );
104- }
105- }
10680 };
10781 #endregion
10882 break;
--- trunk/Nlgp1/Nlgp1/Sprites/Types.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Sprites/Types.cs (revision 833)
@@ -0,0 +1,71 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace Nlgp1.Sprites
7+{
8+ /// <summary>
9+ /// 上下左右での方向を表します。
10+ /// </summary>
11+ [Flags]
12+ public enum Directions
13+ {
14+ /// <summary>
15+ /// 方向なし
16+ /// </summary>
17+ None = 0 ,
18+ /// <summary>
19+ /// 左
20+ /// </summary>
21+ Left = 1 ,
22+ /// <summary>
23+ /// 上
24+ /// </summary>
25+ Top = 2 ,
26+ /// summary>
27+ /// 右
28+ /// </summary>
29+ Right = 3 ,
30+ /// <summary>
31+ /// 下
32+ /// </summary>
33+ Bottom = 8 ,
34+ }
35+ /// <summary>
36+ /// 上・下・左・右の何れかを表す
37+ /// </summary>
38+ public enum Direction
39+ {
40+ /// <summary>
41+ /// 左
42+ /// </summary>
43+ Left = 0 ,
44+ /// <summary>
45+ /// 上
46+ /// </summary>
47+ Top = 1 ,
48+ /// summary>
49+ /// 右
50+ /// </summary>
51+ Right = 2 ,
52+ /// <summary>
53+ /// 下
54+ /// </summary>
55+ Bottom = 3 ,
56+ }
57+ /// <summary>
58+ /// 縦・横方向を表す。
59+ /// </summary>
60+ public enum Aspect
61+ {
62+ /// <summary>
63+ /// 横方向。水平
64+ /// </summary>
65+ Horizontal ,
66+ /// <summary>
67+ /// 縦方向。垂直
68+ /// </summary>
69+ Vertical ,
70+ }
71+}
--- trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Sprites/Sprite.cs (revision 833)
@@ -77,11 +77,11 @@
7777
7878 this.Body = StageMap.World.CreateSpriteBody( this , position );
7979 if( layerType != LayerType.Character ) {
80- this.Body.CreateSpriteShape( SpriteShapeFilter.Hitted, new Octagon( Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f , chipSize.Y / 2.0f ) ) ) );
80+ this.Body.CreateSpriteShape( new SpriteShapeFilter( 1 , 2 ), Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f , chipSize.Y / 2.0f ) ).ToVertices() );
8181 }
8282 else {
83- this.Body.CreateSpriteShape( SpriteShapeFilter.Hitted, new Octagon( Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f - 2.0f , chipSize.Y / 2.0f - 2.0f ) ) , 0.5f ) );
84- this.Shape = this.Body.CreateSpriteShape( SpriteShapeFilter.Hitting , new Octagon( Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f - 2.0f , chipSize.Y / 2.0f - 2.0f ) ) , 0.5f ) );
83+ this.Body.CreateSpriteShape( new SpriteShapeFilter( 1 , 2 ), new Octagon( Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f - 2.0f , chipSize.Y / 2.0f - 2.0f ) ) , 0.5f ).ToVertices() );
84+ this.Shape = this.Body.CreateSpriteShape( new SpriteShapeFilter( 2 , 1 ) , new Octagon( Rectangle.FromCenterRadius( new Vector() , new Vector( chipSize.X / 2.0f - 2.0f , chipSize.Y / 2.0f - 2.0f ) ) , 0.5f ).ToVertices() );
8585 }
8686 this.Body.Load();
8787 }
--- trunk/Nlgp1/Nlgp1/Parameters/Types.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/Types.cs (nonexistent)
@@ -1,71 +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- /// <summary>
9- /// 上下左右での方向を表します。
10- /// </summary>
11- [Flags]
12- public enum Directions
13- {
14- /// <summary>
15- /// 方向なし
16- /// </summary>
17- None = 0 ,
18- /// <summary>
19- /// 左
20- /// </summary>
21- Left = 1 ,
22- /// <summary>
23- /// 上
24- /// </summary>
25- Top = 2 ,
26- /// summary>
27- /// 右
28- /// </summary>
29- Right = 3 ,
30- /// <summary>
31- /// 下
32- /// </summary>
33- Bottom = 8 ,
34- }
35- /// <summary>
36- /// 上・下・左・右の何れかを表す
37- /// </summary>
38- public enum Direction
39- {
40- /// <summary>
41- /// 左
42- /// </summary>
43- Left = 0 ,
44- /// <summary>
45- /// 上
46- /// </summary>
47- Top = 1 ,
48- /// summary>
49- /// 右
50- /// </summary>
51- Right = 2 ,
52- /// <summary>
53- /// 下
54- /// </summary>
55- Bottom = 3 ,
56- }
57- /// <summary>
58- /// 縦・横方向を表す。
59- /// </summary>
60- public enum Aspect
61- {
62- /// <summary>
63- /// 横方向。水平
64- /// </summary>
65- Horizontal ,
66- /// <summary>
67- /// 縦方向。垂直
68- /// </summary>
69- Vertical ,
70- }
71-}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeFilterCollection.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeFilterCollection.cs (nonexistent)
@@ -1,65 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using Box2DX.Collision;
5-using Nlgp1.Box2DX;
6-
7-namespace Nlgp1.Parameters
8-{
9- /// <summary>
10- /// SpriteShapeFilterを変換するクラス
11- /// </summary>
12- internal static class SpriteShapeFilterCollection
13- {
14- static SpriteShapeFilterCollection()
15- {
16- items = new Item[(int)(((SpriteShapeFilter[])(Enum.GetValues(typeof(SpriteShapeFilter)))).Max()) + 1];
17- for (int i = 0; i < items.Length; ++i) {
18- FilterData filterData = new FilterData {
19- CategoryBits = (ushort)(1 << i),
20- MaskBits = (ushort)(1 << ((i + 1) % 2)),
21- };
22- Dictionary<UserDataKind, string> userDataKinds = new Dictionary<UserDataKind, string>();
23- userDataKinds.Add(UserDataKind.Name, Enum.GetName(typeof(FilterData), i));
24- userDataKinds.Add(UserDataKind.CategoryBits, Convert.ToString(filterData.CategoryBits, 2));
25- userDataKinds.Add(UserDataKind.MaskBits, Convert.ToString(filterData.MaskBits, 2));
26- items[i] = new Item(filterData, userDataKinds);
27- }
28- }
29-
30- /// <summary>
31- /// SpriteShapeFilterをFilterDataへ変換する
32- /// </summary>
33- /// <param name="filter">変換元</param>
34- /// <returns>変換先</returns>
35- public static FilterData ToFilterData(SpriteShapeFilter filter)
36- {
37- return items[(int)(filter)].FilterData;
38- }
39-
40- /// <summary>
41- /// SpriteShapeFilterをDictionary&lt;UserDataKind, string&gt;へ変換する
42- /// </summary>
43- /// <param name="filter">変換元</param>
44- /// <returns>変換先</returns>
45- public static Dictionary<UserDataKind, string> ToUserDataKinds(SpriteShapeFilter filter)
46- {
47- return items[(int)(filter)].UserDataKinds;
48- }
49-
50- private sealed class Item
51- {
52- public Item(FilterData filterData, Dictionary<UserDataKind, string> userDataKinds)
53- {
54- this.FilterData = filterData;
55- this.UserDataKinds = userDataKinds;
56- }
57-
58- public readonly FilterData FilterData;
59-
60- public readonly Dictionary<UserDataKind, string> UserDataKinds;
61- }
62-
63- private static readonly Item[] items;
64- }
65-}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 833)
@@ -65,7 +65,7 @@
6565
6666 //}
6767
68- public ISpriteShape CreateSpriteShape(SpriteShapeFilter filter, Octagon area)
68+ public ISpriteShape CreateSpriteShape(SpriteShapeFilter filter, IEnumerable<Vector> area)
6969 {
7070 throw new NotImplementedException();
7171 }
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteContact.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteContact.cs (revision 833)
@@ -25,8 +25,13 @@
2525 Line Position { get; }
2626
2727 /// <summary>
28- /// Sourceからみた相対的な衝突方向
28+ /// 衝突辺のインデックス群
2929 /// </summary>
30- Directions Directions { get; }
30+ IEnumerable<int> EdgeIndices { get; }
31+
32+ /// <summary>
33+ /// 衝突頂点のインデックス群
34+ /// </summary>
35+ IEnumerable<int> VertexIndices { get; }
3136 }
3237 }
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteBody.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteBody.cs (revision 833)
@@ -1,4 +1,5 @@
11 using System;
2+using System.Collections.Generic;
23 using Nlgp1.Sprites;
34 using Nlgp1.Utilities;
45
@@ -15,7 +16,7 @@
1516 /// <param name="filter">衝突フィルター</param>
1617 /// <param name="area">衝突範囲</param>
1718 /// <returns>作成されたオブジェクト</returns>
18- ISpriteShape CreateSpriteShape(SpriteShapeFilter filter, Octagon area);
19+ ISpriteShape CreateSpriteShape(SpriteShapeFilter filter, IEnumerable<Vector> area);
1920
2021 /// <summary>
2122 /// 自身が保有するISpriteShape群を元にIStageWorldへロードする
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeFilter.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeFilter.cs (revision 833)
@@ -5,36 +5,16 @@
55 /// <summary>
66 /// ISpriteShapeの衝突フィルター
77 /// </summary>
8- public enum SpriteShapeFilter
8+ public struct SpriteShapeFilter
99 {
10- /// <summary>
11- /// ブロックへの衝突先
12- /// </summary>
13- Hitted,
10+ public SpriteShapeFilter(ushort categoryBits, ushort maskBits)
11+ {
12+ this.CategoryBits = categoryBits;
13+ this.MaskBits = maskBits;
14+ }
1415
15- /// <summary>
16- /// ブロックへの衝突元
17- /// </summary>
18- Hitting,
16+ public readonly ushort CategoryBits;
1917
20- /// <summary>
21- /// 敵の攻撃先
22- /// </summary>
23- EnemyAttacked,
24-
25- /// <summary>
26- /// 敵の攻撃元
27- /// </summary>
28- EnemyAttacking,
29-
30- /// <summary>
31- /// プレイヤーの攻撃先
32- /// </summary>
33- PlayerAttacked,
34-
35- /// <summary>
36- /// プレイヤーの攻撃元
37- /// </summary>
38- PlayerAttacking,
18+ public readonly ushort MaskBits;
3919 }
4020 }
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteShape.cs (revision 832)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteShape.cs (revision 833)
@@ -23,7 +23,7 @@
2323 /// <summary>
2424 /// 衝突範囲
2525 /// </summary>
26- Octagon Area { get; }
26+ IEnumerable<Vector> Area { get; }
2727
2828 /// <summary>
2929 /// 衝突結果
Show on old repository browser