diff --git a/maps/rust.tscn b/maps/rust.tscn index 4534314..73143ec 100644 --- a/maps/rust.tscn +++ b/maps/rust.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://maps/map.gd" type="Script" id=1] [ext_resource path="res://objects/Camera2D.tscn" type="PackedScene" id=2] @@ -6,6 +6,8 @@ [ext_resource path="res://tilesets/t_rust.tres" type="TileSet" id=4] [ext_resource path="res://objects/player/player.tscn" type="PackedScene" id=5] [ext_resource path="res://objects/enemy/robosnake.tscn" type="PackedScene" id=6] +[ext_resource path="res://objects/enemy/steam.tscn" type="PackedScene" id=7] +[ext_resource path="res://objects/environment/switches/button.tscn" type="PackedScene" id=8] [node name="Map" type="Node2D" groups=["map"]] pause_mode = 1 @@ -38,3 +40,14 @@ position = Vector2( 48, 152 ) position = Vector2( 232, 168 ) left_up_boundry = 4.0 right_down_boundry = 4.0 + +[node name="Steam" parent="Enemies" groups=["button1"] instance=ExtResource( 7 )] +position = Vector2( 96, 152 ) + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] +polygon = PoolVector2Array( 145, 175, 183, 175, 184, 176, 184, 176, 144, 176, 144, 176 ) + +[node name="Button" parent="." instance=ExtResource( 8 )] +position = Vector2( 72, 168 ) diff --git a/objects/enemy/steam.gd b/objects/enemy/steam.gd index 5cbd606..483480f 100644 --- a/objects/enemy/steam.gd +++ b/objects/enemy/steam.gd @@ -21,3 +21,6 @@ func _physics_process(delta): active = true collision_shape.disabled = false particles.emitting = true + +func switch_action(): + queue_free() diff --git a/objects/environment/switches/button.gd b/objects/environment/switches/button.gd new file mode 100644 index 0000000..629fa31 --- /dev/null +++ b/objects/environment/switches/button.gd @@ -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 diff --git a/objects/environment/switches/button.tscn b/objects/environment/switches/button.tscn new file mode 100644 index 0000000..bb8bbc7 --- /dev/null +++ b/objects/environment/switches/button.tscn @@ -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"] diff --git a/objects/environment/switches/switch.gd b/objects/environment/switches/switch.gd new file mode 100644 index 0000000..94091c1 --- /dev/null +++ b/objects/environment/switches/switch.gd @@ -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()