Changeset 5967 for 2015/24/ohjaajat/Dungeon/Dungeon
- Timestamp:
- 2015-06-09 20:35:53 (8 years ago)
- Location:
- 2015/24/ohjaajat/Dungeon/Dungeon/Dungeon
- Files:
-
- 5 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/24/ohjaajat/Dungeon/Dungeon/Dungeon/Dungeon.cs
r5966 r5967 73 73 bool digging = false; 74 74 75 GameObject digArrow; 76 GameObject digArrowHead; 77 75 78 IntMeter kulttuuri = new IntMeter(300, 0, 2000); 76 79 … … 84 87 UlkoAsuRoskaa(); 85 88 Kauppa(); 89 90 digArrow = new GameObject(5, 5); 91 digArrowHead = new GameObject(15, 15); 92 digArrowHead.Shape = Shape.Triangle; 93 digArrowHead.IsVisible = digArrow.IsVisible = false; 94 Add(digArrow, 3); 95 Add(digArrowHead, 3); 86 96 87 97 // Luodaan huoneet ruutuihin. … … 156 166 Keyboard.Listen(Key.F1, ButtonState.Pressed, Begin, null); 157 167 168 // Testi haku huoneesta (0, 0) -> (5, 5). 169 Keyboard.Listen(Key.F2, ButtonState.Pressed, delegate 170 { 171 FindPath(new Point(0, 0), new Point(5, 5)); 172 }, null); 173 158 174 Keyboard.Listen(Key.Space, ButtonState.Pressed, SeuraavaAalto, "Anna kivan barbaariaallon tulla"); 159 175 } … … 185 201 digStart = huone.Location; 186 202 digging = true; 203 digArrowHead.IsVisible = digArrow.IsVisible = true; 187 204 } 188 205 … … 190 207 { 191 208 digging = false; 209 digArrowHead.IsVisible = digArrow.IsVisible = false; 192 210 if (CanDig()) 193 211 { … … 215 233 huone.Roof.Image = kiviKuva; 216 234 huone.Roof.Position = huone.Position; 217 Add(huone.Roof, 2);235 Add(huone.Roof, 1); 218 236 219 237 Mouse.ListenOn(huone, MouseButton.Left, ButtonState.Pressed, AsetaHuone, "Asetetaan ostettu huone paikoilleen", huone); … … 240 258 wall.Image = seinaKuva; 241 259 wall.Angle = suunta.Angle; 242 Add(wall, 1);260 Add(wall, 0); 243 261 return wall; 244 262 } … … 247 265 { 248 266 Room kohdeHuone = GetRoom(MuunnaJypelista(Mouse.PositionOnWorld)); 267 if (kohdeHuone == null) 268 { 269 return false; 270 } 249 271 int dx = Math.Abs(kohdeHuone.Location.X - digStart.X); 250 272 int dy = Math.Abs(kohdeHuone.Location.Y - digStart.Y); … … 252 274 } 253 275 254 protected override void Paint(Canvas canvas)276 protected override void Update(Time time) 255 277 { 256 278 if (digging) 257 279 { 258 canvas.BrushColor = CanDig() ? Color.Green : Color.Red; 259 canvas.DrawLine(huoneet[digStart.X, digStart.Y].Position, Mouse.PositionOnWorld); 260 } 261 base.Paint(canvas); 262 } 280 Color vari = CanDig() ? Color.Green : Color.Red; 281 Vector alku = huoneet[digStart.X, digStart.Y].Position; 282 Vector loppu = Mouse.PositionOnWorld; 283 Vector suunta = loppu - alku; 284 double pituus = suunta.Magnitude; 285 if (pituus <= 2) pituus = 2; 286 287 digArrow.Color = vari; 288 digArrow.Position = alku + suunta * 0.5; 289 digArrow.Angle = suunta.Angle; 290 digArrow.Width = pituus; 291 292 digArrowHead.Color = vari; 293 digArrowHead.Position = alku + suunta; 294 digArrowHead.Angle = suunta.Angle - Angle.FromDegrees(90); 295 } 296 base.Update(time); 297 } 298 299 #region Reitinlöytö 300 301 void FindPath(Point alku, Point loppu) 302 { 303 bool[,] walkable = new bool[huoneet.GetLength(0), huoneet.GetLength(1)]; 304 foreach (var paikka in RuutujenPaikat()) 305 { 306 walkable[paikka.X, paikka.Y] = huoneet[paikka.X, paikka.Y].Dug; 307 } 308 var finder = new AStar.PathFinder(new AStar.SearchParameters(alku, loppu, walkable)); 309 List<Point> path = finder.FindPath(); 310 // Ei ota huomioon ovia :( 311 } 312 313 #endregion 263 314 264 315 #region Extra Juttuja -
2015/24/ohjaajat/Dungeon/Dungeon/Dungeon/Dungeon.csproj
r5927 r5967 113 113 <Compile Include="Ohjelma.cs" /> 114 114 <Compile Include="Dungeon.cs" /> 115 <Compile Include="Pathfinding\Node.cs" /> 116 <Compile Include="Pathfinding\NodeState.cs" /> 117 <Compile Include="Pathfinding\PathFinder.cs" /> 118 <Compile Include="Pathfinding\SearchParameters.cs" /> 115 119 <Compile Include="Properties\AssemblyInfo.cs" /> 116 120 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.