Esempio n. 1
0
 public void EntityCollision(EntityManager E2, SoundEngine soundEngine)
 {
     foreach (Entity e in entities)
     {
         foreach (Entity e2 in E2.entities)
         {
             if (e.Rect.Intersects(e2.Rect))
                 e.OnCollision(e2, soundEngine);
         }
     }
 }
Esempio n. 2
0
        public override void OnCollision(Entity e, SoundEngine soundEngine)
        {
            Type type = e.GetType();

            if (type == typeof(Enemy))
            {
                health--;
                bleeding = true;
                shaking = true;
                soundEngine.PlaySound("mario shrink");
            }
        }
Esempio n. 3
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. 4
0
File: Layer.cs Progetto: lcraver/TM2
 public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine)
 {
     for (int i = 0; i < tiles.Count; i++)
     {
         tiles[i].UpdateCollision(ref entity, inputManager, soundEngine);
     }
 }
Esempio n. 5
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. 6
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. 7
0
File: Tile.cs Progetto: lcraver/TM2
        public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine)
        {
            FloatRect rect = new FloatRect(position.X, position.Y, layer.TileDimensions.X, layer.TileDimensions.Y);

            if (entity.OnTile && containsEntity)
            {
                if (!entity.SyncTilePosition)
                {
                    entity.Position += this.velocity;
                    entity.SyncTilePosition = true;
                }

                if (entity.Rect.Right < rect.Left || entity.Rect.Left > rect.Right || entity.Rect.Bottom != rect.Top)
                {
                    containsEntity = false;
                    entity.ActivateGravity = true;
                    entity.CanJump = false;
                }
            }

            if (entity.Rect.Intersects(rect) && state == State.Solid)
            {
                FloatRect preventity = new FloatRect(entity.PrevPosition.X, entity.PrevPosition.Y, entity.Animation.FrameWidth, entity.Animation.FrameHeight);

                FloatRect prevTile = new FloatRect(this.prevPosition.X, this.prevPosition.Y, layer.TileDimensions.X, layer.TileDimensions.Y);

                if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top)
                {
                    //bottom collision
                    entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight);
                    entity.ActivateGravity = false;
                    entity.OnTile = true;
                    containsEntity = true;
                }
                else if (entity.Rect.Top <= rect.Bottom && preventity.Top >= prevTile.Bottom)
                {
                    //top collision
                    entity.Position = new Vector2(entity.Position.X, position.Y + layer.TileDimensions.Y);
                    entity.ActivateGravity = true;
                }
                else if (entity.Rect.Right >= rect.Left && preventity.Right <= prevTile.Left)
                {
                    entity.Position = new Vector2(position.X - entity.Animation.FrameWidth, entity.Position.Y);
                    entity.Direction = (entity.Direction == 1) ? entity.Direction = 2 : entity.Direction = 1;
                    entity.CanJump = true;
                    entity.Velocity = new Vector2(0, entity.Velocity.Y);
                }
                else if (entity.Rect.Left <= rect.Right && preventity.Left >= prevTile.Left)
                {
                    entity.Position = new Vector2(position.X + layer.TileDimensions.X, entity.Position.Y);
                    entity.Direction = (entity.Direction == 1) ? entity.Direction = 2 : entity.Direction = 1;
                    entity.CanJump = true;
                    entity.Velocity = new Vector2(0, entity.Velocity.Y);
                }
            }
            else if (entity.Rect.Intersects(rect) && state == State.Platform)
            {
                FloatRect preventity = new FloatRect(entity.PrevPosition.X, entity.PrevPosition.Y, entity.Animation.FrameWidth, entity.Animation.FrameHeight);

                FloatRect prevTile = new FloatRect(this.prevPosition.X, this.prevPosition.Y, layer.TileDimensions.X, layer.TileDimensions.Y);

                if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top && inputManager.KeyDown(Keys.Down))
                {
                    //bottom collision
                    //entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight);
                    entity.ActivateGravity = true;
                    entity.OnTile = false;
                    containsEntity = false;
                }
                else if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top)
                {
                    //bottom collision
                    entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight);
                    entity.ActivateGravity = false;
                    entity.OnTile = true;
                    containsEntity = true;
                }
            }

            entity.Animation.Position = entity.Position;
        }
Esempio n. 8
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. 9
0
 public virtual void OnCollision(Entity e, SoundEngine soundEngine)
 {
 }
Esempio n. 10
0
File: Map.cs Progetto: lcraver/TM2
 public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine)
 {
     layer.UpdateCollision(ref entity, inputManager, soundEngine);
 }
Esempio n. 11
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);
        }