Added ConnectionCable
This commit is contained in:
@@ -504,6 +504,8 @@ size = Vector2(32, 32)
|
||||
[node name="AbstractLevel" type="Node2D" unique_id=1364620575]
|
||||
script = ExtResource("1_o2mui")
|
||||
|
||||
[node name="ConnectionCables" type="Node2D" parent="." unique_id=279521385]
|
||||
|
||||
[node name="Platforms" type="Node2D" parent="." unique_id=1140671629]
|
||||
|
||||
[node name="Doors" type="Node2D" parent="." unique_id=1468144392]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://mpsu4g2b5h3a" path="res://game/levels/abstract_level.tscn" id="1_15okj"]
|
||||
[ext_resource type="Script" uid="uid://bc114fx0hcb6s" path="res://game/levels/test_level.gd" id="2_a2sw7"]
|
||||
[ext_resource type="PackedScene" uid="uid://ct6n0u0iegynv" path="res://game/doors/lever_door.tscn" id="2_r01v2"]
|
||||
[ext_resource type="PackedScene" uid="uid://dq3080605jqta" path="res://game/objects/interactive/connection_cable.tscn" id="3_a50fq"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3kyqvuxmfn8f" path="res://game/objects/decorative/fireplace.tscn" id="3_tuvkr"]
|
||||
[ext_resource type="PackedScene" uid="uid://jab32eoyc523" path="res://game/platform/moving_platform.tscn" id="4_h1708"]
|
||||
[ext_resource type="PackedScene" uid="uid://g0n5npbt3hb2" path="res://game/doors/circle_door.tscn" id="4_yrqjd"]
|
||||
@@ -34,6 +35,11 @@ point_count = 2
|
||||
[node name="TestLevel" unique_id=600627332 instance=ExtResource("1_15okj")]
|
||||
script = ExtResource("2_a2sw7")
|
||||
|
||||
[node name="ConnectionCable" parent="ConnectionCables" parent_id_path=PackedInt32Array(279521385) index="0" unique_id=1234500644 instance=ExtResource("3_a50fq")]
|
||||
position = Vector2(208, 13)
|
||||
points = PackedVector2Array(0, 0, 92, 0, 92, -49, 199, -49)
|
||||
width = 1.0
|
||||
|
||||
[node name="AbstractColoredPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="0" unique_id=137546339 instance=ExtResource("24_h1708")]
|
||||
position = Vector2(274, -81)
|
||||
platform_width = 48
|
||||
@@ -120,7 +126,7 @@ position = Vector2(936, -48)
|
||||
[node name="WhiteEnemy" parent="Enemies" parent_id_path=PackedInt32Array(857989772) index="2" unique_id=1447247338 instance=ExtResource("20_rt0xo")]
|
||||
position = Vector2(743, -48)
|
||||
|
||||
[node name="Player" parent="." index="5" unique_id=1058744997]
|
||||
[node name="Player" parent="." index="6" unique_id=1058744997]
|
||||
position = Vector2(-13, 0)
|
||||
|
||||
[node name="GrayWalls" parent="Tiles" parent_id_path=PackedInt32Array(1626037498) index="0" unique_id=557672309]
|
||||
@@ -135,7 +141,7 @@ tile_map_data = PackedByteArray("AAAwAP3/AAAAAAEAAAAwAPz/AAAAAAEAAAAwAPv/AAAAAAE
|
||||
[node name="Traps" parent="Tiles" parent_id_path=PackedInt32Array(1626037498) index="3" unique_id=635748436]
|
||||
tile_map_data = PackedByteArray("AAA9AAcAAAAAAAAAAAA9AAgAAAAAAAEAAAA9AAkAAAAAAAEAAAA=")
|
||||
|
||||
[node name="LevelEnd" parent="." index="9" unique_id=1018767708]
|
||||
[node name="LevelEnd" parent="." index="10" unique_id=1018767708]
|
||||
position = Vector2(1334, 103)
|
||||
|
||||
[node name="CollisionShape2D" parent="LevelEnd" index="0" unique_id=937956890]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="ShaderMaterial" format=3 uid="uid://dbcb2x1xbq37g"]
|
||||
|
||||
[ext_resource type="Shader" uid="uid://dbsrm43wcolg4" path="res://game/shaders/connection_cable.gdshader" id="1_i3upv"]
|
||||
|
||||
[resource]
|
||||
shader = ExtResource("1_i3upv")
|
||||
shader_parameter/glow_radius = 1.0
|
||||
shader_parameter/travel_time = 5.0
|
||||
@@ -0,0 +1,31 @@
|
||||
class_name ConnectionCable
|
||||
extends Line2D
|
||||
|
||||
|
||||
const SHADER_GLOW_INTERVAL = "glow_interval"
|
||||
const SHADER_GLOW_RADIUS = "glow_radius"
|
||||
const SHADER_TRAVEL_TIME = "travel_time"
|
||||
|
||||
const TRAVEL_SPEED = 100.0
|
||||
const GLOW_INTERVAL = 100.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var length := _get_length()
|
||||
var glow_interval := 1.0 / maxi(1, round(length/GLOW_INTERVAL))
|
||||
var glow_radius := 0.5/length
|
||||
var travel_time := length/TRAVEL_SPEED
|
||||
|
||||
material.set_shader_parameter(SHADER_GLOW_INTERVAL, glow_interval)
|
||||
material.set_shader_parameter(SHADER_GLOW_RADIUS, glow_radius)
|
||||
material.set_shader_parameter(SHADER_TRAVEL_TIME, travel_time)
|
||||
|
||||
|
||||
func _get_length() -> float:
|
||||
if points.size() < 2:
|
||||
return 0.0
|
||||
|
||||
var length := 0.0
|
||||
for i in range(points.size() - 1):
|
||||
length += points[i].distance_to(points[i + 1])
|
||||
return length
|
||||
@@ -0,0 +1 @@
|
||||
uid://c1r1ny6xdedil
|
||||
@@ -0,0 +1,10 @@
|
||||
[gd_scene format=3 uid="uid://dq3080605jqta"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c1r1ny6xdedil" path="res://game/objects/interactive/connection_cable.gd" id="1_43n88"]
|
||||
[ext_resource type="Material" uid="uid://dbcb2x1xbq37g" path="res://game/materials/connection_cable.tres" id="1_k2dc5"]
|
||||
|
||||
[node name="ConnectionCable" type="Line2D" unique_id=1234500644]
|
||||
material = ExtResource("1_k2dc5")
|
||||
width = 2.0
|
||||
texture_mode = 2
|
||||
script = ExtResource("1_43n88")
|
||||
@@ -0,0 +1,22 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform float glow_interval : hint_range(0.0, 1.0, 0.00001) = 1.0;
|
||||
uniform float glow_radius : hint_range(0.0, 1.0, 0.00001) = 1.0;
|
||||
uniform float travel_time : hint_range(0.0, 100.0, 1) = 5.0;
|
||||
|
||||
float get_alpha(vec2 uv, float offset) {
|
||||
float dist = fract(mod(TIME, travel_time)/travel_time + offset);
|
||||
float left = uv.x - glow_radius;
|
||||
float right = uv.x + glow_radius;
|
||||
return step(left, dist) * (1.0 - step(right, dist));
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
float alpha = 0.0;
|
||||
float offset = 0.0;
|
||||
for (float offset = 0.0; offset <= 1.0; offset += glow_interval) {
|
||||
alpha += get_alpha(UV, offset);
|
||||
}
|
||||
|
||||
COLOR.a = alpha;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dbsrm43wcolg4
|
||||
Reference in New Issue
Block a user