]> git.r.bdr.sh - rbdr/super-polarity/blob - SuperPolarity/Actors/Bullet.cs
d20289cd536aa832ac8a1e7d5ff2764877474c87
[rbdr/super-polarity] / SuperPolarity / Actors / Bullet.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7
8 namespace SuperPolarity
9 {
10 class Bullet : Actor
11 {
12 protected ParticleEngine particleEngine;
13 public int Power;
14
15 public Bullet(SuperPolarity newGame)
16 : base(newGame)
17 {
18 }
19
20 ~Bullet()
21 {
22 particleEngine = null;
23 }
24
25 public override void Initialize(Texture2D texture, Vector2 position)
26 {
27 base.Initialize(texture, position);
28 BoxDimensions.X = 10;
29 BoxDimensions.Y = 10;
30 BoxDimensions.W = 10;
31 BoxDimensions.Z = 10;
32 MaxVelocity = 8;
33 InitBox();
34 particleEngine = ParticleEffectFactory.CreateBullet(position);
35 }
36
37 public override void Update(GameTime gameTime)
38 {
39 Velocity.X = (float)(MaxVelocity * Math.Cos(Angle));
40 Velocity.Y = (float)(MaxVelocity * Math.Sin(Angle));
41
42 Power = 1;
43
44 Position += Velocity;
45 UpdateBox();
46
47 particleEngine.Update();
48 particleEngine.EmitterLocation = Position;
49 }
50
51 public override void Draw(SpriteBatch spriteBatch)
52 {
53 base.Draw(spriteBatch);
54 particleEngine.Draw(spriteBatch);
55 }
56
57 public override void Collide(Actor other, Rectangle collision)
58 {
59 if (Dying) { return; }
60 if (other.GetType().IsAssignableFrom(typeof(StandardShip)))
61 {
62 Die();
63 return;
64 }
65 }
66
67 protected override void Die()
68 {
69 ActorManager.CheckOut(this);
70 Renderer.CheckOut(this);
71 Parent.Children.Remove(this);
72 }
73
74 public override void CleanUp()
75 {
76 base.CleanUp();
77 this.particleEngine = null;
78 }
79 }
80 }