forked from team-sg/hero-mark-2
add letter block
This commit is contained in:
parent
d318add375
commit
d59c37eb49
5 changed files with 139 additions and 2 deletions
49
objects/hud/letter_block.gd
Normal file
49
objects/hud/letter_block.gd
Normal file
|
@ -0,0 +1,49 @@
|
|||
tool
|
||||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
signal letter_chosen(letter)
|
||||
|
||||
enum Glyph {
|
||||
A, B, C, D, E, F, G, H,
|
||||
I, J, K, L, M, N, O, P,
|
||||
Q, R, S, T, U, V, W, X,
|
||||
Y, Z, _0, _1, _2, _3, _4, _5,
|
||||
_6, _7, _8, _9,
|
||||
}
|
||||
const GLYPH_STRINGS = [
|
||||
"A", "B", "C", "D", "E", "F", "G", "H",
|
||||
"I", "J", "K", "L", "M", "N", "O", "P",
|
||||
"Q", "R", "S", "T", "U", "V", "W", "X",
|
||||
"Y", "Z", "0", "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9",
|
||||
]
|
||||
|
||||
export (Glyph) var glyph: int = 0 setget _set_glyph
|
||||
|
||||
onready var sprite: Sprite = $Sprite
|
||||
onready var _seed: float = randf() * 250.0
|
||||
|
||||
func _set_glyph(value: int) -> void:
|
||||
glyph = value
|
||||
get_node("Sprite").frame = value
|
||||
|
||||
func _ready() -> void:
|
||||
if Engine.editor_hint:
|
||||
return
|
||||
# connect to node in "gets_letters" group so don't have to do the shit manually
|
||||
for node in get_tree().get_nodes_in_group("gets_letters"):
|
||||
if node.has_method("_on_letter_chosen"):
|
||||
connect("letter_chosen", node, "_on_letter_chosen")
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Engine.editor_hint:
|
||||
return
|
||||
sprite.position.x = 4.0 + sin(float(Time.get_ticks_msec()) / 250.0 + _seed)
|
||||
sprite.position.y = 5.0 + sin(float(Time.get_ticks_msec()) / 125.0 + _seed)
|
||||
|
||||
func die() -> void:
|
||||
emit_signal("letter_chosen", GLYPH_STRINGS[glyph])
|
||||
|
||||
func _on_Hitbox_area_entered(area):
|
||||
emit_signal("letter_chosen", GLYPH_STRINGS[glyph])
|
||||
._on_Hitbox_area_entered(area)
|
25
objects/hud/letter_block.tscn
Normal file
25
objects/hud/letter_block.tscn
Normal file
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://objects/hud/letter_block.gd" type="Script" id=1]
|
||||
[ext_resource path="res://graphics/hud/letter_blocks.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 3, 3.5 )
|
||||
|
||||
[node name="LetterBlock" type="Node2D" groups=["enemy"]]
|
||||
script = ExtResource( 1 )
|
||||
blood = false
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 4, 5 )
|
||||
texture = ExtResource( 2 )
|
||||
hframes = 8
|
||||
vframes = 5
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
position = Vector2( 4, 4.5 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
|
Loading…
Add table
Add a link
Reference in a new issue