Example #1
0
        public Sprite(Animation ani, Animation glowAni)
        {
            this.ani = ani;
            this.glowAni = glowAni;

            left = 0;
            top = 0;
            m_color = Color.White;
        }
Example #2
0
        public Sprite(AnimationData aniData, AnimationData glowAniData)
        {
            this.ani = new Animation(aniData);
            this.glowAni = new Animation(glowAniData);

            left = 0;
            top = 0;
            m_color = Color.White;
        }
 public void PlayAnimation(Animation animation)
 {
     if (Animation == animation)
     {
         return;
     }
     this.animation = animation;
     this.frameIndex = 0;
     this.time = 0.0f;
 }
Example #4
0
        public Projectile(double pX, double pY, double velX, double velY, PhysicsSprite.PlayerType creatorId, PhysicsSprite.GlowType glowType)
        {
            this.posX = pX;
            this.posY = pY;
            this.velX = velX / 100;
            this.velY = velY / 100;
            this.creatorId = creatorId;
            this.glowType = glowType;

            ani = new Animation(Game1.Instance.gameData.animations[getGlowFlyAniIndex(glowType)]);
            ani.start();
        }
Example #5
0
        public void Initialize(Animation _animation, Vector2 position)
        {
            //PlayerTexture = texture;
            animation = _animation;
            this.position = position;

            active = true;

            healt = 100;
            playerMoveSpeed = 8.0f;

            currentKbState = new KeyboardState();
            previousKbState = new KeyboardState();
        }
        public void LoadContent(int choice)
        {
            if (choice == 1)
            {
                idleSprite = content.Load<Texture2D>("HeroAsset/IdleHero");
                attackSprite = content.Load<Texture2D>("HeroAsset/AttackHero");

                idleAnimation = new Animation(idleSprite, 0.2f, true, 4);
                attackAnimation = new Animation(attackSprite, 0.2f, true, 4);

                int positionX = 150;
                int positionY = 300;

                PlayerPosition = new Vector2(positionX, positionY);
            }
            else if(choice == 2)
            {
                idleSprite = content.Load<Texture2D>("Support/SpriteSheetSup1");

                idleAnimation = new Animation(idleSprite, 0.2f, true, 3);

                int positionX = 0;
                int positionY = 150;

                PlayerPosition = new Vector2(positionX, positionY);
            }
            else if(choice == 3)
            {
                idleSprite = content.Load<Texture2D>("Support/SpriteSheetSup2");

                idleAnimation = new Animation(idleSprite, 0.2f, true, 3);

                int positionX = 300;
                int positionY = 150;

                PlayerPosition = new Vector2(positionX, positionY);
            }

            if (stateChange == 0)
            {
                spritePlayer.PlayAnimation(idleAnimation);
            }
            else if(stateChange == 1)
            {
                spritePlayer.PlayAnimation(attackAnimation);
            }

            //spriteSupport.PlayAnimation(supportAnimation);
            //spriteSupport2.PlayAnimation(support2Animation);
        }
Example #7
0
 private void playHitAni()
 {
     ani = new Animation(Game1.Instance.gameData.animations[getGlowHitAniIndex(glowType)]);
     ani.start();
 }
Example #8
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);
            // TODO: use this.Content to load your game content here

            Animation playerAnimation = new Animation();
            Texture2D playerTexture = Content.Load<Texture2D>("animations/shipAnimation");

            playerAnimation.Initialize( playerTexture, Vector2.Zero, 115, 69, 8, 30, Color.White, 1f, true );

            Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X,
                GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            player.Initialize(playerAnimation, playerPosition);

            //player.Initialize(Content.Load<Texture2D>("player"), playerPosition);
        }
        /* ***********************************
         * Methods Relating to Animation
         * 
         *************************************/


        /*
         * Create animation object from sprite sheet and frame names.
         * 
         * 
         */

        public Animation AnimationForFrameNames(String[] frameNames, int frameTime, Color frameColor, bool isLooping)
        {
            // create animation object.
            Animation animation = new Animation();
            // create frames array.
            Frame[] frames = new Frame[frameNames.Length];

            // loop through frameNames and poplulate Frame array.
            for ( int i = 0; i < frameNames.Length; i++ )
            {
                frames[i] = SpriteFrameByFrameName(frameNames[i]);   
            }

            // initialize animation and return.
            animation.Initialize(_texture, frames, frameTime, frameColor, isLooping);
            return animation;
        }
