]> git.r.bdr.sh - rbdr/super-polarity/blob - Super Polarity/Actors/Ship.cs
b4706ac41670e8c42180d99b73962e716336be4f
[rbdr/super-polarity] / Super Polarity / Actors / Ship.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 Ship : Actor
11 {
12 public enum Polarity : byte { Negative, Positive, Neutral };
13
14 protected uint HP;
15 public Polarity CurrentPolarity;
16 public uint MagneticRadius;
17
18 protected float FleeVelocity;
19 protected float ActVelocity;
20 protected float ChargeVelocity;
21 protected int RepelRadius;
22
23 protected bool Magnetizing;
24
25 public Ship(Game newGame) : base(newGame) {
26 MagneticRadius = 250;
27 RepelRadius = 100;
28
29 FleeVelocity = 5;
30 ActVelocity = 2;
31 ChargeVelocity = 1.5f;
32 CurrentPolarity = Polarity.Neutral;
33 Magnetizing = false;
34 }
35
36 public virtual void SwitchPolarity()
37 {
38 if (CurrentPolarity == Polarity.Positive)
39 {
40 CurrentPolarity = Polarity.Negative;
41 }
42 else
43 {
44 CurrentPolarity = Polarity.Positive;
45 }
46 }
47
48 public virtual void SetPolarity(Polarity newPolarity)
49 {
50 CurrentPolarity = newPolarity;
51 }
52
53 public virtual void Shoot()
54 {
55 }
56
57 public override void Update(GameTime gameTime)
58 {
59 base.Update(gameTime);
60 Magnetizing = false;
61 }
62
63 public virtual void Magnetize(Ship ship, float distance, float angle)
64 {
65 Magnetizing = true;
66 Polarity polarity = ship.CurrentPolarity;
67
68 if (polarity != CurrentPolarity)
69 {
70 Attract(angle);
71 }
72 else
73 {
74 Repel(distance, angle);
75 }
76 }
77
78 protected void Attract(float angle)
79 {
80 Velocity.X = (float) (ChargeVelocity * Math.Cos(angle));
81 Velocity.Y = (float) (ChargeVelocity * Math.Sin(angle));
82 }
83
84 protected void Repel(float distance, float angle)
85 {
86 if (distance > RepelRadius) { Magnetizing = false; return; }
87 Velocity.X = -(float)(FleeVelocity * Math.Cos(angle));
88 Velocity.Y = -(float)(FleeVelocity * Math.Sin(angle));
89 }
90 }
91 }