NvP: Normal vs Paranormal

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

Moderator: julianmartinez16

User avatar
xacarana
Site Admin
Posts: 1165
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: 10
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: 1165
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

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

Re: NvP: Normal vs Paranormal

Post by xacarana » Fri May 03, 2019 3:50 pm

Image

¡Strike! Queda pendiente el último strike, espero un buen avance para hoy.
Andrés Bedoya Tobón
Profesor
"I only smile in the dark, I only smile when it's complicated" Raybiez

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

Re: NvP: Normal vs Paranormal

Post by xacarana » Fri May 10, 2019 10:25 am

Image

Image

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

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

Re: NvP: Normal vs Paranormal

Post by DanEllisEchavarria » Tue May 14, 2019 2:41 pm

Que se ha hecho?
  1. Dado que tenemos un pc solo hemos podido modificar cosas juntos a tiempos, todo el codigo aqui presentado ha sido hecho por ambos en nuestros encuentros
  2. Hemos realizado un cambio, los objetos ahoran tienen un metodo que ejecutan cuando colisionan con algo
  3. Se ha solucionado que los enemigos no morian con el contacto de las balas
  4. Se ha implementado los scrollbars en los menus
Que problemas hemos tenido
  1. Hemos tenido problemas para mostrar los graficos, se ha empezado una clase ayudante para ellos
  2. Los power up necesitan la clase ayudante para mostrar las animaciones de los powerup
  3. Todavia solo tenemos un computador
  4. se perdieron animaciones, rehaciendo
Que vamos a hacer?
  1. Terminar de implementar el ayudante de animaciones
  2. Terminar de implementar los bosses
  3. parar el tiempo cuando se activa ciertas animaciones
  4. Terminar animaciones de personajes ASAP
Tower.cs

Code: Select all

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using NVP.Entities;
using NVP.Entities.Enemies;
using System;
using System.Collections.Generic;

public class Tower : Entity
{
    public float Velocity = 20f;
    protected float cooldown = 0.9f;
    float timeElapsed = 0;
    Entity ToFire;
    bool fire = true;
    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), 100);
        Dano = 5;
    }
    public void SetBullets(ref List<Bullet> Bullets)
    {
        bullets = Bullets;
    }
    public virtual bool Fire(Entity entity, GameTime game)
    {
        if (entity.Enemigo)
        {
            Enemy enemigo = entity as Enemy;
            var angulo = MathHelper.ToDegrees((float)Math.Acos((double)Vector2.Dot(enemigo.Position.NormalizedCopy(), Position.NormalizedCopy())) + MathHelper.PiOver2);
            rotationDegrees = (angulo);
            bullets.Add(new Bullet(this, Game, Position, Image, Sprite, Velocity, AttackRadius.Radius, angulo));

            return true;
        }
        return false;
    }

    public void Cooldown(GameTime gameTime, Entity e)
    {
        if (fire)
        {
            Fire(e, gameTime);
            fire = false;
        }
        if (!fire)
        {



            timeElapsed += gameTime.GetElapsedSeconds();
            if (timeElapsed > cooldown)
            {
                fire = true;
                timeElapsed = 0;
            }

        }
    }

    public void GetEntities(Entity[] entities)
    {
        Entities = entities;
    }

    public override void Draw(GameTime gameTime)
    {
        base.Draw(gameTime);
        Sprite.DrawCircle(AttackRadius, 50, Color.AliceBlue);
        if (ToFire != null)
            Sprite.DrawLine(Position, ToFire.Position, Color.Black);
    }
    public override void Update(GameTime gameTime)
    {
        ToFire = null;
        float lowerdistance = float.MaxValue;
        foreach (Entity e in Entities)
        {
            float distance = (float)Math.Sqrt(Vector2.Subtract(e.Position, Position).Dot(Vector2.Subtract(e.Position, Position)));

            if (lowerdistance > (float)distance)
            {
                lowerdistance = (float)distance;
            }
            if (distance == lowerdistance && e.Enemigo)
            {
                ToFire = e;
            }
        }
        if (ToFire != null && ToFire.Collider.Intersects(AttackRadius))
            Cooldown(gameTime, ToFire);
        AttackRadius = new CircleF(new Point2(Image.Bounds.Width / 2, Image.Bounds.Height / 2) + Position.ToPoint(), 150);

    }
}
CollisionHelper.cs