Example #10
0
        public override void update(GameTime frameTime)
        {
            base.update(frameTime);

            float dt = (float)(frameTime.ElapsedGameTime.Seconds + frameTime.ElapsedGameTime.Milliseconds * 0.001);

            int newAniIndex = ANI_IDLE;
            if (m_dyingTimer > 0)
            {
                newAniIndex = ANI_DIE;
                m_dyingTimer -= dt;
                byte lum = (byte)(255 * m_dyingTimer / m_deathTime);
                m_color.R = m_color.G = m_color.B = lum;
                if ( m_dyingTimer <=  0.0 )
                {
                    m_dyingTimer = 0.0;
                    Game1.Instance.setState(Game1.State.STATE_SCORES);
                }
            }
            else
            {
                m_velocity += m_acceleration * dt;
                Vector2 position = m_position + m_velocity * dt;
                m_lastDelta = dt;

                bool killVeloX = false;
                bool killVeloY = false;
                if (position.X < 0)
                {
                    killVeloX = true;
                    position.X = 0;
                }
                if (position.X + width >= 256)
                {
                    killVeloX = true;
                    position.X = 255 - width;
                }
                if (position.Y < 0)
                {
                    killVeloY = true;
                    position.Y = 0;
                }
                if (position.Y + height >= 240)
                {
                    killVeloY = true;
                    toggleGlowType();
                    position.Y = 239 - height;
                }

                //downward checks (left middle right)
                {
                    double minY = 240;
                    bool collide = false;
                    float insideHeight = height - 1;
                    Vector2 insideLeftBotOffset = new Vector2(0, insideHeight);
                    Vector2 insideMidBotOffset = new Vector2(width / 2, insideHeight);
                    Vector2 insideRightBotOffset = new Vector2(width - 1, insideHeight);
                    //                collide = CollisionDownHelper(collide, insideLeftBotOffset, position, minY, out minY);
                    collide = CollisionDownHelper(collide, insideMidBotOffset, position, minY, out minY);
                    collide = CollisionDownHelper(collide, insideRightBotOffset, position, minY, out minY);
                    minY -= insideHeight + 1;
                    if (collide)
                    {
                        killVeloY = true;
                        position.Y = Math.Max(0, (float)minY); toggleGlowType();
                    }
                }
                //up checks (left, middle, right)
                {
                    double maxY = 0;
                    bool collide = false;
                    Vector2 insideLeftTopOffset = new Vector2(0, 0);
                    Vector2 insideMidTopOffset = new Vector2(width / 2, 0);
                    Vector2 insideRightTopOffset = new Vector2(width - 1, 0);
                    collide = CollisionUpHelper(collide, insideLeftTopOffset, position, maxY, out maxY);
                    collide = CollisionUpHelper(collide, insideMidTopOffset, position, maxY, out maxY);
                    collide = CollisionUpHelper(collide, insideRightTopOffset, position, maxY, out maxY);
                    if (collide)
                    {
                        killVeloY = true;
                        position.Y = Math.Min(239 - height, (float)maxY + 1);
                    }
                }

                //fwd checks (in quarters top to bottom)
                {
                    bool collide = false, isSlash = false, isBSlash = false;
                    float insideWidth = width - 1;
                    double minY = 240;
                    Vector2 insideRight0Offset = new Vector2(insideWidth, 0);
                    Vector2 insideRight1Offset = new Vector2(insideWidth, height / 3);
                    Vector2 insideRight2Offset = new Vector2(insideWidth, 2 * height / 3);
                    Vector2 insideRight3Offset = new Vector2(insideWidth, height - 1);
                    double fakeY = 240;
                    collide = CollisionRightHelper(collide, insideRight0Offset, position, fakeY, out fakeY, isSlash, out isSlash, isBSlash, out isBSlash);
                    collide = CollisionRightHelper(collide, insideRight1Offset, position, fakeY, out fakeY, isSlash, out isSlash, isBSlash, out isBSlash);
                    collide = CollisionRightHelper(collide, insideRight2Offset, position, minY, out minY, isSlash, out isSlash, isBSlash, out isBSlash);
                    collide = CollisionRightHelper(collide, insideRight3Offset, position, minY, out minY, isSlash, out isSlash, isBSlash, out isBSlash);
                    if (collide)
                    {
                        minY -= height; //wrong for all but last who cares
                        if (isSlash || isBSlash) //slide
                        {
                            position.Y = Math.Min(239 - height, (float)minY - 3);
                        }
                        else
                        {
                            killVeloX = true;
                            //m_color = Color.Red;
                            m_dyingTimer = m_deathTime;
                            foreach (Layer layer in Game1.Instance.gameData.layers)
                            {
                                layer.setSpeed(0.0);
                            }
                        }
                    }
                    /*else
                    {
                        m_color = Color.White;
                    }
                    */
                }

                if (killVeloX) m_velocity.X = 0;
                if (killVeloY) m_velocity.Y = 0;

                m_position = position;

                //patch back the info
                Left = (int)m_position.X;
                Top = (int)m_position.Y;

                if (m_velocity.Y != 0.0)
                {
                    double threshold = 120;
                    if (m_velocity.Y < -threshold) newAniIndex = ANI_JUMP_LEAP;
                    else if (m_velocity.Y >= -threshold && m_velocity.Y < threshold)
                    {
                        newAniIndex = ANI_JUMP_HANG;
                    }
                    else newAniIndex = ANI_JUMP_DROP;
                }
                else
                {
                    newAniIndex = ANI_RUN;
                }
            }

            if (lastAniIndex != newAniIndex)
            {
                ani = new Animation(Game1.Instance.gameData.animations[getPlayerAniIndex(newAniIndex)]);
                ani.start();

                if (newAniIndex == ANI_DIE)
                {
                    glowAni = null;
                }
                else
                {
                    glowAni = new Animation(Game1.Instance.gameData.animations[getPlayerGlowAniIndex(newAniIndex)]);
                    glowAni.start();
                }
                lastAniIndex = newAniIndex;
            }
        }
