1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-21 23:34:18 +00:00

Add random gem coloring

This commit is contained in:
Steffo 2023-10-02 15:45:13 +02:00
parent a17d7ce705
commit 405df6d458
Signed by: steffo
GPG key ID: 2A24051445686895
8 changed files with 91 additions and 15 deletions

View file

@ -1,5 +1,35 @@
# Attribution
## Code
- [Color Conversion Shader](https://github.com/paddy-exe/ShaderFunction-Extras/blob/682301c10a4cc4dbe53b81dade46948e80e25c6a/addons/ShaderFunction-Extras/Color/LicenseInfo.md)
```
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
```
## Fonts
[Press Start Regular](https://www.1001fonts.com/press-start-font.html) by [codeman38](http://www.zone38.net/)
- [Press Start Regular](https://www.1001fonts.com/press-start-font.html) by [codeman38](http://www.zone38.net/)

14
color/Colored.gd Normal file
View file

@ -0,0 +1,14 @@
extends Node
class_name Colored
@export var shader: Shader
@onready var hue: float = Randomizer.rng.randf()
@onready var parent: Sprite2D = get_parent()
func _ready():
var material = ShaderMaterial.new()
material.shader = shader
material.set_shader_parameter("hue", hue)
parent.material = material

6
color/colored.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://vkvtap437nnf"]
[ext_resource type="Script" path="res://color/Colored.gd" id="1_wy58a"]
[node name="Colored" type="Node"]
script = ExtResource("1_wy58a")

View file

@ -1,11 +0,0 @@
extends RigidBody2D
# Called when the node enters the scene tree for the first time.
func _ready():
print($Valuable.value)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

View file

@ -1,9 +1,11 @@
[gd_scene load_steps=8 format=3 uid="uid://w2er6cmul5yx"]
[gd_scene load_steps=10 format=3 uid="uid://bawprh8kluilq"]
[ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_vmemd"]
[ext_resource type="Texture2D" uid="uid://b21bsbo5f0ed7" path="res://entity/gem/gemstone.png" id="3_6jejy"]
[ext_resource type="PackedScene" uid="uid://vkvtap437nnf" path="res://color/colored.tscn" id="4_2cetq"]
[ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_idoeu"]
[ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_7bd6c"]
[ext_resource type="Shader" path="res://entity/gem/gem_shading_material.gdshader" id="5_v6ppl"]
[ext_resource type="Script" path="res://entity/gem/RandomValue.gd" id="6_3lulr"]
[ext_resource type="AudioStream" uid="uid://br25ip30mu174" path="res://audio/conversione/mechanic_sound.wav" id="6_svrnw"]
@ -29,6 +31,9 @@ shape = SubResource("CapsuleShape2D_jkfas")
texture_filter = 1
texture = ExtResource("3_6jejy")
[node name="Colored" parent="CollisionShape2D/Sprite" instance=ExtResource("4_2cetq")]
shader = ExtResource("5_v6ppl")
[node name="Collectible" parent="." instance=ExtResource("4_idoeu")]
type = &"Silver"

View file

@ -0,0 +1,25 @@
shader_type canvas_item;
uniform float hue;
vec3 hsv_to_rgb(vec3 color) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(color.xxx + K.xyz) * 6.0 - K.www);
return color.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), color.y);
}
vec3 rgb_to_hsv(vec3 color) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(color.bg, K.wz), vec4(color.gb, K.xy), step(color.b, color.g));
vec4 q = mix(vec4(p.xyw, color.r), vec4(color.r, p.yzx), step(p.x, color.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
void fragment() {
vec3 hsv = rgb_to_hsv(COLOR.rgb);
hsv.x = hue;
vec3 rgb = hsv_to_rgb(hsv);
COLOR.rgb = rgb;
}

View file

@ -0,0 +1,7 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://dbnxaw6yecsyv"]
[ext_resource type="Shader" path="res://entity/gem/gem_shading_material.gdshader" id="1_h813y"]
[resource]
shader = ExtResource("1_h813y")
shader_parameter/hue = 0.0

View file

@ -11,7 +11,7 @@
[ext_resource type="PackedScene" uid="uid://du3005kwybbrh" path="res://entity/coin_gold/coin_gold.tscn" id="7_hh80i"]
[ext_resource type="PackedScene" uid="uid://ratkps4plkhl" path="res://converters/copper_to_silver/copper_converter.tscn" id="7_ipeok"]
[ext_resource type="PackedScene" uid="uid://but1bdslxp5jl" path="res://converters/silver_to_gold/silver_converter.tscn" id="8_0bbpi"]
[ext_resource type="PackedScene" path="res://entity/gem/gem.tscn" id="8_a3sk0"]
[ext_resource type="PackedScene" uid="uid://bawprh8kluilq" path="res://entity/gem/gem.tscn" id="8_a3sk0"]
[ext_resource type="PackedScene" uid="uid://c2rlx7egl7xiv" path="res://collector/universal_collector.tscn" id="9_7op48"]
[ext_resource type="PackedScene" uid="uid://c5w3b55aiui6c" path="res://collector/collector.tscn" id="9_evdhb"]
[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="10_sayqn"]
@ -61,7 +61,7 @@ shape = SubResource("RectangleShape2D_4uksi")
debug_color = Color(0, 0.6, 0.701961, 0)
[node name="Timer" type="Timer" parent="TimeSpawner"]
wait_time = 0.02
wait_time = 0.1
autostart = true
[node name="ButtonSpawner" parent="." node_paths=PackedStringArray("target") instance=ExtResource("3_qwsty")]