Add state scene to unify the state object
This commit is contained in:
parent
1b3ba37deb
commit
95e301e24a
|
@ -0,0 +1,4 @@
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
export(int) var damage
|
|
@ -1,5 +1,8 @@
|
||||||
[gd_scene format=2]
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://AI/HitBox.gd" type="Script" id=1]
|
||||||
|
|
||||||
[node name="HitBox" type="Area2D"]
|
[node name="HitBox" type="Area2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
export(int) var max_health = 1
|
||||||
|
onready var health = max_health setget set_health
|
||||||
|
|
||||||
|
func set_health(v):
|
||||||
|
if v <= 0:
|
||||||
|
emit_signal("no_health")
|
||||||
|
health = 0
|
||||||
|
else:
|
||||||
|
health = v
|
||||||
|
|
||||||
|
|
||||||
|
signal no_health
|
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://AI/Stats.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Stats" type="Node"]
|
||||||
|
script = ExtResource( 1 )
|
|
@ -0,0 +1,10 @@
|
||||||
|
extends AnimationSprite
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
self.connect("animation_finished", self, "_on_animation_finished")
|
||||||
|
frame = 0
|
||||||
|
play("Animate")
|
||||||
|
|
||||||
|
|
||||||
|
func _on_animation_finished():
|
||||||
|
queue_free()
|
|
@ -1,10 +1,16 @@
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
var knockback = Vector2.ZERO
|
var knockback = Vector2.ZERO
|
||||||
|
onready var stats = $Stats
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
||||||
knockback = move_and_slide(knockback)
|
knockback = move_and_slide(knockback)
|
||||||
|
|
||||||
func _on_HurtBox_area_entered(area):
|
func _on_HurtBox_area_entered(area):
|
||||||
|
stats.health -= area.damage
|
||||||
knockback = area.knockback_vector * 120
|
knockback = area.knockback_vector * 120
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Stats_no_health():
|
||||||
|
queue_free()
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[gd_scene load_steps=13 format=2]
|
[gd_scene load_steps=14 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=1]
|
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=2]
|
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://AI/HurtBox.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://AI/HurtBox.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://Enemies/Bat.gd" type="Script" id=4]
|
[ext_resource path="res://Enemies/Bat.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://AI/Stats.tscn" type="PackedScene" id=5]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=1]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 2 )
|
atlas = ExtResource( 2 )
|
||||||
|
@ -47,6 +48,7 @@ script = ExtResource( 4 )
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 6 )
|
frames = SubResource( 6 )
|
||||||
animation = "Fly"
|
animation = "Fly"
|
||||||
|
frame = 2
|
||||||
playing = true
|
playing = true
|
||||||
offset = Vector2( 0, -12 )
|
offset = Vector2( 0, -12 )
|
||||||
|
|
||||||
|
@ -63,6 +65,10 @@ collision_mask = 0
|
||||||
[node name="CollisionShape2D" parent="HurtBox" index="0"]
|
[node name="CollisionShape2D" parent="HurtBox" index="0"]
|
||||||
position = Vector2( 0, -15 )
|
position = Vector2( 0, -15 )
|
||||||
shape = SubResource( 8 )
|
shape = SubResource( 8 )
|
||||||
|
|
||||||
|
[node name="Stats" parent="." instance=ExtResource( 5 )]
|
||||||
|
max_health = 2
|
||||||
[connection signal="area_entered" from="HurtBox" to="." method="_on_HurtBox_area_entered"]
|
[connection signal="area_entered" from="HurtBox" to="." method="_on_HurtBox_area_entered"]
|
||||||
|
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||||
|
|
||||||
[editable path="HurtBox"]
|
[editable path="HurtBox"]
|
||||||
|
|
|
@ -13,9 +13,9 @@ enum {
|
||||||
|
|
||||||
var state = MOVE
|
var state = MOVE
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
# At the Player scense, player has to be faced to the left for this
|
# At the Player scense, player has to be faced to the right for this
|
||||||
# vector to be correct
|
# vector to be correct
|
||||||
var roll_vector = Vector2.LEFT
|
var roll_vector = Vector2.RIGHT
|
||||||
|
|
||||||
onready var animation_tree = $AnimationTree
|
onready var animation_tree = $AnimationTree
|
||||||
onready var animation_state = animation_tree.get("parameters/playback")
|
onready var animation_state = animation_tree.get("parameters/playback")
|
||||||
|
|
|
@ -636,10 +636,10 @@ anims/RunUp = SubResource( 17 )
|
||||||
tree_root = SubResource( 44 )
|
tree_root = SubResource( 44 )
|
||||||
anim_player = NodePath("../AnimationPlayer")
|
anim_player = NodePath("../AnimationPlayer")
|
||||||
parameters/playback = SubResource( 45 )
|
parameters/playback = SubResource( 45 )
|
||||||
parameters/Attack/blend_position = Vector2( 0, 0 )
|
parameters/Attack/blend_position = Vector2( 1, 0 )
|
||||||
parameters/Idle/blend_position = Vector2( 0, 0 )
|
parameters/Idle/blend_position = Vector2( 1, 0 )
|
||||||
parameters/Roll/blend_position = Vector2( 0, 0 )
|
parameters/Roll/blend_position = Vector2( 1, 0 )
|
||||||
parameters/Run/blend_position = Vector2( 0, 0 )
|
parameters/Run/blend_position = Vector2( 1, 0 )
|
||||||
|
|
||||||
[node name="HitBoxPosition" type="Position2D" parent="."]
|
[node name="HitBoxPosition" type="Position2D" parent="."]
|
||||||
position = Vector2( 0, -5 )
|
position = Vector2( 0, -5 )
|
||||||
|
@ -649,6 +649,7 @@ position = Vector2( 16, 0 )
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
|
damage = 2
|
||||||
|
|
||||||
[node name="CollisionShape2D" parent="HitBoxPosition/SwordHitBox" index="0"]
|
[node name="CollisionShape2D" parent="HitBoxPosition/SwordHitBox" index="0"]
|
||||||
shape = SubResource( 46 )
|
shape = SubResource( 46 )
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
extends Area2D
|
extends "res://AI/HitBox.gd"
|
||||||
|
|
||||||
var knockback_vector = Vector2.ZERO
|
var knockback_vector = Vector2.ZERO
|
||||||
|
|
Loading…
Reference in New Issue