mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-21 15:24:18 +00:00
gemstone
This commit is contained in:
parent
8f053b51ee
commit
0bcb3327cd
8 changed files with 191 additions and 1 deletions
39
entity/gem/Hue.shader
Normal file
39
entity/gem/Hue.shader
Normal file
|
@ -0,0 +1,39 @@
|
|||
shader_type canvas_item;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform float Shift_Hue;
|
||||
|
||||
void fragment() {
|
||||
// Input:3
|
||||
vec3 input_color;
|
||||
vec4 texture_color = texture(TEXTURE, UV);
|
||||
input_color = texture_color.rgb;
|
||||
|
||||
// VectorFunc:2
|
||||
vec3 color_hsv;
|
||||
{
|
||||
vec3 c = input_color;
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
color_hsv=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
color_hsv.x = mod((color_hsv.x + Shift_Hue), 1.0f);
|
||||
|
||||
// VectorFunc:5
|
||||
vec3 color_rgb;
|
||||
{
|
||||
vec3 c = color_hsv;
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
color_rgb=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
// Output:0
|
||||
texture_color = vec4(color_rgb.rgb,texture_color.a);
|
||||
COLOR.rgba = texture_color;
|
||||
|
||||
}
|
15
entity/gem/gemstone.gd
Normal file
15
entity/gem/gemstone.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends RigidBody2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$CollisionShape2D/Sprite.set_material($CollisionShape2D/Sprite.get_material().duplicate(true))
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
var rand_hue = float(randi() % 3)/2.0/3.2
|
||||
#$CollisionShape2D/Sprite.material.set_shader_param("Shift_Hue", rand_hue)
|
||||
#print($CollisionShape2D/Sprite.modulate)
|
||||
#CollisionShape2D/Sprite.modulate = Color.from_ok_hsl(0.5,0,0.9)
|
||||
|
0
entity/gem/gemstone.gdshader
Normal file
0
entity/gem/gemstone.gdshader
Normal file
|
@ -1,7 +1,9 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://6pp1pebasum3"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://6pp1pebasum3"]
|
||||
|
||||
[ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_1d567"]
|
||||
[ext_resource type="Script" path="res://entity/gem/gemstone.gd" id="2_4sf3r"]
|
||||
[ext_resource type="Texture2D" uid="uid://b21bsbo5f0ed7" path="res://entity/gem/gemstone.png" id="2_gmg5g"]
|
||||
[ext_resource type="Shader" path="res://entity/gem/gemstone.gdshader" id="3_v0fk6"]
|
||||
[ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_01x0a"]
|
||||
[ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_wdbjk"]
|
||||
|
||||
|
@ -9,6 +11,10 @@
|
|||
radius = 4.0
|
||||
height = 10.0
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_sakte"]
|
||||
shader = ExtResource("3_v0fk6")
|
||||
shader_parameter/Shift_Hue = null
|
||||
|
||||
[node name="Gemstone" type="RigidBody2D"]
|
||||
collision_layer = 5
|
||||
collision_mask = 7
|
||||
|
@ -18,6 +24,7 @@ physics_material_override = ExtResource("1_1d567")
|
|||
continuous_cd = 1
|
||||
linear_damp = 0.1
|
||||
angular_damp = 0.1
|
||||
script = ExtResource("2_4sf3r")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(2, 2)
|
||||
|
@ -25,6 +32,7 @@ shape = SubResource("CapsuleShape2D_130vq")
|
|||
|
||||
[node name="Sprite" type="Sprite2D" parent="CollisionShape2D"]
|
||||
texture_filter = 1
|
||||
material = SubResource("ShaderMaterial_sakte")
|
||||
texture = ExtResource("2_gmg5g")
|
||||
|
||||
[node name="Collectible" parent="." instance=ExtResource("4_01x0a")]
|
||||
|
|
39
random/Hue.shader
Normal file
39
random/Hue.shader
Normal file
|
@ -0,0 +1,39 @@
|
|||
shader_type canvas_item;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform float Shift_Hue;
|
||||
|
||||
void fragment() {
|
||||
// Input:3
|
||||
vec3 input_color;
|
||||
vec4 texture_color = texture(TEXTURE, UV);
|
||||
input_color = texture_color.rgb;
|
||||
|
||||
// VectorFunc:2
|
||||
vec3 color_hsv;
|
||||
{
|
||||
vec3 c = input_color;
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
color_hsv=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
color_hsv.x = mod((color_hsv.x + Shift_Hue), 1.0f);
|
||||
|
||||
// VectorFunc:5
|
||||
vec3 color_rgb;
|
||||
{
|
||||
vec3 c = color_hsv;
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
color_rgb=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
// Output:0
|
||||
texture_color = vec4(color_rgb.rgb,texture_color.a);
|
||||
COLOR.rgba = texture_color;
|
||||
|
||||
}
|
3
spawner/Node.gd
Normal file
3
spawner/Node.gd
Normal file
|
@ -0,0 +1,3 @@
|
|||
extends Node
|
||||
class_name GemRandomizer
|
||||
static var rng : RandomNumberGenerator = RandomNumberGenerator.new()
|
66
spawner/gemstone_spawner.gd
Normal file
66
spawner/gemstone_spawner.gd
Normal file
|
@ -0,0 +1,66 @@
|
|||
extends Area2D
|
||||
class_name GemstoneSpawner
|
||||
|
||||
## A node which spawns things!
|
||||
|
||||
## The scene to spawn.
|
||||
@export var scene: PackedScene
|
||||
|
||||
## The node to add new scenes to.
|
||||
@export var target: Node
|
||||
|
||||
## Count of how many items should be spawned when possible.
|
||||
var buffer: int = 0
|
||||
|
||||
## Maximum amount of items whose spawn can be buffered.
|
||||
@export var buffer_cap: int
|
||||
|
||||
## Rect in which scenes can be spawned randomly in.
|
||||
@export var spawn_rect: Rect2
|
||||
|
||||
## Minimum rotation degrees that an object can spawn with.
|
||||
@export_range(0, 360) var spawn_rotation_degrees_min: float
|
||||
|
||||
## Maximum rotation degrees that an object can spawn with.
|
||||
@export_range(0, 360) var spawn_rotation_degrees_max: float
|
||||
|
||||
## Maximum amount of bodies overlapping the spawner's area before the spawner stops spawning.
|
||||
@export_range(0, 16, 1, "or_greater") var overlapping_body_count_limit: int
|
||||
|
||||
|
||||
signal spawned(what: Node2D)
|
||||
|
||||
func gem_roll():
|
||||
return Randomizer.rng.randi_range(0,360)
|
||||
|
||||
func spawn():
|
||||
buffer += 1
|
||||
if buffer > buffer_cap:
|
||||
buffer = buffer_cap
|
||||
|
||||
func _select_spawn_position() -> Vector2:
|
||||
return Vector2(
|
||||
Randomizer.rng.randf_range(spawn_rect.position.x, spawn_rect.end.x),
|
||||
Randomizer.rng.randf_range(spawn_rect.position.y, spawn_rect.end.y),
|
||||
)
|
||||
|
||||
func _select_spawn_rotation() -> float:
|
||||
return Randomizer.rng.randf_range(
|
||||
spawn_rotation_degrees_min,
|
||||
spawn_rotation_degrees_max
|
||||
)
|
||||
|
||||
func _do_spawn():
|
||||
if len(get_overlapping_bodies()) > overlapping_body_count_limit:
|
||||
return
|
||||
var instantiated = scene.instantiate()
|
||||
instantiated.
|
||||
instantiated.global_position = global_position + _select_spawn_position()
|
||||
instantiated.rotation_degrees = _select_spawn_rotation()
|
||||
target.add_child(instantiated)
|
||||
spawned.emit()
|
||||
buffer -= 1
|
||||
|
||||
func _physics_process(_delta):
|
||||
if buffer > 0:
|
||||
_do_spawn()
|
20
spawner/gemstone_spawner.tscn
Normal file
20
spawner/gemstone_spawner.tscn
Normal file
|
@ -0,0 +1,20 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://cqbqoc8ftxfos"]
|
||||
|
||||
[ext_resource type="Script" path="res://spawner/gemstone_spawner.gd" id="1_fk8ci"]
|
||||
[ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="2_2di81"]
|
||||
[ext_resource type="PackedScene" uid="uid://6pp1pebasum3" path="res://entity/gem/gemstone.tscn" id="3_goofg"]
|
||||
[ext_resource type="Script" path="res://spawner/Node.gd" id="3_ra5b3"]
|
||||
|
||||
[node name="GemstoneSpawner" type="Node2D"]
|
||||
script = ExtResource("1_fk8ci")
|
||||
buffer_cap = null
|
||||
spawn_rect = null
|
||||
spawn_rotation_degrees_min = null
|
||||
spawn_rotation_degrees_max = null
|
||||
overlapping_body_count_limit = null
|
||||
|
||||
[node name="Spawner" parent="." instance=ExtResource("2_2di81")]
|
||||
scene = ExtResource("3_goofg")
|
||||
|
||||
[node name="GemRandomizer" type="Node" parent="."]
|
||||
script = ExtResource("3_ra5b3")
|
Loading…
Reference in a new issue