added a button :D

This commit is contained in:
pennyrigate 2023-03-03 00:01:02 -05:00
parent 215d930022
commit 34b447cff1
5 changed files with 64 additions and 1 deletions

View file

@ -0,0 +1,10 @@
extends "res://objects/environment/switches/switch.gd"
var pressed = false
func _on_ActivationArea_area_entered(area):
if !pressed:
if area.is_in_group("player"):
activate()
$Sprite.frame = 1
pressed = true

View file

@ -0,0 +1,29 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://graphics/switches/button.png" type="Texture" id=1]
[ext_resource path="res://objects/environment/switches/button.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 2, 0.5 )
[node name="Button" type="Node2D"]
script = ExtResource( 2 )
type = "button"
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 4, 4 )
texture = ExtResource( 1 )
hframes = 2
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"]
polygon = PoolVector2Array( 1, 7, 0, 8, 1, 8, 7, 8, 8, 8, 7, 7 )
[node name="ActivationArea" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="ActivationArea"]
position = Vector2( 4, 6.5 )
shape = SubResource( 1 )
[connection signal="area_entered" from="ActivationArea" to="." method="_on_ActivationArea_area_entered"]

View file

@ -0,0 +1,8 @@
extends Node2D
export var switch_index = 1
export var type = "switch"
func activate():
for object in get_tree().get_nodes_in_group(str(type) + str(switch_index)):
object.switch_action()