NvP: Normal vs Paranormal

Programación Orientada a Objetos (Tower defense - kingdom rush)

Moderator: julianmartinez16

User avatar
xacarana
Site Admin
Posts: 1071
Joined: Fri Jan 15, 2016 6:13 pm

Re: NvP: Normal vs Paranormal

Post by xacarana » Tue Apr 09, 2019 2:35 pm

Image

Es necesario que cada integrante avance en una tarea de código, recuerden que pueden programar los dos al tiempo en una misma tarea, implementar xtreme programming. :!: Deben asignar una tarea que involucre código a cada integrante. Vuelvo a revisar el viernes. :!:
Andrés Bedoya Tobón
Profesor
"I only smile in the dark, I only smile when it's complicated" Raybiez

User avatar
DanEllisEchavarria
Posts: 8
Joined: Thu Aug 30, 2018 5:15 pm

Re: NvP: Normal vs Paranormal

Post by DanEllisEchavarria » Fri Apr 12, 2019 9:34 am

Que se hizo?
[Tower.cs por Dan]

Code: Select all

 public class Tower : Entity
    {
        public float Velocity = 20f;

        List<Bullet> bullets;
        public Tower(Game game, Vector2 position, Texture2D texture, SpriteBatch sprite) : base(game, position, texture, sprite)
        {
            Enemigo = false;
            AttackRadius = new CircleF(new Point2(texture.Bounds.Width / 2, texture.Bounds.Height / 2), 32 * 10);
            Daño = 5;
        }
        public void SetBullets(ref List<Bullet> Bullets)
        {
            bullets = Bullets;
        }
        public virtual bool Fire(Entity entity)
        {
            if (entity.Enemigo)
            {
                var temp = Position - entity.Position;
                var angulo = (float)Math.Atan2(temp.X, temp.Y);
                rotationDegrees = (angulo);
                bullets.Add(new Bullet(this, Game, Position, Image, Sprite, Velocity, AttackRadius.Radius, angulo, entity));
                return  true;
            }
            return false;
        }
        public void GetEntities(Entity[] entities)
        {
            Entities = entities;
        }
        public override void Update(GameTime gameTime)
        {
            bool fired = false;
            foreach (Entity e in Entities)
            {
                if(AttackRadius.Contains(e.BoundingCircle.Center))
                fired = Fire(e);
                if (fired)
                {
                    break;
                }
            }
            AttackRadius = new CircleF(new Point2(Image.Bounds.Width / 2, Image.Bounds.Height / 2) + Position.ToPoint() , 32 * 10);

        }
    }

[Bullet.cs por Cristian]

Code: Select all

public class Bullet : Entity, IDisposable
    {

        public float Lifespan = 0;
        private float Velocity = 0;
        public bool Impacted { get; internal set; }
        public Bullet(Entity sent, Game game, Vector2 position, Texture2D texture, SpriteBatch sprite, float radius, float velocity, float angle, Entity entity) : base(game, position, texture, sprite)
        {
            Lifespan = velocity/radius;
            Velocity = velocity;
            RotationDegrees = angle;
            Entities = new Entity[] { sent, entity };
        }



        public override void Update(GameTime gameTime)
        {
            Lifespan -= (float)gameTime.ElapsedGameTime.TotalSeconds * 60f;
            this.Position += new Vector2((float)Math.Cos((double)RotationDegrees) * Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds, (float)Math.Sin((double)RotationDegrees) * Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds);
            if (BoundingCircle.Intersects(Entities[1].BoundingCircle))
            {
                Entities[1].Life -= Entities[0].Daño;
                Impacted = true;
            }

        }

    }	

[Fragmento de GameSelectedScreen.cs por Dan y Cristian]

Code: Select all

 public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp);
            tiledHelper.Draw(gameTime);
            foreach (var item in towers)
            {
                item.Draw(gameTime);
            }
            foreach (var item in enemies)
            {
                item.Draw(gameTime);
            }
            foreach (var item in bulletsEnemies)
            {
                item.Draw(gameTime);
            }
            foreach (var item in bulletsTower)
            {
                item.Draw(gameTime);
            }
            spriteBatch.End();
            GeonBit.UI.UserInterface.Active.Draw(new SpriteBatch(GraphicsDevice));

        }

        public override void Update(GameTime gameTime)
        {
            GeonBit.UI.UserInterface.Active.Update(gameTime);

            tiledHelper.Update(gameTime);

            delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
            foreach (var item in spawners)
            {
                if(!item.SpawnEnemies(round, ref enemies))
                {
                    if(round <= item.Rondas)
                    NextRound = true;
                }
            }
            List<Entity> ent = new List<Entity>();
            ent = ent.Concat(enemies).ToList();
            ent = ent.Concat(towers).ToList() ;
            foreach (var item in towers)
            {
                if (item.Life < 0)
                {
                    TowerToRemove.Add(item);
                }
                item.GetEntities(ent.ToArray());
                item.Update(gameTime);

            }
            foreach (var item in enemies)
            {
                if(item.Life < 0)
                {
                    enemiesToRemove.Add(item);
                }
                item.GetEntities(ent.ToArray());
                foreach (var inter in intersections)
                {
                    inter.ChangeDirection(item);
            }
                foreach (var inter in intersectionsProb)
                {
                    inter.ChangeDirection(item);
                }
                foreach (var f in Final)
                {
                    if (f.Intersects(item.BoundingCircle))
                    {
                        enemiesToRemove.Add(item); 
                        Life -= item.Daño;
                    }
                }
                item.Update(gameTime);
            }
            List<Bullet> bullets = new List<Bullet>();
            bullets = bullets.Concat(bulletsEnemies).ToList();
            bullets = bullets.Concat(bulletsTower).ToList();

            foreach(var item in bullets)
            {
                item.Update(gameTime);
                if(item.Lifespan < 0 || item.Impacted)
                {
                    bulletsToRemove.Add(item);
                }

            }

            foreach (var item in TowerToRemove)
            {
                towers.Remove(item);
                item.Dispose();
            }
            foreach (var item in enemiesToRemove)
            {
                enemies.Remove(item);
                item.Dispose();
            }
            foreach (var item in bulletsToRemove)
            {
                if (bulletsEnemies.Contains(item))
                {
                    bulletsEnemies.Remove(item);
                }
                else
                {
                    bulletsTower.Remove(item);

                }
                item.Dispose();
            }
            currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds; 
            {
                counter++;
                currentTime -= countDuration; 
            }
            if (counter >= limit)
            {

                counter = 0;
                if (NextRound)
                {
                    round++;
                    NextRound = false;
                }
            }

            TowerToRemove.Clear();
            enemiesToRemove.Clear();
            bulletsToRemove.Clear();
            
        }
Que se va hacer?
Aplicar imagenes para las bullets
Hacer que el ciclo de desintegracion de enemigos se active con el estar en vida negativa o 0
Terminar el transaldo de codigo a otra libreria de procesamiento de objetos

Problemas

El pc de Dan se le daño el cargador, una pequeña desventaja ya que otros computadores disponibles son mas lentos haciendo mas dificil el proceso de programacion, pero todavia se sigue trabajando.

Image
Dan Ellis Echavarria
Curso POO 2

User avatar
xacarana
Site Admin
Posts: 1071
Joined: Fri Jan 15, 2016 6:13 pm

Re: NvP: Normal vs Paranormal

Post by xacarana » Fri Apr 12, 2019 10:19 am

Image
Andrés Bedoya Tobón
Profesor
"I only smile in the dark, I only smile when it's complicated" Raybiez

Post Reply