/
Parasite.cs
145 lines (132 loc) · 4.22 KB
/
Parasite.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ParasiteP1.Utility;
using Microsoft.Xna.Framework.Graphics;
namespace ParasiteP1
{
public class Parasite : ICollidable
{
Vector2 position;
public Vector2 Position { get { return position; } set { position = value; s.position = value; } }
public Vector2 velocity;
public Retractor R;
public Vector2 targetPoint;
public static Parasite Me;
public int bodyTimer = 900;
public bool isDetached = false;
public bool IsDying = false;
public bool isDying { get { return IsDying; } set { IsDying = value; } }
Sprite s;
InputController ic = ContentStorageManager.Get<InputController>("input");
public ControllableShip controlShip;
public short OldGrid { get { return oldGrid; } set { oldGrid = value; } }
protected short oldGrid = -1;
public bool team { get { return false; } set { ;} }
public List<ICollidable> coll;
public Parasite(Vector2 position, Vector2 velocity)
{
this.velocity = velocity;
s = new Sprite(ContentStorageManager.Get<Texture2D>("Parasite"));
s.CenterOriginOnTexture();
s.Scale = 0.5f;
s.position = position;
s.Color = Color.Red;
Me = this;
}
public void Update()
{
if (R != null) R.Update();
if (ic.Detach)
{
Position = controlShip.Position;
controlShip.Die();
isDetached = true;
AudioManager.QueueSound("explosion", false);
}
if (isDetached)
{
if (isDying)
{
GUIVariables.lives--;
Position = new Vector2(Game1.ScreenSize.X / 2, Game1.ScreenSize.Y-100);
}
CheckMoveInput(ic);
if (ic.Fire)
{
ChooseNewShip();
}
}
else
{
//Step to point behind ship
targetPoint = new Vector2(controlShip.Position.X, controlShip.Position.Y + 30);
Position += (targetPoint - Position) * 1 / 60 * 6;
/*
if (bodyTimer < 0) //change later
{
Position = controlShip.Position;
controlShip.Die();
bodyTimer = 900;
isDetached = true;
//AudioManager.QueueSound("explosion", false);
}
bodyTimer--;
*/
}
}
private void ChooseNewShip()
{
if (R == null)
R=new Retractor(Position);
}
public void UseNewShip(Enemy closest)
{
bodyTimer = 900;
//// TODO: Remove enemy
controlShip.isDying = false;
controlShip.s.texture = closest.sprite.texture;
controlShip.s.Color = Color.Red;
controlShip.isInvuln = 180;
isDying = false;
controlShip.Position =Position;
//controlShip.lastFired = 0;
//controlShip.bulletType.Clear();
isDetached = false;
}
public void Die()
{
;
}
private void CheckMoveInput(InputController ic)
{
Vector2 tempVect = new Vector2(0, 0);
if (ic.UpDown)
{
tempVect.Y -= velocity.Y;
}
else if (ic.DownDown)
{
tempVect.Y += velocity.Y;
}
if (ic.LeftDown)
{
tempVect.X -= velocity.X;
}
else if (ic.RightDown)
{
tempVect.X += velocity.X;
}
if (tempVect.LengthSquared() != 0)
tempVect.Normalize();
Position += tempVect * velocity;
}
public void Draw(SpriteBatch sb)
{
if (R != null) R.Draw(sb);
s.Draw(sb);
}
}
}