Skip to content

Commit

Permalink
terminado script da aranha
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipePM01 committed Aug 27, 2020
1 parent 6bed480 commit 5e9907b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pwojeto/Scenes/Spider.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ enabled = true
[node name="JumpTimer" type="Timer" parent="."]
wait_time = 0.1
one_shot = true

[node name="KnockbackTimer" type="Timer" parent="."]
wait_time = 0.15
one_shot = true
[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"]
32 changes: 28 additions & 4 deletions pwojeto/Spider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var GRAVITY=100
var is_jumping=false
var JUMP_ANGLE=PI/6
var JUMP_SPEED=1000
var KNOCKBACK_ANGLE=PI/4
var KNOCKBACK_SPEED=1000
var DAMAGE=30
func _ready():
pass

Expand All @@ -28,12 +31,16 @@ func _physics_process(delta):
velocity.y+=GRAVITY
if is_on_floor() and ((velocity.x<0 and not $RayCastLeft.is_colliding() )or(velocity.x>0 and not $RayCastRight.is_colliding())):
jump()
elif (is_on_floor() or is_on_wall())and $JumpTimer.is_stopped():
elif (is_on_floor() or is_on_wall())and $JumpTimer.is_stopped() and $KnockbackTimer.is_stopped():
is_jumping=false
else:
velocity.y+=GRAVITY
velocity=move_and_slide(velocity,Vector2(0,-1))

for i in get_slide_count():
var collision=get_slide_collision(i)
if collision and collision.collider.is_in_group("character"):
collision.collider.damage(DAMAGE)
knockback()



Expand All @@ -49,7 +56,24 @@ func _on_Area2D_body_exited(body):
if body.is_in_group("character"):
alvo=null
func jump():
print(1)

$JumpTimer.start()
is_jumping=true
velocity=Vector2(0,-1).rotated(JUMP_ANGLE)*JUMP_SPEED
if velocity.x>0:
velocity=Vector2(0,-1).rotated(JUMP_ANGLE)*JUMP_SPEED
else:
velocity=Vector2(0,-1).rotated(-JUMP_ANGLE)*JUMP_SPEED
func knockback():
$KnockbackTimer.start()
is_jumping=true
if velocity.x>0:
velocity=Vector2(0,-1).rotated(KNOCKBACK_ANGLE)*KNOCKBACK_SPEED
else:
velocity=Vector2(0,-1).rotated(-KNOCKBACK_ANGLE)*KNOCKBACK_SPEED


func _on_KnockbackTimer_timeout():
is_jumping=false

func hit():
queue_free()
1 change: 1 addition & 0 deletions pwojeto/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config/icon="res://icon.png"

window/size/width=1920
window/size/height=1080
window/size/fullscreen=true
window/stretch/mode="2d"
window/stretch/aspect="keep"

Expand Down

0 comments on commit 5e9907b

Please sign in to comment.