]> git.r.bdr.sh - rbdr/super-polarity/blame - SuperPolarity/Actors/Ship.cs
Consolidates windows project
[rbdr/super-polarity] / SuperPolarity / Actors / Ship.cs
CommitLineData
2af83e98
BB
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Microsoft.Xna.Framework;
6using Microsoft.Xna.Framework.Graphics;
7
8namespace SuperPolarity
9{
05e4b948 10 class Ship : GameActor
2af83e98
BB
11 {
12 public enum Polarity : byte { Negative, Positive, Neutral };
13
2af83e98
BB
14 public Polarity CurrentPolarity;
15 public uint MagneticRadius;
16
097781e6
BB
17 public float FleeVelocity;
18 public float ActVelocity;
19 public float ChargeVelocity;
b587e9d8 20 public int RepelRadius;
2af83e98
BB
21
22 protected bool Magnetizing;
23
74c15570 24 public Ship(SuperPolarity newGame) : base(newGame) {
2af83e98
BB
25 MagneticRadius = 250;
26 RepelRadius = 100;
27
097781e6 28 HP = 2;
74c15570 29
2af83e98 30 FleeVelocity = 5;
097781e6
BB
31 ActVelocity = 1;
32 ChargeVelocity = 2.5f;
2af83e98
BB
33 CurrentPolarity = Polarity.Neutral;
34 Magnetizing = false;
35 }
36
37 public virtual void SwitchPolarity()
38 {
39 if (CurrentPolarity == Polarity.Positive)
40 {
41 CurrentPolarity = Polarity.Negative;
42 }
43 else
44 {
45 CurrentPolarity = Polarity.Positive;
46 }
47 }
48
49 public virtual void SetPolarity(Polarity newPolarity)
50 {
51 CurrentPolarity = newPolarity;
52 }
53
54 public virtual void Shoot()
55 {
56 }
57
58 public override void Update(GameTime gameTime)
59 {
60 base.Update(gameTime);
61 Magnetizing = false;
62 }
63
64 public virtual void Magnetize(Ship ship, float distance, float angle)
65 {
66 Magnetizing = true;
67 Polarity polarity = ship.CurrentPolarity;
68
69 if (polarity != CurrentPolarity)
70 {
71 Attract(angle);
72 }
73 else
74 {
75 Repel(distance, angle);
76 }
77 }
78
79 protected void Attract(float angle)
80 {
81 Velocity.X = (float) (ChargeVelocity * Math.Cos(angle));
82 Velocity.Y = (float) (ChargeVelocity * Math.Sin(angle));
83 }
84
85 protected void Repel(float distance, float angle)
86 {
87 if (distance > RepelRadius) { Magnetizing = false; return; }
88 Velocity.X = -(float)(FleeVelocity * Math.Cos(angle));
89 Velocity.Y = -(float)(FleeVelocity * Math.Sin(angle));
90 }
91 }
92}