public virtual void AddTarget(IDrawableComponent target)
 {
     if (!targets.Contains(target))
     {
         targets.Add(target);
     }
 }
            public override void Run()
            {
                Canvas canvas = null;

                while (_running)
                {
                    //if (_drawing)
                    //{
                    try
                    {
                        canvas = _surfaceHolder.LockCanvas(null);
                        if (canvas == null)
                        {
                            continue;
                        }

                        canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
                        canvas.DrawBitmap(_fieldBitmap, 0, 0, null);
                        for (int idx = 0; idx < _drawableObjs.Count; idx++)
                        {
                            _drawItem = _drawableObjs[idx];
                            if (_drawItem.CurPosition == null)
                            {
                                continue;
                            }
                            IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            if (drawable == null)
                            {
                                throw new InvalidCastException($"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            }
                            canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y, null);

                            //var list = _drawableObjs[listIdx];
                            //for (int drawObjIdx = 0; drawObjIdx < list.Count; drawObjIdx++)
                            //{
                            //    _drawItem = list[drawObjIdx];
                            //    if (_drawItem.CurPosition == null) continue;
                            //    IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            //    if (drawable == null)
                            //        throw new InvalidCastException(
                            //            $"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            //    canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y,
                            //        null);
                            //}
                        }
                    }
                    catch (System.Exception e)
                    {
                        throw new System.Exception($"There is exception in Canvas field. {e}");
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            _surfaceHolder.UnlockCanvasAndPost(canvas);
                        }
                    }
                    //}
                }
            }
Exemple #3
0
        private void GameComponentRemoved(object sender, GameComponentCollectionEventArgs e)
        {
            IDrawableComponent d = e.GameComponent as IDrawableComponent;

            if (d != null)
            {
                d.DrawOrderChanged -= DrawableDrawOrderChanged;
                d.VisibleChanged   -= DrawableVisibleChanged;

                if (d.Visible)
                {
                    _visibleDrawable.RemoveAll(x => x.DrawOrder.GetHashCode() == d.GetHashCode());
                }
            }

            IUpdatableComponent u = e.GameComponent as IUpdatableComponent;

            if (u != null)
            {
                u.UpdateOrderChanged -= UpdatableUpdateOrderChanged;
                u.UpdatableChanged   -= UpdatableEnabledChanged;

                if (u.Updatable)
                {
                    _enabledUpdatable.Remove(u);
                }

                isCurrentlyUpdatingComponentsDirty = true; //Need to clear the currently Updating collection, that will need to be refreshed.
            }
        }
Exemple #4
0
        private void GameComponentCleaning()
        {
            foreach (var component in _enabledUpdatable)
            {
                IUpdatableComponent u = component as IUpdatableComponent;
                if (u != null)
                {
                    u.UpdateOrderChanged -= UpdatableUpdateOrderChanged;
                    u.UpdatableChanged   -= UpdatableEnabledChanged;
                }
            }

            foreach (var component in _visibleDrawable)
            {
                IDrawableComponent d = component as IDrawableComponent;
                if (d != null)
                {
                    d.DrawOrderChanged -= DrawableDrawOrderChanged;
                    d.VisibleChanged   -= DrawableVisibleChanged;
                }
            }

            if (OnRenderLoopFrozen != null)
            {
                //Remove all Events associated (That haven't been unsubscribed !)
                foreach (Delegate d in OnRenderLoopFrozen.GetInvocationList())
                {
                    OnRenderLoopFrozen -= (RenderLoopFrozen)d;
                }
            }
        }
Exemple #5
0
 private void UpdateIDrawableComponent(IDrawableComponent component)
 {
     if (component.isEnabled())
     {
         component.Update();
     }
 }
Exemple #6
0
        private void GameComponentAdded(object sender, GameComponentCollectionEventArgs e)
        {
            IDrawableComponent d = e.GameComponent as IDrawableComponent;

            if (d != null)
            {
                d.DrawOrderChanged += DrawableDrawOrderChanged;
                d.VisibleChanged   += DrawableVisibleChanged;

                if (d.Visible)
                {
                    AddDrawable(d);
                }
            }

            IUpdatableComponent u = e.GameComponent as IUpdatableComponent;

            if (u != null)
            {
                u.UpdateOrderChanged += UpdatableUpdateOrderChanged;
                u.UpdatableChanged   += UpdatableEnabledChanged;

                if (u.Updatable)
                {
                    AddUpdatable(u);
                }
            }
        }
