forked from team-sg/hero-mark-2
add falling block
This commit is contained in:
parent
d6547b61d4
commit
54f0880864
20 changed files with 153 additions and 26 deletions
31
objects/environment/barrier/barrier.gd
Normal file
31
objects/environment/barrier/barrier.gd
Normal file
|
@ -0,0 +1,31 @@
|
|||
extends Node2D
|
||||
|
||||
export var cost = 0
|
||||
export var label_offset = Vector2.ZERO
|
||||
onready var label = $Label
|
||||
onready var sprite = $Sprite
|
||||
onready var hitbox = $StaticBody2D/CollisionShape2D
|
||||
var open = false
|
||||
|
||||
func _ready():
|
||||
#Tile sprite
|
||||
if scale.y != 1:
|
||||
sprite.set_region_rect(Rect2(0,0,4,scale.y))
|
||||
hitbox.scale.y = scale.y
|
||||
hitbox.position.y += scale.y / 2 - 1
|
||||
scale.y = 1
|
||||
#Label
|
||||
label.visible = true
|
||||
label.set_text(str(cost))
|
||||
label.rect_position.y = scale.y / 2
|
||||
|
||||
func _physics_process(delta):
|
||||
#Open
|
||||
if Game.golds >= cost: open = true
|
||||
if open == true:
|
||||
sprite.region_rect.size.y -= 1
|
||||
if sprite.region_rect.size.y < 1: queue_free()
|
||||
|
||||
func _on_AnimationPlayer_animation_finished(anim_name):
|
||||
if anim_name == "open":
|
||||
queue_free()
|
122
objects/environment/barrier/barrier.tscn
Normal file
122
objects/environment/barrier/barrier.tscn
Normal file
|
@ -0,0 +1,122 @@
|
|||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://objects/environment/barrier/barrier.gd" type="Script" id=1]
|
||||
[ext_resource path="res://graphics/barrier/barrier_2px.png" type="Texture" id=2]
|
||||
[ext_resource path="res://fonts/2ndpuberty..fnt" type="BitmapFont" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 2, 0.5 )
|
||||
|
||||
[sub_resource type="Animation" id=4]
|
||||
resource_name = "initial"
|
||||
length = 0.4
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Rect2( 0, 0, 16, 16 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("StaticBody2D/CollisionShape2D:disabled")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("StaticBody2D:scale")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 1, 1 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=3]
|
||||
resource_name = "open"
|
||||
length = 0.4
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Rect2( 0, 0, 16, 16 ), Rect2( 0, 0, 16, 0 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("StaticBody2D/CollisionShape2D:disabled")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ false, true ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("StaticBody2D:scale")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 1, 1 ), Vector2( 1, 0 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="Theme" id=5]
|
||||
default_font = ExtResource( 3 )
|
||||
|
||||
[node name="Barrier" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 0, 4, 1 )
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
position = Vector2( 2, 0.5 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
anims/initial = SubResource( 4 )
|
||||
anims/open = SubResource( 3 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
visible = false
|
||||
margin_left = -18.0
|
||||
margin_top = -15.0
|
||||
margin_right = 22.0
|
||||
margin_bottom = 5.0
|
||||
theme = SubResource( 5 )
|
||||
text = "00"
|
||||
align = 1
|
||||
|
||||
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"]
|
Loading…
Add table
Add a link
Reference in a new issue