-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bullet.cs
47 lines (36 loc) · 952 Bytes
/
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
using Godot;
using System;
public class Bullet : Spatial
{
public float Speed = 70;
public float Damage = 15;
public float KillTimer = 4;
public float Timer = 0;
public bool HitSomething = false;
public override void _Ready()
{
GetNode("Area").Connect("body_entered", this, "collided");
}
public override void _PhysicsProcess(float delta)
{
var forward_dir = GlobalTransform.basis.z.Normalized();
GlobalTranslate(forward_dir * Speed * delta);
Timer += delta;
if (Timer >= KillTimer)
{
QueueFree();
}
}
public void collided(CollisionObject2D body)
{
if (HitSomething == false)
{
if (body is HittableByBullets hittableByBullets)
{
hittableByBullets.BulletHit(Damage, GlobalTransform);
}
}
HitSomething = true;
QueueFree();
}
}