-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cs
64 lines (56 loc) · 1.32 KB
/
Bullet.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MonoGameInvaders
{
class Bullet
{
public Vector2 position;
public Vector2 velocity;
public Texture2D texture;
public bool IsActive;
public int Damage => 1;
public Bullet()
{
texture = Global.content.Load<Texture2D>("spr_bullet");
Reset();
}
public void Reset()
{
IsActive = false;
position.X = -1000f;
velocity.Y = 0;
}
public void Update()
{
if (IsActive)
{
if (position.Y < 0)
{
Reset();
}
}
position.Y += velocity.Y;
}
public void Draw()
{
if (IsActive)
{
Global.spriteBatch.Draw(texture, position, Color.White);
}
}
public void Fire(Vector2 startPosition)
{
if (!IsActive)
{
IsActive = true;
position = startPosition;
velocity.Y = -5.0f;
}
}
}
}