Exemple #1
0
        public TRex(Texture2D spriteSheet, Vector2 position, SoundEffect jumpSound)
        {
            Position              = position;
            _jumpSound            = jumpSound;
            _idleBackgroundSprite = new Sprite(spriteSheet, TREX_IDLE_BACKGROUND_SPRITE_POS_X, TREX_IDLE_BACKGROUND_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            State            = TRexState.Idle;
            _random          = new Random();
            _idleSprite      = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);

            _blinkAnimation = new SpriteAnimation();
            CreateBlinkAnimation();
            _blinkAnimation.Play();
            _startPosY    = position.Y;
            _runAnimation = new SpriteAnimation();
            _runAnimation.AddFrame(new Sprite(spriteSheet, TREX_RUNNING_SPRITE_ONE_POS_X, TREX_RUNNING_SPRITE_ONE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), 0);
            _runAnimation.AddFrame(new Sprite(spriteSheet, TREX_RUNNING_SPRITE_ONE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_RUNNING_SPRITE_ONE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_LENGTH);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, RUN_ANIMATION_FRAME_LENGTH * 2);
            _runAnimation.Play();

            _duckAnimation = new SpriteAnimation();
            _duckAnimation.AddFrame(new Sprite(spriteSheet, TREX_DUCKING_SPRITE_ONE_POS_X, TREX_DUCKING_SPRITE_ONE_POS_Y, TREX_DUCKING_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), 0);
            _duckAnimation.AddFrame(new Sprite(spriteSheet, TREX_DUCKING_SPRITE_ONE_POS_X + TREX_DUCKING_SPRITE_WIDTH, TREX_DUCKING_SPRITE_ONE_POS_Y, TREX_DUCKING_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_LENGTH);
            _duckAnimation.AddFrame(_duckAnimation[0].Sprite, RUN_ANIMATION_FRAME_LENGTH * 2);
            _duckAnimation.Play();

            _deadSprite = new Sprite(spriteSheet, TREX_DEAD_SPRITE_POS_X, TREX_DEAD_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);

            IsAlive = true;
        }
Exemple #2
0
        public Dino(Texture2D spritesheet, Vector2 position, SoundEffect jumpSound)
        {
            Position = position;

            _startPosY = Position.Y;

            _idleDinoBackgroundSprite = new Sprite(spritesheet, IDLE_BACKGROUND_SPRITE_X, IDLE_BACKGROUND_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);
            State = DinoState.Idle;

            _jumpSound = jumpSound;

            _random = new Random();

            _idleSprite      = new Sprite(spritesheet, DINO_SPRITE_X, DINO_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spritesheet, DINO_SPRITE_X + DINO_SPRITE_WIDTH, DINO_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);

            _blinkAnimation = new SpriteAnimation();
            CreateBlinkAnimation();
            _blinkAnimation.Play();

            _runAnimation = new SpriteAnimation();
            _runAnimation.AddFrame(new Sprite(spritesheet, DINO_RUNNING_SPRITE_ONE_X, DINO_RUNNING_SPRITE_ONE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), 0);
            _runAnimation.AddFrame(new Sprite(spritesheet, DINO_RUNNING_SPRITE_TWO_X, DINO_RUNNING_SPRITE_TWO_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_DURATION);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, RUN_ANIMATION_FRAME_DURATION * 2);
            _runAnimation.Play();

            _duckAnimation = new SpriteAnimation();
            _duckAnimation.AddFrame(new Sprite(spritesheet, DINO_DUCKING_SPRITE_ONE_X, DINO_DUCKING_SPRITE_ONE_Y, DINO_DUCKING_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), 0);
            _duckAnimation.AddFrame(new Sprite(spritesheet, DINO_DUCKING_SPRITE_ONE_X + DINO_DUCKING_SPRITE_WIDTH, DINO_DUCKING_SPRITE_ONE_Y, DINO_DUCKING_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_DURATION);
            _duckAnimation.AddFrame(_duckAnimation[0].Sprite, RUN_ANIMATION_FRAME_DURATION * 2);
            _duckAnimation.Play();
        }
Exemple #3
0
        public TRex(Texture2D spritesheet, Vector2 position, SoundEffect jumpSound)
        {
            this.Position   = position;
            this._JumpSound = jumpSound;
            _IdleBackGround = new Sprite(spritesheet, _IdleBAckGround_posX, _IdleBAckGround_posY, TrexWidth, TrexHeiht);
            State           = TrexState.idle;
            _random         = new Random();

            _IdleSprit       = new Sprite(spritesheet, Trexpos, TrexYpos, TrexWidth, TrexHeiht);
            _IdleBlinkSprite = new Sprite(spritesheet, Trexpos + TrexWidth, TrexYpos, TrexWidth, TrexHeiht);
            _BlinkAnimation  = new SpriteAnimation();

            CreateBlinkAnimation();
            _BlinkAnimation.Play();

            _startposy = Position.Y;


            _runAnimation = new SpriteAnimation();

            _runAnimation.AddFrame(new Sprite(spritesheet, Trexpos + TrexWidth * 2, TrexYpos, TrexWidth, TrexHeiht), 0);
            _runAnimation.AddFrame(new Sprite(spritesheet, Trexpos + TrexWidth * 3, TrexYpos, TrexWidth, TrexHeiht), Run_Length);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, Run_Length * 2);

            _runAnimation.Play();
            _runAnimation.ShouldLoop = true;

            _DuckingAnimation = new SpriteAnimation();
            _DuckingAnimation.AddFrame(new Sprite(spritesheet, Trex_Ducking_X, TrexYpos, TREX_DUCKING_WITDH, TrexHeiht), 0);
            _DuckingAnimation.AddFrame(new Sprite(spritesheet, Trex_Ducking_X + TREX_DUCKING_WITDH, TrexYpos, TREX_DUCKING_WITDH, TrexHeiht), Run_Length);
            _DuckingAnimation.AddFrame(_DuckingAnimation[0].Sprite, Run_Length * 2);

            _DuckingAnimation.Play();
        }
Exemple #4
0
        private void CreateBlinkAnimation()
        {
            _blinkAnimation.Clear();
            _blinkAnimation.ShoudLoop = false;
            double blinkTimeStamp = BLINK_ANIMATION_RANDOM_MIN + _random.NextDouble() * (BLINK_ANIMATION_RANDOM_MAX - BLINK_ANIMATION_RANDOM_MIN);

            _blinkAnimation.AddFrame(_idleSprite, 0);
            _blinkAnimation.AddFrame(_idleBlinkSprite, (float)blinkTimeStamp);
            _blinkAnimation.AddFrame(_idleSprite, (float)blinkTimeStamp + BLINK_ANIMATION_EYE_CLOSE_TIME);
        }
Exemple #5
0
        private void CreateBlinkAnimation()
        {
            _BlinkAnimation.Clear();
            _BlinkAnimation.ShouldLoop = false;

            double BlinktimeStamp = 2f + _random.NextDouble() * (10f - 2f);

            _BlinkAnimation.AddFrame(_IdleSprit, 0);
            _BlinkAnimation.AddFrame(_IdleBlinkSprite, (float)BlinktimeStamp);
            _BlinkAnimation.AddFrame(_IdleSprit, (float)BlinktimeStamp + Blink_Animation);
        }
Exemple #6
0
        private void CreateBlinkAnimation()
        {
            _blinkAnimation.Clear();
            _blinkAnimation.ShouldLoop = false;

            double blinkTimeStamp = DINO_BLINK_MIN_TIME + _random.NextDouble() * (DINO_BLINK_MAX_TIME - DINO_BLINK_MIN_TIME);

            _blinkAnimation.AddFrame(_idleSprite, 0);
            _blinkAnimation.AddFrame(_idleBlinkSprite, (float)blinkTimeStamp);
            _blinkAnimation.AddFrame(_idleSprite, (float)blinkTimeStamp + BLINK_ANIMATION_DURATION);
        }
Exemple #7
0
        private void CreateAnimation(Texture2D spriteSheet)
        {
            Sprite spriteA = new Sprite(spriteSheet, DINO_TEXTURE_COORDS_X, DINO_TEXTURE_COORDS_Y, DINO_WIDTH, DINO_HEIGHT);
            Sprite spriteB = new Sprite(spriteSheet, DINO_TEXTURE_COORDS_X + DINO_WIDTH, DINO_TEXTURE_COORDS_Y, DINO_WIDTH, DINO_HEIGHT);

            _animation = new SpriteAnimation();

            _animation.AddFrame(spriteA, 0);
            _animation.AddFrame(spriteB, FRAME_LENGTH);
            _animation.AddFrame(spriteA, FRAME_LENGTH * 2);

            _animation.ShouldLoop = true;
            _animation.Play();
        }
        public FlyingDino(Trex trex, Vector2 position, Texture2D spriteSheet) : base(trex, position)
        {
            Sprite spriteA = new Sprite(spriteSheet, TEXTURE_COORDS_X, TEXTURE_COORDS_Y, SPRITE_WIDTH, SPRITE_HEIGHT);
            Sprite spriteB = new Sprite(spriteSheet, TEXTURE_COORDS_X + SPRITE_WIDTH, TEXTURE_COORDS_Y, SPRITE_WIDTH, SPRITE_HEIGHT);

            _trex = trex;

            _animation = new SpriteAnimation();
            _animation.AddFrame(spriteA, 0);
            _animation.AddFrame(spriteB, ANIMATION_FRAME_LENGTH);
            _animation.AddFrame(spriteA, ANIMATION_FRAME_LENGTH * 2);
            _animation.ShouldLoop = true;
            _animation.Play();
        }
Exemple #9
0
        /// <summary>
        /// returns a SpriteAnimation given an animationName where the animationName is the folder that contains the images
        /// </summary>
        /// <returns>The sprite animation.</returns>
        /// <param name="animationName">Animation name.</param>
        public SpriteAnimation GetSpriteAnimation(string animationName)
        {
            // create the cache Dictionary if necessary. Return the animation direction if already cached.
            if (_spriteAnimations == null)
            {
                _spriteAnimations = new Dictionary <string, SpriteAnimation>();
            }
            else if (_spriteAnimations.ContainsKey(animationName))
            {
                return(_spriteAnimations[animationName]);
            }

            Point point;

            if (_spriteAnimationDetails.TryGetValue(animationName, out point))
            {
                var animation = new SpriteAnimation {
                    Fps = _animationFPS
                };

                for (var i = point.X; i <= point.Y; i++)
                {
                    animation.AddFrame(Subtextures[i]);
                }

                _spriteAnimations[animationName] = animation;

                return(animation);
            }

            throw new KeyNotFoundException(animationName);
        }
Exemple #10
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);

            font   = Content.Load <SpriteFont>("font");
            cursor = new SpriteSheet("cursor");
            cursor.LoadTexture(Content, 1, 1);
            cursor.SetScale(2f);
            cursor.SetCurrentSprite(0, 0);

            movePointer = new SpriteAnimation("movepointer", Content, 8, 1);
            movePointer.SetScale(1f);
            for (int i = 0; i < 8; i++)
            {
                movePointer.AddFrame(i, 0, 50);
            }

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(Physics.World);
                DebugView.AppendFlags(DebugViewFlags.DebugPanel);
                DebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.Red;
                DebugView.LoadContent(GraphicsDevice, Content);
            }
        }
