mirror of
https://github.com/HarmonyHoney/ROTA.git
synced 2026-07-17 16:46:17 +00:00
buttons and switchblocks! ^.^ <3
This commit is contained in:
parent
feb44b51f6
commit
99fdaa3246
11 changed files with 274 additions and 4 deletions
BIN
media/image/button.png
Normal file
BIN
media/image/button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
media/image/button_floor.png
Normal file
BIN
media/image/button_floor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 5.4 KiB |
BIN
media/image/dashes_fill.png
Normal file
BIN
media/image/dashes_fill.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
43
src/actor/Button.gd
Normal file
43
src/actor/Button.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
tool
|
||||
extends Node2D
|
||||
|
||||
onready var area : Area2D = $Area2D
|
||||
onready var anim : AnimationPlayer = $AnimationPlayer
|
||||
|
||||
var is_press := false
|
||||
|
||||
signal press
|
||||
signal release
|
||||
|
||||
export var is_black := false setget set_black
|
||||
|
||||
func set_black(arg):
|
||||
is_black = arg
|
||||
if is_black:
|
||||
$Sprites/Button.modulate = Color(0, 0, 0)
|
||||
$Sprites/Floor.visible = false
|
||||
else:
|
||||
$Sprites/Button.modulate = Color(1, 1, 1)
|
||||
$Sprites/Floor.visible = true
|
||||
|
||||
func _ready():
|
||||
if Engine.editor_hint: return
|
||||
|
||||
$Sprites/Button.material = $Sprites/Button.material.duplicate()
|
||||
|
||||
for i in get_tree().get_nodes_in_group("switch_block"):
|
||||
if i.is_black == is_black:
|
||||
connect("press", i, "press")
|
||||
connect("release", i, "release")
|
||||
|
||||
func _on_Area2D_body_entered(body):
|
||||
if !is_press:
|
||||
is_press = true
|
||||
emit_signal("press")
|
||||
anim.play("press")
|
||||
|
||||
func _on_Area2D_body_exited(body):
|
||||
if is_press and area.get_overlapping_bodies().size() == 0:
|
||||
is_press = false
|
||||
emit_signal("release")
|
||||
anim.play("release")
|
||||
76
src/actor/Button.tscn
Normal file
76
src/actor/Button.tscn
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
[gd_scene load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://media/image/button.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/actor/Button.gd" type="Script" id=2]
|
||||
[ext_resource path="res://src/shader/button.gdshader" type="Shader" id=3]
|
||||
[ext_resource path="res://media/image/button_floor.png" type="Texture" id=4]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 25, 10 )
|
||||
|
||||
[sub_resource type="Animation" id=4]
|
||||
resource_name = "press"
|
||||
length = 0.3
|
||||
tracks/0/type = "bezier"
|
||||
tracks/0/path = NodePath("Sprites/Button:material:shader_param/offset_y")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"points": PoolRealArray( 0, -0.25, 0, 0.25, 0, 0.3, -0.25, 0, 0.25, 0 ),
|
||||
"times": PoolRealArray( 0, 0.3 )
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=5]
|
||||
resource_name = "release"
|
||||
length = 0.4
|
||||
tracks/0/type = "bezier"
|
||||
tracks/0/path = NodePath("Sprites/Button:material:shader_param/offset_y")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"points": PoolRealArray( 0.3, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0 ),
|
||||
"times": PoolRealArray( 0, 0.4 )
|
||||
}
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=3]
|
||||
shader = ExtResource( 3 )
|
||||
shader_param/offset_y = 0.0
|
||||
shader_param/mask = ExtResource( 4 )
|
||||
|
||||
[node name="Button" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2( 0, 38 )
|
||||
collision_layer = 0
|
||||
collision_mask = 7
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
playback_default_blend_time = 0.1
|
||||
anims/press = SubResource( 4 )
|
||||
anims/release = SubResource( 5 )
|
||||
|
||||
[node name="Sprites" type="Node2D" parent="."]
|
||||
scale = Vector2( 0.25, 0.25 )
|
||||
|
||||
[node name="Button" type="Sprite" parent="Sprites"]
|
||||
material = SubResource( 3 )
|
||||
position = Vector2( -200, 0 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
|
||||
[node name="Floor" type="Sprite" parent="Sprites"]
|
||||
position = Vector2( 0, 176.003 )
|
||||
texture = ExtResource( 4 )
|
||||
centered = false
|
||||
offset = Vector2( -125, 0 )
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
|
||||
[connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"]
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://media/image/passthrough.png" type="Texture" id=1]
|
||||
[ext_resource path="res://media/image/dashes.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/actor/Passthrough.gd" type="Script" id=2]
|
||||
[ext_resource path="res://media/image/rect.png" type="Texture" id=3]
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ visible = false
|
|||
texture = ExtResource( 3 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
visible = false
|
||||
collision_layer = 0
|
||||
collision_mask = 6
|
||||
|
||||
|
|
|
|||
43
src/actor/SwitchBlock.gd
Normal file
43
src/actor/SwitchBlock.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
tool
|
||||
extends Node2D
|
||||
|
||||
onready var dotted : Sprite = $Sprites/Dotted
|
||||
onready var rect : Sprite = $Sprites/Rect
|
||||
onready var area : Area2D = $Area2D
|
||||
onready var static_body : StaticBody2D = $StaticBody2D
|
||||
|
||||
var is_solid := false
|
||||
var is_queue := false
|
||||
|
||||
export var is_black := false setget set_black
|
||||
|
||||
func set_black(arg):
|
||||
is_black = arg
|
||||
$Sprites/Fill.modulate = Color(0, 0, 0) if is_black else Color(1, 1, 1)
|
||||
|
||||
func press():
|
||||
if area.get_overlapping_bodies().size() == 0:
|
||||
make_solid()
|
||||
else:
|
||||
is_queue = true
|
||||
|
||||
func _on_Area2D_body_exited(body):
|
||||
if is_queue and area.get_overlapping_bodies().size() == 0:
|
||||
make_solid()
|
||||
|
||||
func make_solid():
|
||||
is_solid = true
|
||||
is_queue = false
|
||||
static_body.set_collision_layer_bit(0, true)
|
||||
dotted.visible = false
|
||||
rect.visible = true
|
||||
|
||||
func release():
|
||||
is_solid = false
|
||||
is_queue = false
|
||||
static_body.set_collision_layer_bit(0, false)
|
||||
dotted.visible = true
|
||||
rect.visible = false
|
||||
|
||||
|
||||
|
||||
48
src/actor/SwitchBlock.tscn
Normal file
48
src/actor/SwitchBlock.tscn
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://media/image/dashes.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/actor/SwitchBlock.gd" type="Script" id=2]
|
||||
[ext_resource path="res://media/image/rect.png" type="Texture" id=3]
|
||||
[ext_resource path="res://media/image/dashes_fill.png" type="Texture" id=4]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 49, 49 )
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=2]
|
||||
extents = Vector2( 50, 50 )
|
||||
|
||||
[node name="SwitchBlock" type="Node2D" groups=[
|
||||
"switch_block",
|
||||
]]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Sprites" type="Node2D" parent="."]
|
||||
scale = Vector2( 0.25, 0.25 )
|
||||
|
||||
[node name="Dotted" type="Sprite" parent="Sprites"]
|
||||
scale = Vector2( 0.95, 0.95 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Rect" type="Sprite" parent="Sprites"]
|
||||
visible = false
|
||||
texture = ExtResource( 3 )
|
||||
|
||||
[node name="Fill" type="Sprite" parent="Sprites"]
|
||||
texture = ExtResource( 4 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
visible = false
|
||||
collision_layer = 0
|
||||
collision_mask = 7
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"]
|
||||
File diff suppressed because one or more lines are too long
10
src/shader/button.gdshader
Normal file
10
src/shader/button.gdshader
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
uniform float offset_y : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform sampler2D mask;
|
||||
|
||||
void fragment(){
|
||||
vec4 col = texture(TEXTURE, UV - vec2(0.0, offset_y));
|
||||
//col -= texture(mask, UV);
|
||||
COLOR = col;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue