public virtual void Update(ISpriteEntity spriteEntity, GameTime gameTime, BallInput ballInput)
 {
     ballInput.PlayScored();
     _gameManager = ((IGameManager)spriteEntity.Game.Services.GetService(typeof(IGameManager)));
     int score = (int)_gameManager[PlayerScoreKey];
     score++;
     _gameManager[PlayerScoreKey] = score;
 }
예제 #2
0
 public void CollisionNotification(ISpriteEntity collidingWithSpriteEntity)
 {
     if (collidingWithSpriteEntity.Name == "Player1" || collidingWithSpriteEntity.Name == "Player2")
     {
         Ball.Direction = new Vector2(Ball.Direction.X * -1, Ball.Direction.Y);
         Ball.PlayBounce();
         return;
     }
 }
예제 #3
0
        public void PerformCollisionCheck(ISpriteEntity spriteEntityA, ISpriteEntity spriteEntityB)
        {
            Rectangle a = GetBoundingBox(spriteEntityA);
            Rectangle b = GetBoundingBox(spriteEntityB);

            if (PerformCollisionCheck(a, b))
            {
                NotifyCollisionObservers(spriteEntityA, spriteEntityB);
            }
        }
        public void CollisionNotification(ISpriteEntity collidingWithSpriteEntity)
        {
            if (collidingWithSpriteEntity.Name != "Ball")
            {
                return;
            }
            
            _padelEntityController.AnimateBallBounce();

        }
예제 #5
0
 private void NotifyCollisionObservers(ISpriteEntity spriteEntityA, ISpriteEntity spriteEntityB)
 {
     foreach (DictionaryEntry dictionaryEntry in CollisionObserverContainer)
     {
         if (dictionaryEntry.Key.ToString() == spriteEntityA.Name )
         {
             ((ICollisionObserver)dictionaryEntry.Value).CollisionNotification(spriteEntityB);
         }
         if (dictionaryEntry.Key.ToString() == spriteEntityB.Name)
         {
             ((ICollisionObserver)dictionaryEntry.Value).CollisionNotification(spriteEntityA);
         }
     }
 }
예제 #6
0
        public override void LoadContent()
        {
            //Game.Components.Add((IGameComponent)camera);


            background = SpriteEntityFactory.CreateSprite("Background");
            _entities.Add(background);

            player1 = SpriteEntityFactory.CreateSprite("Padel1");
            camera.Focus = player1 as IFocusable;
            _entities.Add(player1);

            player2 = SpriteEntityFactory.CreateSprite("Padel2");
            _entities.Add(player2);



            ball = SpriteEntityFactory.CreateSprite("Ball");
            _entities.Add(ball);

            circle = SpriteEntityFactory.CreateSprite("Circle");
            _entities.Add(circle);

            ballBounce = Game.Content.Load<SoundEffect>("Bounce");


            CollisionManager.RegisterCollision(ball);
            CollisionManager.RegisterCollision(player1);
            CollisionManager.RegisterCollision(player2);

            CollisionManager.RegisterCollisionObserver(ball.Name, ball.Controller as BallController);
            CollisionManager.RegisterCollisionObserver(player1.Name, player1.Controller as PadelKeyboardController);
            CollisionManager.RegisterCollisionObserver(player2.Name, player2.Controller as PadelKeyboardController);

            _hud.LoadContent(); ;
        }
예제 #7
0
 public void UnregisterCollision(ISpriteEntity spriteEntity)
 {
     CollisionEnties.Add(spriteEntity);
 }
예제 #8
0
 /// <summary>
 /// Draws the specified sprite.
 /// </summary>
 /// <param name="spriteEntity">The sprite.</param>
 public virtual void Draw(ISpriteEntity spriteEntity)
 {
     SpriteBatch.Draw(spriteEntity.Texture, spriteEntity.Position, spriteEntity.Source, spriteEntity.Color, spriteEntity.Rotation, spriteEntity.Origin, spriteEntity.Scale, spriteEntity.Effects, spriteEntity.LayerDepth);
 }
예제 #9
0
 public SpriteController(ISpriteEntity mode, IGameManager gameManager) : base(gameManager)
 {
     _model = mode;
     _view = new SpriteView(this, _model);
 }
예제 #10
0
 public Padel(ISpriteEntity spriteEntity)
 {
     Sprite = spriteEntity;
     //Sprite.Origin = new Vector2(Sprite.Size.Width/2, Sprite.Size.Height/2);
 }
예제 #11
0
 /// <summary>
 /// Loads the texture.
 /// </summary>
 /// <param name="assetName">Name of the asset.</param>
 /// <param name="spriteEntity">The spriteEntity.</param>
 public void LoadTexture(string assetName, ISpriteEntity spriteEntity)
 {
     spriteEntity.Texture = GetTexture(assetName) as Texture2D;
     spriteEntity.AssetName = assetName;
     spriteEntity.Source = new Rectangle(0, 0, spriteEntity.Texture.Width, spriteEntity.Texture.Height);
     spriteEntity.Size = new Rectangle(0, 0, (int)(spriteEntity.Texture.Width * spriteEntity.Scale), (int)(spriteEntity.Texture.Height * spriteEntity.Scale));
 }
 public SinusCurveSpriteEntityControllerBase(ISpriteEntity spriteEntity, IGameManager gameManager)
     : base(gameManager)
 {
     _spriteEntity = spriteEntity;
     _view = new SinusCurveSpriteEntityView(this, _spriteEntity);
 }
예제 #13
0
 internal PlayerScoredView(IController controller, ISpriteEntity model)
 {
     Model = model;
 }
예제 #14
0
 public CollisionEventArgs(ISpriteEntity collisionWithSpriteEntity)
 {
     CollisionWithSpriteEntity = collisionWithSpriteEntity;
 }
예제 #15
0
 public Rectangle GetBoundingBox(ISpriteEntity spriteEntity)
 {
     return new Rectangle((int)spriteEntity.Position.X, (int)spriteEntity.Position.Y, spriteEntity.Size.Width, spriteEntity.Size.Height);
 }
 public SinusCurveSpriteEntityView(IController controller, ISpriteEntity model)
 {
     _entitesToRender = new List<ISpriteEntity>();
     _model = model;
 }
예제 #17
0
파일: Ball.cs 프로젝트: swallentin/XNA.Pong
 public Ball(ISpriteEntity spriteEntity)
 {
     Sprite = spriteEntity;
     StartVelocity = Sprite.Velocity;
 }
예제 #18
0
        public override void LoadContent()
        {

            background = SpriteEntityFactory.CreateSprite("OptionsScreen");
        }
예제 #19
0
 public SpriteView(IController controller, ISpriteEntity spriteEntity)
 {
     _controller = controller;
     _model = spriteEntity;
 }