예제 #1
0
        public static GameObject BuildObject(float projectileSpeed, int projectileSize, int maxBounces, Vector2 direction)
        {
            GameObject           obj = new GameObject("projectile");
            ProjectileController projectileController = new ProjectileController()
            {
                ProjectileSpeed = projectileSpeed, Direction = direction, MaxBounces = maxBounces
            };

            obj.AddComponent(projectileController);
            obj.AddComponent(new SimpleBoxCollider()
            {
                Passive = false, Hitbox = new Rectangle(0, 0, projectileSize, projectileSize), CollisionHandler = projectileController.OnCollision, Tags = { "projectile", "firedByPlayer" }
            });
            obj.AddComponent(new RectRenderer()
            {
                Rect      = new Rectangle(0, 0, projectileSize, projectileSize),
                DrawStyle = ShapeDrawStyles.Filled,
                FillColor = Color.White,
            });
            obj.AddComponent(new BoundaryExpirator()
            {
                Boundaries = Display.Screen
            });

            return(obj);
        }
예제 #2
0
        protected override void Update()
        {
            AxisDirections?moveDirection = null;

            if (RawKeyboardInput.IsPressed(Keys.W) || RawGamepadInput.IsDpadPressed(AxisDirections.Up) || RawGamepadInput.IsLeftJoystickPressed(AxisDirections.Up))
            {
                moveDirection = AxisDirections.Up;
            }
            else if (RawKeyboardInput.IsPressed(Keys.D) || RawGamepadInput.IsDpadPressed(AxisDirections.Right) || RawGamepadInput.IsLeftJoystickPressed(AxisDirections.Right))
            {
                moveDirection = AxisDirections.Right;
            }
            else if (RawKeyboardInput.IsPressed(Keys.S) || RawGamepadInput.IsDpadPressed(AxisDirections.Down) || RawGamepadInput.IsLeftJoystickPressed(AxisDirections.Down))
            {
                moveDirection = AxisDirections.Down;
            }
            else if (RawKeyboardInput.IsPressed(Keys.A) || RawGamepadInput.IsDpadPressed(AxisDirections.Left) || RawGamepadInput.IsLeftJoystickPressed(AxisDirections.Left))
            {
                moveDirection = AxisDirections.Left;
            }

            if (moveDirection != null)
            {
                Point destination = coords + ((AxisDirections)moveDirection).ToPoint();

                if (checkCanMove(destination))
                {
                    GameGrid[coords.X, coords.Y]           = null;
                    GameGrid[destination.X, destination.Y] = Object;
                    coords = destination;
                }
            }


            Diagonals?diagonalDir = null;

            if (RawKeyboardInput.IsPressed(Keys.Q))
            {
                diagonalDir = Diagonals.UpLeft;
            }
            else if (RawKeyboardInput.IsPressed(Keys.E))
            {
                diagonalDir = Diagonals.UpRight;
            }
            else if (RawKeyboardInput.IsPressed(Keys.Z))
            {
                diagonalDir = Diagonals.DownLeft;
            }
            else if (RawKeyboardInput.IsPressed(Keys.C))
            {
                diagonalDir = Diagonals.DownRight;
            }

            if (diagonalDir != null)
            {
                Sfx.PlaySfx("sfx1");
                GameObject projectileObj = ProjectileController.BuildObject(PROJ_SPEED, PROJ_SIZE, PROJ_BOUNCES, ((Diagonals)diagonalDir).ToVector2());
                projectileObj.LocalPosition = Object.LocalPosition.Plus(tileSize / 2 - 1);
                Pigeon.World.AddObj(projectileObj);
            }
        }