예제 #1
0
        public override void Spawn()
        {
            var x = Controller.Scene.Size.Width + Node.Size.Width / 2;

            var y = GMath.GenerateRandomInRange(
                Node.Size.Height / 2, Controller.Scene.Size.Height - Node.Size.Height / 2);

            Node.Position = new CGPoint(x, y);

            Move();

            Controller.Scene.AddChild(Node);
        }
예제 #2
0
        private Bonus GenerateBonus()
        {
            var randValue = GMath.GenerateRandomInRange(1, 4);

            if ((int)randValue == 1)
            {
                return(new HealBonus(this));
            }

            if ((int)randValue == 2)
            {
                return(new ShieldsBonus(this));
            }

            return(new WeaponBonus(this));
        }
예제 #3
0
        private SKAction GenerateMovingAction()
        {
            double xMinLimit = Node.Size.Width / 2;
            double xMaxLimit = Controller.Scene.Size.Width - xMinLimit;

            double yMinLimit = Node.Size.Height / 2;
            double yMaxLimit = Controller.Scene.Size.Height - yMinLimit;

            double randX = GMath.GenerateRandomInRange(xMinLimit, xMaxLimit);
            double randY = GMath.GenerateRandomInRange(yMinLimit, yMaxLimit);

            double randTime = GMath.GenerateRandomInRange(2, 5);

            var movePoint = new CGPoint(randX, randY);

            return(SKAction.MoveTo(movePoint, randTime));
        }
예제 #4
0
        private void RotatePlayer(CGPoint mousePosition)
        {
            var playerPosition = Player.Node.Position;

            double mouseDirX = mousePosition.X - playerPosition.X;
            double mouseDirY = mousePosition.Y - playerPosition.Y;

            var mouseDirection = GMath.Normalize(new CGPoint(mouseDirX, mouseDirY));

            double angle = GMath.Dot(mouseDirection, Player.LookDirection);

            if (mouseDirection.Y < 0)
            {
                Player.Node.ZRotation = (nfloat)(-Math.Acos(angle) - Math.PI / 2);
            }
            else
            {
                Player.Node.ZRotation = (nfloat)(Math.Acos(angle) - Math.PI / 2);
            }
        }
예제 #5
0
        public Player(GameController controller, string imgName)
            : base(controller, imgName, GameObjects.player)
        {
            currWeaponLvl = 1;
            hp            = 100;
            shields       = 100;

            DefaultRotation = -Math.PI / 2;
            Node.ZRotation += (nfloat)DefaultRotation;

            Node.SetScale(0.25f);

            Node.Position =
                new CGPoint(Node.Size.Width * 1.5, Controller.Scene.Size.Height * 0.5);

            UpdateWeapon();

            LookDirection = GMath.Normalize(new CGPoint(Controller.Scene.Size.Width, 0));

            Controller.Scene.AddChild(Node);
        }
예제 #6
0
        private void SetLookAtPlayer()
        {
            double playerVectorX = Controller.Player.Node.Position.X - Node.Position.X;
            double playerVectorY = Controller.Player.Node.Position.Y - Node.Position.Y;

            var playerDir = new CGPoint(playerVectorX, playerVectorY);

            playerDir = GMath.Normalize(playerDir);

            var lookDir = Controller.Player.LookDirection;

            double angle = GMath.Dot(playerDir, lookDir);

            if (playerDir.Y < 0)
            {
                Node.ZRotation = (nfloat)(-Math.Acos(angle) - Math.PI / 2);
            }
            else
            {
                Node.ZRotation = (nfloat)(Math.Acos(angle) - Math.PI / 2);
            }
        }
예제 #7
0
        protected Bonus(string spriteImgName, GameController controller)
            : base(spriteImgName)
        {
            this.controller   = controller;
            _node.PhysicsBody = SKPhysicsBody.CreateRectangularBody(_node.Size);
            _node.PhysicsBody.CategoryBitMask    = (uint)GameObjects.bonus;
            _node.PhysicsBody.ContactTestBitMask = (uint)GameObjects.playerBullet;
            _node.PhysicsBody.CollisionBitMask   = (uint)GameObjects.none;

            double maxY = controller.Scene.Size.Height - _node.Size.Height / 2;
            double minY = _node.Size.Height / 2;
            double y    = GMath.GenerateRandomInRange(minY, maxY);
            double x    = controller.Scene.Size.Width + _node.Size.Width / 2;

            _node.Position = new CGPoint(x, y);

            var movingAction = SKAction.MoveBy(-100, 0, 1);

            _node.RunActionAsync(SKAction.RepeatActionForever(movingAction));

            controller.Scene.AddChild(_node);

            controller.BonusesInScene.Add(this);
        }
예제 #8
0
 private void GenerateBonusDelay()
 {
     bonusDelay = GMath.GenerateRandomInRange(10000, 40000);
 }
예제 #9
0
 private void GenerateRandomDelay()
 {
     delay = GMath.GenerateRandomInRange(2000, 10000);
 }