-
Notifications
You must be signed in to change notification settings - Fork 0
/
harrypotter.gd
77 lines (52 loc) · 2.01 KB
/
harrypotter.gd
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
extends Polygon2D
onready var line = $Line2D
onready var collision_polygon_area = $Collision_Trigger/collision_polygon_area
export (int) var h_point_count = 5
var width
# distance between to vertical points
export (float) var v_offset = 10 #10
export (float) var v_offset_trigger = 8 # Default: 2
export (int) var y_min_offset = -30
export (int) var y_max_offset = 30
# list of points that form the cracks shape
var vertices = PoolVector2Array()
var filled = false
func _ready():
line.visible = false
randomize()
var line_start = line.points[0]
var line_end = line.points[1]
width = line_start.distance_to(line_end)
var h_space = width / (h_point_count - 1)
vertices.append(line_start)
for i in range(1, h_point_count-1):
vertices.append(Vector2(h_space * i,0 + rand_range(y_min_offset, y_max_offset)))
vertices.append(line_end)
# trigger_vertices form the trigger area above the actual polygon shape
var trigger_vertices = vertices
# use the upper part of the polygon to create
# the segments used for collisions
for i in range(0, trigger_vertices.size()-1):
var segment = SegmentShape2D.new()
segment.a = trigger_vertices[i]
segment.b = trigger_vertices[i+1]
var collision_shape = CollisionShape2D.new()
collision_shape.set_shape(segment)
collision_shape.set_one_way_collision(true)
$StaticBody2D.add_child(collision_shape)
# now, add the bottom part of the polygon
for j in range(vertices.size()-2, 0, -1):
var v = vertices[j]
vertices.append(Vector2(v.x, v.y + v_offset))
trigger_vertices.append(Vector2(line_end.x, line_end.y + v_offset_trigger))
for j in range(trigger_vertices.size()-2, 0, -1):
var v = trigger_vertices[j]
trigger_vertices.append(Vector2(v.x, v.y + v_offset_trigger))
trigger_vertices.append(Vector2(line_start.x, line_end.y + v_offset_trigger))
set_polygon(vertices)
collision_polygon_area.set_polygon(trigger_vertices)
$Collision_Trigger.position.y += -15 # Default: -5
func fill():
if !filled:
$AnimationPlayer.play("fill")
filled = true