Esempio n. 1
0
File: Enemy.cs Progetto: lcraver/TM2
        public override void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine)
        {
            base.Update(gameTime, input, map, camera, entityManager, soundEngine);
            moveAnimation.IsActive = true;

            syncTilePosition = true;

            if (direction == 1)
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (direction == 2)
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            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;
            }

            ssAnimation.Update(gameTime, ref moveAnimation);
            moveAnimation.Position = position;

            if (gameTime.TotalGameTime - previousEnemySoundTime > enemySoundTime)
            {
                soundEngine.PlaySound("zombie moan", this.position);

                // Update the time left next enemy spawn
                previousEnemySoundTime = gameTime.TotalGameTime;
                var soundSeconds = random.Next(5, 8); // random should be a member of the class
                enemySoundTime = TimeSpan.FromSeconds(soundSeconds);
            }
        }
Esempio n. 2
0
File: Layer.cs Progetto: lcraver/TM2
        public void Update(GameTime gameTime, Camera camera, Map map)
        {
            minX = (int)(MathHelper.Clamp((camera.CurrentPosision.X - camera.HalfViewportWidth) / map.layer.TileDimensions.X - 3 / camera.Zoom, 0, this.MapDimensions.X));
            maxX = (int)(MathHelper.Clamp((camera.CurrentPosision.X + camera.HalfViewportWidth) / map.layer.TileDimensions.X + 3 / camera.Zoom, 0, this.MapDimensions.X));

            minY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y - camera.HalfViewportHeight) / map.layer.TileDimensions.Y - 3 / camera.Zoom, 0, this.MapDimensions.Y));
            maxY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y + camera.HalfViewportHeight) / map.layer.TileDimensions.Y + 3 / camera.Zoom, 0, this.MapDimensions.Y));

            for (int i = 0; i < tiles.Count; i++)
            {
                tiles[i].Update(gameTime);
            }
        }
Esempio n. 3
0
 public void Update(GameTime gameTime, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine)
 {
     for (int i = 0; i < entities.Count; i++)
         entities[i].Update(gameTime, inputManager, map, camera, entityManager, soundEngine);
 }
Esempio n. 4
0
        public override void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine)
        {
            if (shaking)
                camera.Zoom = 1.2f;
            else
                camera.Zoom = 1.0f;

            base.Update(gameTime, input, map, camera, entityManager, soundEngine);
            this.moveAnimation.IsActive = true;
            this.Bleeding = false;
            this.shaking = false;

            syncTilePosition = true;

            if (input.KeyDown(Keys.Right, Keys.D))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
                velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                this.direction = 0;
            }
            else if (input.KeyDown(Keys.Left, Keys.A))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
                velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                this.direction = 1;
            }
            else
            {
                velocity.X = 0;
            }

            if (input.KeyDown(Keys.Up, Keys.W) && !activateGravity)
            {
                velocity.Y = -jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                activateGravity = true;
            }

            if (activateGravity && this.velocity.Y > 0)
            {
                moveAnimation.IsActive = true;
                if (this.Direction == 1)
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 4);
                else
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 5);
            }
            else if (activateGravity && this.velocity.Y < 0)
            {
                moveAnimation.IsActive = true;
                if (this.Direction == 1)
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 6);
                else
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 7);
            }
            else if (!input.KeyDown(Keys.Up, Keys.W, Keys.Left, Keys.A, Keys.Right, Keys.D))
            {
                if (this.Direction == 1)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
                }
                else
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
                }
            }

            if (!input.KeyDown(Keys.Up, Keys.W, Keys.Left, Keys.A, Keys.Right, Keys.D) & velocity.X == 0)
            {
                moveAnimation.IsActive = true;
                if (this.Direction == 1)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                }
                else
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                }
            }

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

            position += velocity;

            moveAnimation.Position = position;
            ssAnimation.Update(gameTime, ref moveAnimation);

            particleEngine.EmitterLocation = new Vector2(this.Position.X + this.Animation.FrameWidth / 2, this.Position.Y + this.Animation.FrameHeight / 2);
            particleEngine.Update(map, gameTime);
        }
Esempio n. 5
0
        public virtual void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine)
        {
            syncTilePosition = false;
            prevPosition = position;

            camMinX = (int)(MathHelper.Clamp((camera.CurrentPosision.X - camera.HalfViewportWidth) / map.layer.TileDimensions.X - 3 / camera.Zoom, 0, map.layer.MapDimensions.X));
            camMaxX = (int)(MathHelper.Clamp((camera.CurrentPosision.X + camera.HalfViewportWidth) / map.layer.TileDimensions.X + 3 / camera.Zoom, 0, map.layer.MapDimensions.X));

            camMinY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y - camera.HalfViewportHeight) / map.layer.TileDimensions.Y - 3 / camera.Zoom, 0, map.layer.MapDimensions.Y));
            camMaxY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y + camera.HalfViewportHeight) / map.layer.TileDimensions.Y + 3 / camera.Zoom, 0, map.layer.MapDimensions.Y));
        }
Esempio n. 6
0
File: Map.cs Progetto: lcraver/TM2
 public void Update(GameTime gameTime, Camera camera, Map map)
 {
     layer.Update(gameTime, camera, map);
 }
Esempio n. 7
0
        /*
        Random random = new Random();

        TimeSpan previousEnemySoundTime, enemySoundTime;
         */
        public override void LoadContent(ContentManager content, InputManager input)
        {
            //make 1x1 pixel dummy texture
            pixel = content.Load<Texture2D>("fade");
            //pixel.SetData(new[] { Color.White });

            camera = new Camera(ScreenManager.Instance.graphicsDevice);
            //viewport = new Viewport(0, 0, (int)ScreenManager.Instance.Dimensions.X, (int)ScreenManager.Instance.Dimensions.Y);

            playerIndex = 0;
            zoom = 1.0f;

            font = content.Load<SpriteFont>("Coolvetica Rg 12");
            base.LoadContent(content, input);

            audio = new AudioManager();
            audio.LoadContent(content, "Map1");
            audio.MusicVolume = 0.5f;
            //audio.PlaySong(0, true);

            map = new Map();
            map.LoadContent(content, map, "Map1");

            player = new EntityManager();
            player.LoadContent("Player", content, "Load/Player.txt", "", input);
            //player.SetPlayer(playerIndex);

            enemies = new EntityManager();
            enemies.LoadContent("Enemy", content, "Load/Enemy.txt", "Level1", input);

            guiManager = new GUIManager();
            guiManager.LoadContent(content, "Map1");

            highlight = content.Load<Texture2D>("highlight");

            soundEngine = new SoundEngine();
            soundEngine.LoadContent(content);
        }