Skip to content

Commit

Permalink
movimento basico, pulo e escalada da aranha implementados
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipePM01 committed Aug 27, 2020
1 parent 3678baa commit 6bed480
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 9 deletions.
42 changes: 42 additions & 0 deletions pwojeto/Scenes/Spider.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Spider.gd" type="Script" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 62.5195, 61.5018 )

[sub_resource type="CircleShape2D" id=2]
radius = 901.289

[node name="Spider" type="KinematicBody2D"]
script = ExtResource( 2 )

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

[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 2, 2 )
texture = ExtResource( 1 )

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

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 0.647079, 1.61767 )
shape = SubResource( 2 )

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

[node name="RayCastLeft" type="RayCast2D" parent="."]
position = Vector2( -74.6544, 50.8628 )
enabled = true

[node name="RayCastRight" type="RayCast2D" parent="."]
position = Vector2( 74.4957, 49.9128 )
enabled = true

[node name="JumpTimer" type="Timer" parent="."]
wait_time = 0.1
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"]
55 changes: 55 additions & 0 deletions pwojeto/Spider.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
extends KinematicBody2D
var alvo=null
var velocity=Vector2(0,0)
var CLIMBSPEED=200
var SPEED=200
var GRAVITY=100
var is_jumping=false
var JUMP_ANGLE=PI/6
var JUMP_SPEED=1000
func _ready():
pass


func _physics_process(delta):
if alvo!=null:
if not is_jumping:

if(global_position<alvo.global_position):
velocity.x=SPEED
elif global_position>alvo.global_position:
velocity.x=-SPEED
else:
velocity.x=0
if is_on_wall():

velocity.y=-CLIMBSPEED
elif not is_on_floor():
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():
is_jumping=false
else:
velocity.y+=GRAVITY
velocity=move_and_slide(velocity,Vector2(0,-1))




func _on_Area2D_body_entered(body):
if body.is_in_group("character"):
$RayCast2D.set_cast_to(body.global_position-global_position)
$RayCast2D.force_raycast_update()
if $RayCast2D.get_collider()==body:
alvo=body


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
16 changes: 8 additions & 8 deletions pwojeto/menus/main_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Scenes/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Bat.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scenes/Spider.tscn" type="PackedScene" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 999.985, 178.658 )
extents = Vector2( 947.372, 151.09 )

[node name="Node2D" type="Node2D"]

Expand All @@ -15,23 +15,23 @@ position = Vector2( 924.007, 657.217 )
shape = SubResource( 1 )

[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"]
position = Vector2( 13.0142, -6.50708 )
position = Vector2( 38.9449, 8.39594 )
polygon = PoolVector2Array( -5.36145, 491.573, 1930.5, 501.334, 1930.5, 764.871, 1.14563, 764.871 )

[node name="StaticBody2D2" type="StaticBody2D" parent="."]
position = Vector2( 2345.83, -160.504 )
rotation = 1.5708

[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2"]
position = Vector2( 841.813, 845.58 )
position = Vector2( 1458.83, 1214.14 )
shape = SubResource( 1 )

[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D2"]
position = Vector2( -154.887, 263.417 )
position = Vector2( 512.81, 601.124 )
polygon = PoolVector2Array( -5.36145, 491.573, 1930.5, 501.334, 1930.5, 764.871, 1.14563, 764.871 )

[node name="Character" parent="." instance=ExtResource( 1 )]
position = Vector2( 917.5, 348.13 )
position = Vector2( 1590.03, 188.714 )

[node name="Bat" parent="." instance=ExtResource( 2 )]
position = Vector2( 434.948, 160.965 )
[node name="Spider" parent="." instance=ExtResource( 2 )]
position = Vector2( 663.636, 343.44 )
1 change: 0 additions & 1 deletion pwojeto/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ config/icon="res://icon.png"

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

Expand Down

0 comments on commit 6bed480

Please sign in to comment.