Glowing crystals mainly
This commit is contained in:
parent
ce0ef75241
commit
49e344f109
8 changed files with 624 additions and 188 deletions
8
components/CrystalGlowComponent.tscn
Normal file
8
components/CrystalGlowComponent.tscn
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://qgxsbmcv0nqh"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://components/scripts/crystal_glow_component.gd" id="1_0l2qm"]
|
||||||
|
|
||||||
|
[node name="CrystalGlowComponent" type="Node2D"]
|
||||||
|
script = ExtResource("1_0l2qm")
|
||||||
|
|
||||||
|
[node name="CrystalGlowContainer" type="Node2D" parent="."]
|
||||||
51
components/scripts/crystal_glow_component.gd
Normal file
51
components/scripts/crystal_glow_component.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
extends Node2D
|
||||||
|
class_name CrystalGlowComponent
|
||||||
|
|
||||||
|
var crystal_glow : PackedScene = preload("res://entities/crystal_glow.tscn")
|
||||||
|
|
||||||
|
@export var tile_map : CustomTileMap = null
|
||||||
|
@onready var crystal_glow_container : Node2D = $CrystalGlowContainer
|
||||||
|
var glowing_crystals : Array = []
|
||||||
|
|
||||||
|
var tile_size : Vector2i
|
||||||
|
var map_pixel_size : Vector2i
|
||||||
|
var tilemap_size : Vector2i
|
||||||
|
var crystal_layer : int = -1
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if !tile_map:
|
||||||
|
Log.err("CrystalGlowComponent: TileMap not set")
|
||||||
|
|
||||||
|
Log.pr("CrystalGlowComponent ready")
|
||||||
|
|
||||||
|
tile_size = tile_map.get_tileset().tile_size
|
||||||
|
map_pixel_size = tilemap_size * tile_size
|
||||||
|
tilemap_size = tile_map.get_used_rect().end - tile_map.get_used_rect().position
|
||||||
|
|
||||||
|
crystal_layer = tile_map.get_layer_id_by_name('Crystals')
|
||||||
|
Log.pr(crystal_layer)
|
||||||
|
add_crystal_glow()
|
||||||
|
|
||||||
|
## Look for crystals in the scene and add the glow to the approprirate angle and colour
|
||||||
|
func add_crystal_glow() -> void:
|
||||||
|
for i in tilemap_size.x:
|
||||||
|
for j in tilemap_size.y:
|
||||||
|
var coords : Vector2i = Vector2i(i, j)
|
||||||
|
var tile_data : TileData = tile_map.get_cell_tile_data(crystal_layer, coords)
|
||||||
|
if tile_data:
|
||||||
|
if tile_data.get_custom_data('glowcolour'):
|
||||||
|
var glow_colour : String = tile_data.get_custom_data('glowcolour')
|
||||||
|
var orientation : String = tile_data.get_custom_data('orientation')
|
||||||
|
|
||||||
|
# Check if this coord is already in the glowing_crystals array
|
||||||
|
if coords in glowing_crystals:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
var glow : CrystalGlow = crystal_glow.instantiate().duplicate()
|
||||||
|
glow.set_position(coords * tile_map.get_tileset().tile_size + tile_map.get_tileset().tile_size / 2)
|
||||||
|
glow.glow_colour = glow_colour
|
||||||
|
glow.orientation = orientation
|
||||||
|
crystal_glow_container.add_child(glow)
|
||||||
|
glowing_crystals.append(coords)
|
||||||
|
|
||||||
|
Log.pr("Glowing crystals: ", glowing_crystals)
|
||||||
|
|
@ -1,75 +1,91 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://di05lhhav43s7"]
|
[gd_scene load_steps=8 format=3 uid="uid://di05lhhav43s7"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://durqtk0juny64" path="res://resources/particles/light_beam.png" id="1_px2l5"]
|
[ext_resource type="Texture2D" uid="uid://durqtk0juny64" path="res://resources/particles/light_beam.png" id="1_px2l5"]
|
||||||
[ext_resource type="Script" path="res://entities/scripts/crystal_glow.gd" id="2_dtblp"]
|
[ext_resource type="Script" path="res://entities/scripts/crystal_glow.gd" id="2_dtblp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b0v24ggq57237" path="res://resources/particles/smallcircle.png" id="3_3ioih"]
|
[ext_resource type="Texture2D" uid="uid://b0v24ggq57237" path="res://resources/particles/smallcircle.png" id="3_3ioih"]
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_trlpq"]
|
[sub_resource type="Curve" id="Curve_ffgoa"]
|
||||||
|
_data = [Vector2(0, 0), 0.0, 1.4, 0, 0, Vector2(0.203642, 1), 0.0, 0.0, 0, 0, Vector2(0.799669, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||||
|
point_count = 4
|
||||||
|
|
||||||
|
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_ruaam"]
|
||||||
|
blend_mode = 1
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_bf3hv"]
|
||||||
resource_name = "CrystalGlow"
|
resource_name = "CrystalGlow"
|
||||||
length = 5.0
|
length = 5.0
|
||||||
loop_mode = 1
|
loop_mode = 1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath(".:energy")
|
tracks/0/path = NodePath("CrystalAreaLight:scale")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0, 2.6, 5),
|
"times": PackedFloat32Array(0, 1.9, 3.2, 5),
|
||||||
"transitions": PackedFloat32Array(-2, -2, -2),
|
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||||
"update": 0,
|
"update": 0,
|
||||||
"values": [2.8, 0.1, 2.8]
|
"values": [Vector2(1, 1), Vector2(1.1, 1.1), Vector2(0.8, 0.8), Vector2(1, 1)]
|
||||||
}
|
}
|
||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("../CrystalAreaLight:energy")
|
tracks/1/path = NodePath("CrystalAreaLight:modulate:a")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(-0.025, 1, 1.8, 2.8, 3.175, 3.875, 4.5, 4.975),
|
"times": PackedFloat32Array(0.00999999, 0.21, 0.61, 1.01, 1.61, 1.81, 2.2, 2.6, 4, 4.2, 4.6, 5),
|
||||||
"transitions": PackedFloat32Array(-2, -2, -2, -2, -2, -2, -2, -2),
|
"transitions": PackedFloat32Array(-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2),
|
||||||
"update": 0,
|
"update": 0,
|
||||||
"values": [1.0, 0.5, 1.0, 0.6, 0.8, 1.0, 1.2, 1.0]
|
"values": [1.0, 0.5, 0.8, 1.0, 1.0, 0.5, 0.8, 1.0, 1.0, 0.5, 0.8, 1.0]
|
||||||
|
}
|
||||||
|
tracks/2/type = "value"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath("CrystalAreaLargeLight:scale")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 2.6, 5),
|
||||||
|
"transitions": PackedFloat32Array(-2, -2, -2),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Vector2(2, 2), Vector2(2.2, 2.2), Vector2(2, 2)]
|
||||||
|
}
|
||||||
|
tracks/3/type = "value"
|
||||||
|
tracks/3/imported = false
|
||||||
|
tracks/3/enabled = true
|
||||||
|
tracks/3/path = NodePath("CrystalGlowLight:scale")
|
||||||
|
tracks/3/interp = 1
|
||||||
|
tracks/3/loop_wrap = true
|
||||||
|
tracks/3/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 2, 5),
|
||||||
|
"transitions": PackedFloat32Array(-2, -2, -2),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Vector2(1, 1), Vector2(2, 1), Vector2(1, 1)]
|
||||||
|
}
|
||||||
|
tracks/4/type = "value"
|
||||||
|
tracks/4/imported = false
|
||||||
|
tracks/4/enabled = true
|
||||||
|
tracks/4/path = NodePath("CrystalGlowLight:modulate:a")
|
||||||
|
tracks/4/interp = 1
|
||||||
|
tracks/4/loop_wrap = true
|
||||||
|
tracks/4/keys = {
|
||||||
|
"times": PackedFloat32Array(0.1, 1.3, 2.8, 4, 5),
|
||||||
|
"transitions": PackedFloat32Array(1, -2, 1, -2, 1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [1.0, 0.5, 1.0, 0.2, 1.0]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_78u0w"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_r67ky"]
|
||||||
_data = {
|
_data = {
|
||||||
"CrystalGlow": SubResource("Animation_trlpq")
|
"CrystalGlow": SubResource("Animation_bf3hv")
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Curve" id="Curve_ffgoa"]
|
|
||||||
_data = [Vector2(0, 0), 0.0, 1.4, 0, 0, Vector2(0.203642, 1), 0.0, 0.0, 0, 0, Vector2(0.799669, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
|
||||||
point_count = 4
|
|
||||||
|
|
||||||
[node name="CrystalGlow" type="Node2D"]
|
[node name="CrystalGlow" type="Node2D"]
|
||||||
script = ExtResource("2_dtblp")
|
script = ExtResource("2_dtblp")
|
||||||
|
|
||||||
[node name="CrystalGlowAnimation" type="AnimationPlayer" parent="."]
|
[node name="CrystalParticles" type="CPUParticles2D" parent="."]
|
||||||
root_node = NodePath("../CrystalGlowLight")
|
self_modulate = Color(0, 1, 1, 0.384314)
|
||||||
libraries = {
|
|
||||||
"": SubResource("AnimationLibrary_78u0w")
|
|
||||||
}
|
|
||||||
autoplay = "CrystalGlow"
|
|
||||||
|
|
||||||
[node name="CrystalGlowLight" type="PointLight2D" parent="."]
|
|
||||||
modulate = Color(1.5, 1.5, 1.5, 1)
|
|
||||||
rotation = 3.14159
|
|
||||||
scale = Vector2(1.71326, 1)
|
|
||||||
color = Color(0.517647, 0.796078, 1, 1)
|
|
||||||
energy = 2.8
|
|
||||||
texture = ExtResource("1_px2l5")
|
|
||||||
offset = Vector2(0, 50)
|
|
||||||
texture_scale = 1.15
|
|
||||||
|
|
||||||
[node name="CrystalAreaLight" type="PointLight2D" parent="."]
|
|
||||||
modulate = Color(1.5, 1.5, 1.5, 1)
|
|
||||||
color = Color(0.372549, 1, 0.996078, 1)
|
|
||||||
texture = ExtResource("3_3ioih")
|
|
||||||
offset = Vector2(0, -6)
|
|
||||||
texture_scale = 1.2
|
|
||||||
|
|
||||||
[node name="CPUParticles2D" type="CPUParticles2D" parent="."]
|
|
||||||
amount = 2
|
amount = 2
|
||||||
lifetime = 5.0
|
lifetime = 5.0
|
||||||
randomness = 0.1
|
randomness = 0.1
|
||||||
|
|
@ -85,3 +101,31 @@ scale_amount_min = 2.0
|
||||||
scale_amount_max = 4.0
|
scale_amount_max = 4.0
|
||||||
scale_amount_curve = SubResource("Curve_ffgoa")
|
scale_amount_curve = SubResource("Curve_ffgoa")
|
||||||
color = Color(1, 1, 1, 0.164706)
|
color = Color(1, 1, 1, 0.164706)
|
||||||
|
|
||||||
|
[node name="CrystalGlowLight" type="Sprite2D" parent="."]
|
||||||
|
modulate = Color(1.5, 1.5, 1.5, 1)
|
||||||
|
self_modulate = Color(0.372549, 1, 0.996078, 0.0823529)
|
||||||
|
material = SubResource("CanvasItemMaterial_ruaam")
|
||||||
|
position = Vector2(0, -31)
|
||||||
|
rotation = 3.14159
|
||||||
|
texture = ExtResource("1_px2l5")
|
||||||
|
offset = Vector2(0, 6)
|
||||||
|
|
||||||
|
[node name="CrystalAreaLight" type="Sprite2D" parent="."]
|
||||||
|
self_modulate = Color(1.5, 1.5, 1.5, 0.408)
|
||||||
|
material = SubResource("CanvasItemMaterial_ruaam")
|
||||||
|
texture = ExtResource("3_3ioih")
|
||||||
|
offset = Vector2(0, 6)
|
||||||
|
|
||||||
|
[node name="CrystalAreaLargeLight" type="Sprite2D" parent="."]
|
||||||
|
modulate = Color(1.2, 1.2, 1.2, 1)
|
||||||
|
self_modulate = Color(0, 1, 1, 0.109804)
|
||||||
|
material = SubResource("CanvasItemMaterial_ruaam")
|
||||||
|
position = Vector2(0, -12)
|
||||||
|
scale = Vector2(2, 2)
|
||||||
|
texture = ExtResource("3_3ioih")
|
||||||
|
|
||||||
|
[node name="CrystalGlowAnimation" type="AnimationPlayer" parent="."]
|
||||||
|
libraries = {
|
||||||
|
"": SubResource("AnimationLibrary_r67ky")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,71 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
class_name CrystalGlow
|
class_name CrystalGlow
|
||||||
|
|
||||||
func _ready() -> void:
|
var glow_colour : String :
|
||||||
Log.pr("CrystalGlow ready")
|
set(value):
|
||||||
|
glow_colour = value.to_lower()
|
||||||
|
var orientation : String:
|
||||||
|
set(value):
|
||||||
|
orientation = value.to_lower()
|
||||||
|
|
||||||
|
var animation_start_timer : float
|
||||||
|
var animation_start_offset : float = randf_range(0, 3)
|
||||||
|
|
||||||
|
var internals_updated : bool = false
|
||||||
|
|
||||||
|
@onready var animation_player : AnimationPlayer = $CrystalGlowAnimation
|
||||||
|
@onready var glow_light : Sprite2D = $CrystalGlowLight
|
||||||
|
@onready var glow_area : Sprite2D = $CrystalAreaLight
|
||||||
|
@onready var glow_area_large : Sprite2D = $CrystalAreaLargeLight
|
||||||
|
@onready var crystal_particles : CPUParticles2D = $CrystalParticles
|
||||||
|
|
||||||
|
func _process(delta : float) -> void:
|
||||||
|
|
||||||
|
# The first time this is processed in the scene we need to update the orientation and colour
|
||||||
|
if !internals_updated:
|
||||||
|
update()
|
||||||
|
internals_updated = true
|
||||||
|
|
||||||
|
animation_start_timer += delta
|
||||||
|
if animation_start_timer >= animation_start_offset and !animation_player.is_playing():
|
||||||
|
animation_player.play('CrystalGlow')
|
||||||
|
|
||||||
|
func update() -> void:
|
||||||
|
update_orientation()
|
||||||
|
update_colour()
|
||||||
|
|
||||||
|
# Update the orientation of the crystal glow so its pointing in the right direction
|
||||||
|
func update_orientation() -> void:
|
||||||
|
if orientation == 'up':
|
||||||
|
rotation = 0
|
||||||
|
elif orientation == 'down':
|
||||||
|
rotation = PI
|
||||||
|
elif orientation == 'left':
|
||||||
|
rotation = -PI/2
|
||||||
|
elif orientation == 'right':
|
||||||
|
rotation = PI/2
|
||||||
|
|
||||||
|
# Update the colour of the crystal glow
|
||||||
|
func update_colour() -> void:
|
||||||
|
|
||||||
|
var base_blue : String = '5ffffe'
|
||||||
|
var base_yellow : String = 'F2F230'
|
||||||
|
var base_red : String = 'FF3333'
|
||||||
|
|
||||||
|
if glow_colour == 'blue':
|
||||||
|
glow_light.self_modulate = base_blue + '15'
|
||||||
|
glow_area.self_modulate = base_blue + '04'
|
||||||
|
glow_area_large.self_modulate = base_blue + '04'
|
||||||
|
crystal_particles.self_modulate = '00ffff62'
|
||||||
|
elif glow_colour == 'yellow':
|
||||||
|
glow_light.self_modulate = base_yellow + '15'
|
||||||
|
glow_area.self_modulate = base_yellow + '04'
|
||||||
|
glow_area_large.self_modulate = base_yellow + '04'
|
||||||
|
crystal_particles.self_modulate = base_yellow + '62'
|
||||||
|
elif glow_colour == 'red':
|
||||||
|
glow_light.self_modulate = base_red + '15'
|
||||||
|
glow_area.self_modulate = base_red + '04'
|
||||||
|
glow_area_large.self_modulate = base_red + '04'
|
||||||
|
crystal_particles.self_modulate = base_red + '62'
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ var astar : AStarGrid2D = AStarGrid2D.new()
|
||||||
@onready var fog_overlay : ColorRect = $FogOverlay
|
@onready var fog_overlay : ColorRect = $FogOverlay
|
||||||
@onready var mushroom_glow_container : Node2D = $MushroomGlowContainer
|
@onready var mushroom_glow_container : Node2D = $MushroomGlowContainer
|
||||||
|
|
||||||
|
|
||||||
@onready var tilemap_size : Vector2i = get_used_rect().end - get_used_rect().position
|
@onready var tilemap_size : Vector2i = get_used_rect().end - get_used_rect().position
|
||||||
@onready var map_rect : Rect2i = Rect2i(Vector2i.ZERO, tilemap_size)
|
@onready var map_rect : Rect2i = Rect2i(Vector2i.ZERO, tilemap_size)
|
||||||
|
|
||||||
|
|
@ -46,12 +45,17 @@ func update_passable() -> void:
|
||||||
for i in tilemap_size.x:
|
for i in tilemap_size.x:
|
||||||
for j in tilemap_size.y:
|
for j in tilemap_size.y:
|
||||||
var coords : Vector2i = Vector2i(i, j)
|
var coords : Vector2i = Vector2i(i, j)
|
||||||
var tile_data : TileData = get_cell_tile_data(0, coords)
|
var tile_data : TileData = get_cell_tile_data(get_layer_id_by_name('Floor'), coords)
|
||||||
if tile_data and tile_data.get_custom_data('navtype') == 'wall':
|
if tile_data and tile_data.get_custom_data('navtype') == 'wall':
|
||||||
astar.set_point_solid(coords)
|
astar.set_point_solid(coords)
|
||||||
else:
|
continue
|
||||||
astar.set_point_solid(coords, false)
|
|
||||||
|
|
||||||
|
tile_data = get_cell_tile_data(get_layer_id_by_name('Water'), coords)
|
||||||
|
if tile_data and tile_data.get_custom_data('navtype') == 'water':
|
||||||
|
astar.set_point_solid(coords)
|
||||||
|
continue
|
||||||
|
|
||||||
|
astar.set_point_solid(coords, false)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func is_point_walkable(check_position : Vector2i) -> bool:
|
func is_point_walkable(check_position : Vector2i) -> bool:
|
||||||
|
|
@ -108,7 +112,7 @@ func filter_indestructible_tiles(coords : Array) -> Array:
|
||||||
return filtered_coords
|
return filtered_coords
|
||||||
|
|
||||||
func check_for_visible_gatherables() -> void:
|
func check_for_visible_gatherables() -> void:
|
||||||
|
return
|
||||||
# Remove all existing glowing lights
|
# Remove all existing glowing lights
|
||||||
for child in mushroom_glow_container.get_children():
|
for child in mushroom_glow_container.get_children():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
@ -132,3 +136,9 @@ func check_for_visible_gatherables() -> void:
|
||||||
glow.colour_name = glow_colour
|
glow.colour_name = glow_colour
|
||||||
mushroom_glow_container.add_child.call_deferred(glow)
|
mushroom_glow_container.add_child.call_deferred(glow)
|
||||||
|
|
||||||
|
func get_layer_id_by_name(level_name : String) -> int:
|
||||||
|
var layers : int = get_layers_count()
|
||||||
|
for i in layers:
|
||||||
|
if get_layer_name(i) == level_name:
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 355 B After Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 17 KiB |
Loading…
Add table
Add a link
Reference in a new issue