From c293efbc1335646076204085ba55fc61124e4eac Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 21 Jul 2020 01:07:58 -0500 Subject: [PATCH] Better respawn and knockback --- Area2D.gd | 4 ++-- Items/Door.tscn | 4 ++-- Title/Death Screen'.gd | 3 ++- ai/Enemy.gd | 2 +- ai/Hell.gd | 6 ++++++ ai/Skeleton Enemy.gd | 14 +++++++++++--- ai/ogre.gd | 8 ++++++++ levels/World.tscn | 20 +++++++++++--------- project.godot | 5 +++++ 9 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Area2D.gd b/Area2D.gd index 5870ff2..ed7a45b 100644 --- a/Area2D.gd +++ b/Area2D.gd @@ -6,5 +6,5 @@ func _process(delta): if get_overlapping_bodies().size() != 0: print("1") if Input.is_action_pressed("open"): - print("2") - get_tree().change_scene("res://levels/World.tscn") + Player.current_scene = "res://levels/World.tscn" + get_tree().change_scene("res://levels/testtscn") diff --git a/Items/Door.tscn b/Items/Door.tscn index 8a24873..eb41718 100644 --- a/Items/Door.tscn +++ b/Items/Door.tscn @@ -19,7 +19,7 @@ tracks/0/keys = { "values": [ 0, 1 ] } -[sub_resource type="RectangleShape2D" id=3] +[sub_resource type="RectangleShape2D" id=2] extents = Vector2( 14, 13 ) [node name="Door" type="Sprite"] @@ -35,5 +35,5 @@ script = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] position = Vector2( 16, 19 ) -shape = SubResource( 3 ) +shape = SubResource( 2 ) [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_Area2D_body_entered"] diff --git a/Title/Death Screen'.gd b/Title/Death Screen'.gd index efde8c7..f72aa2b 100644 --- a/Title/Death Screen'.gd +++ b/Title/Death Screen'.gd @@ -17,7 +17,8 @@ func _ready(): func _on_TextureButton_pressed(): - get_tree().change_scene("res://levels/World.tscn") + Player.respawn() + get_tree().change_scene(Player.current_scene) func _on_TextureButton2_pressed(): diff --git a/ai/Enemy.gd b/ai/Enemy.gd index 8ad542e..37ec697 100644 --- a/ai/Enemy.gd +++ b/ai/Enemy.gd @@ -21,5 +21,5 @@ func apply_gravity(delta, modifier = 1): velocity.y += gravity * delta * modifier func do_knockback(normal): - knockback = normal + knockback = Vector2(4, 4) diff --git a/ai/Hell.gd b/ai/Hell.gd index dc9409c..c2959ff 100644 --- a/ai/Hell.gd +++ b/ai/Hell.gd @@ -37,6 +37,12 @@ func _physics_process(_delta): $Hell.flip_h = true if health <= 0: queue_free() + +func do_knockback(normal): + if $Hell.flip_h == true: + knockback = Vector2(-4, -4) + else: + knockback = Vector2(4, 0) func shoot_fireball(direction): if ShootDelay.is_stopped(): diff --git a/ai/Skeleton Enemy.gd b/ai/Skeleton Enemy.gd index b68d37a..62a24a0 100644 --- a/ai/Skeleton Enemy.gd +++ b/ai/Skeleton Enemy.gd @@ -9,13 +9,14 @@ func apply_gravity(delta, modifier = 1): velocity.y += gravity * delta * modifier func _physics_process(_delta): + var dist = global_position.distance_to(Player.position) + if knockback != Vector2.ZERO: knockback = lerp(knockback, Vector2.ZERO, 0.5) move_and_slide(-knockback * knockback_amount) if knockback.x < 1 and -1 < knockback.x and knockback.y < 1 and -1 < knockback.y: knockback = Vector2.ZERO return - var dist = global_position.distance_to(Player.position) if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player": velocity = Vector2(0, 0) throw_bone(Vector2.LEFT) @@ -30,13 +31,14 @@ func _physics_process(_delta): if dist <= 400: velocity.x = position.direction_to(Globals.player).normalized().x else: - velocity = Vector2(0, 0) + velocity = Vector2(0, 0) if velocity.x > 0: $Skeleton.flip_h = false elif velocity.x < 0: $Skeleton.flip_h = true - + + # Kill if health <= 0: queue_free() @@ -52,4 +54,10 @@ func throw_bone(direction): temp.global_position = ProjectileSpawn.global_position temp.launch_vector(direction) ShootDelay.start() + +func do_knockback(normal): + if $Skeleton.flip_h == true: + knockback = Vector2(-4, -4) + else: + knockback = Vector2(4, 0) diff --git a/ai/ogre.gd b/ai/ogre.gd index 697a231..4c14e68 100644 --- a/ai/ogre.gd +++ b/ai/ogre.gd @@ -8,8 +8,10 @@ onready var Hurtbox = $Area2D func _ready(): speed = 50 + health = 3.5 func _physics_process(delta): + Player.current_scene = "res://levels/World.tscn" if knockback != Vector2.ZERO: knockback = lerp(knockback, Vector2.ZERO, 0.5) move_and_slide(-knockback * knockback_amount) @@ -38,3 +40,9 @@ func deal_damage(): if body.has_method("get_type") && body.get_type() == "player": body.health -= contact_damage DamageCD.start() + +func do_knockback(normal): + if Spr.flip_h == true: + knockback = Vector2(-4, -4) + else: + knockback = Vector2(4, 0) diff --git a/levels/World.tscn b/levels/World.tscn index 3cba4e3..460b450 100644 --- a/levels/World.tscn +++ b/levels/World.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=24 format=2] [ext_resource path="res://meta/DungeonTilemap.tscn" type="PackedScene" id=1] [ext_resource path="res://Player/Player.tscn" type="PackedScene" id=2] @@ -9,11 +9,10 @@ [ext_resource path="res://art/Pedestal.png" type="Texture" id=7] [ext_resource path="res://Items/ChargeWandPickup.tscn" type="PackedScene" id=8] [ext_resource path="res://art/ecoprojectile.png" type="Texture" id=9] +[ext_resource path="res://ai/Skeleton Enemy.tscn" type="PackedScene" id=11] [ext_resource path="res://art/Mana.png" type="Texture" id=12] [ext_resource path="res://Items/Door.tscn" type="PackedScene" id=13] - - [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 169.977, 24.8286 ) @@ -263,7 +262,7 @@ margin_right = 1302.35 margin_bottom = 200.227 rect_scale = Vector2( 0.75, 0.75 ) custom_fonts/font = SubResource( 2 ) -text = "Press 'E'and equip a projectile to be able to shoot" +text = "Press 'E'and equip a spell to be able to shoot" autowrap = true __meta__ = { "_edit_use_anchors_": false @@ -280,7 +279,7 @@ margin_right = 1453.41 margin_bottom = 142.983 rect_scale = Vector2( 0.5, 0.5 ) custom_fonts/font = SubResource( 2 ) -text = "Each projectile does something different" +text = "Each spell does something different" autowrap = true __meta__ = { "_edit_use_anchors_": false @@ -289,13 +288,13 @@ __meta__ = { [node name="sample_text4" type="Label" parent="text/Text6"] anchor_top = -0.000655535 anchor_bottom = -0.000655535 -margin_left = 1426.25 +margin_left = 1425.66 margin_top = 59.1731 -margin_right = 1634.25 +margin_right = 1633.66 margin_bottom = 167.173 rect_scale = Vector2( 0.45, 0.45 ) custom_fonts/font = SubResource( 2 ) -text = "This projectile takes no mana but does little damage" +text = "This spell takes no mana but does little damage" autowrap = true __meta__ = { "_edit_use_anchors_": false @@ -340,7 +339,7 @@ margin_right = 2196.39 margin_bottom = 284.74 rect_scale = Vector2( 0.45, 0.45 ) custom_fonts/font = SubResource( 2 ) -text = "Press 'F' to open" +text = "Press 'F' to open stuff" autowrap = true __meta__ = { "_edit_use_anchors_": false @@ -458,5 +457,8 @@ texture = ExtResource( 9 ) position = Vector2( 1581.08, 38.1216 ) scale = Vector2( 2.66787, 2.66787 ) texture = ExtResource( 12 ) + +[node name="Skeleton Enemy" parent="." instance=ExtResource( 11 )] +position = Vector2( 149.132, 146.16 ) [connection signal="body_entered" from="Area2D" to="Player" method="_on_Area2D_body_entered"] [connection signal="body_entered" from="Area2D" to="text/Text2" method="_on_body_entered"] diff --git a/project.godot b/project.godot index f635f4f..f3c8e77 100644 --- a/project.godot +++ b/project.godot @@ -161,6 +161,11 @@ inventory={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) ] } +open={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":70,"unicode":0,"echo":false,"script":null) + ] +} [layer_names]