예제 #1
0
 /// <summary>
 /// A screen effect manager for creating effects such as screen flashes and fades.
 /// </summary>
 /// <param name="effectRectangle">The rectangle area to draw screen effects.</param>
 public GenScreenEffect(Rectangle effectRectangle)
 {
     EffectRectangle = effectRectangle;
     _fxTexture = new Texture2D(GenG.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
     _fxTexture.SetData<Color>(new[] { Color.White });
     _flashTimer = new GenTimer(0f, null);
     _flashIntensity = 0f;
     _fadeTimer = new GenTimer(0f, null);
 }
예제 #2
0
        /// <summary>
        /// A camera occupies a space on the game screen to draw game objects.
        /// An error will occur if the camera is positioned outside of the game window.
        /// </summary>
        /// <param name="x">The x position of the camera.</param>
        /// <param name="y">The y position of the camera.</param>
        /// <param name="width">The width of the camera.</param>
        /// <param name="height">The height of the camera.</param>
        /// <param name="zoom">The scale at which to draw objects in the camera.</param>
        public GenCamera(float x, float y, int width, int height, float zoom)
        {
            _cameraRect = new Rectangle(0, 0, width, height);
            _cameraView = new GenAABB(0f, 0f, width, height);
            _centerPosition = new Vector2(_cameraView.MidpointX, _cameraView.MidpointY);
            _up = new Vector2(0f, -1f);
            RenderTarget = new RenderTarget2D(GenG.GraphicsDevice, width, height);
            PixelRenderTarget = new RenderTarget2D(GenG.GraphicsDevice, width, height);
            _backgroundTexture = GenU.MakeTexture(Color.White, 1, 1);
            Color = Color.White;
            BgColor = Color.Transparent;
            _scroll = Vector2.Zero;
            _oldScroll = _scroll;
            _velocity = Vector2.Zero;
            _rotation = 0f;
            Origin = new Vector2(width * 0.5f, height * 0.5f);
            Scale = Vector2.One;
            _drawPosition = new Vector2(x + Origin.X, y + Origin.Y);
            _initialZoom = zoom;
            Zoom = _initialZoom;
            CameraFollowType = FollowType.LockOn;
            _followTargets = new List<GenObject>();
            FollowPosition = Vector2.Zero;
            FollowLeading = new Vector2(50, 30);
            _followStrength = 1f;
            MinZoom = _initialZoom;
            MaxZoom = 4f;
            _shakeOffset = Vector2.Zero;
            _shakeIntensity = 0f;
            _shakeDecreasing = false;
            _shakeTimer = new GenTimer(0f, null);
            SpriteEffect = SpriteEffects.None;
            _cameraEffect = new GenScreenEffect(_cameraRect);
            Transform = Matrix.Identity;

            // Set up the default camera blend state as alpha blend.
            BlendState = new BlendState();
            BlendState.ColorSourceBlend = Blend.One;
            BlendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            BlendState.ColorBlendFunction = BlendFunction.Add;
            BlendState.AlphaSourceBlend = Blend.One;
            BlendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            BlendState.AlphaBlendFunction = BlendFunction.Add;
        }
예제 #3
0
 /// <param name="x">The x position of the sprite.</param>
 /// <param name="y">The y position of the sprite.</param>
 /// <param name="texture">The sprite texture.</param>
 /// <param name="width">The width of the object.</param>
 /// <param name="height">The height of the object.</param>
 public GenSprite(float x, float y, Texture2D texture, int width, int height)
     : base(x, y, width, height)
 {
     _sourceRect = new Rectangle(0, 0, width, height);
     _texture = (texture != null) ? LoadTexture(texture, true) : null;
     _drawPosition = Vector2.Zero;
     Color = Color.White;
     Alpha = 1f;
     _drawColor = _color * _alpha;
     DrawOffset = Vector2.Zero;
     Scale = Vector2.One;
     DrawRotated = true;
     Animations = new Dictionary<string, GenAnimation>();
     _currentAnimation = null;
     _spriteEffect = SpriteEffects.None;
     ScrollFactor = Vector2.One;
     _flickerIntensity = 0f;
     _flickerColor = Color.White;
     _flickerPulsing = false;
     _flickerIntensity = 0f;
     _flickerTimer = new GenTimer(0f, null);
     _flickerColor = Color.White;
     _flickerPulsing = false;
     _fadeTimer = new GenTimer(0f, null);
     _fadeDirection = 1;
 }
예제 #4
0
 /// <summary>
 /// Creates a playable animation for a sprite.
 /// </summary>
 /// <param name="sprite">A reference to the sprite that will use this animation.</param>
 /// <param name="frameWidth">The width of each animation frame.</param>
 /// <param name="frameHeight">The height of each animation frame.</param>
 /// <param name="frames">The sequence of frame numbers of the animation. A value of null will play all frames of the animation texture.</param>
 /// <param name="fps">The speed, in frames per second, of the animation.</param>
 /// <param name="isLooping">Determines whether the animation is looping or not.</param>
 /// <param name="frameSpacing">The amount of space, in pixels, between each of the animation frames.</param>
 public GenAnimation(GenSprite sprite, int frameWidth, int frameHeight, int[] frames = null, int fps = 12, bool isLooping = true, int frameSpacing = 0)
 {
     _sprite = sprite;
     Frames = (frames == null) ? new int[0] : frames;
     _frameSpacing = frameSpacing;
     _currentFrame = 0;
     _position = Vector2.Zero;
     _frameRect = new Rectangle(0, 0, frameWidth, frameHeight);
     _frameTimer = new GenTimer(0f, UpdateFrame);
     Fps = fps;
     IsLooping = isLooping;
     FrameCallback = null;
 }