Exemplo n.º 1
0
 /// <summary>
 /// Creates a default MovableCollidable
 /// </summary>
 public MovableCollidable(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world)
     : base(texture, position, drawingLevel, game, world)
 {
     /* Setting up MovableCollidable */
     direction           = Vector2.Zero;
     acceleration        = 0;
     accelerationScaling = 1.0f;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a default Colliding Sprite.
        /// </summary>
        public CollidingSprite(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world)
            : base(texture, position, drawingLevel, game)
        {
            /* Setting up Farseer Physics*/
            this.world = world;

            /* Setting up CollidingSprite */
            id  = Guid.NewGuid();
            tag = TagCategories.UNDEFINED;
        }
Exemplo n.º 3
0
 public CompactZone(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, Color color, Library.Zone.Name shape)
     : base(texture, position, drawingLevel, game, world, color)
 {
     _game           = game;
     Tag             = TagCategories.COMPACTZONE;
     _isShot         = false;
     _shape          = shape;
     _tail           = null;
     _detonationTime = 70;
     _timer          = _detonationTime;
 }
Exemplo n.º 4
0
        public Crystal(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, Color color)
            : base(texture, position, drawingLevel, game, world, color)
        {
            RigidBody.CollisionCategories = Category.Cat5;
            /* Setting up Farseer physics */
            RigidBody.CollidesWith = defaultCollisiosCategory = Category.All ^ Category.Cat9;

            /* Setting up Crystal */
            Tag = TagCategories.CRYSTAL;

            _tail = new ParticleEngine(1, Library.Particle.trailTexture, position, color, Origin, 1.0f, 0.0f, 0.2f, DrawingHelper.DrawingLevel.Low, game);
            SyncedGameCollection.ComponentCollection.Add(_tail);
            _tail.ParticleColor = Color.LightGray;
            IsActive            = true;
        }
Exemplo n.º 5
0
        public Sprite(Texture2D texture, Vector2 position, Color color, DrawingHelper.DrawingLevel drawingLevel, bool centered, Game game)
            : base(game)
        {
            Color    = color;
            Position = position;
            Texture  = texture;
            Scale    = 1.0f;
            Alpha    = 1.0f;

            if (centered)
            {
                Origin = new Vector2(texture.Width / 2, texture.Height / 2);
            }

            DrawOrder = (int)drawingLevel;
        }
Exemplo n.º 6
0
 public ParticleEngine(int particleAmount, Texture2D particleTexture, Vector2 position, Color color, Vector2 origin, float scale, float rotation, float lifetime, DrawingHelper.DrawingLevel drawingLevel, Game game)
     : base(game)
 {
     Initialize();
     _particles         = new List <Particle>();
     _sleepingParticles = new Queue <Particle>();
     _particleAmount    = particleAmount;
     _particlePosition  = position;
     _particleColor     = color;
     _particleOrigin    = origin;
     _particleScale     = scale;
     _particleRotation  = rotation;
     _particleLifetime  = lifetime;
     _particleTexture   = particleTexture;
     _particleOrigin.X  = _particleTexture.Width / 2;
     _particleOrigin.Y  = _particleTexture.Height / 2;
     dLevel             = drawingLevel;
     isOneShot          = false;
 }
Exemplo n.º 7
0
        public Grabbable(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, Color color)
            : base(texture, position, drawingLevel, game, world)
        {
            /* Setting up Farseer Physics */
            RigidBody                     = BodyFactory.CreateCircle(this.world, ConvertUnits.ToSimUnits(texture.Width / 2), 0, ConvertUnits.ToSimUnits(position));
            RigidBody.BodyType            = BodyType.Dynamic;
            RigidBody.CollisionCategories = Category.Cat5;
            RigidBody.CollidesWith        = Category.All ^ Category.Cat9;
            RigidBody.Mass                = 1f;
            RigidBody.LinearDamping       = 0.5f;
            RigidBody.Restitution         = 1f;
            Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            /* Setting up Grabbable*/
            acceleration       = maxAcceleration = 20;
            _shootForce        = 2000f;
            _cooldownInSeconds = 0.5f;
            Color = color;
        }
Exemplo n.º 8
0
        public TexturePolygon(Texture2D texture, Vector2 position, float rotation, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, bool textureCenter)
            : base(texture, position, drawingLevel, game, world)
        {
            // Fetch Texure data
            uint[] data = new uint[texture.Width * texture.Height];
            texture.GetData(data);
            Vertices textureVertices = PolygonTools.CreatePolygon(data, texture.Width, true);

            // Set Polygon Centroid
            if (textureCenter) // Texture based center
            {
                Vector2 centroid = -textureVertices.GetCentroid();
                textureVertices.Translate(ref centroid);
                Origin = new Vector2(texture.Width / 2, texture.Height / 2);
            }
            else // Vertice based center
            {
                Vector2 centroid = -textureVertices.GetCentroid();
                textureVertices.Translate(ref centroid);
                Origin = new Vector2(-centroid.X, -centroid.Y);
            }

            // Simplify Polygon for performance
            textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 4f);
            List <Vertices> list = Triangulate.ConvexPartition(textureVertices, TriangulationAlgorithm.Bayazit);

            // Convert polygon to sim units
            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1));

            foreach (Vertices vertice in list)
            {
                vertice.Scale(ref vertScale);
            }

            // create body compound.
            RigidBody          = BodyFactory.CreateCompoundPolygon(world, list, 1f, BodyType.Static);
            RigidBody.BodyType = BodyType.Static;
            RigidBody.Position = ConvertUnits.ToSimUnits(position);
            RigidBody.Rotation = rotation;
        }
