예제 #1
0
파일: Map.cs 프로젝트: kwhalen89/XNA-game
 public void LoadContent(ContentManager content, Map map, string mapID)
 {
     layer1 = new Layer();
     collision = new Collision();
     id = mapID;
     layer1.LoadContent(map, "Layer1");
     //layer2.LoadContent(map, "Layer2");
     collision.LoadContent(content, mapID);
 }
예제 #2
0
파일: Enemy.cs 프로젝트: kwhalen89/XNA-game
        public override void Update(GameTime gameTime, InputManager input, Collision col, Layer layer)
        {
            base.Update(gameTime, input, col, layer);
            moveAnimation.DrawColor = Color.White;
            if(direction == 1)
            {
                velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
            }
            else if(direction == 2)
            {
                velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
            }

            if (activateGravity)
                velocity.Y += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            else
                velocity.Y = 0;

            position += velocity;

            if(direction == 1 && position.X >= destPosition.X)
            {
                direction = 2;
                destPosition.X = origPosition.X - range;
            }
            else if(direction == 2 && position.X <= destPosition.X)
            {
                direction = 1;
                destPosition.X = origPosition.X + range;
            }

            moveAnimation.Position = position;
            ssAnimation.Update(gameTime, ref moveAnimation);
        }
예제 #3
0
        public override void Update(GameTime gameTime, InputManager input, Collision col, Layer layer)
        {
            base.Update(gameTime, input, col, layer);
            moveAnimation.DrawColor = Color.White;
            moveAnimation.IsActive = true; //will be true and makes player move through row of animations as long as the the last else isn't true which turns animation back off
            if (health > 0)
            {
                if (input.KeyDown(Keys.Right, Keys.D))
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0); //moves to row 0 the row looking right on sprite sheet
                    velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    Direction = 0;
                    if (sound.WalkingInstance.State == SoundState.Stopped)
                    {
                        sound.WalkingInstance.Volume = 0.75f;
                        sound.WalkingInstance.IsLooped = true;
                        sound.WalkingInstance.Play();
                    }
                    else
                        sound.WalkingInstance.Resume();

                }
                else if (input.KeyDown(Keys.Left, Keys.A))
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1); //moves to row 1 the row looking left on sprite sheet
                    velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    Direction = 1;
                    if (sound.WalkingInstance.State == SoundState.Stopped)
                    {
                        sound.WalkingInstance.Volume = 0.75f;
                        sound.WalkingInstance.IsLooped = true;
                        sound.WalkingInstance.Play();
                    }
                    else
                        sound.WalkingInstance.Resume();
                }
                else
                {
                    moveAnimation.IsActive = false; //if key isn't pressed turn off X axis scrolling on sprite sheet  
                    velocity.X = 0;
                    if (sound.WalkingInstance.State == SoundState.Playing)
                        sound.WalkingInstance.Pause();
                }
                if (input.KeyDown(Keys.Up, Keys.W) && !activateGravity)
                {
                    velocity.Y = -jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    activateGravity = true;
                    sound.Jump.Play();
                }
                if (activateGravity)
                    velocity.Y += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                else
                    velocity.Y = 0;

                if (input.KeyDown(Keys.R) && keyPressed == false) //if R is pressed add a bullet as long as key isn't already pressed
                {
                    if (Direction == 0)
                        bullets1.Add(position);
                    else
                        bullets2.Add(position);
                    keyPressed = true;
                }
                if (Keyboard.GetState().IsKeyUp(Keys.R)) //only way to fire again is to unpress key
                    keyPressed = false;

                for (int i = 0; i < bullets1.Count; i++)
                {
                    float x = bullets1[i].X;
                    x += bulletSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    bullets1[i] = new Vector2(x, bullets1[i].Y);
                }

                for (int i = 0; i < bullets2.Count; i++)
                {
                    float x = bullets2[i].X;
                    x -= bulletSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    bullets2[i] = new Vector2(x, bullets2[i].Y);
                }
                position += velocity;
                moveAnimation.Position = position;
                ssAnimation.Update(gameTime, ref moveAnimation);
                Camera.Instance.SetFocalPoint(new Vector2(position.X, ScreenManager.Instance.Dimensions.Y / 2));
            }
        }
예제 #4
0
 public virtual void Update(GameTime gameTime, InputManager input, Collision col, Layer layer)
 {
     syncTilePostion = false;
     prevPosition = position;
 }