Code: Select all

using System.Collections.Generic;

namespace NVP.Helpers
{
    public class CollisionHelper
    {
        List<ICollisionableObject> Collisionables = new List<ICollisionableObject>();
        public void Initialize(params ICollisionableObject[] collisionableObjects)
        {
            foreach (var c in collisionableObjects)
            {
                Collisionables.Add(c);
            }
        }
        public void Initialize(List<ICollisionableObject> collisionableObjects)
        {
            Collisionables = collisionableObjects;
        }



        public void Update()
        {
            foreach (var c in Collisionables)
            {
                if (!c.IsActive)
                    continue;
                foreach (var c2 in Collisionables)
                {
                    if (!c2.IsActive)
                        continue;
                    if (c.Collider.Intersects(c2.Collider))
                    {
                        c.OnCollision(c2);
                    }
                }
            }
        }

    }
}
Entity

Code: Select all

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using NVP.Helpers;
using System;

namespace NVP.Entities
{
    public abstract class Entity : SimpleDrawableGameComponent, IDisposable, ICollisionableObject
    {
        protected bool disposed = false;
        public int Life { get; set; }
        public int Dano { get; set; }
        public Entity[] Entities { get; set; }
        public CircleF Collider { get; set; }
        public CircleF AttackRadius { get; set; }
        public bool IsActive { get; set; } = true;
        public bool Enemigo { get; set; }
        protected float rotationDegrees;
        public float RotationDegrees
        {
            get { return rotationDegrees; }
            set
            {
                rotationDegrees = value;
            }
        }
        public Texture2D Image;

        public Vector2 Position { get; set; }

        public Game Game { get; internal set; }
        protected SpriteBatch Sprite;

        public Entity(Game game, Vector2 position, Texture2D texture, SpriteBatch sprite)
        {
            Game = game;

            Sprite = sprite;
            Position = position;
            Image = texture;
            Collider = new CircleF(new Point2(texture.Bounds.Width / 2, texture.Bounds.Height / 2) + position.ToPoint(), texture.Bounds.Width / 2);
            AttackRadius = new CircleF(new Point2(texture.Bounds.Width / 2, texture.Bounds.Height / 2) + position.ToPoint(), 2 * texture.Bounds.Width / 2);
        }
        public override void Draw(GameTime gameTime)
        {
            Sprite.Draw(Image, Position, new Rectangle(0, 0, Image.Width, Image.Height), Color.White, RotationDegrees, new Vector2(Image.Width / 2, Image.Height / 2), 1, SpriteEffects.None, 1);
        }

        public override void Update(GameTime gameTime)
        {
            Collider = new CircleF(new Point2(Image.Bounds.Width / 2, Image.Bounds.Height / 2) + Position.ToPoint(), Image.Bounds.Width / 2);

        }


        protected override void UnloadContent()
        {
            Image = null;

        }




        public virtual Entity DetectarEnemigos(Entity other)
        {
            return other.Collider.Intersects(AttackRadius) ? other : this;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
                return;

            if (disposing)
            {
                Image = null;
                Sprite = null;
            }

            disposed = true;
        }

        public virtual void OnCollision(ICollisionableObject collisionableObject) { }
    }
}
collisionobject.cs

Code: Select all

using MonoGame.Extended;

namespace NVP.Helpers
{
    public interface ICollisionableObject
    {

        CircleF Collider { get; set; }
        bool IsActive { get; set; }
        void OnCollision(ICollisionableObject collisionableObject);
    }
}
Bullet.cs

Code: Select all

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using NVP.Entities;
using NVP.Helpers;
using System;

public class Bullet : Entity, IDisposable
{

    public bool IsOutsideHisSpawner = false;
    private float Velocity = 0;
    public bool Impacted { get; internal set; }
    private Entity Sender;

    public Bullet(Entity sent, Game game, Vector2 position, Texture2D texture, SpriteBatch sprite, float radius, float velocity, float angle) : base(game, position, texture, sprite)
    {

        Velocity = velocity;
        RotationDegrees = angle;
        Sender = sent;
        Collider = new CircleF(new Point2(Image.Bounds.Width / 2, Image.Bounds.Height / 2) + Position.ToPoint(), Image.Bounds.Width / 2);
    }