Example #11
0
        public void Load()
        {
            Stand = new Animation((Texture2D)Storage.Images["Sprites/" + Name + "/Stand"],100);
            Move = new Animation((Texture2D)Storage.Images["Sprites/" + Name + "/Move"],100);
            Shoot = new Animation((Texture2D)Storage.Images["Sprites/" + Name + "/Shoot"],100);
            Die = new Animation((Texture2D)Storage.Images["Sprites/" + Name + "/Die"],100);
            state = State.Stand;

            base.LoadContent();
        }
        public void LoadContent()
        {
            idleSprite = content.Load<Texture2D>("Monster/MonsterO1");
            hitSprite = content.Load<Texture2D>("Monster/MonsterO1Hit");

            #region HpBar
            HundredHP = content.Load<Texture2D>("HP/100");
            NinetyHP = content.Load<Texture2D>("HP/90");
            EightyHP = content.Load<Texture2D>("HP/80");
            SeventyHP = content.Load<Texture2D>("HP/70");
            SixtyHP = content.Load<Texture2D>("HP/60");
            FiftyHP = content.Load<Texture2D>("HP/50");
            FourtyHP = content.Load<Texture2D>("HP/40");
            ThirtyHP = content.Load<Texture2D>("HP/30");
            TwentyHP = content.Load<Texture2D>("HP/20");
            TenHP = content.Load<Texture2D>("HP/10");
            ZeroHP = content.Load<Texture2D>("HP/0");
            #endregion

            curHpTex = HundredHP;
            idleAnimation = new Animation(idleSprite, 0.2f, true, 6);
            HitAnimation = new Animation(hitSprite, 0.2f, true, 3);

            int positionX = 100;
            int positionY = 150;
            PlayerPosition = new Vector2(positionX, positionY);

            if (stateChange == 0)
            {
                spritePlayer.PlayAnimation(idleAnimation);
            }
            else if (stateChange == 1)
            {
                spritePlayer.PlayAnimation(HitAnimation);
            }
        }