From ac863b11dfa98816cf91fee12de6af16572b9763 Mon Sep 17 00:00:00 2001 From: batataazul Date: Thu, 27 Aug 2020 23:50:10 -0300 Subject: [PATCH] Grupo inimigo criado, tentei fazer a espada --- pwojeto/Scenes/actors/enemies/Bat.tscn | 4 +- pwojeto/Scenes/actors/enemies/Spider.tscn | 60 ++++++++++++++- pwojeto/Scenes/actors/player/Character.tscn | 83 ++++++++++++++++++--- pwojeto/Scripts/Character.gd | 24 ++++++ pwojeto/Scripts/Morcego.gd | 4 + pwojeto/Spider.gd | 7 ++ pwojeto/project.godot | 5 ++ 7 files changed, 173 insertions(+), 14 deletions(-) diff --git a/pwojeto/Scenes/actors/enemies/Bat.tscn b/pwojeto/Scenes/actors/enemies/Bat.tscn index b183bf2..98a422a 100644 --- a/pwojeto/Scenes/actors/enemies/Bat.tscn +++ b/pwojeto/Scenes/actors/enemies/Bat.tscn @@ -3,7 +3,7 @@ [ext_resource path="res://Scripts/Morcego.gd" type="Script" id=1] [ext_resource path="res://icon.png" type="Texture" id=2] -[sub_resource type="RectangleShape2D" id=4] +[sub_resource type="RectangleShape2D" id=1] extents = Vector2( 61.4362, 60.6278 ) [sub_resource type="SpriteFrames" id=2] @@ -26,7 +26,7 @@ radius = 655.591 script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource( 4 ) +shape = SubResource( 1 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] scale = Vector2( 2, 2 ) diff --git a/pwojeto/Scenes/actors/enemies/Spider.tscn b/pwojeto/Scenes/actors/enemies/Spider.tscn index a570346..ffd3c5a 100644 --- a/pwojeto/Scenes/actors/enemies/Spider.tscn +++ b/pwojeto/Scenes/actors/enemies/Spider.tscn @@ -1,6 +1,6 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=7 format=2] -[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Assets/Aranha/Aranha andando.png" type="Texture" id=1] [ext_resource path="res://Spider.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] @@ -9,6 +9,51 @@ extents = Vector2( 62.5195, 61.5018 ) [sub_resource type="CircleShape2D" id=2] radius = 901.289 +[sub_resource type="Animation" id=4] +resource_name = "andando" +loop = true +step = 0.0416667 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.0416667, 0.0833333, 0.125, 0.166667, 0.208333, 0.25, 0.291667, 0.333333, 0.375, 0.416667, 0.458333, 0.5, 0.541667, 0.583333, 0.625, 0.666667, 0.708333, 0.75, 0.791667, 0.833333, 0.875, 0.916667, 0.958333, 1 ), +"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ), +"update": 1, +"values": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0 ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Sprite:visible") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ true, true ] +} + +[sub_resource type="Animation" id=3] +resource_name = "parado" +step = 1.0 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite:frame") +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": 1, +"values": [ 0 ] +} + [node name="Spider" type="KinematicBody2D"] script = ExtResource( 2 ) @@ -16,8 +61,12 @@ script = ExtResource( 2 ) shape = SubResource( 1 ) [node name="Sprite" type="Sprite" parent="."] -scale = Vector2( 2, 2 ) +position = Vector2( 4.24241, -3.72709 ) +scale = Vector2( 0.104778, 0.224614 ) texture = ExtResource( 1 ) +vframes = 5 +hframes = 5 +frame = 10 [node name="Area2D" type="Area2D" parent="."] @@ -42,6 +91,11 @@ one_shot = true [node name="KnockbackTimer" type="Timer" parent="."] wait_time = 0.15 one_shot = true + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +autoplay = "parado" +anims/andando = SubResource( 4 ) +anims/parado = SubResource( 3 ) [connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"] [connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"] [connection signal="timeout" from="KnockbackTimer" to="." method="_on_KnockbackTimer_timeout"] diff --git a/pwojeto/Scenes/actors/player/Character.tscn b/pwojeto/Scenes/actors/player/Character.tscn index 4a2c309..6666616 100644 --- a/pwojeto/Scenes/actors/player/Character.tscn +++ b/pwojeto/Scenes/actors/player/Character.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://Scripts/Character.gd" type="Script" id=1] [ext_resource path="res://Scenes/menus/pause_menu.tscn" type="PackedScene" id=2] @@ -8,12 +8,8 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 43, 50.3809 ) -[sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 6.44367, 30.6272 ) - [sub_resource type="Animation" id=3] -resource_name = "golpeEspada" -loop = true +resource_name = "golpeEspadaDireita" step = 0.25 tracks/0/type = "value" tracks/0/path = NodePath("Espada:visible") @@ -52,6 +48,52 @@ tracks/2/keys = { "values": [ 45.0, 55.0, 75.0, 85.0, 95.0 ] } +[sub_resource type="Animation" id=4] +resource_name = "golpeEspadaEsquerda" +step = 0.25 +tracks/0/type = "value" +tracks/0/path = NodePath("Espada2/CollisionShape2D:disabled") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ false, true ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Espada2:visible") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ true, false ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("Espada2:rotation_degrees") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"times": PoolRealArray( 0, 0.25, 0.5, 0.75, 1 ), +"transitions": PoolRealArray( 1, 1, 1, 1, 1 ), +"update": 0, +"values": [ 315.0, 305.0, 295.0, 285.0, 275.0 ] +} + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 6.44367, 37.4059 ) + +[sub_resource type="RectangleShape2D" id=5] +extents = Vector2( 6.44367, 37.4059 ) + [node name="Character" type="KinematicBody2D" groups=[ "character", ]] @@ -81,12 +123,19 @@ one_shot = true [node name="Pause_menu" parent="CanvasLayer" instance=ExtResource( 2 )] visible = false +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/golpeEspadaDireita = SubResource( 3 ) +anims/golpeEspadaEsquerda = SubResource( 4 ) + [node name="Espada" type="Area2D" parent="."] +visible = false position = Vector2( 61.0175, 5.1272 ) -rotation = 0.919089 +rotation = 1.65806 +scale = Vector2( 1, 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Espada"] shape = SubResource( 2 ) +disabled = true __meta__ = { "_edit_lock_": true } @@ -97,5 +146,21 @@ __meta__ = { "_edit_lock_": true } -[node name="AnimationPlayer" type="AnimationPlayer" parent="."] -anims/golpeEspada = SubResource( 3 ) +[node name="Espada2" type="Area2D" parent="."] +visible = false +position = Vector2( -61.8802, -1.22958 ) +rotation = 4.79966 +scale = Vector2( 1, 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Espada2"] +shape = SubResource( 5 ) +disabled = true +__meta__ = { +"_edit_lock_": true +} + +[node name="Sprite" type="Sprite" parent="Espada2"] +texture = ExtResource( 4 ) +__meta__ = { +"_edit_lock_": true +} diff --git a/pwojeto/Scripts/Character.gd b/pwojeto/Scripts/Character.gd index 9320ad4..7061adf 100644 --- a/pwojeto/Scripts/Character.gd +++ b/pwojeto/Scripts/Character.gd @@ -10,7 +10,15 @@ var life=100 var double_jump_cost=10 var wall_jump_cost=5 var has_wall_jump=true +onready var espadaDir = $Espada +onready var espadaEsq = $Espada2 +var direita = true func _ready(): + if direita: + espadaDir.connect("body_entered",self,"atack") + else: + espadaEsq.connect("body_entered",self,"atack") + set_physics_process(true) pass # Replace with function body. func _physics_process(delta): @@ -19,14 +27,24 @@ func _physics_process(delta): $CanvasLayer/Pause_menu.visible = true get_tree().paused = true pass + if Input.is_action_pressed("melee_atack"): + if direita: + $AnimationPlayer.play("golpeEspadaDireita") + else: + $AnimationPlayer.play("golpeEspadaEsquerda") + pass if Input.is_action_pressed("left") and $WallJumpTimer.is_stopped(): velocity.x=-SPEED if $Sprite.flip_h==false: $Sprite.flip_h=true + #$Espada/Sprite.flip_h = true + direita = false elif Input.is_action_pressed("right" ) and $WallJumpTimer.is_stopped(): velocity.x=SPEED if $Sprite.flip_h==true: $Sprite.flip_h=false + #$Espada/Sprite.flip_h = false + direita = true elif $WallJumpTimer.is_stopped(): velocity.x=0 if Input.is_action_just_pressed("jump") : @@ -64,3 +82,9 @@ func damage(damage): life-=damage if life<0: queue_free() + +func atack(body): + if body.is_in_group("enemy"): + body.hit() + pass + pass diff --git a/pwojeto/Scripts/Morcego.gd b/pwojeto/Scripts/Morcego.gd index a102fa3..c72ff17 100644 --- a/pwojeto/Scripts/Morcego.gd +++ b/pwojeto/Scripts/Morcego.gd @@ -4,6 +4,10 @@ var velocity=Vector2(0,0) var SPEED=200 var DAMAGE=25 var knockback_speed=1000 + +func _ready(): + add_to_group("enemy") + set_physics_process(true) func _physics_process(delta): if alvo!=null and $KnockbackTimer.is_stopped(): velocity=alvo.global_position-global_position diff --git a/pwojeto/Spider.gd b/pwojeto/Spider.gd index 9da4ffe..c46da90 100644 --- a/pwojeto/Spider.gd +++ b/pwojeto/Spider.gd @@ -11,6 +11,8 @@ var KNOCKBACK_ANGLE=PI/4 var KNOCKBACK_SPEED=1000 var DAMAGE=30 func _ready(): + + add_to_group("enemie") pass @@ -20,10 +22,15 @@ func _physics_process(delta): if(global_positionalvo.global_position: + $Sprite.flip_h = true + $AnimationPlayer.play("andando") velocity.x=-SPEED else: velocity.x=0 + $AnimationPlayer.play("parado") if is_on_wall(): velocity.y=-CLIMBSPEED diff --git a/pwojeto/project.godot b/pwojeto/project.godot index 3e1ba7e..0085af0 100644 --- a/pwojeto/project.godot +++ b/pwojeto/project.godot @@ -79,6 +79,11 @@ jump={ , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) ] } +melee_atack={ +"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":32,"unicode":0,"echo":false,"script":null) + ] +} [rendering]