-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cs
More file actions
44 lines (37 loc) · 1022 Bytes
/
Bullet.cs
File metadata and controls
44 lines (37 loc) · 1022 Bytes
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
using Raylib_cs;
using System.Numerics;
namespace SharpAsteroids
{
public class Bullet
{
public Vector2 Pos => new Vector2(posX, posY); //shorthand for Vector2 getter method
public float Radius => radius;
int posX;
int posY;
Vector2 dir;
float radius = 5f;
float speed = 3f;
Color redSemi = new Color(230, 41, 55, 125);
public static event Action<Bullet>? LeftScreen;
public Bullet(int x, int y, Vector2 v)
{
posX = x;
posY = y;
dir = v;
}
public void Update()
{
posX += (int)(dir.X * speed);
posY += (int)(dir.Y * speed);
// Destroy self offscreen
if (posY < 0 || posX < 0 || posY > 480 || posX > 800)
{
LeftScreen?.Invoke(this);
}
}
public void Draw()
{
Raylib.DrawCircle((int)posX, (int)posY, radius, redSemi);
}
}
}