public override void Update(GameTime gameTime, ref Animation a)
        {
            currentFrame = a.CurrentFrame;
            if (a.IsActive)
            {
                frameCounter += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (frameCounter >= switchFrame)
                {
                    frameCounter = 0;
                    currentFrame.X++;

                    if (currentFrame.X * a.FrameWidth >= a.Image.Width)
                        currentFrame.X = 0;
                }
            }
            else
            {
                frameCounter = 0;
                if (currentFrame.Y == 0)
                    currentFrame.X = 3;
                else
                    currentFrame.X = 0;
            }
            a.CurrentFrame = currentFrame;
            a.SourceRect = new Rectangle((int)a.CurrentFrame.X * a.FrameWidth, (int)a.CurrentFrame.Y * a.FrameHeight, 
                a.FrameWidth, a.FrameHeight);
        }
示例#2
0
 public void SetTile(State state, Motion motion, Vector2 position, Texture2D tileSheet, Rectangle tileArea)
 {
     this.state = state;
     this.motion = motion;
     this.position = position;
     increase = true;
     moveSpeed = 100f;
     tileImage = CropImage(tileSheet, tileArea);
     range = 50;
     counter = 0;
     animation = new Animation();
     animation.LoadContent(ScreenManager.Instance.Content, tileImage, "", position);
     containsEntity = false;
     velocity = Vector2.Zero;
 }
示例#3
0
        public override void Update(GameTime gameTime, ref Animation a)
        {
            if (a.IsActive)
            {
                if (!stopUpdating)
                {
                    if (!increase)
                        a.Alpha -= fadeSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    else
                        a.Alpha += fadeSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (a.Alpha <= 0.0f)
                    {
                        a.Alpha = 0.0f;
                        increase = !increase;
                    }
                    else if (a.Alpha >= 1.0f)
                    {
                        a.Alpha = 1.0f;
                        increase = false;
                    } 
               }

                if (a.Alpha == activateValue)
                {
                    stopUpdating = true;
                    timer -= gameTime.ElapsedGameTime;
                    if (timer.TotalSeconds <= 0)
                    {
                        timer = defaultTime;
                        stopUpdating = false;

                    }
                }
            }
            else
            {
                a.Alpha = defaultAlpha;
                stopUpdating = false;
            }
        }
示例#4
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
            bulletText = Content.Load<Texture2D>("bullet");
            Animation playerAnimation = new Animation();
            Texture2D tank = Content.Load<Texture2D>("tank");
            playerAnimation.Initialize(tank,
                                           new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2),
                                           tank.Width,
                                           tank.Height,
                                           1,0,Color.White,1f,true);
            player = new Player();
            player.Initialize(new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2), tank, 10f);

            enemyText = Content.Load<Texture2D>("garfield");

            sf = Content.Load<SpriteFont>("gameFont");
        }
示例#5
0
        public virtual void LoadContent(ContentManager content, List<string> attributes, List<string> contents, InputManager input)
        {
            this.content = new ContentManager(content.ServiceProvider, "Content");
            moveAnimation = new Animation();
            ssAnimation = new SpriteSheetAnimation();
            for (int i = 0; i < attributes.Count; i++)
            {
                switch (attributes[i])
                {
                    case "Health":
                        health = int.Parse(contents[i]);
                        break;
                    case "Frames":
                        string[] frames = contents[i].Split(',');
                        moveAnimation.Frames = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                        break;
                    case "Image":
                        image = this.content.Load<Texture2D>(contents[i]);
                        break;
                    case "Position":
                        frames = contents[i].Split(',');
                        position = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                        break;
                    case "MoveSpeed":
                        moveSpeed = float.Parse(contents[i]);
                        break;
                    case "Range":
                        range = int.Parse(contents[i]);
                        break;
                }
            }

            gravity = 100f;
            velocity = Vector2.Zero;
            syncTilePostion = false;
            activateGravity = true;
            moveAnimation.LoadContent(content, image, "", position);
        }
示例#6
0
 public virtual void UnloadContent()
 {
     content.Unload();
     moveAnimation = null;
     gravity = 0.0f;
     syncTilePostion = false;
     activateGravity = false;
     velocity = Vector2.Zero;
     ssAnimation = null;
 }
示例#7
0
 public virtual void Update(GameTime gameTime, ref Animation a)
 { 
 
 }