Пример #1
0
        public override bool OnCollisionEnter(GameObject hit)
        {
            if (hit is Ball)
            {
                soundEffect.Play();
            }

            return false;
        }
Пример #2
0
 public override bool OnCollisionEnter(GameObject hit)
 {
     if(hit is Ball)
     {
         Game1.Instance.SpawnMoreBalls(2);
         Game1.Instance.PowerUpDeath();
         hadBeenTriggered = true;
         Game1.suicidalObjects.Add(this);
     }
     return true;
 }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var wallTexture = Content.Load<Texture2D>("wall");
            _topWall = new GameObject(wallTexture,Vector2.Zero);
            _bottomWall = new GameObject(wallTexture, new Vector2(0, Window.ClientBounds.Height - wallTexture.Height));

            var paddleTexture = Content.Load<Texture2D>("paddle");
            Vector2 position;

            position = new Vector2(0, (Window.ClientBounds.Height - paddleTexture.Height)/2);
            _playerOne = new Racket(paddleTexture, position);

            position = new Vector2((Window.ClientBounds.Width - paddleTexture.Width),
                                   (Window.ClientBounds.Height - paddleTexture.Height)/2);
            _playerTwo  = new Racket(paddleTexture, position);

            var ballTexture = Content.Load<Texture2D>("ball");
            position = new Vector2(_playerOne.BoundingBox.Right + 1, (Window.ClientBounds.Height - ballTexture.Height)/2);
            _ball = new GameObject(ballTexture, position, new Vector2(8f, -8f));
        }
Пример #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            IsMouseVisible = true;
            masterServerIP = File.ReadAllText(@"Content\MasterServerIP.txt");

            if (!hasStarted)
            {
                state = State.Connect;
                focus = FieldFocus.Name;
                serverNameTextHost = new InputBox(new Vector2(100, 100));
                passwordTextHost = new InputBox(new Vector2(100, 130));
                serverNameTextJoin = new InputBox(new Vector2(100, 400));
                passwordTextJoin = new InputBox(new Vector2(100, 430));
            }

            ballCount = 1;
            powerCount = 1;
            powerTimer = 0;
            allGameObjects = new List<GameObject>();
            allGameObjects.Clear();
            suicidalObjects = new List<GameObject>();
            addThese = new List<GameObject>();
            windowHeight = Window.ClientBounds.Height;
            windowWidth = Window.ClientBounds.Width;

            if (hasStarted)
            {
                #region
                Sprite pongSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None);
                Sprite ballSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None);
                Sprite wallSprite = new Sprite(new Vector2(200, 200), 1, new Vector2(80, 2), Color.White, SpriteEffects.None);
                Sprite netSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(0.5f, 1), Color.White, SpriteEffects.None, @"PongMiddle");

                Rectangle pongCollision = new Rectangle(0, 0, 10, 82);
                Rectangle ballColl = new Rectangle(0, 0, 15, 15);
                Rectangle pwrColl = new Rectangle(0, 0, 40, 40);
                Rectangle wallCollision = new Rectangle(0, 0, Window.ClientBounds.Width, 15);

                SpriteA animatedSprite = new SpriteA(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None, @"powerpad");
                animatedSprite.CreateAnimation("Orb", 8, 0, 1, (648 / 8), (486 / 6), Vector2.Zero, 15f);
                animatedSprite.PlayAnimation("Orb");
                PowerUp powerup = new PowerUp(animatedSprite, new Vector2(rnd.Next(50, 600), rnd.Next(100, 350)), new Vector2(40, 0), 0, Content, pwrColl);

                SoundEffect wallBounce = Content.Load<SoundEffect>(@"SoundFX\wall_effect");
                SoundEffect pad1Bounce = Content.Load<SoundEffect>(@"SoundFX\pad1_effect");
                SoundEffect pad2Bounce = Content.Load<SoundEffect>(@"SoundFX\pad2_effect");

                GameObject net = new GameObject(netSprite, new Vector2(windowWidth / 2, windowHeight / 2), new Vector2(1, 0), 0, Content, new Rectangle(0, 0, 0, 0));

                if (isHost)
                {
                    p1Pad = new PongPaddle(PlayerNumber.player1, pongSprite, new Vector2(50, 250), new Vector2(0, 0), 100, Content, pongCollision, pad1Bounce);
                    p2PadGobject = new Dummyclass(pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, 'p', ClientPort, pad2Bounce);
                    myBallDummy = null;
                }
                else
                {
                    p1Pad = new PongPaddle(PlayerNumber.player1, pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, pad1Bounce);
                    p2PadGobject = new Dummyclass(pongSprite, new Vector2(50, 250), new Vector2(0, 0), 100, Content, pongCollision, 'p', ClientPort, pad1Bounce);
                    myBallDummy = new Dummyclass(ballSprite, new Vector2(400, 200), new Vector2(0, 0), 0, Content, ballColl, 'b', ClientPort + 1, null);
                }
                p1Pad.Sprite.Scale = new Vector2(1, 8);
                //P2 is basicly useless though
                p2Pad = new PongPaddle(PlayerNumber.player2, pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, pad2Bounce);
                myBall = new Ball(ballSprite, new Vector2(400, 200), new Vector2(40f, 20), 100, Content, ballColl, rnd);

                Wall topWall = new Wall(wallSprite, new Vector2(Window.ClientBounds.Width * 0.5f, 0), new Vector2(0, 1), 0, Content, wallCollision, wallBounce);
                Wall bottomWall = new Wall(wallSprite, new Vector2(Window.ClientBounds.Width * 0.5f, Window.ClientBounds.Bottom), new Vector2(0, -1), 0, Content, wallCollision, wallBounce);

                allGameObjects.Add(p1Pad);
                allGameObjects.Add(p2Pad);
                allGameObjects.Add(myBall);
                allGameObjects.Add(topWall);
                //allGameObjects.Add(powerup);
                allGameObjects.Add(myBallDummy);
                allGameObjects.Add(bottomWall);
                allGameObjects.Add(p2PadGobject);
                allGameObjects.Add(net);
                hasJustScored = false;
                #endregion
            }
        }
Пример #5
0
 public virtual bool OnCollisionEnter(GameObject hit)
 {
     return false;
 }
Пример #6
0
 /// <summary>
 /// Checks if a collision has happened with the given GameObject.
 /// Hint: This can be used with objects that isn't registered as a collidable Object by the GameWorld class
 /// </summary>
 /// <param name="other">The object you wish to check has collided with you</param>
 /// <returns>Returns true if a collision has happened</returns>
 public bool IsCollidingWith(GameObject other)
 {
     return collisionRect.Intersects(other.collisionRect);
 }
Пример #7
0
 public static bool CheckCollision(GameObject ob1, GameObject ob2)
 {
     if (ob1.Bounds.Intersects(ob2.Bounds))
         return true;
     return false;
 }