public static void Update()
        {
            if (!_higherLevel)
            {
                foreach (ISpriteInstance instance in _instances.Values)
                {
                    _advancedInstance = instance as IAdvancedSpriteInstance;
                    if (_advancedInstance != null)
                    {
                        if (_advancedInstance.Updating)
                        {
                            if (_advancedInstance.SpriteBase.Update(_advancedInstance) == 0)
                            {
                                if (_advancedInstance.Speed <= 0)
                                {
                                    throw new Exception("Instance: " + _advancedInstance.InstanceName + "'s speed must be greater than 0");
                                }
                                else
                                {
                                    _gameFramePerAnimFrame = (1 / _advancedInstance.Speed) * (1 / _advancedInstance.Animation.BaseSpeed);
                                }

                                if (_gameFramePerAnimFrame < 0)
                                {
                                    throw new Exception("Animation: " + _advancedInstance.Animation.AnimationName + " from Sprite:" + _advancedInstance.SpriteBase.SpriteID + " must have a speed greater than 0");
                                }
                                else if (_gameFramePerAnimFrame > 1)
                                {
                                    if (_advancedInstance.InternalFrame >= _gameFramePerAnimFrame)
                                    {
                                        _advancedInstance.InternalFrame = 0;
                                        _advancedInstance.Frame++;
                                    }
                                    else
                                    {
                                        _advancedInstance.InternalFrame++;
                                    }
                                    if (_advancedInstance.Frame >= _advancedInstance.Animation.FrameCount)
                                    {
                                        _advancedInstance.Frame = 0;
                                    }
                                }
                                else
                                {
                                    _gameFramePerAnimFrame   = 1 / _gameFramePerAnimFrame;
                                    _advancedInstance.Frame += (int)_gameFramePerAnimFrame;
                                    if (_advancedInstance.Frame >= _advancedInstance.Animation.FrameCount)
                                    {
                                        _advancedInstance.Frame = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public static bool CheckCollision(string instancename1, string instancename2, bool AllowTranslucent1, bool AllowTranslucent2)
        {
            _drawRect    = new Rectangle((int)_instances[instancename1].Location.X, (int)(_instances[instancename1].Location.Y), (int)(_instances[instancename1].SpriteBase.SourceRect.Width * _instances[instancename1].Scale.X), (int)(_instances[instancename1].SpriteBase.SourceRect.Height * _instances[instancename1].Scale.Y));
            _colInstance = _instances[instancename1] as IAdvancedSpriteInstance;
            if (_colInstance != null)
            {
                _drawRect.Width  = (int)(_colInstance.Animation.StartingSource.Width * _colInstance.Scale.X);
                _drawRect.Height = (int)(_colInstance.Animation.StartingSource.Height * _colInstance.Scale.Y);
            }
            _colRect     = new Rectangle((int)_instances[instancename2].Location.X, (int)(_instances[instancename2].Location.Y), (int)(_instances[instancename2].SpriteBase.SourceRect.Width * _instances[instancename2].Scale.X), (int)(_instances[instancename2].SpriteBase.SourceRect.Height * _instances[instancename2].Scale.Y));
            _colInstance = _instances[instancename2] as IAdvancedSpriteInstance;
            if (_colInstance != null)
            {
                _colRect.Width  = (int)(_colInstance.Animation.StartingSource.Width * _colInstance.Scale.X);
                _colRect.Height = (int)(_colInstance.Animation.StartingSource.Height * _colInstance.Scale.Y);
            }
            if (_drawRect.Intersects(_colRect))
            {
                _colSource2  = _instances[instancename2].SpriteBase.CollisonSource;
                _colSource   = _instances[instancename1].SpriteBase.CollisonSource;
                _colTexture  = _instances[instancename1].SpriteBase.SpriteSheet;
                _colTexture2 = _instances[instancename2].SpriteBase.SpriteSheet;
                _colInstance = _instances[instancename1] as IAdvancedSpriteInstance;
                if (_colInstance != null)
                {
                    _colSource  = new Rectangle(_colInstance.Animation.StartCollision.X + (_colInstance.Animation.StartCollision.Width * _colInstance.Frame), _colInstance.Animation.StartCollision.Y, _colInstance.Animation.StartCollision.Width, _colInstance.Animation.StartCollision.Height);
                    _colTexture = _colInstance.Animation.SpriteSheet;
                }
                _colInstance = _instances[instancename1] as IAdvancedSpriteInstance;
                if (_colInstance != null)
                {
                    _colSource2  = new Rectangle(_colInstance.Animation.StartCollision.X + (_colInstance.Animation.StartCollision.Width * _colInstance.Frame), _colInstance.Animation.StartCollision.Y, _colInstance.Animation.StartCollision.Width, _colInstance.Animation.StartCollision.Height);
                    _colTexture2 = _colInstance.Animation.SpriteSheet;
                }

                _colColors  = SpriteUtilities.GetColColors(_colTexture, _colSource);
                _colColors2 = SpriteUtilities.GetColColors(_colTexture2, _colSource2);

                return(SpriteUtilities.SpriteCollisionPixel(_instances[instancename1], _instances[instancename2], _colColors, _colColors2, _colSource, _colSource2, AllowTranslucent1, AllowTranslucent2));
            }
            return(false);
        }
        public static void Draw()
        {
            foreach (ISpriteInstance instance in _instances.Values)
            {
                if (instance.Drawing)
                {
                    _drawRect         = new Rectangle((int)instance.Location.X, (int)(instance.Location.Y), (int)(instance.SpriteBase.SourceRect.Width * instance.Scale.X), (int)(instance.SpriteBase.SourceRect.Height * instance.Scale.Y));
                    _advancedInstance = instance as IAdvancedSpriteInstance;
                    if (_advancedInstance != null)
                    {
                        if (_advancedInstance.SpriteBase.Animations.ContainsKey(_advancedInstance.CurrentAnimation))
                        {
                            if (_advancedInstance.Animation.SpriteSheet != null)
                            {
                                _advancedSource    = _advancedInstance.Animation.StartingSource;
                                _advancedSource.X += _advancedSource.Width * _advancedInstance.Frame;
                                _drawRect.Width    = (int)(_advancedSource.Width * instance.Scale.X);
                                _drawRect.Height   = (int)(_advancedSource.Height * instance.Scale.Y);
                                if (instance.SpriteBase.Draw(instance, _drawRect) == 0)
                                {
                                    UniversalVariables.spriteBatch.Draw(_advancedInstance.Animation.SpriteSheet, _drawRect, _advancedSource, instance.DrawColor, instance.Rotation, instance.SpriteBase.Origin, instance.DrawEffects, instance.Depth);
                                }
                            }
                        }
                    }
                    else if (instance.SpriteBase.Draw(instance, _drawRect) == 0)
                    {
                        if (instance.SpriteBase.SpriteSheet != null)
                        {
                            UniversalVariables.spriteBatch.Draw(instance.SpriteBase.SpriteSheet, _drawRect, instance.SpriteBase.SourceRect, instance.DrawColor, instance.Rotation, instance.SpriteBase.Origin, instance.DrawEffects, instance.Depth);
                        }
                    }
                }
            }

            foreach (ISpriteTextInstance instance in _textInstances.Values)
            {
                UniversalVariables.spriteBatch.DrawString(instance.TextBase.Font, instance.Text, instance.Location, instance.DrawColor, instance.Rotation, instance.Origin, instance.Scale, instance.DrawEffects, instance.Depth);
            }
        }
예제 #4
0
        public static void Update()
        {
            if (!BasicSpriteRegistry.HigherLevel)
            {
                BasicSpriteRegistry.HigherLevel = false;
            }
            foreach (ISpriteInstance instance in BasicSpriteRegistry.Instances.Values)
            {
                int update = _advancedInstance.SpriteBase.Update(_advancedInstance);
                _advancedInstance = instance as IAdvancedSpriteInstance;
                if (_advancedInstance != null)
                {
                    if (_advancedInstance.Updating)
                    {
                        if (update == 0)
                        {
                            if (_advancedInstance.Speed <= 0)
                            {
                                throw new Exception("Instance: " + _advancedInstance.InstanceName + "'s speed must be greater than 0");
                            }
                            else
                            {
                                _gameFramePerAnimFrame = (1 / _advancedInstance.Speed) * (1 / _advancedInstance.Animation.BaseSpeed);
                            }

                            if (_gameFramePerAnimFrame < 0)
                            {
                                throw new Exception("Animation: " + _advancedInstance.Animation.AnimationName + " from Sprite:" + _advancedInstance.SpriteBase.SpriteID + " must have a speed greater than 0");
                            }
                            else if (_gameFramePerAnimFrame > 1)
                            {
                                if (_advancedInstance.InternalFrame >= _gameFramePerAnimFrame)
                                {
                                    _advancedInstance.InternalFrame = 0;
                                    _advancedInstance.Frame++;
                                }
                                else
                                {
                                    _advancedInstance.InternalFrame++;
                                }
                            }
                            else
                            {
                                _gameFramePerAnimFrame   = 1 / _gameFramePerAnimFrame;
                                _advancedInstance.Frame += (int)_gameFramePerAnimFrame;
                            }
                        }

                        _movinstance = instance as IMovingSpriteInstance;
                        if (_movinstance != null)
                        {
                            if (update == 0)
                            {
                                _movinstance.Location += _movinstance.Velocity;
                                _tempvect              = _movinstance.Velocity;
                                if (_movinstance.Velocity.X > 0)
                                {
                                    if (_movinstance.Velocity.X >= _movinstance.Deceleration.X)
                                    {
                                        _tempvect.X -= _movinstance.Deceleration.X;
                                    }
                                    else
                                    {
                                        _tempvect.X = 0;
                                    }
                                }
                                if (_movinstance.Velocity.X < 0)
                                {
                                    if (_movinstance.Velocity.X <= -_movinstance.Deceleration.X)
                                    {
                                        _tempvect.X += _movinstance.Deceleration.X;
                                    }
                                    else
                                    {
                                        _tempvect.X = 0;
                                    }
                                }
                                if (_movinstance.Velocity.Y > 0)
                                {
                                    if (_movinstance.Velocity.Y >= _movinstance.Deceleration.X)
                                    {
                                        _tempvect.Y -= _movinstance.Deceleration.Y;
                                    }
                                    else
                                    {
                                        _tempvect.Y = 0;
                                    }
                                }
                                if (_movinstance.Velocity.Y < 0)
                                {
                                    if (_movinstance.Velocity.Y <= -_movinstance.Deceleration.Y)
                                    {
                                        _tempvect.Y += _movinstance.Deceleration.Y;
                                    }
                                    else
                                    {
                                        _tempvect.Y = 0;
                                    }
                                }

                                _movinstance.Velocity = _tempvect;
                            }
                        }
                    }
                }
            }

            foreach (IMultiSpriteInstance _mulInstance in _multiInstances)
            {
                foreach (IMovingSpriteInstance inst in _mulInstance.Sprites)
                {
                    int update = _advancedInstance.SpriteBase.Update(inst);

                    if (_advancedInstance.Updating)
                    {
                        if (update == 0)
                        {
                            if (_advancedInstance.Speed <= 0)
                            {
                                throw new Exception("Instance: " + _advancedInstance.InstanceName + "'s speed must be greater than 0");
                            }
                            else
                            {
                                _gameFramePerAnimFrame = (1 / _advancedInstance.Speed) * (1 / _advancedInstance.Animation.BaseSpeed);
                            }

                            if (_gameFramePerAnimFrame < 0)
                            {
                                throw new Exception("Animation: " + _advancedInstance.Animation.AnimationName + " from Sprite:" + _advancedInstance.SpriteBase.SpriteID + " must have a speed greater than 0");
                            }
                            else if (_gameFramePerAnimFrame > 1)
                            {
                                if (_advancedInstance.InternalFrame >= _gameFramePerAnimFrame)
                                {
                                    _advancedInstance.InternalFrame = 0;
                                    _advancedInstance.Frame++;
                                }
                                else
                                {
                                    _advancedInstance.InternalFrame++;
                                }
                                if (_advancedInstance.Frame >= _advancedInstance.Animation.FrameCount)
                                {
                                    _advancedInstance.Frame = 0;
                                }
                            }
                            else
                            {
                                _gameFramePerAnimFrame   = 1 / _gameFramePerAnimFrame;
                                _advancedInstance.Frame += (int)_gameFramePerAnimFrame;
                                if (_advancedInstance.Frame >= _advancedInstance.Animation.FrameCount)
                                {
                                    _advancedInstance.Frame = 0;
                                }
                            }
                        }

                        if (update == 0)
                        {
                            _movinstance.Location += _movinstance.Velocity;
                            _tempvect              = _movinstance.Velocity;
                            if (_movinstance.Velocity.X > 0)
                            {
                                if (_movinstance.Velocity.X >= _movinstance.Deceleration.X)
                                {
                                    _tempvect.X -= _movinstance.Deceleration.X;
                                }
                                else
                                {
                                    _tempvect.X = 0;
                                }
                            }
                            if (_movinstance.Velocity.X < 0)
                            {
                                if (_movinstance.Velocity.X <= -_movinstance.Deceleration.X)
                                {
                                    _tempvect.X += _movinstance.Deceleration.X;
                                }
                                else
                                {
                                    _tempvect.X = 0;
                                }
                            }
                            if (_movinstance.Velocity.Y > 0)
                            {
                                if (_movinstance.Velocity.Y >= _movinstance.Deceleration.X)
                                {
                                    _tempvect.Y -= _movinstance.Deceleration.Y;
                                }
                                else
                                {
                                    _tempvect.Y = 0;
                                }
                            }
                            if (_movinstance.Velocity.Y < 0)
                            {
                                if (_movinstance.Velocity.Y <= -_movinstance.Deceleration.Y)
                                {
                                    _tempvect.Y += _movinstance.Deceleration.Y;
                                }
                                else
                                {
                                    _tempvect.Y = 0;
                                }
                            }

                            _movinstance.Velocity = _tempvect;
                        }
                    }
                }
            }
        }
예제 #5
0
 public byte Update(IAdvancedSpriteInstance _instance)
 {
     _instance.Location = new Vector2(InputManager.Mou.X, InputManager.Mou.Y);
     return(0);
 }