-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.cs
81 lines (67 loc) · 2.02 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using FNAEngine2D;
using FNAEngine2D.Collisions;
using FNAEngine2D.GameObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pong
{
public class Bullet: GameObject, IUpdate
{
public const int BULLET_WIDTH = 4;
public const int BULLET_HEIGHT = 18;
/// <summary>
/// Speed of the bullet
/// </summary>
private float _speed = 600f;
/// <summary>
/// Type to manage the colliders
/// </summary>
private Type[] _colliderTypes = new Type[] { typeof(GameBorder), typeof(Block) };
/// <summary>
/// Constructor
/// </summary>
public Bullet(float x, float y)
{
this.Location = new Vector2(x, y);
this.Width = BULLET_WIDTH;
this.Height = BULLET_HEIGHT;
}
/// <summary>
/// Loading
/// </summary>
protected override void Load()
{
Add(new TextureBox("bullet", this.Bounds));
}
/// <summary>
/// Update
/// </summary>
public void Update()
{
int deplacementY = -(int)(_speed * this.ElapsedGameTimeSeconds);
Collision collision = this.GetCollision(this.X, this.Y + deplacementY, _colliderTypes);
if (collision != null)
{
foreach (GameObject collideObj in collision.CollidesWith)
{
if (collideObj is Block)
{
//Collapse avec un block, on va détruire le block...
((Block)collideObj).Hit();
GetContent<SoundEffect>("sfx\\hit").Data.Play();
}
}
this.Destroy();
}
else
{
this.TranslateY(deplacementY);
}
}
}
}