Beispiel #1
0
 public ProjectileComponent(EasyTopDownGame game, EasyGameComponent originatingComponent, string sheetName, Vector2 direction, float velocity)
     : base(game, sheetName)
 {
     SetStartPosition(originatingComponent, direction);
     SetInMotion(direction, velocity);
     this.Body.IsBullet = true;
 }
Beispiel #2
0
 public ProjectileComponent(EasyTopDownGame game, EasyGameComponent originatingComponent, string sheetName, Vector2 direction, float velocity)
     : base(game, sheetName)
 {
     SetStartPosition(originatingComponent, direction);
     SetInMotion(direction, velocity);
     this.Body.IsBullet = true;
 }
Beispiel #3
0
 public void BallBrickCollision(EasyGameComponent ball, EasyGameComponent brick)
 {
     brick.Remove();
     EffectGameComponent effect = AddEffect("colorexplosion", brick.DisplayPosition);
     effect.SecondsPerFrame = .05;
     effect.OverlayColor = brick.OverlayColor;
 }
Beispiel #4
0
        public static Rectangle GetAABB(EasyGameComponent component)
        {
            AABB overallAABB = new AABB();

            component.Body.FixtureList.ForEach(delegate(Fixture fixture)
            {
                for (int i = 0; i < fixture.Shape.ChildCount; i++)
                {
                    AABB currentAABB;
                    Transform transform;
                    fixture.Body.GetTransform(out transform);
                    fixture.Shape.ComputeAABB(out currentAABB, ref transform, i);
                    overallAABB.Combine(ref currentAABB);
                }
            });

            int left   = (int)overallAABB.UpperBound.X;
            int right  = (int)overallAABB.LowerBound.X;
            int top    = (int)overallAABB.UpperBound.Y;
            int bottom = (int)overallAABB.LowerBound.Y;

            Rectangle rectangle = new Rectangle(left, top, right - left, bottom - top);

            return(rectangle);
        }
