private void initPlankBody(Player player) { player.updatePlankPositionVectors(); player.plankBody = BodyFactory.CreateRectangle(World, Player.plankLength, 10, 100f); player.plankBody.CollisionCategories = Category.Cat2; player.plankBody.CollidesWith = Category.Cat1 | Category.Cat4; player.plankBody.Position = player.centralPlankPosition.convertToVector2(); player.plankBody.BodyType = BodyType.Dynamic; player.plankBody.Restitution = 0f; plankBodySprite = new Sprite(ScreenManager.Assets.TextureFromShape(player.plankBody.FixtureList[0].Shape, MaterialType.Squares, Color.Orange, 1f)); player.fixedMouseJointL = new FixedMouseJoint(player.plankBody, player.leftPlankPosition.convertToVector2()); player.fixedMouseJointL.MaxForce = 1000.0f * player.plankBody.Mass; World.AddJoint(player.fixedMouseJointL); player.fixedMouseJointC = new FixedMouseJoint(player.plankBody, player.centralPlankPosition.convertToVector2()); player.fixedMouseJointC.MaxForce = 1000.0f * player.plankBody.Mass; World.AddJoint(player.fixedMouseJointC); player.fixedMouseJointR = new FixedMouseJoint(player.plankBody, player.rightPlankPosition.convertToVector2()); player.fixedMouseJointR.MaxForce = 1000.0f * player.plankBody.Mass; World.AddJoint(player.fixedMouseJointR); player.plankBody.Awake = true; player.fixedMouseJointL.DampingRatio = 1.0f; player.fixedMouseJointC.DampingRatio = 1.0f; player.fixedMouseJointR.DampingRatio = 1.0f; }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (otherScreenHasFocus) { return; } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); populatePresent(); if (Keyboard.GetState().IsKeyDown(Keys.P)){ ScreenManager.AddScreen(new PauseMenuScreen(this)); } if (skeletonData != null) { for (int i = 0; i < skeletonData.Length; i++) { Skeleton skel = skeletonData[i]; if (skel.TrackingState == SkeletonTrackingState.Tracked) { // update the gesture controller gestureControllerHandler.UpdateAllGestures(skel); if (gestureControllerHandler.Gesture != null && gestureControllerHandler.Gesture.Equals("Joined Hands Anywhere")) { ScreenManager.AddScreen(new MainMenuScreen());//TODO vidjet dal je bolje samo zalijepit mainMenu gore ili ne //gestureControllerHandler.Gesture = null; } if (!players.ContainsKey(i)) { Player newPlayer = new Player(new Majlo(ScreenManager.Content)); //TODO sredit ovo - nekakav random ili sta vec newPlayer.inputPosition = new KinectController(0, 0, 0); initPlankBody(newPlayer); gameMode = GameMode.TWO_PLAYERS_VS; if (gameMode == GameMode.TWO_PLAYERS_VS) { if (players.Count > 0) { newPlayer.basketId = createBasket(new Vector2((int)(ScreenManager.GraphicsDevice.Viewport.Width / 2.5), ScreenManager.GraphicsDevice.Viewport.Height / 3)); } else { newPlayer.basketId = createBasket(new Vector2(-(int)(ScreenManager.GraphicsDevice.Viewport.Width / 2.5), ScreenManager.GraphicsDevice.Viewport.Height / 3)); } } else { // they have the same basket (later when adding score it will add it for both players) newPlayer.basketId = players[0].basketId; } players.Add(i, newPlayer); } players[i].inputPosition.HandleInput( gameTime, skel.Joints[Microsoft.Kinect.JointType.HandLeft], skel.Joints[Microsoft.Kinect.JointType.HandRight], skel.Joints[Microsoft.Kinect.JointType.Head], skel.Joints[Microsoft.Kinect.JointType.ShoulderCenter], new Vector2(ScreenManager.GraphicsDevice.Viewport.Width - players[i].getPlankLength(), ScreenManager.GraphicsDevice.Viewport.Height)); players[i].update(); } else { if (players.ContainsKey(i)) { Player p = players[i]; p.plankBody.Dispose(); players.Remove(i); for (int basketCount = 0; basketCount < baskets.Count; basketCount++) { if (p.basketId == baskets[basketCount].basketCoverBody.BodyId) { baskets[basketCount].basketBody.Dispose(); baskets.RemoveAt(basketCount); break; } } } } } } // keyboard player else if (players.Count > 0) { players[0].inputPosition.HandleInput( gameTime, emptyJoint, emptyJoint, emptyJoint, emptyJoint, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width - players[0].getPlankLength(), ScreenManager.GraphicsDevice.Viewport.Height)); players[0].update(); } }
private void drawPlayer(Player player) { player.Draw(ScreenManager.SpriteBatch); //only for development ScreenManager.SpriteBatch.Draw(circleTexture, player.leftPlankPosition.convertToVector2(), Color.Black); ScreenManager.SpriteBatch.Draw(circleTexture, player.centralPlankPosition.convertToVector2(), Color.Black); ScreenManager.SpriteBatch.Draw(circleTexture, player.rightPlankPosition.convertToVector2(), Color.Black); }
public override void LoadContent() { base.LoadContent(); Player initialPlayer = new Player(new VodafoneMascot(ScreenManager.Content)); players = new Dictionary<int, Player>(); baskets = new List<ComplexBodies.Basket>(); if (KinectSensor.KinectSensors.Count > 0) { kinect = KinectSensor.KinectSensors[0]; kinect.SkeletonStream.Enable(); kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinectSkeletonFrameReady); kinect.Start(); initialPlayer.inputPosition = new KinectController(0, 0, 0); } else { initialPlayer.inputPosition = new KeyboardController(0, 0); initialPlayer.basketId = createBasket(new Vector2((int)(-ScreenManager.GraphicsDevice.Viewport.Width / 2.5), ScreenManager.GraphicsDevice.Viewport.Height / 3)); players.Add(0, initialPlayer); } background = ScreenManager.Content.Load<Texture2D>("space-earth-stratosphere"); explosionTexture = ScreenManager.Content.Load<Texture2D>("star"); xScorePosition = -ScreenManager.GraphicsDevice.Viewport.Width / 2 + 20; yScorePosition = -ScreenManager.GraphicsDevice.Viewport.Height / 2 + 20; scoreFont = ScreenManager.Content.Load<SpriteFont>("Font"); scoreColors = new Color[2]; scoreColors[0] = Color.Red; scoreColors[1] = Color.Yellow; presentBodies = new List<Body>(); presentSpriteBodyMapping = new Dictionary<int, Sprite>(); explosionsStopwatch = Stopwatch.StartNew(); explosionTimesLocationsMapping = new Dictionary<double, Vector2>(); presentTextures = new List<Texture2D>(); presentTextures.Add(ScreenManager.Content.Load<Texture2D>("PresentPictures/present_1_transparent")); presentTextures.Add(ScreenManager.Content.Load<Texture2D>("PresentPictures/present_2_transparent")); presentTextures.Add(ScreenManager.Content.Load<Texture2D>("PresentPictures/present_3_transparent")); presentTextures.Add(ScreenManager.Content.Load<Texture2D>("PresentPictures/present_4_transparent")); if (players.Count > 0) { initPlankBody(players[0]); } initEdges(); int radius = 5; int outerRadius = radius * 2 + 2; // So circle doesn't go out of bounds Texture2D texture = new Texture2D(ScreenManager.GraphicsDevice, outerRadius, outerRadius); circleTexture = TextureParser.CreateCircle(radius, outerRadius, texture); random = new Random(); World.Gravity = new Vector2(0, ScreenManager.GraphicsDevice.Viewport.Height / 15); jointTexture = ScreenManager.Content.Load<Texture2D>("joint"); gestureControllerHandler = new GestureControllerHandler(); kinectPongDAL = new KinectPongDAL(); lowestHighscore = kinectPongDAL.getLowestHighscore(maximumTopScorers); gameStopwatch = new Stopwatch(); gameStopwatch.Start(); base.EnableCameraControl = false; }