Beispiel #1
0
        public SwordSprite(Texture2D texture, int msPerFrame, float scale, Vector2 rotationPoint, CombatableCharacter swordOwner)
        {
            this.layerDepth = DEFAULT_LAYER_DEPTH;
            this.msPerFrame = msPerFrame;
            this.texture = texture;
            this.scale = scale;
            this.rotationPoint = rotationPoint;
            this.rotation = 0;
            this.swordOwner = swordOwner;
            Animating = false;
            charactersHit = new List<CombatableCharacter>();

            // Extract collision data
            textureData =
                new Color[texture.Width * texture.Height];
            texture.GetData(textureData);
        }
Beispiel #2
0
 public void Attack(CombatableCharacter enemy)
 {
     int damage = (int)(Strength - (0.5 * enemy.Defense));
     enemy.HitPoints -= damage;
 }
Beispiel #3
0
        // source: http://xbox.create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel_transformed
        public bool Intersects(CombatableCharacter character, GameLevel currentLevel)
        {
            bool intersectionOccured = false;

            // Update the character's transform
            Matrix characterTransform =
                Matrix.CreateTranslation(new Vector3(character.Position, 0.0f));

            // Build the sword's transform
            Matrix swordTransform =
                Matrix.CreateTranslation(new Vector3(-rotationPoint, 0.0f)) *
                Matrix.CreateScale(scale) *
                Matrix.CreateRotationZ(rotation) *
                Matrix.CreateTranslation(new Vector3(anchorPosition, 0.0f));

            // Calculate the bounding rectangle of this block in world space
            int anchorOffset = (int)(rotationPoint.Y - texture.Height);
            Rectangle swordRectangle = CalculateBoundingRectangle(
                     new Rectangle(0, 0,
                         (int)(anchorOffset + texture.Width),
                         (int)(anchorOffset + texture.Height)),
                     swordTransform);

            // The per-pixel check is expensive, so check the bounding rectangles
            // first to prevent testing pixels when collisions are impossible.
            if (character.AsRectangle().Intersects(swordRectangle))
            {
                // Check collision with person
                if (IntersectPixels(characterTransform, character.CharacterSprite.Texture.Width,
                                    character.CharacterSprite.Texture.Height, character.TextureData,
                                    swordTransform, texture.Width,
                                    texture.Height, textureData))
                {
                    intersectionOccured = true;

                }
            }

            return intersectionOccured;
        }