-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magic_Bullet.cs
executable file
·54 lines (50 loc) · 1.21 KB
/
Magic_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
using Godot;
using System;
public class Magic_Bullet : Area2D
{
[Signal]
delegate void attack(int damage);
private int speed = 1000;
private int damage = 30;
private float reduction_time = (float)0.5;
private int damage_reduction = 5;
private bool hitting = false;
private Vector2 velocity = new Vector2();
public void start(Vector2 pos, Vector2 dir)
{
Position = pos;
Rotation = dir.Angle();
velocity = dir * speed;
GetNode<Timer>("damage_reduction_timer").WaitTime = reduction_time;
GetNode<Timer>("damage_reduction_timer").Start();
}
public override void _Process(float delta)
{
if(!hitting)
{Position += velocity * delta;}
if(damage <= 0)
{explode();}
}
public void explode()
{
GetNode<AnimatedSprite>("bullet_sprite").Play("Hit");
hitting = true;
}
private void _on_Magic_Bullet_body_entered(object body)
{
if(body.ToString() != "player" && body.ToString() != "Orb")
{explode();}
if(body.ToString() == "Warden")
{Warden warden = (Warden)body;
warden.take_damage(damage);}
}
private void _on_damage_reduction_timer_timeout()
{
if(damage > 0)
{damage = damage - damage_reduction;}
}
private void _on_bullet_sprite_animation_finished()
{
QueueFree();
}
}