public void UpdateHitboxPosition(SpriteClass ESprite, PositionComponent EPosition)
        {
            SpriteClass eSprite  = ESprite;
            Texture2D   Etexture = eSprite.texture;

            HitBox = new Rectangle((int)EPosition.XCoor, (int)EPosition.YCoor, Etexture.Width, Etexture.Height);
        }
        public CollisionBoxComponet(SpriteClass Entitysprite, PositionComponent Entityposition)
        {
            SpriteClass EntitySprite = Entitysprite;
            Texture2D   texture      = EntitySprite.texture;

            // Look into how rectangle is generated, make sure that the position corresponds to the centor of the sprite**************************************
            HitBox = new Rectangle((int)Entityposition.XCoor, (int)Entityposition.YCoor, texture.Width / 2, texture.Height / 2);
        }
        public void Follow(SpriteClass target)
        {
            var position = Matrix.CreateTranslation(
                //-target_position.X - (target_rectangle.Width / 2),
                0,
                -target.y - (target.textureHeight / 2), 0);

            var offset = Matrix.CreateTranslation(0, Game1.screenHeight / 2, 0);

            //Console.WriteLine("pos: " + position.ToString());
            //Console.WriteLine("offset: " + offset.ToString());

            Transform = position * offset;

            //var Transform = Matrix.CreateTranslation(100, 100, 0);
        }
        public override void Draw(GameTime gameTime)    // overridden draw function that will render all entities with a sprite component every Darw() call
        {
            Game1.spriteBatch.Begin();
            foreach (var entityID in ActiveEntities)
            {
                // Get the entity that the entityID references
                Entity entity = Game1._world.GetEntity(entityID);

                //      **Get Position**
                // Pull the PositionComponent from the entity
                ECSComponents.PositionComponent entityPositionComponent = entity.Get <ECSComponents.PositionComponent>();
                // Get the coordinates of the entity from the entity's PositionComponent
                var entityX = entityPositionComponent.XCoor;
                var entityY = entityPositionComponent.YCoor;
                var angle   = entityPositionComponent.Angle;

                //      **Get Sprite**
                // Pull the SpriteComponent from the entity
                ECSComponents.SpriteComponent entitySpriteComponent = entity.Get <ECSComponents.SpriteComponent>();
                // Get the Texture2D of the entity from the entity's SpriteComponent
                SpriteClass sprite = entitySpriteComponent.Sprite;
                Microsoft.Xna.Framework.Graphics.Texture2D texture = sprite.texture;
                float scale = entitySpriteComponent.Scale;

                // draw the entity
                Vector2 spritePosition = new Vector2(entityX, entityY);
                Game1.spriteBatch.Draw(texture,
                                       spritePosition,
                                       null,
                                       Color.White,
                                       angle,
                                       new Vector2(texture.Width / 2, texture.Height / 2),
                                       new Vector2(scale, scale),
                                       Microsoft.Xna.Framework.Graphics.SpriteEffects.None,
                                       0f);
            }
            Game1.spriteBatch.End();
        }
Example #5
0
 public SpriteComponent(SpriteClass newSprite, float newScale)
 {
     Sprite = newSprite;
     Scale  = newScale;
 }