Exemple #11
0
 public Nom(ContentManager content)
 {
     _spriteAnim = new SpriteAnimation("nomnom", content, 10, 1);
     for (int i = 0; i < 10; i++)
     {
         _spriteAnim.AddFrame(i, 0, 100);
     }
     _offsetPos        = new Vector2(0, -_spriteBottomOffset * _size);
     _centerOfRotation = new Vector2(_width * 0.5f, _height - _spriteBottomOffset);
 }
Exemple #12
0
        private void LoadAnimations()
        {
            if (!File.Exists("Content/" + name + ".txt"))
            {
                return;
            }

            string[] lines = File.ReadAllLines("Content/" + name + ".txt"); //Read the textfile for the animations

            //parse every line
            for (int i = 0; i < lines.Length; i++)
            {
                string[] data = lines[i].Split(' ');

                //every line needs at least 2 arguments
                if (data.Length < 2)
                {
                    continue;
                }

                GoombaState state  = (GoombaState)Enum.Parse(typeof(GoombaState), data[0]);
                int         length = int.Parse(data[1]);

                //parse the optional looping for animations
                bool loopable = false;
                if (data.Length > 2)
                {
                    loopable = ("loop" == data[2]);
                }

                //parse the optional speed for animations
                float speed = 1;
                if (data.Length > 3)
                {
                    speed = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture);
                }

                //create the animation and fill it with frames
                SpriteAnimation animation = new SpriteAnimation(loopable, speed);
                for (int j = i * frameCount.X; j < i * frameCount.X + length; j++)
                {
                    animation.AddFrame(j);
                }

                animations.Add(state, animation); //add the animation to the hashmap
            }
        }
        public GameObject SpawnFire(float positionX, float positionY, int life)
        {
            int        thisGameObjectType = (int)PyroGameObjectTypes.Fire;
            GameObject result             = mGameObjectPool.Allocate();

            result.SetPosition(positionX, positionY);
            result.ActivationRadius = mActivationRadius_AlwaysActive;
            result.width            = 32;
            result.height           = 32;

            result.life = life;
            result.team = GameObject.Team.NONE;


            FixedSizeArray <BaseObject> staticData = GetStaticData(thisGameObjectType);

            if (staticData == null)
            {
                ContentManager content           = sSystemRegistry.Game.Content;
                int            staticObjectCount = 10;
                staticData = new FixedSizeArray <BaseObject>(staticObjectCount);

                // Animation Data
                float     animationDelay = 0.16f;
                const int fileImageSize  = 64;
                Rectangle crop           = new Rectangle(0, 0, fileImageSize, fileImageSize);

                SpriteAnimation fire100 = new SpriteAnimation((int)FireAnimation.Fire100, 2);
                fire100.Loop = true;
                fire100.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire1"), animationDelay, crop));
                fire100.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire1"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                SpriteAnimation fire80 = new SpriteAnimation((int)FireAnimation.Fire80, 2);
                fire80.Loop = true;
                fire80.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire2"), animationDelay, crop));
                fire80.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire2"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                SpriteAnimation fire60 = new SpriteAnimation((int)FireAnimation.Fire60, 2);
                fire60.Loop = true;
                fire60.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire3"), animationDelay, crop));
                fire60.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire3"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                SpriteAnimation fire40 = new SpriteAnimation((int)FireAnimation.Fire40, 2);
                fire40.Loop = true;
                fire40.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire4"), animationDelay, crop));
                fire40.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire4"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                SpriteAnimation fire20 = new SpriteAnimation((int)FireAnimation.Fire20, 2);
                fire20.Loop = true;
                fire20.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire5"), animationDelay, crop));
                fire20.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire5"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                SpriteAnimation fire0 = new SpriteAnimation((int)FireAnimation.Fire0, 2);
                fire0.Loop = true;
                fire0.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire6"), animationDelay, crop));
                fire0.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire6"), animationDelay, crop, SpriteEffects.FlipHorizontally));

                //animations
                staticData.Add(fire100);
                staticData.Add(fire80);
                staticData.Add(fire60);
                staticData.Add(fire40);
                staticData.Add(fire20);
                staticData.Add(fire0);

                SetStaticData(thisGameObjectType, staticData);
            }

            RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent));

            render.Priority       = PyroSortConstants.FIRE;
            render.CameraRelative = true;

            SpriteComponent sprite = (SpriteComponent)AllocateComponent(typeof(SpriteComponent));

            sprite.SetSize((int)result.width, (int)result.height);
            sprite.SetRenderComponent(render);
            sprite.SetRenderMode(SpriteComponent.RenderMode.RotateToFacingDirection);

            LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>();

            result.Add(render);
            result.Add(lifetime);
            result.Add(sprite);

            AddStaticData(thisGameObjectType, result, sprite);

            sprite.PlayAnimation((int)FireAnimation.Fire100);

            return(result);
        }
        public GameObject SpawnPlayerDead(float positionX, float positionY, Vector2 facingDir)
        {
            int        thisGameObjectType = (int)PyroGameObjectTypes.PlayerDead;
            GameObject result             = mGameObjectPool.Allocate();

            result.SetPosition(positionX, positionY);
            result.ActivationRadius = mActivationRadius_AlwaysActive;
            result.width            = 32;
            result.height           = 32;
            result.facingDirection  = facingDir;

            result.life = 1;
            result.team = GameObject.Team.NONE;


            FixedSizeArray <BaseObject> staticData = GetStaticData(thisGameObjectType);

            if (staticData == null)
            {
                ContentManager content           = sSystemRegistry.Game.Content;
                int            staticObjectCount = 1;
                staticData = new FixedSizeArray <BaseObject>(staticObjectCount);

                // Animation Data
                float     animationDelay = 0.16f;
                Rectangle crop32         = new Rectangle(0, 0, 32, 32);
                //Idle
                SpriteAnimation idle = new SpriteAnimation((int)Animations.Idle, 2);
                idle.Loop = true;
                idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_Death"), animationDelay, crop32));
                idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_Death"), animationDelay, crop32, SpriteEffects.FlipHorizontally));

                //animations
                staticData.Add(idle);

                SetStaticData(thisGameObjectType, staticData);
            }

            RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent));

            render.Priority       = PyroSortConstants.PLAYER;
            render.CameraRelative = true;

            SpriteComponent sprite = (SpriteComponent)AllocateComponent(typeof(SpriteComponent));

            sprite.SetSize((int)result.width, (int)result.height);
            sprite.SetRenderComponent(render);
            sprite.SetRenderMode(SpriteComponent.RenderMode.RotateToFacingDirection);

            LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>();

            result.Add(render);
            result.Add(lifetime);
            result.Add(sprite);

            AddStaticData(thisGameObjectType, result, sprite);

            sprite.PlayAnimation((int)Animations.Idle);

            return(result);
        }
Exemple #15
0
 public void CreateDuckingAnimation()
 {
     _duckAnimation.AddFrame(_duckSpriteOne, 0);
     _duckAnimation.AddFrame(_duckSpriteTwo, ANIMATION_FRAME_LENGTH);
     _duckAnimation.AddFrame(_duckSpriteOne, ANIMATION_FRAME_LENGTH * 2);
 }
Exemple #16
0
 public void CreateRunAnimation()
 {
     _runAnimation.AddFrame(_runningSpriteOne, 0);
     _runAnimation.AddFrame(_runningSpriteTwo, ANIMATION_FRAME_LENGTH);
     _runAnimation.AddFrame(_runningSpriteOne, ANIMATION_FRAME_LENGTH * 2);
 }