This commit is contained in:
1 parent
c40cbc4574
commit
231629d91e
28 files changed
+434
-91
No files matched your search
@@ -0,0 +1,49 @@
|
||||
class_name Block_Simple
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Last known sprite. In edge cases involving states.
|
||||
|
||||
# Block type refers to our specific block script.
|
||||
# They should always extend eventually from block_simple.
|
||||
@export var block_type:Script
|
||||
|
||||
# Set the animation (sprite sheet) to the specfied block types.
|
||||
func SetSpriteSheet(animation):
|
||||
$Sprite.animation = animation
|
||||
|
||||
# If this is false (default) then the block is horizontally facing.
|
||||
@export var is_vertical:bool
|
||||
|
||||
# Tags the block has. These dictate interactions.
|
||||
# These must be strings.
|
||||
@export var tags:Array = [str]
|
||||
|
||||
# Rotate the block in a way that we can control.
|
||||
# Default to 90 because that's a common use case.
|
||||
func rotate_block(degrees:int = 90):
|
||||
rotate(degrees)
|
||||
|
||||
# This runs BEFORE the instance is loaded.
|
||||
# There's a lot you can't do here, as it doesn't exist yet.
|
||||
func _init():
|
||||
pass
|
||||
#SetSpriteSheet(str(block_type))
|
||||
#set_script(block_type)
|
||||
|
||||
# This runs AFTER the instance is loaded.
|
||||
# This runs BEFORE the instance is added to the scene tree.
|
||||
func _ready() -> void:
|
||||
if is_vertical:
|
||||
rotate_block(90)
|
||||
set_script(block_type)
|
||||
|
||||
# This runs every frame. Expensive.
|
||||
func _process(delta: float) -> void:
|
||||
var _last_known_delta = delta
|
||||
|
||||
func on_player_near(body: Node2D) -> void:
|
||||
print("Player is touching block with tags: " + str(tags))
|
||||
|
||||
func on_player_leave(body: Node2D) -> void:
|
||||
print("Player is leaving block with tags: " + str(tags))
|
||||
@@ -0,0 +1 @@
|
||||
uid://b65ci82qp1pa0
|
||||
@@ -0,0 +1,54 @@
|
||||
[gd_scene format=3 uid="uid://ckqable762x8v"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b65ci82qp1pa0" path="res://level_editor/blocks/block_simple.gd" id="1_64qyq"]
|
||||
[ext_resource type="Script" uid="uid://2nvcig3fqetr" path="res://level_editor/blocks/block_spike.gd" id="2_rhp63"]
|
||||
[ext_resource type="Texture2D" uid="uid://blbaaqyrt8dtk" path="res://art/block/block.png" id="2_xmhd5"]
|
||||
[ext_resource type="Texture2D" uid="uid://bu5wgerfu7cbc" path="res://art/spike.png" id="3_rhp63"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_f3sb7"]
|
||||
size = Vector2(16, 14)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_q6akc"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_xmhd5")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"block_simple",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_rhp63")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"block_spike",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lxo14"]
|
||||
|
||||
[node name="Block_Simple" type="RigidBody2D" unique_id=1409784601]
|
||||
gravity_scale = 0.0
|
||||
freeze = true
|
||||
script = ExtResource("1_64qyq")
|
||||
block_type = ExtResource("2_rhp63")
|
||||
tags = [null]
|
||||
|
||||
[node name="BlockShape" type="CollisionShape2D" parent="." unique_id=1866755047]
|
||||
shape = SubResource("RectangleShape2D_f3sb7")
|
||||
|
||||
[node name="Sprite" type="AnimatedSprite2D" parent="." unique_id=321127444]
|
||||
texture_filter = 1
|
||||
sprite_frames = SubResource("SpriteFrames_q6akc")
|
||||
animation = &"block_simple"
|
||||
autoplay = "block_simple"
|
||||
|
||||
[node name="EffectCollision" type="Area2D" parent="." unique_id=1756054567]
|
||||
|
||||
[node name="EffectShape" type="CollisionShape2D" parent="EffectCollision" unique_id=392861580]
|
||||
shape = SubResource("RectangleShape2D_lxo14")
|
||||
|
||||
[connection signal="body_entered" from="EffectCollision" to="." method="on_player_near"]
|
||||
[connection signal="body_exited" from="EffectCollision" to="." method="on_player_leave"]
|
||||
@@ -0,0 +1,25 @@
|
||||
class_name Block_Spike
|
||||
|
||||
extends Block_Simple
|
||||
|
||||
# This runs BEFORE the instance is loaded.
|
||||
# There's a lot you can't do here, as it doesn't exist yet.
|
||||
func _init():
|
||||
is_vertical = false
|
||||
tags = ["Spike","Hazard"]
|
||||
|
||||
# This runs AFTER the instance is loaded.
|
||||
# This runs BEFORE the instance is added to the scene tree.
|
||||
func _ready() -> void:
|
||||
if is_vertical:
|
||||
rotate_block(90)
|
||||
|
||||
# This runs every frame. Expensive.
|
||||
func _process(delta: float) -> void:
|
||||
var _last_known_delta = delta
|
||||
|
||||
func on_player_near(body: Node2D) -> void:
|
||||
print("Player is touching block with tags: " + str(tags))
|
||||
|
||||
func on_player_leave(body: Node2D) -> void:
|
||||
print("Player is leaving block with tags: " + str(tags))
|
||||
@@ -0,0 +1 @@
|
||||
uid://2nvcig3fqetr
|
||||
Reference in new issue
Block a user