Exemple #7
0
 public void OnDrawableZChanged(IDrawableComponent drawableComponent, float previousZ)
 {
     foreach (var camera in _cameras)
     {
         camera.OnZChanged(drawableComponent, previousZ);
     }
 }
Exemple #8
0
 private void DrawIDrawableComponent(IDrawableComponent component)
 {
     if (component.isVisible())
     {
         component.Draw(_spriteBatch);
     }
 }
Exemple #9
0
 public Meteor(GameContext gameContext, IMeteorStrategy meteorStrategy, IHealthComponent healthComponent, IComponent <IGameObject> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent)
 {
     _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _meteorStrategy    = meteorStrategy ?? throw new ArgumentNullException(nameof(meteorStrategy));
     _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
     _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
     _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
 }
Exemple #10
0
        public Bullet(GameContext gameContext, int damageAmount, IComponent <IGameObject> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent)
        {
            _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
            _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
            _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));

            CollisionDamageAmount = damageAmount;
        }
Exemple #11
0
 private void AddDrawable(IDrawableComponent d)
 {
     //Add all Draw call linked to this Component
     foreach (var drawOrder in d.DrawOrders.DrawOrdersCollection)
     {
         _visibleDrawable.Add(new DrawableComponentHolder(d, drawOrder));
     }
     _visibleDrawable.Sort(DrawableComparison);
 }
Exemple #12
0
        public Enemy(GameContext gameContext, int initialMaxHealth, int initialCollisionDamage, int scoreValue, float aggroRange, IHealthComponent healthComponent, IComponent <IEnemy> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent, PlayerManager playerManager)
        {
            _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
            _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
            _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
            _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
            _playerManager     = playerManager ?? throw new ArgumentNullException(nameof(playerManager));

            _initialMaxHealth       = initialMaxHealth;
            _initialCollisionDamage = initialCollisionDamage;
            _scoreValue             = scoreValue;
            _aggroRange             = aggroRange;
        }
Exemple #13
0
        internal void DeregisterComponent(Component c)
        {
            var t = c.GetType();

            _componentList[t].Remove(c);

            IDrawableComponent drawableComponent = c as IDrawableComponent;

            if (drawableComponent != null)
            {
                _drawableComponents.Remove(drawableComponent);
            }
        }
Exemple #14
0
        /// <summary>
        /// Regular Skydome loading
        /// </summary>
        public RegularSkyDome(D3DEngine d3dEngine, CameraManager <ICameraFocused> camManager, WorldFocusManager worldFocusManager, IClock clock, IWeather weather, [Named("Stars")] IDrawableComponent skyStars, [Named("Clouds")] IDrawableComponent clouds)
            : base(d3dEngine, clock, weather)
        {
            this.IsDefferedLoadContent = true;

            _camManager        = camManager;
            _worldFocusManager = worldFocusManager;
            _clock             = clock;
            _skyStars          = skyStars;
            _clouds            = clouds;

            this.DrawOrders.UpdateIndex(0, 40);
            cloudDrawIndex = this.DrawOrders.AddIndex(989, "Clouds");
        }
Exemple #15
0
        public Weapon(string name, Character parent, ProjectileType type)
        {
            _name                  = name;
            _weaponCharge          = 0;
            _stateComponent        = new StateComponent <WeaponState>(WeaponState.IdleState);
            _projectileSpawnOffset = new Vector(0, 5);
            _projectileType        = type;
            _projectileFactory     = new ProjectileFactory(type);
            _weaponAngle           = _minWepAngleRad;
            _usesSatellite         = false;
            _parent                = parent;

            _drawableComponent = new DrawableComponent(this);
            _SightComponent    = new DrawableSightComponent(this);
        }
