Advertisement
2019PASTEBIN2019

Untitled

Jul 7th, 2019
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 102.98 KB | None | 0 0
  1. f
  2. ************************************
  3. //------------------------------------------------------------------------------
  4. // <copyright file="FallingThings.cs" company="Microsoft">
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // </copyright>
  7. //------------------------------------------------------------------------------
  8.  
  9. // This module contains code to do display falling shapes, and do
  10. // hit testing against a set of segments provided by the Kinect NUI, and
  11. // have shapes react accordingly.
  12.  
  13. namespace ShapeGame
  14. {
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Globalization;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Media;
  21. using System.Windows.Media.Imaging;
  22. using System.Windows.Shapes;
  23. using Microsoft.Kinect;
  24. using ShapeGame.Utils;
  25.  
  26. // FallingThings is the main class to draw and maintain positions of falling shapes. It also does hit testing
  27. // and appropriate bouncing.
  28. public class FallingThings
  29. {
  30. private const double BaseGravity = 0.017;
  31. private const double BaseAirFriction = 0.994;
  32.  
  33. private readonly Dictionary<PolyType, PolyDef> polyDefs = new Dictionary<PolyType, PolyDef>
  34. {
  35. { PolyType.Triangle, new PolyDef { Sides = 3, Skip = 1 } },
  36. { PolyType.Star, new PolyDef { Sides = 5, Skip = 2 } },
  37. { PolyType.Pentagon, new PolyDef { Sides = 5, Skip = 1 } },
  38. { PolyType.Square, new PolyDef { Sides = 4, Skip = 1 } },
  39. { PolyType.Hex, new PolyDef { Sides = 6, Skip = 1 } },
  40. { PolyType.Star7, new PolyDef { Sides = 7, Skip = 3 } },
  41. { PolyType.Circle, new PolyDef { Sides = 1, Skip = 1 } },
  42. { PolyType.Bubble, new PolyDef { Sides = 0, Skip = 1 } }
  43. };
  44.  
  45. private readonly List<Thing> things = new List<Thing>();
  46. private readonly Random rnd = new Random();
  47. private readonly int maxThings;
  48. private readonly int intraFrames = 1;
  49. private readonly Dictionary<int, int> scores = new Dictionary<int, int>();
  50. private const double DissolveTime = 0.4;
  51. private Rect sceneRect;
  52. private double targetFrameRate = 60;
  53. private double dropRate = 2.0;
  54. private double shapeSize = 1.0;
  55. private double baseShapeSize = 20;
  56. private GameMode gameMode = GameMode.Off;
  57. private double gravity = BaseGravity;
  58. private double gravityFactor = 1.0;
  59. private double airFriction = BaseAirFriction;
  60. private int frameCount;
  61. private bool doRandomColors = true;
  62. private double expandingRate = 1.0;
  63. private System.Windows.Media.Color baseColor = System.Windows.Media.Color.FromRgb(0, 0, 0);
  64. private PolyType polyTypes = PolyType.All;
  65. private DateTime gameStartTime;
  66. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  67. //@@לדעת מהי העצם שפגע ב"סינג"
  68. private string currentTypeOfHit;//@@
  69. public bool loadImg;
  70. private int score = 0;
  71. private string basketOrShape;
  72. private int numOfScore = 0;
  73. private JointType _currentTypeOfHit;
  74. private bool _shapeTurn = true;//תור תפיסת הצורה למעלה
  75. private Tuple<Point, Point, KeyValuePair<string, string>> _wantedGesture;
  76. private bool _canTouchBasket = false;
  77. private int currentIndexshapePositionList = 0;
  78. public bool GetLoadImg() { return loadImg; }
  79.  
  80.  
  81. List<Tuple<Point, Point, KeyValuePair<string, string>>> _shapeBasketList = new List<Tuple<Point, Point, KeyValuePair<string, string>>>()
  82. {
  83. new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeLeftUp*/new System.Windows.Point(200, 200), /*posBasketRightDown*/new System.Windows.Point(400, 400), /*"D1 right"*/new KeyValuePair<string, string>("HandRight","HandRight")),
  84. new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeRightUp*/new System.Windows.Point(400, 200), /*posBasketLeftDown*/new System.Windows.Point(200, 400), /*"D1 left"*/new KeyValuePair<string, string>("HandLeft","HandLeft")),
  85. new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeRightUp*/new System.Windows.Point(400, 200), /*posBasketLeftDown*/new System.Windows.Point(200, 400), /*"D2 right"*/new KeyValuePair<string, string>("HandRight","HandRight")),
  86. new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeLeftUp*/new System.Windows.Point(200, 200), /*posBasketRightDown*/new System.Windows.Point(400, 400), /*"D2 left"*/new KeyValuePair<string, string>("HandLeft","HandLeft")),
  87.  
  88. //new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeRightUp*/new System.Windows.Point(400, 200), /*posBasketLeftDown*/new System.Windows.Point(200, 400), /*"D2 right"*/new KeyValuePair<string, string>("HandRight","HandLeft")),
  89. //new Tuple<Point, Point, KeyValuePair<string, string>>(/*posShapeLeftUp*/new System.Windows.Point(200, 200), /*posBasketRightDown*/new System.Windows.Point(400, 400), /*"D2 left"*/new KeyValuePair<string, string>("HandLeft","HandRight"))
  90.  
  91.  
  92. };
  93.  
  94.  
  95.  
  96.  
  97.  
  98. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  99.  
  100.  
  101.  
  102.  
  103.  
  104. public FallingThings(int maxThings, double framerate, int intraFrames)
  105. {
  106. this.maxThings = maxThings;
  107. this.intraFrames = intraFrames;
  108. this.targetFrameRate = framerate * intraFrames;
  109. this.SetGravity(this.gravityFactor);
  110. this.sceneRect.X = this.sceneRect.Y = 0;
  111. this.sceneRect.Width = this.sceneRect.Height = 100;
  112. this.shapeSize = this.sceneRect.Height * this.baseShapeSize / 1000.0;
  113. this.expandingRate = Math.Exp(Math.Log(6.0) / (this.targetFrameRate * DissolveTime));
  114. }
  115.  
  116. public enum ThingState
  117. {
  118. Falling = 0, //$$-נופל
  119. Bouncing = 1,//$$-מתפוצץ
  120. Dissolving = 2,//$$-מעומעם
  121. Remove = 3//$$-מוסר
  122. }
  123.  
  124. public static Label MakeSimpleLabel(string text, Rect bounds, System.Windows.Media.Brush brush)
  125. {
  126. Label label = new Label { Content = text };
  127. if (bounds.Width != 0)
  128. {
  129. label.SetValue(Canvas.LeftProperty, bounds.Left);
  130. label.SetValue(Canvas.TopProperty, bounds.Top);
  131. label.Width = bounds.Width;
  132. label.Height = bounds.Height;
  133. }
  134.  
  135. label.Foreground = brush;
  136. label.FontFamily = new System.Windows.Media.FontFamily("Arial");
  137. label.FontWeight = FontWeight.FromOpenTypeWeight(600);
  138. label.FontStyle = FontStyles.Normal;
  139. label.HorizontalAlignment = HorizontalAlignment.Center;
  140. label.VerticalAlignment = VerticalAlignment.Center;
  141. return label;
  142. }
  143.  
  144. public void SetFramerate(double actualFramerate)
  145. {
  146. this.targetFrameRate = actualFramerate * this.intraFrames;
  147. this.expandingRate = Math.Exp(Math.Log(6.0) / (this.targetFrameRate * DissolveTime));
  148. if (this.gravityFactor != 0)
  149. {
  150. this.SetGravity(this.gravityFactor);
  151. }
  152. }
  153.  
  154. public void SetBoundaries(Rect r)
  155. {
  156. this.sceneRect = r;
  157. this.shapeSize = r.Height * this.baseShapeSize / 1000.0;
  158. }
  159.  
  160. public void SetDropRate(double f)
  161. {
  162. this.dropRate = f;
  163. }
  164.  
  165. public void SetSize(double f)
  166. {
  167. this.baseShapeSize = f;
  168. this.shapeSize = this.sceneRect.Height * this.baseShapeSize / 1000.0;
  169. }
  170.  
  171. public void SetShapesColor(System.Windows.Media.Color color, bool doRandom)
  172. {
  173. this.doRandomColors = doRandom;
  174. this.baseColor = color;
  175. }
  176.  
  177. public void Reset()
  178. {
  179. for (int i = 0; i < this.things.Count; i++)
  180. {
  181. Thing thing = this.things[i];
  182. if ((thing.State == ThingState.Bouncing) || (thing.State == ThingState.Falling))//bbb
  183. {
  184. thing.State = ThingState.Dissolving;//bbb
  185. thing.Dissolve = 0;
  186. this.things[i] = thing;
  187. }
  188. }
  189.  
  190. this.gameStartTime = DateTime.Now;
  191. this.scores.Clear();
  192. }
  193.  
  194. public void SetGameMode(GameMode mode)
  195. {
  196. this.gameMode = mode;
  197. this.gameStartTime = DateTime.Now;
  198. this.scores.Clear();
  199. }
  200.  
  201. public void SetGravity(double f)
  202. {
  203. this.gravityFactor = f;
  204. this.gravity = f * BaseGravity / this.targetFrameRate / Math.Sqrt(this.targetFrameRate) / Math.Sqrt(this.intraFrames);
  205. this.airFriction = f == 0 ? 0.997 : Math.Exp(Math.Log(1.0 - ((1.0 - BaseAirFriction) / f)) / this.intraFrames);
  206.  
  207. if (f == 0)
  208. {
  209. // Stop all movement as well!
  210. for (int i = 0; i < this.things.Count; i++)
  211. {
  212. Thing thing = this.things[i];
  213. thing.XVelocity = thing.YVelocity = 0;
  214. this.things[i] = thing;
  215. }
  216. }
  217. }
  218.  
  219. public void SetPolies(PolyType polies)
  220. {
  221. this.polyTypes = polies;
  222. }
  223.  
  224. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$////@@
  225.  
  226. public string GetcurrentTypeOfHitThing()
  227. {
  228.  
  229. return currentTypeOfHit;
  230.  
  231. }//@@
  232. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$////@@
  233.  
  234.  
  235. public HitType LookForHits(Dictionary<Bone, BoneData> segments, int playerId)
  236. {
  237. DateTime cur = DateTime.Now;
  238.  
  239. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//?
  240. //מאתחלים את ערך החזרת הפונקציה(סוג הפגיעה-פןפ,שום פגיעה,סקוויז וכו)בשום פגיעה
  241. HitType allHits = HitType.None; //bbb
  242.  
  243. // Zero out score if necessary
  244. if (!this.scores.ContainsKey(playerId))
  245. {
  246. this.scores.Add(playerId, 0);
  247. }
  248.  
  249. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//?
  250. //עוברים במקביל על כל מקטעי השלד ועל הצורות ובודקים אם היתה פגיעה
  251. foreach (var pair in segments)
  252. {
  253. for (int i = 0; i < this.things.Count; i++)
  254. {
  255.  
  256.  
  257. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  258. //מאתחל משתנה שישמור את סוג הפגיעה לשום פגיעה
  259.  
  260. HitType hit = HitType.None; //bbb
  261. Thing thing = this.things[i];
  262. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  263. //בודק פגיעה בסינג בתנאי שהסינג היה במצב "פגיע" 0
  264. if (thing.CanHit)
  265. {
  266. switch (thing.State)
  267. {
  268.  
  269. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//?
  270. //מצבים בהם ישנה אפשרות לפגוע
  271. case ThingState.Bouncing://bbb
  272. case ThingState.Falling://bbb
  273. {
  274. var hitCenter = new System.Windows.Point(0, 0); //bbb
  275. double lineHitLocation = 0; //bbb
  276. Segment seg = pair.Value.GetEstimatedSegment(cur);
  277.  
  278. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  279. //אם הפונקציה "איט" החזריה "טרו" סימן שהיתה פגיעה
  280.  
  281. if (thing.Hit(seg, ref hitCenter, ref lineHitLocation)) //bbb
  282. {
  283.  
  284.  
  285. double fMs = 1000;
  286.  
  287. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  288. //כאשר זמן פגיעה בצורה שונה מהערך שאתחלו אותה
  289. if (thing.TimeLastHit != DateTime.MinValue)//bbb
  290. {
  291.  
  292. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  293. //fMs-מחשבים את מספר השניות שעברו מזמן שהצורה אותחלה והוצגה בעצם על המסך עד לזמן שנפגעה
  294. //ומחשבים את ממוצע משך זמן הפגיעה
  295. //cur-זהו הזמן האמיתי של הפגיעה
  296. fMs = cur.Subtract(thing.TimeLastHit).TotalMilliseconds; //bbb
  297. thing.AvgTimeBetweenHits = (thing.AvgTimeBetweenHits * 0.8) + (0.2 * fMs); //bbb
  298. }
  299. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  300. //לשם בדיקה-מתי הזמן של הסינג נשאר אותו דבר
  301. else if (thing.TimeLastHit != DateTime.MinValue)
  302. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  303. {
  304. ;
  305. }
  306.  
  307. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  308. //נעדכן את "סינג" בזמן האמיתי של הפגיעה
  309. thing.TimeLastHit = cur; //bbb
  310.  
  311. // Bounce off head and hands
  312.  
  313. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  314. //פגיעה בעצמות ראש/ידיים/רגלים
  315. if (seg.IsCircle())
  316. {
  317.  
  318. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  319. //שמתי בהערה כדי שלא תזוז הצורה בתנועה לא נכונה
  320. // Bounce off of hand/head/foot
  321. //thing.BounceOff(
  322. // hitCenter.X,
  323. // hitCenter.Y,
  324. // seg.Radius,
  325. // pair.Value.XVelocity / this.targetFrameRate,
  326. // pair.Value.YVelocity / this.targetFrameRate);
  327. if (fMs > 100.0)
  328. {
  329. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  330. //במצב שהיתה פגיעה חלשה--נגיעה קלה עם היד
  331. hit |= HitType.Hand; //bbb
  332. }
  333. }
  334. else
  335. {
  336. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  337. //שמתי בהערה כדי שלא תזוז הצורה בתנועה לא נכונה
  338.  
  339. // Bounce off line segment
  340. //double velocityX = (pair.Value.XVelocity * (1.0 - lineHitLocation)) + (pair.Value.XVelocity2 * lineHitLocation);
  341. //double velocityY = (pair.Value.YVelocity * (1.0 - lineHitLocation)) + (pair.Value.YVelocity2 * lineHitLocation);
  342.  
  343. //thing.BounceOff(
  344. // hitCenter.X,
  345. // hitCenter.Y,
  346. // seg.Radius,
  347. // velocityX / this.targetFrameRate,
  348. // velocityY / this.targetFrameRate);
  349.  
  350. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  351. //במצב של פגיעה בזרוע
  352. if (fMs > 100.0)
  353. {
  354. hit |= HitType.Arm; //bbb
  355. }
  356. }
  357.  
  358. if (this.gameMode == GameMode.TwoPlayer)
  359. {
  360. if (thing.State == ThingState.Falling)//bbb
  361. {
  362. thing.State = ThingState.Bouncing;//bbb
  363. thing.TouchedBy = playerId;
  364. thing.Hotness = 1;
  365. thing.FlashCount = 0;
  366. }
  367. else if (thing.State == ThingState.Bouncing)//bbb
  368. {
  369. if (thing.TouchedBy != playerId)
  370. {
  371. if (seg.IsCircle())
  372. {
  373. thing.TouchedBy = playerId;
  374. thing.Hotness = Math.Min(thing.Hotness + 1, 4);
  375. }
  376. else
  377. {
  378. hit |= HitType.Popped; //bbb
  379. this.AddToScore(thing.TouchedBy, 5 << (thing.Hotness - 1), thing.Center, "");
  380. }
  381. }
  382. }
  383. }
  384. else if (this.gameMode == GameMode.Solo)
  385. {
  386. //$$$$$$$$$$$$$$$$$$$$$$
  387. //@@בשביל לצבוע את הסגמנט שפגע ב"סינג
  388.  
  389. var w1 = pair.Key.Joint1;
  390. var w2 = pair.Key.Joint2;
  391. //@@
  392. JointType typeOfHit = pair.Key.Joint1;
  393. currentTypeOfHit = typeOfHit.ToString(); //1234
  394.  
  395. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  396.  
  397. //אם רוצים לחלק לפי סוג פגיעה
  398. //switch (typeOfHit)
  399. //{
  400. // case JointType.AnkleLeft:
  401. // //Console.WriteLine("The color is red");
  402. // //numOfScore = 21;
  403. // break;
  404. // case JointType.AnkleRight:
  405. // //Console.WriteLine("The color is green");
  406. // // numOfScore = 2;
  407. // break;
  408. // case JointType.ElbowLeft:
  409. // //Console.WriteLine("The color is blue");
  410. // //numOfScore = 3;
  411. // break;
  412. // case JointType.ElbowRight:
  413. // //Console.WriteLine("The color is red");
  414. // //numOfScore = 4;
  415. // break;
  416. // case JointType.FootLeft:
  417. // //Console.WriteLine("The color is green");
  418. // //numOfScore = 5;
  419. // break;
  420. // case JointType.FootRight:
  421. // //Console.WriteLine("The color is blue");
  422. // //numOfScore = 6;
  423. // break;
  424. // case JointType.HandLeft:
  425. // //Console.WriteLine("The color is red");
  426. // //numOfScore = 7;
  427. // break;
  428. // case JointType.HandRight:
  429. // //Console.WriteLine("The color is green");
  430. // //numOfScore = 8;
  431. // break;
  432. // case JointType.Head:
  433. // //Console.WriteLine("The color is blue");
  434. // //numOfScore = 9;
  435. // break;
  436. // case JointType.HipCenter:
  437. // //Console.WriteLine("The color is red");
  438. // //numOfScore = 10;
  439. // break;
  440. // case JointType.HipLeft:
  441. // //Console.WriteLine("The color is green");
  442. // //numOfScore = 11;
  443. // break;
  444. // case JointType.HipRight:
  445. // //Console.WriteLine("The color is blue");
  446. // //numOfScore = 12;
  447. // break;
  448. // case JointType.KneeLeft:
  449. // //Console.WriteLine("The color is red");
  450. // //numOfScore = 13;
  451. // break;
  452. // case JointType.KneeRight:
  453. // //Console.WriteLine("The color is green");
  454. // //numOfScore = 14;
  455. // break;
  456. // case JointType.ShoulderCenter:
  457. // //Console.WriteLine("The color is blue");
  458. // //numOfScore = 15;
  459. // break;
  460. // case JointType.ShoulderLeft:
  461. // //Console.WriteLine("The color is red");
  462. // numOfScore = 16;
  463. // break;
  464. // case JointType.ShoulderRight:
  465. // //Console.WriteLine("The color is red");
  466. // numOfScore = 17;
  467. // break;
  468. // case JointType.Spine:
  469. // //Console.WriteLine("The color is green");
  470. // //numOfScore = 18;
  471. // break;
  472. // case JointType.WristLeft:
  473. // //Console.WriteLine("The color is blue");
  474. // //numOfScore = 19;
  475. // break;
  476. // case JointType.WristRight:
  477. // //Console.WriteLine("The color is red");
  478. // //numOfScore = 20;
  479. // break;
  480. // default:
  481. // //Console.WriteLine("The color is unknown.");
  482. // // numOfScore = 200;
  483. // break;
  484. //}
  485.  
  486.  
  487. //@@
  488. //$$$$$$$$$$$$$$$$$$$$$$$$
  489.  
  490. if (seg.IsCircle())
  491. {
  492.  
  493. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  494. //היתה פגיעה והצורה היתה במצב נפילה(מצב בו היא מאותחלת ברגע שנכנסת למערך ה"סינגים" ןמןצגת על המסך) תעדכן אותה להיות במצב מתפוצץ
  495. if (thing.State == ThingState.Falling)//bbb
  496. {
  497. thing.State = ThingState.Bouncing;//bbb
  498. thing.TouchedBy = playerId;
  499. thing.Hotness = 1;
  500. thing.FlashCount = 0;
  501. }
  502. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  503. //כאשר ה"סינג" כבר במצב מעומעם-נגדיר את סוג הפגיעה להיות "פופ" ונרצה להציג ניקוד על הפגיעה(במקום הצורה שנפגעה) ולעדכן ניקוד כללי
  504. else if ((thing.State == ThingState.Bouncing) && (fMs > 100.0))//bbb
  505. {
  506.  
  507. hit |= HitType.Popped; //bbb
  508.  
  509.  
  510. }
  511. }
  512. }
  513.  
  514. this.things[i] = thing;
  515. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  516. //אם ממוצע משך זמן הפגיעה קטן מ8 זה אומר שהפגיעה היתה מסוג "פופ" או "סקייז
  517. if (thing.AvgTimeBetweenHits < 8) //bbb
  518. {
  519. hit |= HitType.Popped | HitType.Squeezed; //bbb
  520.  
  521.  
  522. }
  523. }
  524. }
  525.  
  526. break;
  527. }
  528. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  529. //היתה פגיעה והיא והיא מסוג "פופ" תעדכןאת מצב ה"סינג" להיות מעומעם ותעדכן כמה דברים שצריך בכמה דברים שדרושים כדי להיכנס למצב הזה
  530. //הוספנו אפשרות ל"סקייז"
  531. if ((hit & HitType.Popped) != 0 || (hit & HitType.Squeezed) != 0)/* /*|| (hit & HitType.Arm)!=0 || (hit & HitType.Hand)!=0 )*/ //$$
  532. {
  533. if (thing.TypeOfShape == "shape")
  534. {
  535. if (currentTypeOfHit == _wantedGesture.Item3.Key)
  536. {
  537. loadImg = false; //$$
  538. thing.State = ThingState.Dissolving;
  539. thing.Dissolve = 0;
  540. thing.XVelocity = thing.YVelocity = 0;
  541. thing.SpinRate = (thing.SpinRate * 6) + 0.2;
  542. this.things[i] = thing;
  543.  
  544. numOfScore = 5;
  545.  
  546.  
  547.  
  548. }
  549.  
  550. }
  551. else if (thing.TypeOfShape == "basket")
  552. {
  553. if (currentTypeOfHit == _wantedGesture.Item3.Value)
  554. {
  555.  
  556. loadImg = true; //$$
  557. thing.State = ThingState.Dissolving;
  558. thing.Dissolve = 0;
  559. thing.XVelocity = thing.YVelocity = 0;
  560. thing.SpinRate = (thing.SpinRate * 6) + 0.2;
  561. this.things[i] = thing;
  562.  
  563.  
  564. numOfScore = 2;
  565.  
  566.  
  567.  
  568.  
  569. }
  570. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  571. //כאשר ה"סינג" כבר במצב מעומעם נרצה להציג ניקוד על הפגיעה(במקום הצורה שהתפוצצה) ולעדכן ניקוד כללי אך זאת בתנאי שמצב המשחק אינו כבוי כלומר יש 1/2 שחקנים במשחק
  572.  
  573. if (this.gameMode != GameMode.Off)
  574. {
  575. this.AddToScore(
  576. thing.TouchedBy,
  577. numOfScore,
  578. thing.Center, "joint" + " " + currentTypeOfHit);
  579. }
  580. thing.TouchedBy = playerId;
  581. }
  582.  
  583. allHits |= hit; //bbb
  584. }
  585. }
  586. }
  587. }
  588. return allHits; //bbb
  589. }
  590.  
  591. public void AdvanceFrame()
  592. {
  593. // Move all things by one step, accounting for gravity
  594. for (int thingIndex = 0; thingIndex < this.things.Count; thingIndex++)
  595. {
  596. Thing thing = this.things[thingIndex];
  597. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  598. //כך מונעים תזוזה של צורה-הן רק הסתבובבו אך לא יזוזו ממש
  599. //thing.Center.Offset(thing.XVelocity, thing.YVelocity);//$$
  600. thing.YVelocity += this.gravity * this.sceneRect.Height;
  601. thing.YVelocity *= this.airFriction;
  602. thing.XVelocity *= this.airFriction;
  603. thing.Theta += thing.SpinRate;
  604.  
  605. // bounce off walls
  606. if ((thing.Center.X - thing.Size < 0) || (thing.Center.X + thing.Size > this.sceneRect.Width))
  607. {
  608. thing.XVelocity = -thing.XVelocity;
  609. thing.Center.X += thing.XVelocity;
  610. }
  611.  
  612. // Then get rid of one if any that fall off the bottom
  613. if (thing.Center.Y - thing.Size > this.sceneRect.Bottom)
  614. {
  615. thing.State = ThingState.Remove;//bbb
  616. }
  617.  
  618. // Get rid of after dissolving.
  619.  
  620.  
  621. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  622. // במצב שה"סינג" במצב מעומעם תעמעם את ה"סינג" שלו כאשר המשתנה "דיסולב" שהפך בין מצב התפוצצות למצב עמעום ל0
  623. //עולה לאט לאט וכשהוא גדול שווה ל1 מצב ה"סינג" הופך להיות במצב מוסר
  624. if (thing.State == ThingState.Dissolving)//bbb
  625. {
  626.  
  627. thing.Dissolve += 1 / (this.targetFrameRate * DissolveTime);
  628. //$$$$$$$$$$$$$$$כך גודל הצורה לא משתנה כאשר נוגעים ביד הלא נכונה
  629. //thing.Size *= this.expandingRate;
  630. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  631.  
  632. if (thing.Dissolve >= 1.0)
  633. {
  634. thing.State = ThingState.Remove;//bbb
  635. }
  636. }
  637.  
  638. this.things[thingIndex] = thing;
  639. }
  640.  
  641. // Then remove any that should go away now
  642.  
  643. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  644. //לאחר שעבר על מערך ה"סינגים" בודק אם יש "סינגים" שצריך להסיר
  645.  
  646. for (int i = 0; i < this.things.Count; i++)
  647. {
  648. Thing thing = this.things[i];
  649. if (thing.State == ThingState.Remove)//bbb
  650. {
  651. this.things.Remove(thing);
  652.  
  653. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  654. //לאחר שפגע בצורה למעלה מאפשר פגיעה בסל
  655. //בהתחלה ברשימה הופיה קודם הצורה למעלה ומיד אחריה הצורה שבסל
  656. // כיוון שהסרנו את הצורה למעלה הצורה של הסל תפסה את מקומה
  657. int index = i;
  658. for (int k = 0; k < things.Count; k++)
  659. {
  660. if (k == index)
  661. {
  662. Thing thingToUpdate = this.things[k];
  663. thingToUpdate.CanHit = true;
  664. this.things[k] = thingToUpdate;
  665. }
  666. }
  667. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  668. i--;
  669. }
  670. }
  671.  
  672. // Create any new things to drop based on dropRate
  673. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  674. //if we want a few shape together we need to change code to:
  675. //if ((this.things.Count < this.maxThings) && (this.rnd.NextDouble() < this.dropRate / this.targetFrameRate) && (this.polyTypes != PolyType.None))
  676. if ((this.things.Count < 1) && (this.rnd.NextDouble() < this.dropRate / this.targetFrameRate) && (this.polyTypes != PolyType.None)) //$$
  677. {
  678. PolyType[] alltypes =
  679. {
  680. PolyType.Triangle, PolyType.Square, PolyType.Star, PolyType.Pentagon,
  681. PolyType.Hex, PolyType.Star7, PolyType.Circle, PolyType.Bubble
  682. };
  683. byte r;
  684. byte g;
  685. byte b;
  686.  
  687. if (this.doRandomColors)
  688. {
  689. r = (byte)(this.rnd.Next(215) + 40);
  690. g = (byte)(this.rnd.Next(215) + 40);
  691. b = (byte)(this.rnd.Next(215) + 40);
  692. }
  693. else
  694. {
  695. r = (byte)Math.Min(255.0, this.baseColor.R * (0.7 + (this.rnd.NextDouble() * 0.7)));
  696. g = (byte)Math.Min(255.0, this.baseColor.G * (0.7 + (this.rnd.NextDouble() * 0.7)));
  697. b = (byte)Math.Min(255.0, this.baseColor.B * (0.7 + (this.rnd.NextDouble() * 0.7)));
  698. }
  699.  
  700. PolyType tryType;
  701. do
  702. {
  703. tryType = alltypes[this.rnd.Next(alltypes.Length)];
  704. }
  705. while ((this.polyTypes & tryType) == 0);
  706.  
  707.  
  708. this.DropNewThing(tryType, this.shapeSize, System.Windows.Media.Color.FromRgb(r, g, b), currentIndexshapePositionList);
  709. currentIndexshapePositionList += 1;
  710.  
  711. }
  712. }
  713.  
  714. public void DrawFrame(UIElementCollection children)
  715. {
  716. this.frameCount++;
  717.  
  718. // Draw all shapes in the scene
  719. for (int i = 0; i < this.things.Count; i++)
  720. {
  721. Thing thing = this.things[i];
  722. if (thing.Brush == null)
  723. {
  724. thing.Brush = new SolidColorBrush(thing.Color);
  725. double factor = 0.4 + (((double)thing.Color.R + thing.Color.G + thing.Color.B) / 1600);
  726. thing.Brush2 =
  727. new SolidColorBrush(
  728. System.Windows.Media.Color.FromRgb(
  729. (byte)(255 - ((255 - thing.Color.R) * factor)),
  730. (byte)(255 - ((255 - thing.Color.G) * factor)),
  731. (byte)(255 - ((255 - thing.Color.B) * factor))));
  732. thing.BrushPulse = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 255));
  733. }
  734.  
  735.  
  736. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  737. //כאשר היתה פגיעה והצורה היתה במצב מתפוצץ
  738. if (thing.State == ThingState.Bouncing)//bbb
  739. {
  740. // Pulsate edges
  741. double alpha = Math.Cos((0.15 * (thing.FlashCount++) * thing.Hotness) * 0.5) + 0.5;
  742. int type = i;
  743. children.Add(
  744. this.MakeSimpleShape(
  745. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  746. //החלפנו לצורך צורות מוגדרות מראש
  747. //this.polyDefs[thing.Shape].Sides,
  748. //this.polyDefs[thing.Shape].Skip,
  749. //thing.Size,
  750. //thing.Theta,
  751. //thing.Center,
  752. //thing.Brush,
  753. //thing.BrushPulse,
  754. //thing.Size * 0.1,
  755. //alpha));
  756. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  757. thing.TypeOfShape,
  758. i,
  759. this.polyDefs[thing.Shape].Sides,
  760. this.polyDefs[thing.Shape].Skip,
  761. thing.Size,
  762. thing.Theta,
  763. thing.Center,
  764. thing.Brush,
  765. thing.BrushPulse,
  766. (thing.TypeOfShape == "basket") ? 0 : 3,
  767. alpha));
  768. this.things[i] = thing;
  769. }
  770. else
  771. {
  772. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  773. //במצב מעומעם נרצה לשנות את אטימות הצבע של ה"סינג
  774. if (thing.State == ThingState.Dissolving)//bbb
  775. {
  776. thing.Brush.Opacity = 1.0 - (thing.Dissolve * thing.Dissolve);
  777. }
  778. int type = i;//$$
  779. children.Add(
  780. this.MakeSimpleShape(
  781.  
  782. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  783. //החלפנו לצורך צורות מוגדרות מראש
  784. //this.polyDefs[thing.Shape].Sides,
  785. //this.polyDefs[thing.Shape].Skip,
  786. //thing.Size,
  787. //thing.Theta,
  788. //thing.Center,
  789. //thing.Brush,
  790. //(thing.State == ThingState.Dissolving) ? null : thing.Brush2,
  791. //1,
  792. //1));
  793. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  794. thing.TypeOfShape,
  795. i,
  796. this.polyDefs[thing.Shape].Sides,
  797. this.polyDefs[thing.Shape].Skip,
  798. thing.Size,
  799. thing.Theta,
  800. thing.Center,
  801. thing.Brush,
  802. (thing.State == ThingState.Dissolving) ? null : thing.Brush2,
  803. (thing.TypeOfShape == "basket") ? 0 : 3,
  804. 1));
  805. }
  806. }
  807. // Show scores
  808. if (this.scores.Count != 0)
  809. {
  810. int i = 0;
  811. foreach (var score in this.scores)
  812. {
  813. Label label = MakeSimpleLabel(
  814. score.Value.ToString(CultureInfo.InvariantCulture),
  815. new Rect(
  816. (0.02 + (i * 0.6)) * this.sceneRect.Width,
  817. 0.01 * this.sceneRect.Height,
  818. 0.4 * this.sceneRect.Width,
  819. 0.3 * this.sceneRect.Height),
  820. new SolidColorBrush(System.Windows.Media.Color.FromArgb(200, 255, 255, 255)));
  821. label.FontSize = Math.Max(1, Math.Min(this.sceneRect.Width / 12, this.sceneRect.Height / 12));
  822. children.Add(label);
  823. i++;
  824. }
  825. }
  826.  
  827. // Show game timer
  828. if (this.gameMode != GameMode.Off)
  829. {
  830. TimeSpan span = DateTime.Now.Subtract(this.gameStartTime);
  831. string text = span.Minutes.ToString(CultureInfo.InvariantCulture) + ":" + span.Seconds.ToString("00");
  832.  
  833. Label timeText = MakeSimpleLabel(
  834. text,
  835. new Rect(
  836. 0.1 * this.sceneRect.Width, 0.25 * this.sceneRect.Height, 0.89 * this.sceneRect.Width, 0.72 * this.sceneRect.Height),
  837. new SolidColorBrush(System.Windows.Media.Color.FromArgb(160, 255, 255, 255)));
  838. timeText.FontSize = Math.Max(1, this.sceneRect.Height / 16);
  839. timeText.HorizontalContentAlignment = HorizontalAlignment.Right;
  840. timeText.VerticalContentAlignment = VerticalAlignment.Bottom;
  841. children.Add(timeText);
  842. }
  843. }
  844.  
  845. private static double SquaredDistance(double x1, double y1, double x2, double y2)
  846. {
  847. return ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1));
  848. }
  849.  
  850. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  851. //הוספנו קבלת סוג הפגיעה
  852.  
  853. private void AddToScore(int player, int points, System.Windows.Point center, string typeOfHit)
  854. {
  855. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  856. //ניקוד על פגיעה ספציפית
  857. if (this.scores.ContainsKey(player))
  858. {
  859. this.scores[player] = this.scores[player] + points;
  860. }
  861. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  862. //ניקוד כללי
  863.  
  864.  
  865. else
  866. {
  867. this.scores.Add(player, points);
  868. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  869. //לשם בדיקה-מתי מציג פעמיים ניקוד באותו מסך
  870. if(scores.Count>1)
  871. {
  872. ;
  873. }
  874. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  875.  
  876. }
  877.  
  878. // FlyingText.NewFlyingText(this.sceneRect.Width / 300, center, "+" + points);
  879. }
  880. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  881. //הוספנו קבלת nextPos
  882. private void DropNewThing(PolyType newShape, double newSize, System.Windows.Media.Color newColor, int nextPos)
  883. {
  884. // Only drop within the center "square" area
  885. double dropWidth = this.sceneRect.Bottom - this.sceneRect.Top;
  886. if (dropWidth > this.sceneRect.Right - this.sceneRect.Left)
  887. {
  888. dropWidth = this.sceneRect.Right - this.sceneRect.Left;
  889. }
  890.  
  891. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  892. //רצינו צורות עם מאפינים קבועים ולכן החלפנו
  893.  
  894. //var newThing = new Thing
  895. //{
  896. // Size = newSize,
  897. // YVelocity = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
  898. // XVelocity = 0,
  899. // Shape = newShape,
  900. // Center = new System.Windows.Point((this.rnd.NextDouble() * dropWidth) + ((this.sceneRect.Left + this.sceneRect.Right - dropWidth) / 2), this.sceneRect.Top - newSize),
  901. // SpinRate = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
  902. // Theta = 0,
  903. // TimeLastHit = DateTime.MinValue,
  904. // AvgTimeBetweenHits = 100,
  905. // Color = newColor,
  906. // Brush = null,
  907. // Brush2 = null,
  908. // BrushPulse = null,
  909. // Dissolve = 0,
  910. // State = ThingState.Falling,
  911. // TouchedBy = 0,
  912. // Hotness = 0,
  913. // FlashCount = 0
  914. //};
  915.  
  916. //this.things.Add(newThing);
  917. for (int i = 0; i < _shapeBasketList.Count; i++)
  918.  
  919. {
  920. if (i == nextPos)
  921. {
  922.  
  923. _wantedGesture = _shapeBasketList[i];
  924.  
  925.  
  926. var newThing = new Thing
  927. {
  928. Size = newSize,
  929. YVelocity = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
  930. XVelocity = 0,
  931. Shape = newShape,
  932. Center = _shapeBasketList[i].Item1,
  933. SpinRate = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
  934. Theta = 0,
  935. TimeLastHit = DateTime.MinValue,
  936. AvgTimeBetweenHits = 100,
  937. Color = newColor,
  938. Brush = null,
  939. Brush2 = null,
  940. BrushPulse = null,
  941. Dissolve = 0,
  942. State = ThingState.Falling,
  943. CanHit = true,
  944. TypeOfShape = "shape",
  945. TouchedBy = 0,
  946. Hotness = 0,
  947. FlashCount = 0,
  948.  
  949. };
  950.  
  951.  
  952. var basket = new Thing
  953. {
  954.  
  955. Size = 60,
  956. YVelocity = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
  957. XVelocity = 0,
  958. Shape = PolyType.Square,
  959. Center = _shapeBasketList[i].Item2,
  960.  
  961. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  962. //מנענו את תזוזת הסל
  963. //SpinRate = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
  964. SpinRate = 0,//$$
  965. Theta = 0,
  966. TimeLastHit = DateTime.MinValue,
  967. AvgTimeBetweenHits = 100,
  968. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  969. //הגדרנו את צורת הסל לצבע שקוף(כי הרי עליה יש תמונה ולא נרצה שיראו את קצוות הצורה
  970. //Color = newColor,
  971. Color = Color.FromRgb(0, 0, 0),
  972. Brush = null,
  973. Brush2 = null,
  974. BrushPulse = Brushes.Transparent,
  975. Dissolve = 0,
  976. State = ThingState.Falling,
  977. CanHit = false,
  978. TypeOfShape = "basket",
  979. TouchedBy = 0,
  980. Hotness = 0,
  981. FlashCount = 0
  982. };
  983. this.things.Add(newThing);
  984. this.things.Add(basket);
  985.  
  986. }
  987. }
  988. }
  989.  
  990. private Shape MakeSimpleShape(
  991. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  992. //הוספנו מאפיינים לצורה
  993. string typeOfShape,//$$
  994. int type,//$$
  995. int numSides,
  996. int skip,
  997. double size,
  998. double spin,
  999. System.Windows.Point center,
  1000. System.Windows.Media.Brush brush,
  1001. System.Windows.Media.Brush brushStroke,
  1002. double strokeThickness,
  1003. double opacity)
  1004. {
  1005. if (numSides <= 1)
  1006. {
  1007. var circle = new Ellipse { Width = size * 2, Height = size * 2, Stroke = brushStroke };
  1008. if (circle.Stroke != null)
  1009. {
  1010. circle.Stroke.Opacity = opacity;
  1011. }
  1012.  
  1013. circle.StrokeThickness = strokeThickness * ((numSides == 1) ? 1 : 2);
  1014. circle.Fill = (numSides == 1) ? brush : null;
  1015. circle.SetValue(Canvas.LeftProperty, center.X - size);
  1016. circle.SetValue(Canvas.TopProperty, center.Y - size);
  1017. return circle;
  1018. }
  1019.  
  1020. var points = new PointCollection(numSides + 2);
  1021. double theta = spin;
  1022. for (int i = 0; i <= numSides + 1; ++i)
  1023. {
  1024. points.Add(new System.Windows.Point((Math.Cos(theta) * size) + center.X, (Math.Sin(theta) * size) + center.Y));
  1025. theta = theta + (2.0 * Math.PI * skip / numSides);
  1026. }
  1027.  
  1028. var polyline = new Polyline { Points = points, Stroke = brushStroke };
  1029. if (polyline.Stroke != null)
  1030. {
  1031. polyline.Stroke.Opacity = opacity;
  1032. }
  1033.  
  1034.  
  1035. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1036. //המילוי של הצורה יהיה מסוג צבע(לצורה)/מסוג תמונה(לסל)0
  1037.  
  1038. if (typeOfShape == "basket")
  1039. {
  1040. //$$$$$$$$$$$$$$$4 relative sorce-התמונה נטענת מתוך הנתיב שנמצא בתוך הפרויקט .../shapegame/bin/debug/image
  1041. polyline.Fill = new ImageBrush(new BitmapImage(new Uri("image/basket1.jpg", UriKind.Relative)));
  1042. //$$$$$$$$$$$$$$$4 not relative sorce
  1043. //polyline.Fill = new ImageBrush(new BitmapImage(new Uri(@"C:\Users\User\Desktop\Downloads\basket1.jpg")));
  1044. basketOrShape = "basket";
  1045. }
  1046. else
  1047. {
  1048. polyline.Fill = brush;
  1049. basketOrShape = "shape";
  1050. }
  1051. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1052.  
  1053.  
  1054. polyline.FillRule = FillRule.Nonzero;
  1055. polyline.StrokeThickness = strokeThickness;
  1056. return polyline;
  1057. }
  1058.  
  1059. internal struct PolyDef
  1060. {
  1061. public int Sides;
  1062. public int Skip;
  1063. }
  1064.  
  1065. // The Thing struct represents a single object that is flying through the air, and
  1066. // all of its properties.
  1067. private struct Thing
  1068. {
  1069. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1070. //הוספנו מאפיינים לצורה
  1071. public System.Windows.Media.ImageBrush image;//$$
  1072. public bool CanHit;//$$
  1073. public string TypeOfShape;//regular shape or basket //$$
  1074. public System.Windows.Point Center;
  1075. public double Size;
  1076. public double Theta;
  1077. public double SpinRate;
  1078. public double YVelocity;
  1079. public double XVelocity;
  1080. public PolyType Shape;
  1081. public System.Windows.Media.Color Color;
  1082. public System.Windows.Media.Brush Brush;
  1083. public System.Windows.Media.Brush Brush2;
  1084. public System.Windows.Media.Brush BrushPulse;
  1085. public double Dissolve;
  1086. public ThingState State;
  1087. public DateTime TimeLastHit;
  1088. public double AvgTimeBetweenHits;
  1089. public int TouchedBy; // Last player to touch this thing-השחקן שנגע בצורה
  1090.  
  1091. public int Hotness; // Score level
  1092. public int FlashCount;
  1093.  
  1094. // Hit testing between this thing and a single segment. If hit, the center point on
  1095. // the segment being hit is returned, along with the spot on the line from 0 to 1 if
  1096. // a line segment was hit.
  1097.  
  1098. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1099. //מחזירה טרו אם היתה פגיעה בין "סינג" ואחת מהסגמטים=מקטעי השלד
  1100. public bool Hit(Segment seg, ref System.Windows.Point hitCenter, ref double lineHitLocation)
  1101. {
  1102. double minDxSquared = this.Size + seg.Radius;
  1103. minDxSquared *= minDxSquared;
  1104.  
  1105. // See if falling thing hit this body segment
  1106. if (seg.IsCircle())
  1107. {
  1108. if (SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) <= minDxSquared)
  1109. {
  1110. hitCenter.X = seg.X1; //bbb
  1111. hitCenter.Y = seg.Y1;//bbb
  1112. lineHitLocation = 0;//bbb
  1113. return true;
  1114. }
  1115. }
  1116. else
  1117. {
  1118. double sqrLineSize = SquaredDistance(seg.X1, seg.Y1, seg.X2, seg.Y2);
  1119. if (sqrLineSize < 0.5)
  1120. {
  1121. // if less than 1/2 pixel apart, just check dx to an endpoint
  1122. return SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) < minDxSquared;
  1123. }
  1124.  
  1125. // Find dx from center to line
  1126. double u = ((this.Center.X - seg.X1) * (seg.X2 - seg.X1)) + (((this.Center.Y - seg.Y1) * (seg.Y2 - seg.Y1)) / sqrLineSize);
  1127. if ((u >= 0) && (u <= 1.0))
  1128. { // Tangent within line endpoints, see if we're close enough
  1129. double intersectX = seg.X1 + ((seg.X2 - seg.X1) * u);
  1130. double intersectY = seg.Y1 + ((seg.Y2 - seg.Y1) * u);
  1131.  
  1132. if (SquaredDistance(this.Center.X, this.Center.Y, intersectX, intersectY) < minDxSquared)
  1133. {
  1134. lineHitLocation = u;//bbb
  1135. hitCenter.X = intersectX;//bbb
  1136. hitCenter.Y = intersectY;//bbb
  1137. return true;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. // See how close we are to an endpoint
  1143. if (u < 0)
  1144. {
  1145. if (SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) < minDxSquared)
  1146. {
  1147. lineHitLocation = 0;//bbb
  1148. hitCenter.X = seg.X1;//bbb
  1149. hitCenter.Y = seg.Y1;//bbb
  1150. return true;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. if (SquaredDistance(this.Center.X, this.Center.Y, seg.X2, seg.Y2) < minDxSquared)
  1156. {
  1157. lineHitLocation = 1;//bbb
  1158. hitCenter.X = seg.X2;//bbb
  1159. hitCenter.Y = seg.Y2;//bbb
  1160. return true;
  1161. }
  1162. }
  1163. }
  1164.  
  1165. return false;
  1166. }
  1167.  
  1168. return false;
  1169. }
  1170.  
  1171. // Change our velocity based on the object's velocity, our velocity, and where we hit.
  1172. public void BounceOff(double x1, double y1, double otherSize, double fXv, double fYv)
  1173. {
  1174. double x0 = this.Center.X;
  1175. double y0 = this.Center.Y;
  1176. double xv0 = this.XVelocity - fXv;
  1177. double yv0 = this.YVelocity - fYv;
  1178. double dist = otherSize + this.Size;
  1179. double dx = Math.Sqrt(((x1 - x0) * (x1 - x0)) + ((y1 - y0) * (y1 - y0)));
  1180. double xdif = x1 - x0;
  1181. double ydif = y1 - y0;
  1182. double newvx1 = 0;
  1183. double newvy1 = 0;
  1184.  
  1185. x0 = x1 - (xdif / dx * dist);
  1186. y0 = y1 - (ydif / dx * dist);
  1187. xdif = x1 - x0;
  1188. ydif = y1 - y0;
  1189.  
  1190. double bsq = dist * dist;
  1191. double b = dist;
  1192. double asq = (xv0 * xv0) + (yv0 * yv0);
  1193. double a = Math.Sqrt(asq);
  1194. if (a > 0.000001)
  1195. {
  1196. // if moving much at all...
  1197. double cx = x0 + xv0;
  1198. double cy = y0 + yv0;
  1199. double csq = ((x1 - cx) * (x1 - cx)) + ((y1 - cy) * (y1 - cy));
  1200. double tt = asq + bsq - csq;
  1201. double bb = 2 * a * b;
  1202. double power = a * (tt / bb);
  1203. newvx1 -= 2 * (xdif / dist * power);
  1204. newvy1 -= 2 * (ydif / dist * power);
  1205. }
  1206.  
  1207. this.XVelocity += newvx1;
  1208. this.YVelocity += newvy1;
  1209. this.Center.X = x0;
  1210. this.Center.Y = y0;
  1211. }
  1212. }
  1213. }
  1214. }
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224. m
  1225. *************************************
  1226. //------------------------------------------------------------------------------
  1227. // <copyright file="MainWindow.xaml.cs" company="Microsoft">
  1228. // Copyright (c) Microsoft Corporation. All rights reserved.
  1229. // </copyright>
  1230. //------------------------------------------------------------------------------
  1231.  
  1232. // This module contains code to do Kinect NUI initialization,
  1233. // processing, displaying players on screen, and sending updated player
  1234. // positions to the game portion for hit testing.
  1235.  
  1236.  
  1237. //*******************הערה חשובה************************
  1238.  
  1239. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$// הוספת הערה שלי
  1240.  
  1241. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//הוספת הערה שלי לא בטוחה בנכונותה
  1242.  
  1243. //$$ שורות קוד שאני הוספתי
  1244.  
  1245. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1246. //... כל הקטע התחום אני הוספתי
  1247. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1248. //*******************************************************
  1249.  
  1250.  
  1251.  
  1252. namespace ShapeGame
  1253. {
  1254. using System;
  1255. using System.Collections.Generic;
  1256. using System.ComponentModel;
  1257. using System.Linq;
  1258. using System.Media;
  1259. using System.Windows.Media;
  1260. using System.Windows.Media.Imaging;
  1261. using System.Runtime.InteropServices;
  1262. using System.Threading;
  1263. using System.Windows;
  1264. using System.Windows.Controls;
  1265. using System.Windows.Data;
  1266. using System.Windows.Threading;
  1267. using Microsoft.Kinect;
  1268. using Microsoft.Kinect.Toolkit;
  1269. using Microsoft.Samples.Kinect.WpfViewers;
  1270. using ShapeGame.Speech;
  1271. using ShapeGame.Utils;
  1272. //@@
  1273. using System.Windows.Media;
  1274. //@@
  1275.  
  1276. /// <summary>
  1277. /// Interaction logic for MainWindow.xaml
  1278. /// </summary>
  1279. ///
  1280. public partial class MainWindow : Window
  1281. {
  1282. public static readonly DependencyProperty KinectSensorManagerProperty =
  1283. DependencyProperty.Register(
  1284. "KinectSensorManager",
  1285. typeof(KinectSensorManager),
  1286. typeof(MainWindow),
  1287. new PropertyMetadata(null));
  1288.  
  1289. #region Private State
  1290. private const int TimerResolution = 2; // ms
  1291. private const int NumIntraFrames = 3;
  1292. private const int MaxShapes = 80;
  1293. private const double MaxFramerate = 70;
  1294. private const double MinFramerate = 15;
  1295. private const double MinShapeSize = 12;
  1296. private const double MaxShapeSize = 90;
  1297. private const double DefaultDropRate = 2.5;
  1298. private const double DefaultDropSize = 32.0;
  1299. private const double DefaultDropGravity = 1.0;
  1300.  
  1301. private readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
  1302. private readonly SoundPlayer popSound = new SoundPlayer();
  1303. private readonly SoundPlayer hitSound = new SoundPlayer();
  1304. private readonly SoundPlayer squeezeSound = new SoundPlayer();
  1305. private readonly KinectSensorChooser sensorChooser = new KinectSensorChooser();
  1306.  
  1307. private double dropRate = DefaultDropRate;
  1308. private double dropSize = DefaultDropSize;
  1309. private double dropGravity = DefaultDropGravity;
  1310. private DateTime lastFrameDrawn = DateTime.MinValue;
  1311. private DateTime predNextFrame = DateTime.MinValue;
  1312. private double actualFrameTime;
  1313.  
  1314.  
  1315.  
  1316. private Skeleton[] skeletonData;
  1317.  
  1318. // Player(s) placement in scene (z collapsed):
  1319. private Rect playerBounds;
  1320. private Rect screenRect;
  1321.  
  1322. private double targetFramerate = MaxFramerate;
  1323. private int frameCount;
  1324. private bool runningGameThread;
  1325. private FallingThings myFallingThings;
  1326. private int playersAlive;
  1327. //$$$$$$$$$$$$$$$$
  1328. private int numOfPlayers = 0;
  1329. private System.Windows.Point positionOnScreen;
  1330. private int currentIndexOfImg = 0;
  1331. private int counter = 0;
  1332. public List<string> Image = new List<string>() { "D1L", "D2R", "D2L", "D1R" };
  1333. private double size;
  1334. //$$$$$$$$$$$$$$$
  1335.  
  1336.  
  1337. private SpeechRecognizer mySpeechRecognizer;
  1338. #endregion Private State
  1339.  
  1340. #region ctor + Window Events
  1341.  
  1342. public MainWindow()
  1343. {
  1344.  
  1345.  
  1346.  
  1347. this.KinectSensorManager = new KinectSensorManager();
  1348. this.KinectSensorManager.KinectSensorChanged += this.KinectSensorChanged;
  1349. this.DataContext = this.KinectSensorManager;
  1350.  
  1351. InitializeComponent();
  1352.  
  1353. // this.SensorChooserUI.KinectSensorChooser = sensorChooser;
  1354.  
  1355. sensorChooser.Start();
  1356.  
  1357. // Bind the KinectSensor from the sensorChooser to the KinectSensor on the KinectSensorManager
  1358. var kinectSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
  1359. BindingOperations.SetBinding(this.KinectSensorManager, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);
  1360.  
  1361. this.RestoreWindowState();
  1362. }
  1363.  
  1364. public KinectSensorManager KinectSensorManager
  1365. {
  1366. get { return (KinectSensorManager)GetValue(KinectSensorManagerProperty); }
  1367. set { SetValue(KinectSensorManagerProperty, value); }
  1368. }
  1369.  
  1370. // Since the timer resolution defaults to about 10ms precisely, we need to
  1371. // increase the resolution to get framerates above between 50fps with any
  1372. // consistency.
  1373. [DllImport("Winmm.dll", EntryPoint = "timeBeginPeriod")]
  1374. private static extern int TimeBeginPeriod(uint period);
  1375.  
  1376. private void RestoreWindowState()
  1377. {
  1378. // Restore window state to that last used
  1379. Rect bounds = Properties.Settings.Default.PrevWinPosition;
  1380. if (bounds.Right != bounds.Left)
  1381. {
  1382. this.Top = bounds.Top;
  1383. this.Left = bounds.Left;
  1384. this.Height = bounds.Height;
  1385. this.Width = bounds.Width;
  1386. }
  1387.  
  1388. this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
  1389. }
  1390.  
  1391. private void WindowLoaded(object sender, EventArgs e)
  1392. {
  1393. playfield.ClipToBounds = true;
  1394.  
  1395. this.myFallingThings = new FallingThings(MaxShapes, this.targetFramerate, NumIntraFrames);
  1396.  
  1397. this.UpdatePlayfieldSize();
  1398.  
  1399. this.myFallingThings.SetGravity(this.dropGravity);
  1400. this.myFallingThings.SetDropRate(this.dropRate);
  1401. this.myFallingThings.SetSize(this.dropSize);
  1402. this.myFallingThings.SetPolies(PolyType.All);
  1403. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  1404. //בזמן טעינת חלון המשחק מצב המשחק-לכבוי
  1405. this.myFallingThings.SetGameMode(GameMode.Off);
  1406.  
  1407. this.popSound.Stream = Properties.Resources.Pop_5;
  1408. this.hitSound.Stream = Properties.Resources.Hit_2;
  1409. this.squeezeSound.Stream = Properties.Resources.Squeeze;
  1410.  
  1411. this.popSound.Play();
  1412.  
  1413. TimeBeginPeriod(TimerResolution);
  1414. var myGameThread = new Thread(this.GameThread);
  1415. myGameThread.SetApartmentState(ApartmentState.STA);
  1416. myGameThread.Start();
  1417.  
  1418. double size = this.screenRect.Width / 30;
  1419. System.Windows.Point positionOnScreen = new Point(this.screenRect.Width / 2, this.screenRect.Height / 2);
  1420. string str = "סימונוע";
  1421. FlyingText.NewFlyingText(size, positionOnScreen, str);
  1422.  
  1423. //$$$$$$$$$$$מיקום טקסט סימונוע size(20.6333333333333) and position(point( 309.5 ,344)) of the text in start of game $$$$$$$$$$$$$$$$
  1424. //enableAec.Content = size.ToString() +" "+ positionOnScreen.X.ToString()+" "+ positionOnScreen.Y.ToString();
  1425. }
  1426. private void WindowClosing(object sender, CancelEventArgs e)
  1427. {
  1428. sensorChooser.Stop();
  1429.  
  1430. this.runningGameThread = false;
  1431. Properties.Settings.Default.PrevWinPosition = this.RestoreBounds;
  1432. Properties.Settings.Default.WindowState = (int)this.WindowState;
  1433. Properties.Settings.Default.Save();
  1434. }
  1435.  
  1436. private void WindowClosed(object sender, EventArgs e)
  1437. {
  1438. this.KinectSensorManager.KinectSensor = null;
  1439. }
  1440.  
  1441. #endregion ctor + Window Events
  1442.  
  1443. #region Kinect discovery + setup
  1444.  
  1445. private void KinectSensorChanged(object sender, KinectSensorManagerEventArgs<KinectSensor> args)
  1446. {
  1447. if (null != args.OldValue)
  1448. {
  1449. this.UninitializeKinectServices(args.OldValue);
  1450. }
  1451.  
  1452. // Only enable this checkbox if we have a sensor
  1453. enableAec.IsEnabled = null != args.NewValue;
  1454.  
  1455. if (null != args.NewValue)
  1456. {
  1457. this.InitializeKinectServices(this.KinectSensorManager, args.NewValue);
  1458. }
  1459. }
  1460.  
  1461. // Kinect enabled apps should customize which Kinect services it initializes here.
  1462. private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
  1463. {
  1464. // Application should enable all streams first.
  1465. kinectSensorManager.ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;
  1466. kinectSensorManager.ColorStreamEnabled = true;
  1467.  
  1468. sensor.SkeletonFrameReady += this.SkeletonsReady;
  1469. kinectSensorManager.TransformSmoothParameters = new TransformSmoothParameters
  1470. {
  1471. Smoothing = 0.5f,
  1472. Correction = 0.5f,
  1473. Prediction = 0.5f,
  1474. JitterRadius = 0.05f,
  1475. MaxDeviationRadius = 0.04f
  1476. };
  1477. kinectSensorManager.SkeletonStreamEnabled = true;
  1478. kinectSensorManager.KinectSensorEnabled = true;
  1479.  
  1480. if (!kinectSensorManager.KinectSensorAppConflict)
  1481. {
  1482. // Start speech recognizer after KinectSensor started successfully.
  1483. this.mySpeechRecognizer = SpeechRecognizer.Create();
  1484.  
  1485. if (null != this.mySpeechRecognizer)
  1486. {
  1487. this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething;
  1488. this.mySpeechRecognizer.Start(sensor.AudioSource);
  1489. }
  1490.  
  1491. enableAec.Visibility = Visibility.Visible;
  1492. this.UpdateEchoCancellation(this.enableAec);
  1493. }
  1494. }
  1495.  
  1496. // Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here.
  1497. private void UninitializeKinectServices(KinectSensor sensor)
  1498. {
  1499. sensor.SkeletonFrameReady -= this.SkeletonsReady;
  1500.  
  1501. if (null != this.mySpeechRecognizer)
  1502. {
  1503. this.mySpeechRecognizer.Stop();
  1504. this.mySpeechRecognizer.SaidSomething -= this.RecognizerSaidSomething;
  1505. this.mySpeechRecognizer.Dispose();
  1506. this.mySpeechRecognizer = null;
  1507. }
  1508.  
  1509. enableAec.Visibility = Visibility.Collapsed;
  1510. }
  1511. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1512. //
  1513.  
  1514. private void SetImg()
  1515. {
  1516. if (myFallingThings.GetLoadImg())
  1517. {
  1518. myFallingThings.loadImg = false;
  1519. bool t = myFallingThings.GetLoadImg();
  1520. ////if (currentIndexOfImg ==2 || currentIndexOfImg==4 ||currentIndexOfImg==6 ||currentIndexOfImg==8)
  1521. //if (counter % 2 == 1)
  1522. //{
  1523.  
  1524. //Image specificImg = (Image)counter;
  1525. var c = currentIndexOfImg;
  1526. string specificImg = Image[currentIndexOfImg];
  1527. movement.Source = new BitmapImage(new Uri(@"C:\Users\nava\Videos\פרויקטים מעודכנים\2\1\ShapeGame\image\" + specificImg.ToString() + ".PNG"));
  1528.  
  1529. currentIndexOfImg++;
  1530. if (currentIndexOfImg == 4)
  1531. {
  1532. currentIndexOfImg = 0;
  1533. System.Windows.Point p = new System.Windows.Point(309.5, 344);
  1534. //FlyingText.NewFlyingText(20.6333333333333, p, "winner");
  1535.  
  1536. }
  1537.  
  1538. // var x = counter;
  1539. // var y = specificImg;
  1540. // var z = currentIndexOfImg;
  1541.  
  1542. //$$$$$$$$$$$$$$$4 relative sorce-התמונה נטענת מתוך הנתיב שנמצא בתוך הפרויקט .../shapegame/bin/debug/image
  1543. //movement.Source = new BitmapImage(new Uri("image/" + specificImg.ToString() + ".PNG",UriKind.Relative));
  1544. //var a = "image/" + specificImg.ToString() + ".PNG".ToString();
  1545. // a = a.ToString();
  1546. //movement.Source = new BitmapImage(new Uri("image/D1L.PNG", UriKind.Relative));
  1547. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4
  1548.  
  1549. //$$$$$$$$$$$$$$$4 not relative sorce
  1550. //movement.Source = new BitmapImage(new Uri(@"C:\Users\User\source\repos\פרויקטים מעודכנים\פרויקטים מעודכנים\1\finalProject_(10)\finalProject (10)\2\ShapeGame\image\D1L.PNG"));
  1551. //movement.Source = new BitmapImage(new Uri(@"C:\Users\User\source\repos\פרויקטים מעודכנים\פרויקטים מעודכנים\1\finalProject_(10)\finalProject (10)\2\ShapeGame\image\" + specificImg.ToString() + ".PNG"));
  1552.  
  1553. }
  1554. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4
  1555.  
  1556. //if (currentIndexOfImg == 3)
  1557. // currentIndexOfImg = 0;
  1558. //var a = counter;
  1559. //counter++;
  1560.  
  1561. else
  1562. {
  1563. ;
  1564. }
  1565.  
  1566.  
  1567. }
  1568. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1569.  
  1570.  
  1571.  
  1572. #endregion Kinect discovery + setup
  1573.  
  1574. #region Kinect Skeleton processing
  1575. private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e)
  1576. {
  1577. using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
  1578. {
  1579. if (skeletonFrame != null)
  1580. {
  1581. int skeletonSlot = 0;
  1582.  
  1583. if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
  1584. {
  1585. this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
  1586. }
  1587.  
  1588. skeletonFrame.CopySkeletonDataTo(this.skeletonData);
  1589.  
  1590.  
  1591. foreach (Skeleton skeleton in this.skeletonData)
  1592. {
  1593.  
  1594. if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
  1595. {
  1596. Player player;
  1597.  
  1598.  
  1599. if (this.players.ContainsKey(skeletonSlot))
  1600. {
  1601.  
  1602. player = this.players[skeletonSlot];
  1603. }
  1604. else
  1605. {
  1606. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1607. //קן חדש כלומר בתחילת המשחק/כאשר נקודת הכיול נעלמה
  1608. //כאשר נקודת הכיול נעלמת הוא מסיר את השחקן מהמערך-גודל המערך כמו בתחילת המשחק שווה ל0
  1609. //במקרה שיש יותר משחקן אחד מול המצלמה הוא בעצם רוצה להוסיף למערך פעמיים
  1610. //התנאי הזה יגרום לו להוסיף תמיד פעם אחת בלבד
  1611. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1612. player = new Player(skeletonSlot);
  1613.  
  1614. player.SetJointsAndBonesBrushesOfPlayers(players.Count);
  1615.  
  1616. player.SetBounds(this.playerBounds);
  1617.  
  1618.  
  1619. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1620. //קן חדש כלומר בתחילת המשחק/כאשר נקודת הכיול נעלמה
  1621. //כאשר נקודת הכיול נעלמת הוא מסיר את השחקן מהמערך-גודל המערך כמו בתחילת המשחק שווה ל0
  1622. //במקרה שיש יותר משחקן אחד מול המצלמה הוא בעצם רוצה להוסיף למערך פעמיים
  1623. //התנאי הזה יגרום לו להוסיף תמיד פעם אחת בלבד
  1624. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1625.  
  1626. if (players.Count == 0) //$$
  1627. {
  1628. player = new Player(skeletonSlot);
  1629.  
  1630. player.SetJointsAndBonesBrushesOfPlayers(players.Count);
  1631.  
  1632. player.SetBounds(this.playerBounds);
  1633.  
  1634. this.players.Add(skeletonSlot, player);
  1635. string s = "add" + skeletonSlot.ToString() + "," + player.GetId();
  1636.  
  1637.  
  1638. }
  1639.  
  1640. }
  1641.  
  1642. player.LastUpdated = DateTime.Now;
  1643.  
  1644. // Update player's bone and joint positions
  1645. if (skeleton.Joints.Count > 0)
  1646. {
  1647. player.IsAlive = true;
  1648.  
  1649. // Head, hands, feet (hit testing happens in order here)
  1650. player.UpdateJointPosition(skeleton.Joints, JointType.Head);
  1651. player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft);
  1652. player.UpdateJointPosition(skeleton.Joints, JointType.HandRight);
  1653. player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft);
  1654. player.UpdateJointPosition(skeleton.Joints, JointType.FootRight);
  1655.  
  1656. // Hands and arms
  1657. player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight);
  1658. player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight);
  1659. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight);
  1660.  
  1661. player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft);
  1662. player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft);
  1663. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft);
  1664.  
  1665. // Head and Shoulders
  1666. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head);
  1667. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter);
  1668. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight);
  1669.  
  1670. // Legs
  1671. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft);
  1672. player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft);
  1673. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft);
  1674.  
  1675. player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight);
  1676. player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight);
  1677. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight);
  1678.  
  1679. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter);
  1680. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight);
  1681.  
  1682. // Spine
  1683. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter);
  1684. }
  1685. }
  1686.  
  1687. skeletonSlot++;
  1688. }
  1689. }
  1690. }
  1691. }
  1692.  
  1693. private void CheckPlayers()
  1694. {
  1695. foreach (var player in this.players)
  1696. {
  1697.  
  1698. if (!player.Value.IsAlive)
  1699. {
  1700. // Player left scene since we aren't tracking it anymore, so remove from dictionary
  1701. this.players.Remove(player.Value.GetId());
  1702. break;
  1703. }
  1704. }
  1705.  
  1706. // Count alive players
  1707. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1708. //alive-מספר השחקנים שיש במשחק
  1709. int alive = this.players.Count(player => player.Value.IsAlive);
  1710.  
  1711. if (alive != this.playersAlive)
  1712. {
  1713. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1714. //ישנם 2 שחקנים במשחק ולכן מצב המשחק =ל2 שחקנים
  1715. if (alive == 2)
  1716. {
  1717. this.myFallingThings.SetGameMode(GameMode.TwoPlayer);
  1718. }
  1719. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1720. //ישנו שחקן אחד בלבד במשחק ולכן מצב המשחק =ל2שחקן אחד
  1721. else if (alive == 1)
  1722. {
  1723. this.myFallingThings.SetGameMode(GameMode.Solo);
  1724. }
  1725. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1726. //אים אף שחקן במשחק ולכן מצב המשחק=ל כבוי
  1727. else if (alive == 0)
  1728. {
  1729. this.myFallingThings.SetGameMode(GameMode.Off);
  1730. }
  1731.  
  1732. if ((this.playersAlive == 0) && (this.mySpeechRecognizer != null))
  1733. {
  1734. BannerText.NewBanner(
  1735. Properties.Resources.Vocabulary,
  1736. this.screenRect,
  1737. true,
  1738. System.Windows.Media.Color.FromArgb(200, 255, 255, 255));
  1739. }
  1740.  
  1741. this.playersAlive = alive;
  1742. }
  1743. }
  1744.  
  1745. private void PlayfieldSizeChanged(object sender, SizeChangedEventArgs e)
  1746. {
  1747. this.UpdatePlayfieldSize();
  1748. }
  1749.  
  1750. private void UpdatePlayfieldSize()
  1751. {
  1752. // Size of player wrt size of playfield, putting ourselves low on the screen.
  1753. this.screenRect.X = 0;
  1754. this.screenRect.Y = 0;
  1755. this.screenRect.Width = this.playfield.ActualWidth;
  1756. this.screenRect.Height = this.playfield.ActualHeight;
  1757.  
  1758. BannerText.UpdateBounds(this.screenRect);
  1759.  
  1760. this.playerBounds.X = 0;
  1761. this.playerBounds.Width = this.playfield.ActualWidth;
  1762. this.playerBounds.Y = this.playfield.ActualHeight * 0.2;
  1763. this.playerBounds.Height = this.playfield.ActualHeight * 0.75;
  1764.  
  1765. foreach (var player in this.players)
  1766. {
  1767. player.Value.SetBounds(this.playerBounds);
  1768. }
  1769.  
  1770. Rect fallingBounds = this.playerBounds;
  1771. fallingBounds.Y = 0;
  1772. fallingBounds.Height = playfield.ActualHeight;
  1773. if (this.myFallingThings != null)
  1774. {
  1775. this.myFallingThings.SetBoundaries(fallingBounds);
  1776. }
  1777. }
  1778. #endregion Kinect Skeleton processing
  1779.  
  1780. #region GameTimer/Thread
  1781. private void GameThread()
  1782. {
  1783. this.runningGameThread = true;
  1784. this.predNextFrame = DateTime.Now;
  1785. this.actualFrameTime = 1000.0 / this.targetFramerate;
  1786.  
  1787. // Try to dispatch at as constant of a framerate as possible by sleeping just enough since
  1788. // the last time we dispatched.
  1789. while (this.runningGameThread)
  1790. {
  1791. // Calculate average framerate.
  1792. DateTime now = DateTime.Now;
  1793. if (this.lastFrameDrawn == DateTime.MinValue)
  1794. {
  1795. this.lastFrameDrawn = now;
  1796. }
  1797.  
  1798. double ms = now.Subtract(this.lastFrameDrawn).TotalMilliseconds;
  1799. this.actualFrameTime = (this.actualFrameTime * 0.95) + (0.05 * ms);
  1800. this.lastFrameDrawn = now;
  1801.  
  1802. // Adjust target framerate down if we're not achieving that rate
  1803. this.frameCount++;
  1804. if ((this.frameCount % 100 == 0) && (1000.0 / this.actualFrameTime < this.targetFramerate * 0.92))
  1805. {
  1806. this.targetFramerate = Math.Max(MinFramerate, (this.targetFramerate + (1000.0 / this.actualFrameTime)) / 2);
  1807. }
  1808.  
  1809. if (now > this.predNextFrame)
  1810. {
  1811. this.predNextFrame = now;
  1812. }
  1813. else
  1814. {
  1815. double milliseconds = this.predNextFrame.Subtract(now).TotalMilliseconds;
  1816. if (milliseconds >= TimerResolution)
  1817. {
  1818. Thread.Sleep((int)(milliseconds + 0.5));
  1819. }
  1820. }
  1821.  
  1822. this.predNextFrame += TimeSpan.FromMilliseconds(1000.0 / this.targetFramerate);
  1823.  
  1824. this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<int>(this.HandleGameTimer), 0);
  1825. }
  1826. }
  1827.  
  1828.  
  1829.  
  1830.  
  1831. private void HandleGameTimer(int param)
  1832. {
  1833. // Every so often, notify what our actual framerate is
  1834. if ((this.frameCount % 100) == 0)
  1835. {
  1836. this.myFallingThings.SetFramerate(1000.0 / this.actualFrameTime);
  1837. }
  1838.  
  1839. // Advance animations, and do hit testing.
  1840. for (int i = 0; i < NumIntraFrames; ++i)
  1841. {
  1842. foreach (var pair in this.players)
  1843. {
  1844.  
  1845.  
  1846. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1847. //ברגע שיש כבר שחקן אחד במערך-ברגע שיציג שחקן לפחות אחד על המסך יתחיל לחפש פגיעה
  1848. HitType hit = this.myFallingThings.LookForHits(pair.Value.Segments, pair.Value.GetId());
  1849.  
  1850.  
  1851. //@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1852. //@@אם היתה פגיעה ב"סינג" לא משנה מאיזה סוג
  1853. if (hit != HitType.None)//@@ //1234
  1854. {//@@ //1234
  1855. int playerIdOfCurrentHitThing = pair.Key;//@@ //1234
  1856. //@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$// //1234
  1857. //@@צביעת הסגמנט שפגע ב"סינג //1234
  1858. KeyValuePair<string, int> typeAndIdPlayerOfCurrentHitThing = new KeyValuePair<string, int>(); //1234
  1859. { //1234
  1860. new KeyValuePair<string, int>(myFallingThings.GetcurrentTypeOfHitThing(), playerIdOfCurrentHitThing); //1234
  1861. } //1234
  1862. this.players[pair.Key].typeAndPlayerIdHit = typeAndIdPlayerOfCurrentHitThing; //1234
  1863.  
  1864. }//@@
  1865. if ((hit & HitType.Squeezed) != 0)//bbb
  1866. {
  1867. this.squeezeSound.Play();
  1868. SetImg(); //$$
  1869.  
  1870.  
  1871. }
  1872. else if ((hit & HitType.Popped) != 0)//bbb
  1873. {
  1874. this.popSound.Play();
  1875. SetImg(); //$$
  1876.  
  1877.  
  1878. }
  1879. else if ((hit & HitType.Hand) != 0)//bbb
  1880. {
  1881. this.hitSound.Play();
  1882. }
  1883. }
  1884.  
  1885. this.myFallingThings.AdvanceFrame();
  1886. }
  1887.  
  1888. // Draw new Wpf scene by adding all objects to canvas
  1889. playfield.Children.Clear();
  1890. this.myFallingThings.DrawFrame(this.playfield.Children);
  1891. foreach (var player in this.players)
  1892. {
  1893.  
  1894. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1895. //לדעת כמה שחקנים יש במערך בכל זמן-לשם בדיקה
  1896. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  1897.  
  1898. if (players.Count > 1)//$$
  1899. numOfPlayers= players.Count;//$$
  1900. player.Value.Draw(playfield.Children);
  1901. }
  1902.  
  1903. BannerText.Draw(playfield.Children);
  1904. FlyingText.Draw(playfield.Children);
  1905.  
  1906.  
  1907.  
  1908. this.CheckPlayers();
  1909. }
  1910. #endregion GameTimer/Thread
  1911.  
  1912. #region Kinect Speech processing
  1913. private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
  1914. {
  1915. FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched);
  1916. switch (e.Verb)
  1917. {
  1918. case SpeechRecognizer.Verbs.Pause:
  1919. this.myFallingThings.SetDropRate(0);
  1920. this.myFallingThings.SetGravity(0);
  1921. break;
  1922. case SpeechRecognizer.Verbs.Resume:
  1923. this.myFallingThings.SetDropRate(this.dropRate);
  1924. this.myFallingThings.SetGravity(this.dropGravity);
  1925. break;
  1926. case SpeechRecognizer.Verbs.Reset:
  1927. this.dropRate = DefaultDropRate;
  1928. this.dropSize = DefaultDropSize;
  1929. this.dropGravity = DefaultDropGravity;
  1930. this.myFallingThings.SetPolies(PolyType.All);
  1931. this.myFallingThings.SetDropRate(this.dropRate);
  1932. this.myFallingThings.SetGravity(this.dropGravity);
  1933. this.myFallingThings.SetSize(this.dropSize);
  1934. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  1935. this.myFallingThings.Reset();
  1936. break;
  1937. case SpeechRecognizer.Verbs.DoShapes:
  1938. this.myFallingThings.SetPolies(e.Shape);
  1939. break;
  1940. case SpeechRecognizer.Verbs.RandomColors:
  1941. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  1942. break;
  1943. case SpeechRecognizer.Verbs.Colorize:
  1944. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  1945. break;
  1946. case SpeechRecognizer.Verbs.ShapesAndColors:
  1947. this.myFallingThings.SetPolies(e.Shape);
  1948. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  1949. break;
  1950. case SpeechRecognizer.Verbs.More:
  1951. this.dropRate *= 1.5;
  1952. this.myFallingThings.SetDropRate(this.dropRate);
  1953. break;
  1954. case SpeechRecognizer.Verbs.Fewer:
  1955. this.dropRate /= 1.5;
  1956. this.myFallingThings.SetDropRate(this.dropRate);
  1957. break;
  1958. case SpeechRecognizer.Verbs.Bigger:
  1959. this.dropSize *= 1.5;
  1960. if (this.dropSize > MaxShapeSize)
  1961. {
  1962. this.dropSize = MaxShapeSize;
  1963. }
  1964.  
  1965. this.myFallingThings.SetSize(this.dropSize);
  1966. break;
  1967. case SpeechRecognizer.Verbs.Biggest:
  1968. this.dropSize = MaxShapeSize;
  1969. this.myFallingThings.SetSize(this.dropSize);
  1970. break;
  1971. case SpeechRecognizer.Verbs.Smaller:
  1972. this.dropSize /= 1.5;
  1973. if (this.dropSize < MinShapeSize)
  1974. {
  1975. this.dropSize = MinShapeSize;
  1976. }
  1977.  
  1978. this.myFallingThings.SetSize(this.dropSize);
  1979. break;
  1980. case SpeechRecognizer.Verbs.Smallest:
  1981. this.dropSize = MinShapeSize;
  1982. this.myFallingThings.SetSize(this.dropSize);
  1983. break;
  1984. case SpeechRecognizer.Verbs.Faster:
  1985. this.dropGravity *= 1.25;
  1986. if (this.dropGravity > 4.0)
  1987. {
  1988. this.dropGravity = 4.0;
  1989. }
  1990.  
  1991. this.myFallingThings.SetGravity(this.dropGravity);
  1992. break;
  1993. case SpeechRecognizer.Verbs.Slower:
  1994. this.dropGravity /= 1.25;
  1995. if (this.dropGravity < 0.25)
  1996. {
  1997. this.dropGravity = 0.25;
  1998. }
  1999.  
  2000. this.myFallingThings.SetGravity(this.dropGravity);
  2001. break;
  2002. }
  2003. }
  2004.  
  2005. private void EnableAecChecked(object sender, RoutedEventArgs e)
  2006. {
  2007. var enableAecCheckBox = (CheckBox)sender;
  2008. this.UpdateEchoCancellation(enableAecCheckBox);
  2009. }
  2010.  
  2011. private void UpdateEchoCancellation(CheckBox aecCheckBox)
  2012. {
  2013. this.mySpeechRecognizer.EchoCancellationMode = aecCheckBox.IsChecked != null && aecCheckBox.IsChecked.Value
  2014. ? EchoCancellationMode.CancellationAndSuppression
  2015. : EchoCancellationMode.None;
  2016. }
  2017.  
  2018. #endregion Kinect Speech processing
  2019. }
  2020. }
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030. p
  2031. ***********************************
  2032. //------------------------------------------------------------------------------
  2033. // <copyright file="Player.cs" company="Microsoft">
  2034. // Copyright (c) Microsoft Corporation. All rights reserved.
  2035. // </copyright>
  2036. //------------------------------------------------------------------------------
  2037.  
  2038. namespace ShapeGame
  2039. {
  2040. using System;
  2041. using System.Collections.Generic;
  2042. using System.Linq;
  2043. using System.Windows;
  2044. using System.Windows.Controls;
  2045. using System.Windows.Media;
  2046. using System.Windows.Shapes;
  2047. using Microsoft.Kinect;
  2048. using ShapeGame.Utils;
  2049.  
  2050. public class Player
  2051. {
  2052. private const double BoneSize = 0.01;
  2053. private const double HeadSize = 0.075;
  2054. private const double HandSize = 0.03;
  2055.  
  2056. // Keeping track of all bone segments of interest as well as head, hands and feet
  2057. private /*readonly*/ Dictionary<Bone, BoneData> segments = new Dictionary<Bone, BoneData>();
  2058. public /*$$ readonly $$*/ System.Windows.Media.Brush jointsBrush;
  2059. public /*$$ readonly $$*/ System.Windows.Media.Brush bonesBrush;
  2060. public /*$$ readonly $$*/ System.Windows.Media.Brush jointsBrushesOFsegmentHit = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 189, 0)) /*צהוב*/;
  2061. public /*$$ readonly $$*/ System.Windows.Media.Brush bonesBrushesOFsegmentHit = new SolidColorBrush(System.Windows.Media.Color.FromRgb(13, 120, 61))/*ירוק*/;
  2062. /*private$$*/
  2063. public readonly int id;
  2064. private static int colorId;
  2065. private Rect playerBounds;
  2066. private System.Windows.Point playerCenter;
  2067. private double playerScale;
  2068. //$$$$$$$$$$$$4
  2069. private int i =0;
  2070. int indexSegmentHit = 0;
  2071.  
  2072.  
  2073. //$$public bool isHit=false;
  2074.  
  2075. public KeyValuePair<string,int> typeAndPlayerIdHit;
  2076. public string str;
  2077. //$$$$$$$$$$$$$$
  2078.  
  2079.  
  2080. public Player(int skeletonSlot)
  2081. {
  2082. this.id = skeletonSlot;
  2083. }
  2084.  
  2085. public bool IsAlive { get; set; }
  2086.  
  2087. public DateTime LastUpdated { get; set; }
  2088.  
  2089. public Dictionary<Bone, BoneData> Segments
  2090. {
  2091. get
  2092. {
  2093. return this.segments;
  2094. }
  2095. }
  2096.  
  2097. public int GetId()
  2098. {
  2099. return this.id;
  2100. }
  2101.  
  2102.  
  2103. public void SetJointsAndBonesBrushesOfPlayers(int numOfPlayers) //$$
  2104. {
  2105.  
  2106. if (numOfPlayers == 0) //$$
  2107. {
  2108.  
  2109. this.jointsBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(10, 2, 18)); //$$סגול
  2110. this.bonesBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(130, 20, 240)); //$$שחור
  2111. this.LastUpdated = DateTime.Now;//$$
  2112. }
  2113. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  2114. //במקרה של שני שחקנים צבע השלד יוגרל
  2115.  
  2116. else
  2117. {
  2118. // Generate one of 7 colors for player
  2119. int[] mixR = { 1, 1, 1, 0, 1, 0, 0 };
  2120. int[] mixG = { 1, 1, 0, 1, 0, 1, 0 };
  2121. int[] mixB = { 1, 0, 1, 1, 0, 0, 1 };
  2122. byte[] jointCols = { 245, 200 };
  2123. byte[] boneCols = { 235, 160 };
  2124.  
  2125.  
  2126. int i = colorId;
  2127. colorId = (colorId + 1) % mixR.Count();
  2128.  
  2129. this.bonesBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(jointCols[mixR[i]], jointCols[mixG[i]], jointCols[mixB[i]]));
  2130. this.jointsBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(boneCols[mixR[i]], boneCols[mixG[i]], boneCols[mixB[i]]));
  2131. this.LastUpdated = DateTime.Now;
  2132. }
  2133. }
  2134.  
  2135.  
  2136.  
  2137.  
  2138. public void SetBounds(Rect r)
  2139. {
  2140. this.playerBounds = r;
  2141. this.playerCenter.X = (this.playerBounds.Left + this.playerBounds.Right) / 2;
  2142. this.playerCenter.Y = (this.playerBounds.Top + this.playerBounds.Bottom) / 2;
  2143. this.playerScale = Math.Min(this.playerBounds.Width, this.playerBounds.Height / 2);
  2144. }
  2145.  
  2146. public void UpdateBonePosition(Microsoft.Kinect.JointCollection joints, JointType j1, JointType j2)
  2147. {
  2148. var seg = new Segment(
  2149. (joints[j1].Position.X * this.playerScale) + this.playerCenter.X,
  2150. this.playerCenter.Y - (joints[j1].Position.Y * this.playerScale),
  2151. (joints[j2].Position.X * this.playerScale) + this.playerCenter.X,
  2152. this.playerCenter.Y - (joints[j2].Position.Y * this.playerScale))
  2153. { Radius = Math.Max(3.0, this.playerBounds.Height * BoneSize) / 2 };
  2154. this.UpdateSegmentPosition(j1, j2, seg);
  2155. }
  2156.  
  2157. public void UpdateJointPosition(Microsoft.Kinect.JointCollection joints, JointType j)
  2158. {
  2159. var seg = new Segment(
  2160. (joints[j].Position.X * this.playerScale) + this.playerCenter.X,
  2161. this.playerCenter.Y - (joints[j].Position.Y * this.playerScale))
  2162. { Radius = this.playerBounds.Height * ((j == JointType.Head) ? HeadSize : HandSize) / 2 };
  2163. this.UpdateSegmentPosition(j, j, seg);
  2164. }
  2165.  
  2166. public void Draw(UIElementCollection children)
  2167. {
  2168.  
  2169.  
  2170. if (!this.IsAlive)
  2171. {
  2172. return;
  2173. }
  2174.  
  2175. // Draw all bones first, then circles (head and hands).
  2176. DateTime cur = DateTime.Now;
  2177. foreach (var segment in this.segments)
  2178. {
  2179.  
  2180. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  2181. //תפיסת הסגמנט שפגע ב"סינג" על מנת לצבוע אותו בצבע אחר
  2182. var isHitSegment1 = (/*id == segmentAndPlayerIdHit.Value && */segment.Key.Joint1.ToString().Equals(typeAndPlayerIdHit.Key));//$$
  2183.  
  2184.  
  2185. Segment seg = segment.Value.GetEstimatedSegment(cur);
  2186. if (!seg.IsCircle())
  2187. {
  2188.  
  2189. var line = new Line
  2190. {
  2191. StrokeThickness = seg.Radius * 2,
  2192. X1 = seg.X1,
  2193. Y1 = seg.Y1,
  2194. X2 = seg.X2,
  2195. Y2 = seg.Y2,
  2196. Stroke = isHitSegment1 ? jointsBrushesOFsegmentHit : this.bonesBrush,//$$ //1234
  2197. StrokeEndLineCap = PenLineCap.Round,
  2198. StrokeStartLineCap = PenLineCap.Round
  2199. };
  2200.  
  2201. children.Add(line);
  2202. }
  2203.  
  2204.  
  2205.  
  2206. }
  2207.  
  2208. foreach (var segment in this.segments)
  2209. {
  2210. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  2211. //תפיסת הסגמנט שפגע ב"סינג" על מנת לצבוע אותו בצבע אחר
  2212. var isHitSegment2 = (/*id == segmentAndPlayerIdHit.Value && */segment.Key.Joint1.ToString().Equals(typeAndPlayerIdHit.Key));//$$
  2213.  
  2214. var s = segment.Key.Joint1.ToString();
  2215.  
  2216. Segment seg = segment.Value.GetEstimatedSegment(cur);
  2217. if (seg.IsCircle())
  2218. {
  2219.  
  2220. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//??
  2221. //תפיסת הסגמנט שפגע ב"סינג" על מנת לצבוע אותו בצבע אחר
  2222.  
  2223. var circle = new Ellipse { Width = seg.Radius * 2, Height = seg.Radius * 2 };
  2224. circle.SetValue(Canvas.LeftProperty, seg.X1 - seg.Radius);
  2225. circle.SetValue(Canvas.TopProperty, seg.Y1 - seg.Radius);
  2226. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
  2227. //צבע המתאר של מקומות עגולים כמו יד שמסמן כמו בוקס (עגול) והראש יהיה בצבע של המפרקים
  2228.  
  2229. circle.Stroke = isHitSegment2 ? jointsBrushesOFsegmentHit : this.jointsBrush;//צבע המפרקים //$$
  2230. circle.StrokeThickness = 1;
  2231. circle.Fill = isHitSegment2 ? jointsBrushesOFsegmentHit : this.bonesBrush;//צבע העצמות //$$
  2232.  
  2233.  
  2234. children.Add(circle);
  2235. }
  2236.  
  2237. }
  2238.  
  2239. // Remove unused players after 1/2 second.
  2240. if (DateTime.Now.Subtract(this.LastUpdated).TotalMilliseconds > 500)
  2241. {
  2242. this.IsAlive = false;
  2243. }
  2244. }
  2245.  
  2246. private void UpdateSegmentPosition(JointType j1, JointType j2, Segment seg)
  2247. {
  2248. var bone = new Bone(j1, j2);
  2249. if (this.segments.ContainsKey(bone))
  2250. {
  2251. BoneData data = this.segments[bone];
  2252. data.UpdateSegment(seg);
  2253. this.segments[bone] = data;
  2254.  
  2255. }
  2256. else
  2257. {
  2258. this.segments.Add(bone, new BoneData(seg));
  2259. }
  2260. }
  2261. }
  2262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement