Exemple #1
0
 public void removeFromMyOnCollision(GameObject gameObject)
 {
     foreach (Fixture fix in gameObject.body.FixtureList)
     {
         fix.OnCollision -= MyOnCollision;
     }
 }
Exemple #2
0
 public void addToMyOnCollision(GameObject gameObject)
 {
     foreach (Fixture fix in gameObject.body.FixtureList)
     {
         fix.OnCollision += MyOnCollision;
     }
 }
Exemple #3
0
 public void remove(GameObject gameObject)
 {
     this.objects.Remove(gameObject);
 }
Exemple #4
0
        protected override void Update(GameTime gameTime)
        {
            GamePadState gamepad = GamePad.GetState(PlayerIndex.One);
            KeyboardState keyboard = Keyboard.GetState();
            MouseState mouse = Mouse.GetState();

            //soundEngineInstance.Volume = 0.25f;
            //soundEngineInstance.IsLooped = true;
            //soundEngineInstance.Play();

            if (gamepad.Buttons.Back == ButtonState.Pressed ||
                keyboard.IsKeyDown(Keys.Escape))
                this.Exit();

            if (keyboard.IsKeyDown(Keys.R))
            {
                //audioEngine.Update();
                overlay.CenterString = "";
                offset.Y = 0;
                stopBackgroundmusic();
                restartGame();
            }

            if (keyboard.IsKeyDown(Keys.Space))
            {
                startFallingBalls = true;
                startBackgroundmusic();
                level.enableFallingBalls();
            }

            if (oldMouseWheelValue != mouse.ScrollWheelValue)
            {
                offset.Y -= (oldMouseWheelValue - mouse.ScrollWheelValue) / 3;
                oldMouseWheelValue = mouse.ScrollWheelValue;
            }
            if (keyboard.IsKeyDown(Keys.Up) || keyboard.IsKeyDown(Keys.Down))
            {
                if (keyboard.IsKeyDown(Keys.Up))
                {
                    //playerOffset.Y += 10;
                    offset.Y += 10;
                }

                if (keyboard.IsKeyDown(Keys.Down))
                {
                    //playerOffset.Y -= 10;
                    offset.Y -= 10;
                }
            }
            else
            {
                if (scrollBackDelay > 0)
                {
                    scrollBackDelay--;
                }
                else
                {
                    if (playerOffset.Y > 0) playerOffset.Y -= 0.5f;
                    if (playerOffset.Y < 0) playerOffset.Y += 0.5f;
                }
            }

            if (keyboard.IsKeyDown(Keys.Left))
            {
                cursorOffset.X -= 1;
            }

            if (keyboard.IsKeyDown(Keys.Right))
            {
                cursorOffset.X += 1;
            }

            keyboardState = keyboard;
            gamepadState = gamepad;

            Vector2 pos = ScreenToWorld(mouseController.Cursor);
            if (mouseController.IsNewMouseButtonPressed(MouseButtons.LEFT_BUTTON) && !startFallingBalls)
            {
                if (fixedMouseJoint == null)
                {
                    Fixture savedFixture = this.level.world.TestPoint(pos);
                    if (savedFixture != null)
                    {
                        foreach (GameObject obj in level.addObjects.objects)
                        {
                            if (obj.body == savedFixture.Body)
                            {
                                movingObject = obj;
                                level.addObjects.objects.Remove(obj);
                                movingObject.body.CollidesWith = Category.None;
                                movingObject.body.FixedRotation = true;
                                fixedMouseJoint = new FixedMouseJoint(movingObject.body, pos);
                                fixedMouseJoint.MaxForce = 1000.0f * movingObject.body.Mass;
                                this.level.world.AddJoint(fixedMouseJoint);
                                movingObject.color = Color.DarkCyan;
                                Console.WriteLine("Body Clicked " + movingObject.body.Position);
                                bodyclickedEffect.Play();
                                break;
                            }
                        }

                        foreach (GameObject obj in level.gamefield.objects)
                        {
                            if (obj.isMoveable && obj.body == savedFixture.Body)
                            {
                                movingObject = obj;
                                level.gamefield.objects.Remove(obj);
                                movingObject.body.CollidesWith = Category.None;
                                movingObject.body.FixedRotation = true;
                                movingObject.body.BodyType = BodyType.Dynamic;
                                fixedMouseJoint = new FixedMouseJoint(movingObject.body, pos);
                                fixedMouseJoint.MaxForce = 1000.0f * movingObject.body.Mass;
                                this.level.world.AddJoint(fixedMouseJoint);
                                movingObject.color = Color.DarkCyan;
                                Console.WriteLine("Body Clicked " + movingObject.body.Position);
                                bodyclickedEffect.Play();
                                break;
                            }
                        }

                    }
                }
                else
                {
                    this.level.world.RemoveJoint(fixedMouseJoint);
                    fixedMouseJoint = null;
                    movingObject.color = Color.Blue;
                    movingObject.body.BodyType = BodyType.Static;
                    movingObject.body.CollidesWith = Category.All;
                    movingObject.body.Awake = true;
                    level.gamefield.add(movingObject);
                    movingObject = null;
                    bodyPlacedEffect.Play();
                }
            }

            if (mouseController.IsNewMouseButtonPressed(MouseButtons.RIGHT_BUTTON) && movingObject != null)
            {
                movingObject.body.FixedRotation = false;
                movingObject.body.Rotation += 0.7f;
                movingObject.body.FixedRotation = true;
            }

            if (fixedMouseJoint != null)
            {
                fixedMouseJoint.WorldAnchorB = pos;
            }

            base.Update(gameTime);
            level.update(gameTime);
            mouseController.Update(gameTime);
        }
Exemple #5
0
 public void add(GameObject gameObject)
 {
     this.objects.Add( gameObject );
 }