Skip to content

Commit

Permalink
enemies can hurt player
Browse files Browse the repository at this point in the history
  • Loading branch information
theRemix committed Jan 30, 2022
1 parent 54807e9 commit faf7f77
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 52 deletions.
10 changes: 5 additions & 5 deletions Enemies/EnemyTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ onready var animationPlayer = $AnimationPlayer

signal subdued


func _ready():
state = pick_random_state([IDLE, WANDER])

Expand All @@ -56,7 +55,7 @@ func _physics_process(delta):
animation.play("idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
seek_player()

if wanderController.get_time_left() == 0:
update_wander()
WANDER:
Expand All @@ -74,11 +73,14 @@ func _physics_process(delta):
accelerate_towards_point(player.global_position, delta)
else:
state = IDLE

if softCollision.is_colliding():
velocity += softCollision.get_push_vector() * delta * 400
velocity = move_and_slide(velocity)

func _on_HitBox_body_entered(body):
if body.has_method("hurt"):
body.hurt()

func get_facing_direction(vec_to_location):
var facing_vec = get_facing_vector(vec_to_location)
Expand Down Expand Up @@ -113,5 +115,3 @@ func seek_player():
state = CHASE




2 changes: 2 additions & 0 deletions Enemies/EnemyTemplate.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ collision_mask = 2
[node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."]
process_parent = true
physics_process_parent = true

[connection signal="body_entered" from="HitBox" to="." method="_on_HitBox_body_entered"]
9 changes: 5 additions & 4 deletions Enemies/GreyDragonAshigaru.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"frames": [ ExtResource( 2 ) ],
"loop": true,
"name": "idle",
"name": "alert",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "alert",
"name": "idle",
"speed": 5.0
} ]

Expand All @@ -38,6 +38,7 @@ height = 76.8543
radius = 168.662

[node name="GreyDragonAshigaru" instance=ExtResource( 1 )]
collision_layer = 80
script = ExtResource( 4 )

[node name="AnimatedSprite" parent="." index="0"]
Expand Down
9 changes: 5 additions & 4 deletions Enemies/GreyDragonSamurai.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

[sub_resource type="SpriteFrames" id=6]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"frames": [ ExtResource( 4 ) ],
"loop": true,
"name": "idle",
"name": "alert",
"speed": 5.0
}, {
"frames": [ ExtResource( 4 ) ],
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "alert",
"name": "idle",
"speed": 5.0
} ]

Expand All @@ -38,6 +38,7 @@ height = 67.306
radius = 218.324

[node name="GreyDragonSamurai" instance=ExtResource( 1 )]
collision_layer = 80
script = ExtResource( 2 )

[node name="AnimatedSprite" parent="." index="0"]
Expand Down
9 changes: 5 additions & 4 deletions Enemies/WhiteTigerAshigaru.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"frames": [ ExtResource( 2 ) ],
"loop": true,
"name": "idle",
"name": "alert",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "alert",
"name": "idle",
"speed": 5.0
} ]

Expand All @@ -38,6 +38,7 @@ height = 63.8221
radius = 186.578

[node name="WhiteTigerAshigaru" instance=ExtResource( 1 )]
collision_layer = 144
script = ExtResource( 4 )

[node name="AnimatedSprite" parent="." index="0"]
Expand Down
25 changes: 17 additions & 8 deletions Enemies/WhiteTigerSamurai.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@

[sub_resource type="SpriteFrames" id=10]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"frames": [ ExtResource( 4 ) ],
"loop": true,
"name": "idle",
"name": "alert",
"speed": 5.0
}, {
"frames": [ ExtResource( 4 ) ],
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "alert",
"name": "idle",
"speed": 5.0
} ]

[sub_resource type="CapsuleShape2D" id=9]
radius = 16.2152
height = 71.6582
height = 24.0

[sub_resource type="CapsuleShape2D" id=8]
radius = 11.5902
height = 77.3613

[sub_resource type="CapsuleShape2D" id=7]
radius = 18.3174
height = 69.1355
radius = 34.0
height = 101.365

[sub_resource type="CapsuleShape2D" id=6]
radius = 20.4196
Expand All @@ -38,6 +37,7 @@ height = 72.4991
radius = 200.808

[node name="WhiteTigerSamurai" instance=ExtResource( 1 )]
collision_layer = 144
script = ExtResource( 2 )
min_speed = 85
max_speed = 150
Expand All @@ -48,18 +48,27 @@ frames = SubResource( 10 )
animation = "idle"

[node name="CollisionShape2D" parent="." index="1"]
position = Vector2( 0, 46 )
rotation = 1.5708
shape = SubResource( 9 )

[node name="Hurtbox" parent="." index="2"]
visible = false

[node name="CollisionShape2D" parent="Hurtbox" index="0"]
shape = SubResource( 8 )

[node name="CollisionShape2D" parent="HitBox" index="0"]
shape = SubResource( 7 )

[node name="SoftCollision" parent="." index="4"]
visible = false

[node name="CollisionShape2D" parent="SoftCollision" index="0"]
shape = SubResource( 6 )

[node name="PlayerDetectionZone" parent="." index="5"]
visible = false
collision_mask = 66

