-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvader.cs
66 lines (59 loc) · 1.81 KB
/
Invader.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
namespace MonoGameInvaders
{
abstract class Invader : SpriteObject
{
public Vector2 Velocity;
public bool IsDead;
public abstract int GetScore();
public Invader(string assetName)
{
Texture = Global.content.Load<Texture2D>(assetName);
}
public static Invader Create(InvaderTypes invaderType)
{
Invader createdInvader = null;
switch(invaderType)
{
case InvaderTypes.Blue:
createdInvader = new BlueInvader();
break;
case InvaderTypes.Red:
createdInvader = new RedInvader();
break;
case InvaderTypes.Yellow:
createdInvader = new YellowInvader();
break;
case InvaderTypes.Green:
createdInvader = new GreenInvader();
break;
case InvaderTypes.Mothership:
createdInvader = new MotherShip();
break;
}
return createdInvader;
}
public override void Update()
{
if (HitPoints == 0)
{
IsDead = true;
}
Position.X += Velocity.X;
if ((Position.X > Global.width - Texture.Width) || (Position.X < 0))
{
Position.X -= Velocity.X;
Velocity.X = -Velocity.X;
Position.Y += Velocity.Y;
}
}
public void Draw()
{
Global.spriteBatch.Draw(Texture, Position, Color.White);
}
}
}