aboutsummaryrefslogtreecommitdiff
path: root/SuperPolarity/Actors/Bullet.cs
blob: 780177765a6f4abd79bce6c694e5bfa15873358b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SuperPolarity
{
    class Bullet : GameActor
    {
        protected ParticleEngine particleEngine;
        public int Power;

        public Bullet(SuperPolarity newGame)
            : base(newGame)
        {
        }

        ~Bullet()
        {
            particleEngine = null;
        }

        public override void Initialize(Texture2D texture, Vector2 position)
        {
            base.Initialize(texture, position);
            BoxDimensions.X = 10;
            BoxDimensions.Y = 10;
            BoxDimensions.W = 10;
            BoxDimensions.Z = 10;
            MaxVelocity = 8;
            InitBox();
            particleEngine = ParticleEffectFactory.CreateBullet(position);
        }

        public override void Update(GameTime gameTime)
        {
            Velocity.X = (float)(MaxVelocity * Math.Cos(Angle));
            Velocity.Y = (float)(MaxVelocity * Math.Sin(Angle));

            Power = 1;

            Position += Velocity;
            UpdateBox();

            particleEngine.Update();
            particleEngine.EmitterLocation = Position;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            particleEngine.Draw(spriteBatch);
        }

        public override void Collide(Actor other, Rectangle collision)
        {
            if (Dying) { return; }
            if (other.GetType().IsAssignableFrom(typeof(StandardShip)))
            {
                Die();
                return;
            }
        }

        protected override void Die()
        {
            ActorManager.CheckOut(this);
            Renderer.CheckOut(this);
            Parent.Children.Remove(this);
        }

        public override void CleanUp()
        {
            base.CleanUp();
            this.particleEngine = null;
        }
    }
}