1
Fork 0
mirror of https://github.com/RYGhub/the-cold-night.git synced 2024-11-25 14:14:19 +00:00

Add fire scripting

This commit is contained in:
Steffo 2022-04-02 20:06:35 +02:00
parent 6b2cb18319
commit c1adb9adb8
Signed by: steffo
GPG key ID: 6965406171929D01
4 changed files with 67 additions and 4 deletions

View file

@ -8,16 +8,26 @@
config_version=4 config_version=4
_global_script_classes=[ {
"base": "Sprite",
"class": "Fire",
"language": "GDScript",
"path": "res://src/Fire.gd"
} ]
_global_script_class_icons={
"Fire": ""
}
[application] [application]
config/name="LD50" config/name="LD50"
run/main_scene="res://src/MainMenu.tscn" run/main_scene="res://src/Game.tscn"
config/icon="res://src/icon.png"
[display] [display]
window/size/width=1280 window/size/width=1280
window/size/height=720 window/size/height=720
window/size/resizable=false
[physics] [physics]

42
src/Fire.gd Normal file
View file

@ -0,0 +1,42 @@
extends Sprite
export var intensity: float = 0.5 setget set_intensity
export var change_per_second: float = - 1.0 / 60.0
export var min_intensity: float = 0
export var max_intensity: float = INF
signal intensity_at_max
signal intensity_at_min
var intensity_reached_max_triggered: bool = false
var intensity_reached_min_triggered: bool = false
signal intensity_reached_min
signal intensity_reached_max
func set_intensity(value):
intensity = clamp(value, min_intensity, max_intensity)
print(intensity)
# Update everything that needs to be updated when the intensity changes
$Light.texture_scale = value
# Trigger signals
# max intensity signal
if intensity == max_intensity:
emit_signal("intensity_at_max")
if not intensity_reached_max_triggered:
emit_signal("intensity_reached_max")
intensity_reached_max_triggered = true
else:
intensity_reached_max_triggered = false
# min intensity signal
if intensity == min_intensity:
emit_signal("intensity_at_min")
if not intensity_reached_min_triggered:
emit_signal("intensity_reached_min")
intensity_reached_min_triggered = true
else:
intensity_reached_min_triggered = false
func _process(delta):
set_intensity(intensity + (delta * change_per_second))

View file

@ -1,13 +1,15 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://src/Light.png" type="Texture" id=1] [ext_resource path="res://src/Light.png" type="Texture" id=1]
[ext_resource path="res://src/White.png" type="Texture" id=2] [ext_resource path="res://src/White.png" type="Texture" id=2]
[ext_resource path="res://src/Fire.gd" type="Script" id=3]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 ) extents = Vector2( 16, 16 )
[node name="Fire" type="Sprite"] [node name="Fire" type="Sprite"]
texture = ExtResource( 2 ) texture = ExtResource( 2 )
script = ExtResource( 3 )
[node name="Light" type="Light2D" parent="."] [node name="Light" type="Light2D" parent="."]
texture = ExtResource( 1 ) texture = ExtResource( 1 )

View file

@ -13,4 +13,13 @@ tile_data = PoolIntArray( 0, 2, 0, 1, 2, 0, 2, 2, 0, 3, 2, 0, 4, 2, 0, 5, 2, 0,
position = Vector2( 553, 296 ) position = Vector2( 553, 296 )
[node name="Fire" parent="." instance=ExtResource( 3 )] [node name="Fire" parent="." instance=ExtResource( 3 )]
position = Vector2( 594, 305 ) position = Vector2( 597, 323 )
[node name="Fire2" parent="." instance=ExtResource( 3 )]
position = Vector2( 251, 458 )
[node name="Fire3" parent="." instance=ExtResource( 3 )]
position = Vector2( 622, 549 )
[node name="Fire4" parent="." instance=ExtResource( 3 )]
position = Vector2( 325, 147 )