Beispiel #1
0
        public PlayerJetActor(PlayerJetSprite sprite, int player_number)
        {
            InitializeComponent();

            _player_number = player_number;
            // Store the sprite/model passed via dependency injection to a local variable.
            _sprite = sprite;

            // Set the sprite height and width based on actor geometery.  Sprite height and width
            // is important for the (rough) first pass on collision detection.
            SetSpriteHeightAndWidth();

            // Setup sprite secondary boundaries for collisions based on actor geometry.
            // This is needed for the detailed second pass on collisions.
            Vector extent = new Vector(_sprite.Width / 2.0, _sprite.Height / 2.0);
            double radius = _sprite.Width / 2.0;

            Vector center = Vector.Add(extent, _sprite.Position);

            // Attach observer/callbacks we need from sprite to actor.
            _sprite.Moved     += new MovedHandler(_Sprite_Moved);
            _sprite.Removed   += new RemoveHandler(_Sprite_Removed);
            _sprite.Collision += new CollisionHandler(_Sprite_Collision);

            _sprite.CalmCollision     += new CollisionHandler(_Sprite_CalmCollision);
            _sprite.SpinningCollision += new CollisionHandler(_Sprite_SpinningCollision);
            _sprite.PulsingCollision  += new CollisionHandler(_Sprite_PulsingCollision);

            _sprite.NowSpinningStateChange += new PlayerJetSprite.StateChangeHandler(_PlayerJetSprite_NowSpinningStateChange);
            _sprite.NowPulsingStateChange  += new PlayerJetSprite.StateChangeHandler(_PlayerJetSprite_NowPulsingStateChange);
            _sprite.NowCalmStateChange     += new PlayerJetSprite.StateChangeHandler(_PlayerJetSprite_NowCalmStateChange);

            _sprite.Collision    += new CollisionHandler(_PlayerJetSprite_Collision);
            _sprite.NonCollision += new CollisionHandler(_PlayerJetSprite_NonCollision);


            ////////////////////////////////////////////////////////////
            // Insert a transformation group into the *root* UIElment (above the first canvas) to control the
            // actors roation and  position during animation.  Keep a reference to _roate and _translate to
            // change the ship heading and position on each move (when the "Moved" callback happens).
            TransformGroup _transforms = new TransformGroup();

            _rotate.CenterX = 0.0;             // Set the center of rotation
            _rotate.CenterY = 0.0;
            _transforms.Children.Add(_rotate); // Note: _rotate MUST be added before _translate or it will not rotate relative to ship center.

            _transforms.Children.Add(_translate);
            this.RenderTransform = _transforms;

            // Find the story boards in the xaml, so we can start/stop the animations when we want to.
            _spinning_story = (Storyboard)TryFindResource("PlayerJetSpinningKey");
            _pulsing_story  = (Storyboard)TryFindResource("PlayerJetPulsingKey");

            // Set the color of the jet's body based on the player number.
            JetBodyPoly.Fill = createJetColor(_player_number);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pilot_name"></param>
        /// <param name="position"></param>
        /// <param name="direction"></param>
        /// <param name="speed"></param>
        /// <param name="game_stage_limits"></param>
        /// <returns></returns>
        PlayerJetActor PlayerJetAddToStage(string pilot_name, int player_number, Vector position, Vector direction, double speed, Rect game_stage_limits)
        {
            //////////////////////////////////
            // Make a new sprite.
            PlayerJetSprite sprite = new PlayerJetSprite(position, direction, speed);

            sprite.Reset();                                 // Get the sprite in a default/known state.

            // Setup callbackks used for things like removal and scoring.
            sprite.Removed           += new RemoveHandler(SpriteRemoveHandler);
            sprite.CalmCollision     += new CollisionHandler(PilotCalmCollisionScoring);
            sprite.SpinningCollision += new CollisionHandler(PilotSpinningCollisionScoring);
            sprite.PulsingCollision  += new CollisionHandler(PilotPulsingCollisionScoring);


            // Setup the ship event handling (e.g. for reporting ship status to player).
            sprite.Collision    += new CollisionHandler(PilotCollidedTracking);      // Calls PilotCollidedTracking method when ship collides.
            sprite.NonCollision += new CollisionHandler(PilotNonCollisionTracking);  // Calls PlayerNonCollisionTracking method (once per turn) when ship does NOT collide.


            //////////////////////////////////
            // Make a new actor.
            PlayerJetActor actor = new PlayerJetActor(sprite, player_number);   // Make a new actor and give it a reference to its sprite.

            actor.Visibility = Visibility.Hidden;
            _game_stage.Children.Add(actor);                // Add the actor to the stage.

            sprite.IsMoving  = true;
            sprite.Position  = position;                    // Set the position, direction, speed, etc.
            sprite.Direction = direction;
            sprite.Speed     = speed;
            _active_sprites.Add(sprite);                    // Add the sprite to the list of moving sprites.
            sprite.Move();
            actor.Visibility = Visibility.Visible;          // Make the actor visible in the stage again.


            actor.Sprite.setBounceLimits(_game_stage_limits);
            return(actor);
        }