/
PlayerShip.cs
116 lines (105 loc) · 3.52 KB
/
PlayerShip.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SpaceWars
{
public class PlayerShip : SpaceShip
{
public new const string CollisionGroupString = "PlayerShip";
public PlayerShip(MatrixCoords topLeft)
: base(topLeft, new char[,]{{'='}},new MatrixCoords(0,0), 30)
{
this.body = GetSpaceShipBody();
}
public override char[,] GetSpaceShipBody()
{
char[,] body = new char[,]
{
{' ',' ','/','|','\\',' ',' '},
{' ','/','(',' ',')','\\',' '},
{'/',' ',' ','_',' ',' ','\\'},
{' ',' ','/',' ','\\',' ',' '}
};
return body;
}
public override string GetCollisionGroupString()
{
return PlayerShip.CollisionGroupString;
}
public void MoveLeft()
{
this.topLeft.Col--;
if (this.topLeft.Col <= -3)
{
this.topLeft.Col = SpaceWarsMain.WorldCols - 3;
}
}
public void MoveRight()
{
this.topLeft.Col++;
if (this.topLeft.Col >= SpaceWarsMain.WorldCols-3)
{
this.topLeft.Col = -3;
}
}
public override void Update()
{
}
public int GetLife
{
get
{
return this.life;
}
}
public override IEnumerable<GameObject> ProduceObjects()
{
List<PlayerWeapons> shells = new List<PlayerWeapons>();
if (base.bulletFired)
{
shells.Add(new PlayerBullet(new MatrixCoords(this.topLeft.Row, this.topLeft.Col + 3), -1, 0));
this.bulletFired = false;
return shells;
}
if (base.rocketFired)
{
shells.Add(new PlayerRocket(new MatrixCoords(this.topLeft.Row + 1, this.topLeft.Col + 7), new char[,] { { '|' } }, -2, 0));
shells.Add(new PlayerRocket(new MatrixCoords(this.topLeft.Row + 1, this.topLeft.Col - 1), new char[,] { { '|' } }, -2, 0));
this.rocketFired = false;
return shells;
}
if (base.leftBlasterFired)
{
shells.Add(new LeftBlaster(new MatrixCoords(this.topLeft.Row, this.topLeft.Col + 3), -1, -1));
this.leftBlasterFired = false;
return shells;
}
if (base.rightBlasterFired)
{
shells.Add(new RightBlaster(new MatrixCoords(this.topLeft.Row, this.topLeft.Col + 3), -1, 1));
this.rightBlasterFired = false;
return shells;
}
if (base.superRocketCount > 0 && base.superRocketFired)
{
shells.Add(new NuclearMissile(new MatrixCoords(this.topLeft.Row - 3, this.topLeft.Col + 3), new char[,] { { } }, -2, 0));
this.superRocketCount--;
this.superRocketFired = false;
return shells;
}
return shells;
}
public override void RespondToCollision(CollisionData collisionData)
{
if (collisionData.hitObjectsCollisionGroupStrings.Contains(Gift.CollisionGroupString))
{
this.life++;
}
else
{
base.RespondToCollision(collisionData);
}
}
}
}