    public override void Update(GameTime gameTime)
    {
        if (!Sender.AttackRadius.Intersects(Collider))
        {
            IsOutsideHisSpawner = true;
        }
        this.Position += new Vector2((float)Math.Cos((double)RotationDegrees) * Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds, (float)Math.Sin((double)RotationDegrees) * Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds);
        base.Update(gameTime);
    }
    public override void OnCollision(ICollisionableObject collisionableObject)
    {
        var col = collisionableObject as Entity;
        if (col.Enemigo)
        {
            col.Life -= Sender.Dano;
            Impacted = true;
        }
    }
}
Ongoing
AnimationHelper.cs

Code: Select all

Codigo no hecho
Image
PowerUP animado
Image
Scrollbar1
Image
Scrollbar2


Image
Personajes a poder usarse
Image
Personajes a poder usarse 2
Image
Template de personajes
Art by:Antifare for OpenGameArt
Image
Arte por: Ruffus
Dan Ellis Echavarria
Curso POO 2

User avatar
CristianEscobar
Posts: 5
Joined: Thu Aug 30, 2018 5:09 pm

Re: NvP: Normal vs Paranormal

Post by CristianEscobar » Wed May 22, 2019 1:01 pm

¿Qué hemos hecho?
Creamos una clase para ayudarnos con las animaciones de todos los personajes y torres
Se le ha dado una animación a los power ups y a cada personaje del juego

¿Qué vamos a hacer?
Corregir un bug que sucede al poner las torres
¿Qué dificultades hemos tenido?
Falta de tiempo por la semana de finales

Code: Select all

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Spritesheet;
using System.Collections.Generic;
using a = Spritesheet;
namespace NVP.Helpers
{
    public class AnimationHelper<T>
    {
        private bool IsPaused;
        private a.Spritesheet Spritesheet;
        private Animation Animation;
        private Dictionary<T, Animation> AnimationsKeys;
        private SpriteBatch Sprite;
        (int x, int y) size;
        public AnimationHelper(SpriteBatch sprite, Texture2D spritesheet, int width, int height)
        {
            size = (width, height);
            Spritesheet = new a.Spritesheet(spritesheet).WithGrid(size);
            Sprite = sprite;
        }

        public void Play(T toPlay, Repeat.Mode mode = Repeat.Mode.LoopWithReverse)
        {
            Animation = AnimationsKeys[toPlay];
            if (IsPaused)
            {
                Animation.Resume();
                return;
            }
            IsPaused = false;
            Animation.Start(mode);
        }

        public void Pause()
        {
            Animation.Pause();
            IsPaused = true;
        }
        public void Stop()
        {
            Animation.Stop();
            IsPaused = false;
        }
        public void Reset()
        {
            Animation.Reset();
            IsPaused = false;

        }

        public void FlipX()
        {
            Animation.FlipX();
        }
        public void FlipY()
        {
            Animation.FlipY();
        }

        public void CreateAnimation(T Key, (int x, int y)[] Frames, bool flipx = false, bool flipy = false)
        {

            if (flipx)
            {
                AnimationsKeys.Add(Key, Spritesheet.CreateAnimation(Frames).FlipX());
            }
            else if (flipy)
            {
                AnimationsKeys.Add(Key, Spritesheet.CreateAnimation(Frames).FlipY());

            }
            else
            {
                AnimationsKeys.Add(Key, Spritesheet.CreateAnimation(Frames));

            }
        }
        public void Update(GameTime gameTime)
        {
            Animation.Update(gameTime);
        }
        public void Draw(Vector2 Position, float RotationDegrees)
        {
            Sprite.Draw(Animation, Position, Color.White, RotationDegrees);

        }
    }
}
Cristian Escobar Roqueme
Pdoo 2

User avatar
CristianEscobar
Posts: 5
Joined: Thu Aug 30, 2018 5:09 pm

Re: NvP: Normal vs Paranormal

Post by CristianEscobar » Fri May 24, 2019 11:05 am

Cristian Escobar Roqueme
Pdoo 2

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

Re: NvP: Normal vs Paranormal

Post by DanEllisEchavarria » Fri May 31, 2019 5:02 pm

Diagrama de clase Suerte leyendo todo esto \OwO/
Image
Poster
Image
Evidencias de ayer
Image
Image
Image
Image
Image
Image

https://github.com/Deecellar/NvP
Dan Ellis Echavarria
Curso POO 2

Post Reply