[node name="CollisionShape2D" parent="PlayerDetectionZone" index="0"]
Expand Down
3 changes: 3 additions & 0 deletions Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ position = Vector2( 1088, 1584 )
[node name="WhiteTigerSamurai3" parent="YSort" instance=ExtResource( 4 )]
position = Vector2( 1080, 88 )

[node name="WhiteTigerSamurai_TEST" parent="YSort" instance=ExtResource( 4 )]
position = Vector2( 957, -458 )

[node name="WhiteTigerSamurai4" parent="YSort" instance=ExtResource( 4 )]
position = Vector2( 2056, -368 )

Expand Down
7 changes: 6 additions & 1 deletion Overlap/Hurtbox.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]

[ext_resource path="res://Overlap/Hurtbox.gd" type="Script" id=1]

[sub_resource type="CapsuleShape2D" id=1]
radius = 17.0
height = 22.0

[node name="Hurtbox" type="Area2D"]
script = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="Timer" type="Timer" parent="."]

Expand Down
27 changes: 19 additions & 8 deletions Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ enum {
PLACE
}

export var ACCELERATION = 160
export var MAX_SPEED = 80
export var FRICTION = 500
export var ACCELERATION = 1
export var MAX_SPEED = 180
export var FRICTION = 1500

onready var whiteTiger = $Sprites/WhiteTiger
onready var greyDragon = $Sprites/GreyDragon
onready var ninja = $Sprites/Ninja
onready var stats = $Health
onready var hurtInvincibilityTimer = $HurtInvincibilityTimer

# TODO:
# var stats = PlayerStats
var velocity = Vector2.ZERO
var state = MOVE
var transforming = false
var disguise = null
var invincible := false



func _ready():
disguise = ninja
hurtInvincibilityTimer.connect("timeout", self, "_on_Hurtbox_invincibility_timeout")


func _physics_process(delta):
Expand All @@ -44,14 +47,14 @@ func move_state(delta):
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

velocity = move_and_slide(velocity)

# TODO: Add steal and transform code here


Expand All @@ -73,6 +76,12 @@ func hide_disguises():
for disguise in all_disguises:
disguise.visible = false

func hurt():
printerr("HURT")
# play hurt animation
# bounce away?
stats.health = stats.health - 1
invincible = true

func _on_ChangingHitBox_area_entered(area):
hide_disguises()
Expand All @@ -83,4 +92,6 @@ func _on_ChangingHitBox_area_entered(area):

func _on_ChangingTimer_timeout():
disguise.visible = true


func _on_Hurtbox_invincibility_timeout():
invincible = false
28 changes: 12 additions & 16 deletions Player/Player.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=12 format=2]

[ext_resource path="res://assets/entities/player/animations/ninja-walk-forward.png" type="Texture" id=1]
[ext_resource path="res://Player/Player.gd" type="Script" id=2]
[ext_resource path="res://Overlap/Hurtbox.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/entities/player/animations/ninja-dragon-samurai-walk-forward.png" type="Texture" id=4]
[ext_resource path="res://assets/entities/player/player tiger samurai.png" type="Texture" id=5]
[ext_resource path="res://Util/Stats.tscn" type="PackedScene" id=6]

[sub_resource type="CapsuleShape2D" id=1]
radius = 18.4465
height = 65.5583

[sub_resource type="CapsuleShape2D" id=2]
radius = 16.5161
height = 64.8679
radius = 12.0
height = 30.0

[sub_resource type="CapsuleShape2D" id=3]
radius = 28.5026
Expand Down Expand Up @@ -46,12 +42,14 @@ states/NinjaWalkDown/position = Vector2( 514, 72 )
[sub_resource type="AnimationNodeStateMachinePlayback" id=6]

[node name="Player" type="KinematicBody2D"]
collision_layer = 3
collision_layer = 7
collision_mask = 9
script = ExtResource( 2 )
ACCELERATION = 200

[node name="WorldCollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 1, 47 )
rotation = 1.5708
shape = SubResource( 1 )

[node name="Sprites" type="YSort" parent="."]
Expand All @@ -69,12 +67,8 @@ visible = false
texture = ExtResource( 4 )
hframes = 4

[node name="Hurtbox" parent="." instance=ExtResource( 3 )]

[node name="CollisionShape2D" parent="Hurtbox" index="0"]
shape = SubResource( 2 )

[node name="ChangingHitBox" type="Area2D" parent="."]
visible = false
collision_layer = 0
collision_mask = 256

Expand All @@ -92,7 +86,9 @@ tree_root = SubResource( 5 )
anim_player = NodePath("../AnimationPlayer")
parameters/playback = SubResource( 6 )

[node name="Health" parent="." instance=ExtResource( 6 )]

[node name="HurtInvincibilityTimer" type="Timer" parent="."]

[connection signal="area_entered" from="ChangingHitBox" to="." method="_on_ChangingHitBox_area_entered"]
[connection signal="timeout" from="ChangingHitBox/ChangingTimer" to="." method="_on_ChangingTimer_timeout"]

[editable path="Hurtbox"]
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ window/size/height=900

disguise_tiger={
"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":84,"unicode":0,"echo":false,"script":null)
"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":84,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
disguise_dragon={
"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":68,"unicode":0,"echo":false,"script":null)
"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":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
tilesize={
Expand Down

0 comments on commit faf7f77

Please sign in to comment.