root/src/AIDemos/Screens/Demos/Demo5.cs
| 15 | 23 | ||
|---|---|---|---|
22 | { | 22 | { |
23 | public class Demo5 : DemoGameScreen | 23 | public class Demo5 : DemoGameScreen |
24 | { | 24 | { |
25 | AIEngine _engine; | ||
26 | 25 | ||
27 | public Demo5() | 26 | public Demo5():base("Demo 5 - A Bigger World","") |
28 | { | 27 | { |
29 | TransitionOnTime = TimeSpan.FromSeconds(1.5); | 28 | TransitionOnTime = TimeSpan.FromSeconds(1.5); |
30 | TransitionOffTime = TimeSpan.FromSeconds(0.5); | 29 | TransitionOffTime = TimeSpan.FromSeconds(0.5); |
31 | Title = "Demo 5 - A Bigger World"; | ||
32 | Description = "An Agent is added to the world and set to patrol an area."; | ||
33 | 30 | ||
34 | | ||
35 | } | 31 | } |
36 | 32 | ||
37 | public override void LoadContent() | 33 | public override void LoadContent() |
... | ... | ||
39 | base.LoadContent(); | 35 | base.LoadContent(); |
40 | 36 | ||
41 | LoadAI(); | 37 | LoadAI(); |
42 | //primitiveBatch.CameraPosition = new Vector2(-(_engine.World.Map.Cluster[0].Width / 2), -(_engine.World.Map.Cluster[0].Height / 2)); | ||
43 | ((DrawableWorld)_engine.World).Font = gameFont; | ||
44 | ((DrawableWorld)_engine.World).Batch = ScreenManager.SpriteBatch; | ||
45 | | ||
46 | 38 | ||
47 | 39 | CenterCamOnMap(); | |
40 | ((DrawableWorld)_engine.World).Batch = ScreenManager.SpriteBatch; | ||
41 | ((DrawableWorld)_engine.World).Font= gameFont; | ||
48 | ScreenManager.Game.ResetElapsedTime(); | 42 | ScreenManager.Game.ResetElapsedTime(); |
49 | } | 43 | } |
50 | private void LoadAI() | 44 | private void LoadAI() |
51 | { | 45 | { |
52 | _engine = new AIEngine(); | ||
53 | _engine.CreateWorld(new DrawableWorld()); | 46 | _engine.CreateWorld(new DrawableWorld()); |
54 | _engine.World.LoadMapDataFromTexture( | 47 | _engine.World.LoadMapDataFromTexture( |
55 | content.Load<Texture2D>("DemoTextures/MAPDemo3"), | 48 | content.Load<Texture2D>("DemoTextures/MAPDemo3"), |
56 | 8, | 49 | 4, |
57 | 8, | 50 | 4, |
58 | 32, | 51 | 32, |
59 | typeof(DrawableGrid)); | 52 | typeof(DrawableGrid)); |
60 | 53 | ||
61 | GridCell fromcell=_engine.World.Map.AllCells.First<GridCell>( | 54 | //GridCell fromcell=_engine.World.Map.AllCells.First<GridCell>( |
62 | a => a.Labels[AIConsts.COLORR]==0&& | 55 | // a => a.Labels[AIConsts.COLORR]==0&& |
63 | a.Labels[AIConsts.COLORG]==255 && | 56 | // a.Labels[AIConsts.COLORG]==255 && |
64 | a.Labels[AIConsts.COLORB]==0); | 57 | // a.Labels[AIConsts.COLORB]==0); |
65 | GridCell tocell = _engine.World.Map.AllCells.First<GridCell>( | 58 | //GridCell tocell = _engine.World.Map.AllCells.First<GridCell>( |
66 | a => a.Labels[AIConsts.COLORR] == 255 && | 59 | // a => a.Labels[AIConsts.COLORR] == 255 && |
67 | a.Labels[AIConsts.COLORG] == 0 && | 60 | // a.Labels[AIConsts.COLORG] == 0 && |
68 | a.Labels[AIConsts.COLORB] == 0); | 61 | // a.Labels[AIConsts.COLORB] == 0); |
69 | GameActor actor = new GameActor(fromcell.Position, 5); | 62 | //GameActor actor = new GameActor(fromcell.Position, 5); |
70 | actor.Locomotion = new Brains.Framework.Locomotion.LocomtionSteering(); | 63 | //actor.Locomotion = new Brains.Framework.Locomotion.LocomtionSteering(); |
71 | actor.Locomotion.MaxSpeed = 50; | 64 | //actor.Locomotion.MaxSpeed = 70; |
72 | actor.Locomotion.MaxRotation = MathHelper.TwoPi; | 65 | //actor.Locomotion.MaxRotation = MathHelper.TwoPi; |
73 | 66 | ||
74 | _engine.World.AddActor(actor); | 67 | //_engine.World.AddActor(actor); |
75 | SequenceBehavior _sequence = new SequenceBehavior(); | 68 | //SequenceBehavior _sequence = new SequenceBehavior(); |
76 | 69 | ||
77 | 70 | ||
78 | DrawableBehaviorGoTo _goto = new DrawableBehaviorGoTo(); | 71 | //DrawableBehaviorGoTo _goto = new DrawableBehaviorGoTo(); |
79 | _goto.StartNode = fromcell; | 72 | //_goto.StartNode = fromcell; |
80 | _goto.EndNode = tocell; | 73 | //_goto.EndNode = tocell; |
81 | _sequence.SubBehaviors.Add(_goto); | 74 | //_sequence.SubBehaviors.Add(_goto); |
82 | _sequence.SubBehaviors.Add(new DieBehavior()); | 75 | //_sequence.SubBehaviors.Add(new DieBehavior()); |
83 | actor.RootBehavior = _sequence; | 76 | //actor.RootBehavior = _sequence; |
84 | 77 | ||
85 | } | 78 | } |
86 | class CellComparer:IComparer | 79 | class CellComparer:IComparer |
... | ... | ||
158 | Color.Black, 0, 0); | 151 | Color.Black, 0, 0); |
159 | 152 | ||
160 | SpriteBatch spriteBatch = ScreenManager.SpriteBatch; | 153 | SpriteBatch spriteBatch = ScreenManager.SpriteBatch; |
161 | 154 | | |
162 | spriteBatch.Begin(); | 155 | spriteBatch.Begin(); |
163 | 156 | ||
164 | base.Draw(gameTime); | 157 | base.Draw(gameTime); |
Download diff