Exemplo n.º 9
0
        public EvilCrystal(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, Color color)
            : base(texture, position, drawingLevel, game, world)
        {
            RigidBody                     = BodyFactory.CreateCircle(this.world, ConvertUnits.ToSimUnits(texture.Width / 2), 0, ConvertUnits.ToSimUnits(position));
            RigidBody.BodyType            = BodyType.Dynamic;
            RigidBody.CollisionCategories = Category.Cat5;
            RigidBody.CollidesWith        = Category.All ^ Category.Cat9;
            RigidBody.Mass                = 1f;
            RigidBody.LinearDamping       = 0.5f;
            RigidBody.Restitution         = 1f;
            Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
            Tag    = TagCategories.UNDEFINED;

            _tail = new ParticleEngine(1, Library.Particle.trailTexture, position, color, Origin, 1.0f, 0.0f, 0.2f, DrawingHelper.DrawingLevel.Low, game);
            SyncedGameCollection.ComponentCollection.Add(_tail);
            if (color == Color.White)
            {
                _tail.ParticleColor = Color.LightGray;
            }

            acceleration = maxAcceleration = 20;
            Color        = color;
        }
Exemplo n.º 10
0
 public Particle(Texture2D texture, Vector2 position, Color color, Vector2 origin, float scale, float rotation, float lifetime, DrawingHelper.DrawingLevel drawingLevel, Game game)
     : base(texture, position, drawingLevel, game)
 {
     _lifetime       = lifetime;
     _timeSinceStart = 0.0f;
     Color           = color;
     Origin          = origin;
     Scale           = scale;
     Rotation        = rotation;
     Alpha           = 1.0f;
 }
Exemplo n.º 11
0
 public Sprite(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game)
     : this(texture, position, Color.White, drawingLevel, false, game)
 {
 }
Exemplo n.º 12
0
        public Goal(Texture2D goalTexture, Texture2D borderTexture, Vector2 position, GoalDirections direction, DrawingHelper.DrawingLevel drawingLevel, Game game, World world)
            : base(game)
        {
            InnerCircle = new DummyCircle(position, ((goalTexture.Width / 2) / 2) / 2, game, world);
            InnerCircle.setOnCollisionFunction(OnCollision);
            InnerCircle.SetCollisionCategory(Category.Cat10);
            OuterCircle = new Circle(goalTexture, position, goalTexture.Width / 2, game, world);
            OuterCircle.RigidBody.CollisionCategories = Category.Cat9;
            //OuterCircle.setOnCollisionFunction(OnCollision);

            float   borderRotation = 0;
            Vector2 borderPosition = Vector2.Zero;

            #region direction cases
            switch (direction) // TODO: Add all directions.
            {
            case GoalDirections.North:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;

            case GoalDirections.NorthEast:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;

            case GoalDirections.East:
                borderRotation = 0;
                borderPosition = new Vector2((position.X + borderTexture.Width / 2) + 5.30973f, (position.Y) - 0.63129f);     // TODO: hardcoded offset
                break;

            case GoalDirections.SouthEast:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;

            case GoalDirections.South:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;

            case GoalDirections.SouthWest:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;

            case GoalDirections.West:
                borderRotation = (float)Math.PI;
                borderPosition = new Vector2((position.X - borderTexture.Width / 2) - 5.30973f, (position.Y) + 0.63129f);     // TODO: other solution for very specific offset for texture/vertice position
                break;

            case GoalDirections.NorthWest:
                borderRotation = 0;
                borderPosition = new Vector2(position.X + borderTexture.Width / 2, position.Y);
                break;
            }
            #endregion

            Border = new TexturePolygon(borderTexture, borderPosition, borderRotation, DrawingHelper.DrawingLevel.High, game, world, false);
            Border.SetCollisionCategory(Category.Cat10);
            Border.SetCollideWithCategory(Category.All);

            SyncedGameCollection.ComponentCollection.Add(OuterCircle);
            SyncedGameCollection.ComponentCollection.Add(InnerCircle);
            SyncedGameCollection.ComponentCollection.Add(Border);
        }
Exemplo n.º 13
0
 public Movable(Texture2D texture, Vector2 position, DrawingHelper.DrawingLevel drawingLevel, Game game, World world, Vector2 direction, float constantForce)
     : base(texture, position, drawingLevel, game)
 {
     this.direction     = direction;
     this.constantForce = constantForce;
 }
Exemplo n.º 14
0
        public EvilUnit(Texture2D texture, Vector2 position, Color color, Game game, World world, DrawingHelper.DrawingLevel drawingLevel, Unit copyOf, float offset)
            : base(texture, position, drawingLevel, game, world)
        {
            ;
            RigidBody                     = BodyFactory.CreateCircle(this.world, ConvertUnits.ToSimUnits(texture.Width / 2), 0, ConvertUnits.ToSimUnits(position));
            RigidBody.BodyType            = BodyType.Dynamic;
            RigidBody.CollisionCategories = Category.Cat1;
            RigidBody.CollidesWith        = Category.All ^ Category.Cat1;
            RigidBody.Mass                = 10f;
            RigidBody.LinearDamping       = 5f;
            RigidBody.Restitution         = 0.1f;

            Origin = new Vector2(texture.Width / 2, texture.Height / 2);

            acceleration           = 40;
            Color                  = color;
            _trailParticleLifetime = 0.2f;
            _trail                 = new ParticleEngine(1, Library.Particle.trailTexture, position, color, Origin, 1.0f, 0.0f, _trailParticleLifetime, DrawingHelper.DrawingLevel.Low, game);

            SyncedGameCollection.ComponentCollection.Add(_trail);
            Tag = TagCategories.UNDEFINED;

            _copyOf = copyOf;
            _offset = offset;
        }