forked from spaceyjase/godot-bulletml-prototype
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mover.cs
77 lines (65 loc) · 1.5 KB
/
Mover.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
using BulletMLLib.SharedProject;
using Godot;
namespace bulletmltemplate
{
/// <summary>
/// Mover - represents a bullet in game, moved by the MoveManager.
/// </summary>
public partial class Mover : Bullet
{
private bool used;
private Node2D ParentNode { get; set; }
private Node2D BulletNode { get; set; }
public Mover(IBulletManager myBulletManager) : base(myBulletManager)
{
}
public override void PostUpdate()
{
// something something out of bounds
if (X < 0f || X > Main.ViewportWidth || Y < 0f || Y > Main.ViewportHeight)
{
Used = false;
}
}
public override float X
{
get => Position.x;
set
{
var position = Position;
position.x = value;
Position = position;
BulletNode.Position = Position;
}
}
public override float Y
{
get => Position.y;
set
{
var position = Position;
position.y = value;
Position = position;
BulletNode.Position = Position;
}
}
public Vector2 Position { get; set; }
public bool Used
{
get => used;
set
{
used = value;
BulletNode.Visible = value;
}
}
public void Init()
{
ParentNode = Main.Instance;
var scene = ResourceLoader.Load<PackedScene>("Bullet.tscn");
BulletNode = scene.Instantiate() as Node2D;
ParentNode.AddChild(BulletNode);
Used = true;
}
}
}