-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulletHoleCanvas.cs
71 lines (63 loc) · 1.52 KB
/
BulletHoleCanvas.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
using System;
using System.Collections.Generic;
using Godot;
public partial class BulletHoleCanvas : Node2D
{
List<Hole> holes = new();
static Texture2D bulletHole1 = GD.Load<Texture2D>("res://Assets/bullet-hole1.png");
static Texture2D bulletHole2 = GD.Load<Texture2D>("res://Assets/bullet-hole2.png");
static Vector2 baseHoleSize = new(50, 50);
static Color[] colors = [
Colors.White,
Colors.LightBlue,
Colors.LightGray,
Colors.LightCyan,
];
public void Shoot()
{
holes.Add(new Hole
{
Offset = new Vector2(
-0.1f * GD.Randf() * 0.1f,
-0.1f * GD.Randf() * 0.1f
),
Color = colors[GD.Randi() % colors.Length],
Scale = 0.6f + GD.Randf() * 0.4f,
Rotation = GD.Randf() * (float)Math.PI,
ImageType = GD.Randi() % 1,
});
QueueRedraw();
}
public override void _Draw()
{
foreach (var hole in holes)
{
DrawImage(hole);
}
}
void DrawImage(Hole hole)
{
var winSize = GetWindow().Size;
var center = new Vector2(winSize.X / 2, winSize.Y / 2);
var texture = hole.ImageType == 0 ? bulletHole1 : bulletHole2;
var size = baseHoleSize * hole.Scale;
DrawSetTransform(center, hole.Rotation);
DrawTextureRect(texture, new Rect2
{
Position = -size / 2,
Size = size,
}, false, hole.Color);
}
public void Clear()
{
holes.Clear();
}
class Hole
{
public Vector2 Offset { get; set; } = Vector2.Zero;
public Color Color { get; set; } = Colors.White;
public float Scale { get; set; } = 1;
public float Rotation { get; set; }
public uint ImageType { get; set; }
}
}