Exemple #16
0
        public Player(GameContext gameContext, IHealthComponent healthComponent, IComponent <IPlayer> inputComponent, IPlayerPhysicsComponent physicsComponent, IDrawableComponent <IPlayer> graphicsComponent, IProjectilesManager projectileManager)
        {
            _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
            _inputComponent    = inputComponent ?? throw new ArgumentNullException(nameof(inputComponent));
            _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
            _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
            _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
            _projectileManager = projectileManager ?? throw new ArgumentNullException(nameof(projectileManager));

            _acceleratingSoundEffect    = _gameContext.GameAudio.CreateSoundEffect(_gameContext.AssetManager.GetSoundEffect(GameConstants.ThrusterConstants.Thruster1Constants.Audio.ThrustingSoundEffectName));
            _invulnerabilitySoundEffect = _gameContext.GameAudio.CreateSoundEffect(_gameContext.AssetManager.GetSoundEffect(GameConstants.PlayerConstants.Audio.InvulnerableSoundEffectName));

            _invulnerableStopwatch = new Stopwatch();
            _flashingStopwatch     = new Stopwatch();
        }
Exemple #17
0
        private void DrawableVisibleChanged(object sender, EventArgs e)
        {
            IDrawableComponent d = (IDrawableComponent)sender;

            if (d.Visible)
            {
                foreach (var drawOrder in d.DrawOrders.DrawOrdersCollection)
                {
                    _visibleDrawable.Add(new DrawableComponentHolder(d, drawOrder));
                }
                _visibleDrawable.Sort(DrawableComparison);
            }
            else
            {
                _visibleDrawable.RemoveAll(x => x.DrawOrder.GetHashCode() == d.GetHashCode());
            }
        }
Exemple #18
0
        internal void RegisterComponent(Component c)
        {
            var t = c.GetType();

            if (_componentList == null)
            {
                _componentList = new Dictionary <Type, List <Component> >();
            }
            if (!(_componentList.ContainsKey(t)))
            {
                _componentList[t] = new List <Component>();
            }
            _componentList[t].Add(c);

            IDrawableComponent drawableComponent = c as IDrawableComponent;

            if (drawableComponent != null)
            {
                _drawableComponents.Add(drawableComponent);
                SortDrawableComponents();
            }
        }
        public void SetGameComponent(IGameComponent gamecomp, int drawIndex)
        {
            DetachAll();

            _gamecomp       = gamecomp;
            _drawOrderindex = drawIndex;

            lblGameComp.Text = _gamecomp.Name;
            _parent.Children.Add(lblGameComp);                  //Show the Label

            if (drawIndex == 0)
            {
                IUpdatableComponent updateableComponent = _gamecomp as IUpdatableComponent;
                if (updateableComponent != null)
                {
                    optUpdatable.Selected = updateableComponent.Updatable;
                    _parent.Children.Add(optUpdatable);

                    updateOrder.Text = updateableComponent.UpdateOrder.ToString();
                    _parent.Children.Add(updateOrder);
                }
            }

            IDrawableComponent drawableComponent = _gamecomp as IDrawableComponent;

            if (drawableComponent != null)
            {
                if (drawIndex == 0)
                {
                    optDrawable.Selected = drawableComponent.Visible;
                    _parent.Children.Add(optDrawable);
                }

                lblGameComp.Text += " " + drawableComponent.DrawOrders.DrawOrdersCollection[drawIndex].Name;

                drawOrder.Text = drawableComponent.DrawOrders.DrawOrdersCollection[drawIndex].Order.ToString();
                _parent.Children.Add(drawOrder);
            }
        }
Exemple #20
0
 public DrawableComponent(IDrawableComponent parent, Bitmap bitmap)
     : this(parent, new Sprite(bitmap))
 {
 }
Exemple #21
0
 public HelpMainMenuState(GameContext gameContext, IDrawableComponent <IGameState> helpMainMenuStateGraphics)
 {
     _gameContext = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _helpMainMenuStateGraphics = helpMainMenuStateGraphics ?? throw new ArgumentNullException(nameof(helpMainMenuStateGraphics));
 }
