• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision709 (tree)
Zeit2011-02-15 00:20:44
Autorbiikame

Log Message

ソリューション構成を変更

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1.B2DX/Gamemain.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1.B2DX/Gamemain.cs (revision 709)
@@ -0,0 +1,177 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Text;
4+using DxLibDLL;
5+using Box2DX.Collision;
6+using Box2DX.Common;
7+using Box2DX.Dynamics;
8+using System.Collections;
9+
10+namespace Nlgp1.B2DX.Test
11+{
12+ internal class Gamemain
13+ {
14+
15+
16+ static void Main()//Mainにするとこちらがコンパイルできる
17+ {
18+ try
19+ {
20+ DX.SetWindowSize(512, 384);
21+ DX.ChangeWindowMode(true);
22+ DX.SetAlwaysRunFlag(false);
23+ DX.DxLib_Init();
24+
25+
26+
27+ //画像読み込み
28+ DX.Graph mech;
29+ const float pi = (float)(System.Math.PI);
30+
31+ mech = DX.LoadGraph("mech.png");
32+
33+ AABB worldBox = new AABB();
34+ //左上座標の定義
35+ worldBox.LowerBound = new Vec2(0, 0);
36+ //右下座標の定義
37+ worldBox.UpperBound = new Vec2(500, 400);
38+ //重力の定義
39+ Vec2 grav = new Vec2(0, 0);
40+
41+ World world = new World(worldBox, grav, false);
42+ DebugDraw dd = new Debug();
43+ dd.AppendFlags(DebugDraw.DrawFlags.Shape);
44+ world.SetDebugDraw(dd);
45+
46+ world.SetContactListener(new ContactEvent());
47+
48+
49+ Vec2[] gravAr = new Vec2[]
50+ {
51+ new Vec2(0, -18),
52+ new Vec2(18, 0),
53+ new Vec2(-18,0),
54+ new Vec2(0,18)
55+ };
56+
57+ bool keyflag = false;
58+ //サイズは半径で設定する
59+ //todo IBoxインターフェイスからIBox.MakeShapeとか呼びだして、構成すれば処理を分けられるはず
60+ DynamicRigid d = new DynamicRigid(new Vec2(42, 170), 90 * pi / 180, world, 16, 16, false,
61+ new Dictionary<UserDataKind, string>()
62+ {
63+ { UserDataKind.Name, "player" },
64+ { UserDataKind.CategoryBits,"111" },
65+ {UserDataKind.MaskBits,"111"},
66+ {UserDataKind.GroupIndex,"10"}
67+ },
68+ new Dictionary<ObjectDataKind,float>(),
69+ true);
70+ StaticRigid s = new StaticRigid(new Vec2(240, 202), 0, world, 16, 16, true, new Dictionary<UserDataKind, string>() { { UserDataKind.Name, "enemy" }, { UserDataKind.Filter, "111" } }
71+ ,false);
72+ StaticRigid wall = new StaticRigid(new Vec2(250, 16), 0, world, 250, 16, true,
73+ new Dictionary<UserDataKind, string>()
74+ {
75+ { UserDataKind.Name, "wall" },
76+ { UserDataKind.Filter, "110" },
77+ {UserDataKind.GroupIndex,"1"}
78+ }
79+ ,false);
80+ StaticRigid floor = new StaticRigid(new Vec2(500, 168), 0, world, 16, 150, true,
81+ new Dictionary<UserDataKind, string>()
82+ {
83+ { UserDataKind.Name, "floor" },
84+ { UserDataKind.Filter, "101" }
85+ }
86+ ,false);
87+
88+ //dに新しいボディを定義する
89+ //最初にこれ以上新しいボディは作らないと宣言する、さもないとボディは作られない
90+ d.Alregene = false;
91+ float friction = 0, density = 2, restitution = 0;
92+ Polygondef2 p2 = new Polygondef2(friction, restitution, density,new myUserData());
93+ p2.SetAsBox(3, 3, new Vec2(20, 1), 0);
94+ d.Addtolist(p2);
95+ d.MakeBody(world);
96+
97+ //自キャラとの距離を固定する
98+ //Joints joints = new Joints(d.SelfBody, s.SelfBody);
99+ //world.CreateJoint(joints.MakeDistanceJoint());
100+
101+ //ObjectDataKindのAngularDampingは無視されます
102+ float angularDamping = 0.3f, lineardamping = 0.5f, fric2 = 0.4f, rest2 = 2f, dens2 = 1;
103+ FilterData f=new FilterData();
104+ f.CategoryBits = 1;
105+ f.GroupIndex = 1; f.MaskBits = 1;
106+ DynamicRigid d2 = new DynamicRigid(new Vec2(50, 60), 0 * pi / 180, lineardamping, angularDamping);
107+ d2.SetAsBox(16, 16, new Polygondef2(fric2, rest2, dens2, new myUserData("d2", 1, f, 2)), false);
108+ Polygondef2 d2p = new Polygondef2(friction, restitution, density, new myUserData("d2p", 3, f, 2));
109+ d2p.SetAsBox(24, 12, new Vec2(-20, 1), 0);
110+ d2p.Fil();
111+
112+ d2.Addtolist(d2p);
113+ d2.NoRotate = false;
114+ d2.MakeBody(world);
115+
116+ DynamicRigid c1 = new DynamicRigid(new Vec2(300, 90), 0, 0, 0);
117+ c1.SetAsCircle(new CircleDef2(new Vec2(), 20, 0, 0, 1, new myUserData()), false);
118+ c1.MakeBody(world);
119+
120+ DX.SetDrawScreen(DX.DX_SCREEN_BACK);
121+
122+ //todo GetNameAndIdとかやりたい,worldを継承?
123+ //GetNameAndId(); --> Dic<int,string> {{1,"player"},{2,"wall"}}
124+ //GetName(2); -->"player"
125+ //GetIdArr("enemy"); -->["1","4"]
126+
127+ while (DX.ProcessMessage())
128+ {
129+
130+ //List<Shape> shape = d2.Shapelist;
131+ //このインデックスをSetFilterに渡す
132+ //Shape.GetBody().GetUserData();がユーザーデータ
133+ //Shape.Get
134+ f.MaskBits=1;
135+ d2.SetFilter(f, 1);
136+
137+ if (DX.CheckHitKey(DX.KEY_INPUT.RETURN) && !keyflag)
138+ {
139+ //瞬間的にある方向に力を加える(270度が設定されているのでオブジェクトから見て真上へ)
140+ d.ApplyImpulse(new Vec2(0, -990));
141+ }
142+
143+ if (!DX.CheckHitKey(DX.KEY_INPUT.RETURN))
144+ {
145+ keyflag = false;
146+ }
147+
148+ if (DX.CheckHitKey(DX.KEY_INPUT.LEFT))
149+ {
150+ d.ApplyRelativeImpulse(new Vec2(-3 * d.Mass, 0),90);
151+ //d.SelfBody.ApplyTorque(20*d.SelfBody.GetMass());
152+ }
153+ DX.ClearDrawScreen();
154+ DX.ProcessActKeyInput();
155+ DX.DrawString(2, 7, world.Gravity.X.ToString(), new DX.COLOR_U8(0xffffff));
156+ DX.DrawString(2, 27, world.Gravity.Y.ToString(), new DX.COLOR_U8(0xffffff));
157+
158+ DX.DrawRotaGraph((int)d.Position.X, (int)d.Position.Y, 1, d.Angle, mech, true, true);
159+ DX.DrawRotaGraph((int)s.Position.X, (int)s.Position.Y, 1, 0, mech, false);
160+
161+ //試しのRaycast,自分の下から30から10だけ下に光を伸ばす
162+ d2.color = Colors.Red;
163+ Shape[] hit = d2.Raycast(new Vec2(0, 30), new Vec2(0, 50));
164+ world.Step(1 / 60f, 8, 1);
165+
166+ DX.ScreenFlip();
167+ } DX.DxLib_End();
168+ } catch (Exception e)
169+ {
170+ System.Console.Write(e.ToString());
171+ throw;
172+ }
173+ }
174+
175+
176+ }
177+}
--- trunk/Nlgp1/Nlgp1.B2DX.Test/Gamemain.cs (revision 708)
+++ trunk/Nlgp1/Nlgp1.B2DX.Test/Gamemain.cs (nonexistent)
@@ -1,176 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Text;
4-using DxLibDLL;
5-using Box2DX.Collision;
6-using Box2DX.Common;
7-using Box2DX.Dynamics;
8-using System.Collections;
9-
10-namespace Nlgp1.B2DX.Test
11-{
12- internal class Gamemain
13- {
14-
15-
16- static void Start()//Mainにするとこちらがコンパイルできる
17- {
18- try
19- {
20- DX.SetWindowSize(512, 384);
21- DX.ChangeWindowMode(true);
22- DX.SetAlwaysRunFlag(false);
23- DX.DxLib_Init();
24-
25-
26-
27- //画像読み込み
28- DX.Graph mech;
29- const float pi = (float)(System.Math.PI);
30-
31- mech = DX.LoadGraph("mech.png");
32-
33- AABB worldBox = new AABB();
34- //左上座標の定義
35- worldBox.LowerBound = new Vec2(0, 0);
36- //右下座標の定義
37- worldBox.UpperBound = new Vec2(500, 400);
38- //重力の定義
39- Vec2 grav = new Vec2(0, 0);
40-
41- World world = new World(worldBox, grav, false);
42- DebugDraw dd = new Debug();
43- dd.AppendFlags(DebugDraw.DrawFlags.Shape);
44- world.SetDebugDraw(dd);
45-
46- world.SetContactListener(new ContactEvent());
47-
48-
49- Vec2[] gravAr = new Vec2[]
50- {
51- new Vec2(0, -18),
52- new Vec2(18, 0),
53- new Vec2(-18,0),
54- new Vec2(0,18)
55- };
56-
57- bool keyflag = false;
58- //サイズは半径で設定する
59- //todo IBoxインターフェイスからIBox.MakeShapeとか呼びだして、構成すれば処理を分けられるはず
60- DynamicRigid d = new DynamicRigid(new Vec2(42, 170), 90 * pi / 180, world, 16, 16, false,
61- new Dictionary<UserDataKind, string>()
62- {
63- { UserDataKind.Name, "player" },
64- { UserDataKind.CategoryBits,"111" },
65- {UserDataKind.MaskBits,"111"},
66- {UserDataKind.GroupIndex,"10"}
67- },
68- new Dictionary<ObjectDataKind,float>(),
69- true);
70- StaticRigid s = new StaticRigid(new Vec2(240, 202), 0, world, 16, 16, true, new Dictionary<UserDataKind, string>() { { UserDataKind.Name, "enemy" }, { UserDataKind.Filter, "111" } }
71- ,false);
72- StaticRigid wall = new StaticRigid(new Vec2(250, 16), 0, world, 250, 16, true,
73- new Dictionary<UserDataKind, string>()
74- {
75- { UserDataKind.Name, "wall" },
76- { UserDataKind.Filter, "110" },
77- {UserDataKind.GroupIndex,"1"}
78- }
79- ,false);
80- StaticRigid floor = new StaticRigid(new Vec2(500, 168), 0, world, 16, 150, true,
81- new Dictionary<UserDataKind, string>()
82- {
83- { UserDataKind.Name, "floor" },
84- { UserDataKind.Filter, "101" }
85- }
86- ,false);
87-
88- //dに新しいボディを定義する
89- //最初にこれ以上新しいボディは作らないと宣言する、さもないとボディは作られない
90- d.Alregene = false;
91- float friction = 0, density = 2, restitution = 0;
92- Polygondef2 p2 = new Polygondef2(friction, restitution, density,new myUserData());
93- p2.SetAsBox(3, 3, new Vec2(20, 1), 0);
94- d.Addtolist(p2);
95- d.MakeBody(world);
96-
97- //自キャラとの距離を固定する
98- //Joints joints = new Joints(d.SelfBody, s.SelfBody);
99- //world.CreateJoint(joints.MakeDistanceJoint());
100-
101- //ObjectDataKindのAngularDampingは無視されます
102- float angularDamping = 0.3f, lineardamping = 0.5f, fric2 = 0.4f, rest2 = 2f, dens2 = 1;
103- FilterData f=new FilterData();
104- f.CategoryBits = 1;
105- f.GroupIndex = 1; f.MaskBits = 1;
106- DynamicRigid d2 = new DynamicRigid(new Vec2(50, 60), 0 * pi / 180, lineardamping, angularDamping);
107- d2.SetAsBox(16, 16, new Polygondef2(fric2, rest2, dens2, new myUserData("d2", 1, f, 2)), false);
108- Polygondef2 d2p = new Polygondef2(friction, restitution, density, new myUserData("d2p", 3, f, 2));
109- d2p.SetAsBox(24, 12, new Vec2(-20, 1), 0);
110- d2p.Fil();
111-
112- d2.Addtolist(d2p);
113- d2.NoRotate = false;
114- d2.MakeBody(world);
115-
116- DynamicRigid c1 = new DynamicRigid(new Vec2(300, 90), 0, 0, 0);
117- c1.SetAsCircle(new CircleDef2(new Vec2(), 20, 0, 0, 1, new myUserData()), false);
118- c1.MakeBody(world);
119-
120- DX.SetDrawScreen(DX.DX_SCREEN_BACK);
121-
122- //todo GetNameAndIdとかやりたい,worldを継承?
123- //GetNameAndId(); --> Dic<int,string> {{1,"player"},{2,"wall"}}
124- //GetName(2); -->"player"
125- //GetIdArr("enemy"); -->["1","4"]
126-
127- while (DX.ProcessMessage())
128- {
129-
130- //List<Shape> shape = d2.Shapelist;
131- //このインデックスをSetFilterに渡す
132- //Shape.GetBody().GetUserData();がユーザーデータ
133- //Shape.Get
134- f.MaskBits=1;
135- d2.SetFilter(f, 1);
136-
137- if (DX.CheckHitKey(DX.KEY_INPUT.RETURN) && !keyflag)
138- {
139- //瞬間的にある方向に力を加える(270度が設定されているのでオブジェクトから見て真上へ)
140- d.ApplyImpulse(new Vec2(0, -990));
141- }
142-
143- if (!DX.CheckHitKey(DX.KEY_INPUT.RETURN))
144- {
145- keyflag = false;
146- }
147-
148- if (DX.CheckHitKey(DX.KEY_INPUT.LEFT))
149- {
150- d.ApplyRelativeImpulse(new Vec2(-3 * d.Mass, 0),90);
151- //d.SelfBody.ApplyTorque(20*d.SelfBody.GetMass());
152- }
153- DX.ClearDrawScreen();
154- DX.ProcessActKeyInput();
155- DX.DrawString(2, 7, world.Gravity.X.ToString(), new DX.COLOR_U8(0xffffff));
156- DX.DrawString(2, 27, world.Gravity.Y.ToString(), new DX.COLOR_U8(0xffffff));
157-
158- DX.DrawRotaGraph((int)d.Position.X, (int)d.Position.Y, 1, d.Angle, mech, true, true);
159- DX.DrawRotaGraph((int)s.Position.X, (int)s.Position.Y, 1, 0, mech, false);
160-
161- //試しのRaycast,自分の下から30から10だけ下に光を伸ばす
162- d2.color = Colors.Red;
163- Shape[] hit = d2.Raycast(new Vec2(0, 30), new Vec2(0, 50));
164- world.Step(1 / 60f, 8, 1);
165-
166- DX.ScreenFlip();
167- } DX.DxLib_End();
168- } catch (Exception e)
169- {
170- System.Console.Write(e.ToString());
171- }
172- }
173-
174-
175- }
176-}
Show on old repository browser