コード例 #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;
 }
コード例 #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;
 }
コード例 #3
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 public void BallBrickCollision(EasyGameComponent ball, EasyGameComponent brick)
 {
     brick.Remove();
     EffectGameComponent effect = AddEffect("colorexplosion", brick.DisplayPosition);
     effect.SecondsPerFrame = .05;
     effect.OverlayColor = brick.OverlayColor;
 }
コード例 #4
0
ファイル: PhysicsHelper.cs プロジェクト: pinh3ad/EasyXNA
        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);
        }
コード例 #5
0
ファイル: CollisionManager.cs プロジェクト: pinh3ad/EasyXNA
        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);
        }
コード例 #6
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
        /// <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);
        }
コード例 #7
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
        /// <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);
        }
コード例 #8
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
        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);
        }
コード例 #9
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 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;
 }
コード例 #10
0
ファイル: ComponentRegistry.cs プロジェクト: pinh3ad/EasyXNA
        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);
            //}
        }
コード例 #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;
     }
 }
コード例 #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;
 }
コード例 #13
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
        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);
        }
コード例 #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;
        }
コード例 #15
0
ファイル: PhysicsHelper.cs プロジェクト: pinh3ad/EasyXNA
        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;
        }
コード例 #16
0
ファイル: CollisionManager.cs プロジェクト: pinh3ad/EasyXNA
        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;
        }
コード例 #17
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 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);
 }
コード例 #18
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
 /// <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);
 }
コード例 #19
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
 /// <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);
 }
コード例 #20
0
ファイル: EasyTopDownGame.cs プロジェクト: pinh3ad/EasyXNA
 /// <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;
 }
コード例 #21
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 public void WizardRubyCollision(EasyGameComponent wizard, EasyGameComponent ruby)
 {
     EffectGameComponent effect = AddEffect("zap", ruby.DisplayPosition);
     display1.Score++;
     ruby.Remove();
     AddRuby();
 }
コード例 #22
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 public void AddRuby()
 {
     ruby = this.AddComponent("ruby");
     ruby.SetRandomPosition(viewableArea);
 }
コード例 #23
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 public void FireballMonsterCollision(EasyGameComponent fireball, EasyGameComponent monster)
 {
     AddEffect("colorexplosion", monster.DisplayPosition);
     monster.Remove();
     fireball.Remove();
 }
コード例 #24
0
ファイル: GameLoop.cs プロジェクト: pinh3ad/EasyXNA
 public void FireballBrickCollision(EasyGameComponent fireball, EasyGameComponent brick)
 {
     fireball.Remove();
 }