Beispiel #5
0
        public bool FireEvent(EasyGameComponent componentOne, EasyGameComponent componentTwo)
        {
            if (componentOne.IsRemoved || componentTwo.IsRemoved)
            {
                return(false);
            }

            //The order of the keys matters, because the game loop will be expecting to get the components in the right order
            string keyOneFirst = keyify(componentOne.Category, componentTwo.Category);

            if (handlers.ContainsKey(keyOneFirst))
            {
                handlers[keyOneFirst].Invoke(componentOne, componentTwo);
                return(true);
            }

            string keyTwoFirst = keyify(componentTwo.Category, componentOne.Category);

            if (handlers.ContainsKey(keyTwoFirst))
            {
                handlers[keyTwoFirst].Invoke(componentTwo, componentOne);
                return(true);
            }

            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a simple component to the game using the given image.
        /// </summary>
        /// <param name="imageName">The name of the image to load and draw for this component</param>
        /// <returns>A simple EasyGameComponent object</returns>
        public EasyGameComponent AddComponent(string imageName)
        {
            EasyGameComponent easyGameComponent = new EasyGameComponent(this, imageName);

            AddComponent(easyGameComponent);
            return(easyGameComponent);
        }
Beispiel #7
0
        /// <summary>
        /// This is a callback for the physics engine so that it can raise collision events back to the game
        /// </summary>
        /// <param name="f1"></param>
        /// <param name="f2"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        public bool OnFixtureCollision(Fixture f1, Fixture f2, Contact contact)
        {
            EasyGameComponent componentOne = (EasyGameComponent)f1.Body.UserData;
            EasyGameComponent componentTwo = (EasyGameComponent)f2.Body.UserData;
            bool collisionHandled          = CollisionManager.FireEvent(componentOne, componentTwo);

            return(true);
        }
Beispiel #8
0
        private EasyGameComponent AddWall(int startX, int startY, int row, int col, string imageName)
        {
            EasyGameComponent wall = this.AddComponent(imageName);
            int x = (startX) + (col * wall.Width);
            int y = (startY) + (row * wall.Height);

            wall.Static = true;
            wall.SetPosition(x, y);
            return(wall);
        }
Beispiel #9
0
 public EasyGameComponent AddBall()
 {
     ball = AddComponent("ball");
     ball.EdgeFriction = 0;
     ball.Rotateable = true;
     ball.BounceFactor = 1;
     ball.Static = false;
     ball.SetPosition(200, 700);
     ball.IsBullet = true;
     ball.Nudge(.6f, -.6f);
     ball.MaxVelocity = 2f;
     ball.ConstantVelocity = 10;
     return ball;
 }
Beispiel #10
0
        public void Add(EasyGameComponent component)
        {
            //allComponents.Add(component.ObjectId, component);

            //string key = component.Category;
            //if (this.ContainsKey(key) == false)
            //{
            //    ComponentMapByGuid newMap = new ComponentMapByGuid();
            //    newMap.Add(component.ObjectId, component);
            //    this.Add(key, newMap);
            //}
            //else
            //{
            //    ComponentMapByGuid map = this[key];
            //    map.Add(component.ObjectId, component);
            //}
        }
Beispiel #11
0
 private void handleCharacter(char character, int row, int col)
 {
     if (functionMap.ContainsKey(character))
     {
         Func <EasyGameComponent> handler   = functionMap[character];
         EasyGameComponent        component = handler();
         if (component != null)
         {
             //component.MoveToGrid(col, row);
         }
     }
     else if (nameMap.ContainsKey(character))
     {
         string            componentType = nameMap[character];
         EasyGameComponent component     = game.AddComponent(componentType);
         //component.MoveToGrid(col, row);
         component.Static = true;
     }
 }
Beispiel #12
0
 private void SetStartPosition(EasyGameComponent originatingComponent, Vector2 direction)
 {
     Vector2 positionOffset = Vector2.Zero;
     if (direction.Equals(ProjectileDirections.Up))
     {
         positionOffset = originatingComponent.Height * .6f * direction;
     }
     else if (direction.Equals(ProjectileDirections.Down))
     {
         positionOffset = originatingComponent.Height * .6f * direction;
     }
     else if (direction.Equals(ProjectileDirections.Left))
     {
         positionOffset = originatingComponent.Width * .6f * direction;
     }
     else if (direction.Equals(ProjectileDirections.Right))
     {
         positionOffset = originatingComponent.Width * .6f * direction;
     }
     DisplayPosition = originatingComponent.DisplayPosition + positionOffset;
 }
Beispiel #13
0
        public Rectangle AddRectangle(int startX, int startY, int rows, int columns, params string[] imageNames)
        {
            EasyGameComponent firstWall = null;
            EasyGameComponent lastWall  = null;

            for (int row = 0; row < rows; row++)
            {
                if (row == 0 || row == rows - 1)
                {
                    for (int col = 0; col < columns; col++)
                    {
                        string            imageName = RandomHelper.PickOne(imageNames);
                        EasyGameComponent wall      = AddWall(startX, startY, row, col, imageName);
                        if (row == 0 && col == 0)
                        {
                            firstWall = wall;
                        }
                        if (row == rows - 1 && col == columns - 1)
                        {
                            lastWall = wall;
                        }
                    }
                }
                else
                {
                    for (int col = 0; col < columns; col = col + columns - 1)
                    {
                        string imageName = RandomHelper.PickOne(imageNames);
                        AddWall(startX, startY, row, col, imageName);
                    }
                }
            }
            Rectangle viewableArea = new Rectangle();

            viewableArea.X      = (int)firstWall.DisplayPosition.X + (firstWall.Width / 2);
            viewableArea.Y      = (int)firstWall.DisplayPosition.Y + (firstWall.Height / 2);
            viewableArea.Width  = (int)lastWall.DisplayPosition.X - (lastWall.Width / 2) - viewableArea.X;
            viewableArea.Height = (int)lastWall.DisplayPosition.Y - (lastWall.Height / 2) - viewableArea.Y;
            return(viewableArea);
        }
Beispiel #14
0
        private void SetStartPosition(EasyGameComponent originatingComponent, Vector2 direction)
        {
            Vector2 positionOffset = Vector2.Zero;

            if (direction.Equals(ProjectileDirections.Up))
            {
                positionOffset = originatingComponent.Height * .6f * direction;
            }
            else if (direction.Equals(ProjectileDirections.Down))
            {
                positionOffset = originatingComponent.Height * .6f * direction;
            }
            else if (direction.Equals(ProjectileDirections.Left))
            {
                positionOffset = originatingComponent.Width * .6f * direction;
            }
            else if (direction.Equals(ProjectileDirections.Right))
            {
                positionOffset = originatingComponent.Width * .6f * direction;
            }
            DisplayPosition = originatingComponent.DisplayPosition + positionOffset;
        }
Beispiel #15
0
        public static Rectangle GetAABB(EasyGameComponent component)
        {
            AABB overallAABB = new AABB();
            component.Body.FixtureList.ForEach(delegate(Fixture fixture)
            {
                for (int i = 0; i < fixture.Shape.ChildCount; i++)
                {
                    AABB currentAABB;
                    Transform transform;
                    fixture.Body.GetTransform(out transform);
                    fixture.Shape.ComputeAABB(out currentAABB, ref transform, i);
                    overallAABB.Combine(ref currentAABB);
                }
            });

            int left = (int)overallAABB.UpperBound.X;
            int right = (int)overallAABB.LowerBound.X;
            int top = (int)overallAABB.UpperBound.Y;
            int bottom = (int)overallAABB.LowerBound.Y;

            Rectangle rectangle = new Rectangle(left, top, right - left, bottom - top);
            return rectangle;
        }
Beispiel #16
0
        public bool FireEvent(EasyGameComponent componentOne, EasyGameComponent componentTwo)
        {
            if (componentOne.IsRemoved || componentTwo.IsRemoved)
            {
                return false;
            }

            //The order of the keys matters, because the game loop will be expecting to get the components in the right order
            string keyOneFirst = keyify(componentOne.Category, componentTwo.Category);
            if (handlers.ContainsKey(keyOneFirst))
            {
                handlers[keyOneFirst].Invoke(componentOne, componentTwo);
                return true;
            }

            string keyTwoFirst = keyify(componentTwo.Category, componentOne.Category);
            if (handlers.ContainsKey(keyTwoFirst))
            {
                handlers[keyTwoFirst].Invoke(componentTwo, componentOne);
                return true;
            }

            return false;
        }
Beispiel #17
0
 public void WizardMonsterCollision(EasyGameComponent wizard, EasyGameComponent monster)
 {
     wizard.Remove();
     AddEffect("colorexplosion", wizard.DisplayPosition);
     String message = RandomHelper.PickOne("OUCH", "DEAD", "RIP", "BYE");
     TextEffect textEffect = AddTextEffect("segoe", message, wizard.DisplayPosition, Color.Red);
     textEffect.SecondsToLive = 1;
     textEffect.MakeFlashingText(Color.WhiteSmoke, .05);
     AddTimedEvent(3, AddWizard1, 1);
 }
Beispiel #18
0
 /// <summary>
 /// Allows implementers to pass in their own extensions of EasyGameComponent
 /// </summary>
 /// <param name="component"></param>
 protected void AddComponent(EasyGameComponent component)
 {
     this.Components.Add(component);
 }
Beispiel #19
0
 /// <summary>
 /// Allows implementers to pass in their own extensions of EasyGameComponent
 /// </summary>
 /// <param name="component"></param>
 protected void AddComponent(EasyGameComponent component)
 {
     this.Components.Add(component);
 }
Beispiel #20
0
 /// <summary>
 /// Adds a simple component to the game using the given image.
 /// </summary>
 /// <param name="imageName">The name of the image to load and draw for this component</param>
 /// <returns>A simple EasyGameComponent object</returns>
 public EasyGameComponent AddComponent(string imageName)
 {
     EasyGameComponent easyGameComponent = new EasyGameComponent(this, imageName);
     AddComponent(easyGameComponent);
     return easyGameComponent;
 }
Beispiel #21
0
 public void WizardRubyCollision(EasyGameComponent wizard, EasyGameComponent ruby)
 {
     EffectGameComponent effect = AddEffect("zap", ruby.DisplayPosition);
     display1.Score++;
     ruby.Remove();
     AddRuby();
 }
Beispiel #22
0
 public void AddRuby()
 {
     ruby = this.AddComponent("ruby");
     ruby.SetRandomPosition(viewableArea);
 }
Beispiel #23
0
 public void FireballMonsterCollision(EasyGameComponent fireball, EasyGameComponent monster)
 {
     AddEffect("colorexplosion", monster.DisplayPosition);
     monster.Remove();
     fireball.Remove();
 }
Beispiel #24
0
 public void FireballBrickCollision(EasyGameComponent fireball, EasyGameComponent brick)
 {
     fireball.Remove();
 }