コード例 #1
0
        public void AttemptMissileLaunch(double currentTime)
        {
            double timeSinceLastFired = currentTime - timeLastFiredMissile;

            if (timeSinceLastFired > firingInterval)
            {
                timeLastFiredMissile = currentTime;
                // avoid duplicating costly math ops
                float shipDirection = ShipOrientation;
                float cos           = (float)Math.Cos(shipDirection);
                float sin           = (float)Math.Sin(shipDirection);

                var position = new CGPoint(Position.X + missileLaunchDistance * cos,
                                           Position.Y + missileLaunchDistance * sin);
                SKNode missile = new MissileNode(this, position);
                Scene.AddChild(missile);

                missile.PhysicsBody.Velocity = PhysicsBody.Velocity;
                var vector = new CGVector(missileLaunchImpulse * cos, missileLaunchImpulse * sin);
                missile.PhysicsBody.ApplyImpulse(vector);
            }
        }
コード例 #2
0
        public void AttemptMissileLaunch(double currentTime)
        {
            double timeSinceLastFired = currentTime - timeLastFiredMissile;
            if (timeSinceLastFired > firingInterval) {
                timeLastFiredMissile = currentTime;
                // avoid duplicating costly math ops
                float shipDirection = ShipOrientation;
                float cos = (float) Math.Cos (shipDirection);
                float sin = (float) Math.Sin (shipDirection);

                var position = new PointF (Position.X + missileLaunchDistance * cos,
                    Position.Y + missileLaunchDistance * sin);
                SKNode missile = new MissileNode (this, position);
                Scene.AddChild (missile);

                missile.PhysicsBody.Velocity = PhysicsBody.Velocity;
                var vector = new CGVector (missileLaunchImpulse * cos, missileLaunchImpulse * sin);
                missile.PhysicsBody.ApplyImpulse (vector);
            }
        }