Exemple #22
0
 public MainMenuState(GameContext gameContext, IDrawableComponent <IGameState> mainMenuStateGraphics, IGameMenu textMenu)
 {
     _gameContext           = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _mainMenuStateGraphics = mainMenuStateGraphics ?? throw new ArgumentNullException(nameof(mainMenuStateGraphics));
     _textMenu = textMenu ?? throw new ArgumentNullException(nameof(textMenu));
 }
        private void RefreshDataGrid()
        {
            int rowid = 0;

            List <GameCompHolder> GameCompHolders = new List <GameCompHolder>();

            //Get full list of gamecomponent, making the drawcall things "flat"
            foreach (var gc in _game.GameComponents)
            {
                IDrawableComponent drawable = gc as IDrawableComponent;
                if (drawable == null)
                {
                    int order = ((IUpdatableComponent)gc).UpdateOrder;
                    if (_isDrawingSorted)
                    {
                        if (_sortDescending)
                        {
                            order = int.MinValue;
                        }
                        else
                        {
                            order = int.MinValue;
                        }
                    }

                    //It's an uptabable components, add it as is
                    GameCompHolders.Add(new GameCompHolder()
                    {
                        GameComp = gc,
                        IndexId  = 0,
                        OrderId  = order
                    });
                }
                else
                {
                    //ITs an drawable components, need to add each index of it separalty
                    foreach (var draworder in drawable.DrawOrders.DrawOrdersCollection)
                    {
                        int order = drawable.UpdateOrder;
                        if (_isDrawingSorted)
                        {
                            order = draworder.Order;
                        }

                        //It's an uptabable components, add it as is
                        GameCompHolders.Add(new GameCompHolder()
                        {
                            GameComp = gc,
                            IndexId  = draworder.DrawID,
                            OrderId  = order
                        });
                    }
                }
            }

            _totalItems        = GameCompHolders.Count;
            _vsc.ThumbMaxValue = _totalItems;


            if (_sortDescending)
            {
                GameCompHolders = GameCompHolders.OrderByDescending(x => x.OrderId).ToList();
            }
            else
            {
                GameCompHolders = GameCompHolders.OrderBy(x => x.OrderId).ToList();
            }

            for (int i = _listOffset; i < GameCompHolders.Count; i++)
            {
                if (rowid < _nbrRowsToShow)
                {
                    Rows[rowid].SetGameComponent(GameCompHolders[i].GameComp, GameCompHolders[i].IndexId);
                    rowid++;
                }
            }

            for (; rowid < _nbrRowsToShow; rowid++)
            {
                Rows[rowid].DetachAll();
            }

            updateSlider();
        }
Exemple #24
0
 /// <summary>
 /// Compares this instance to the specified <see cref="IDrawableComponent"/> instance.
 /// </summary>
 /// <param name="other">The <see cref="IDrawableComponent"/> instance to compare to this instance.</param>
 /// <returns>
 ///     <list type="bullet">
 ///         <item>A negative number if this instance shall be drawn before the <paramref name="other"/> instance.</item>
 ///         <item>Zero if the this instance and the <paramref name="other"/> instance may be drawn in any order.</item>
 ///         <item>A positive number if this instance shall be drawn after the <paramref name="other"/> instance.</item>
 ///     </list>
 /// </returns>
 public int CompareTo(IDrawableComponent other)
 {
     return(other == null ? -1 : this == other ? 0 : this.DrawOrder.CompareTo(other.DrawOrder));
 }
Exemple #25
0
 public DrawableComponent(IDrawableComponent parent)
 {
     _parent = parent;
     _sprite = null;
 }
Exemple #26
0
 public SplashState(GameContext gameContext, IDrawableComponent <IGameState> splashStateGraphics)
 {
     _gameContext         = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _splashStateGraphics = splashStateGraphics ?? throw new ArgumentNullException(nameof(splashStateGraphics));
 }
Exemple #27
0
 public DrawableComponent(IDrawableComponent parent, Sprite sprite)
 {
     _parent = parent;
     _sprite = sprite;
 }
 public override void AddTarget(IDrawableComponent target)
 {
     base.AddTarget(target);
     startingPositions.Add(target.Position);
 }
Exemple #29
0
 public HealthPack(GameContext gameContext, IComponent <IGameObject> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent)
 {
     _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
     _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
 }
Exemple #30
0
 /// <summary>
 /// Requests for the specified object's content to be loaded.
 /// </summary>
 /// <param name="obj">Object to load content for.</param>
 public void LoadDrawableContent(IDrawableComponent obj)
 {
     obj.LoadContent(this.parentGame.Content);
 }