Skeleton works perfectly now

This commit is contained in:
Diego 2020-07-18 17:07:40 -05:00
parent b675495c6e
commit b2317e09c7
15 changed files with 269 additions and 158 deletions

View file

@ -1,16 +0,0 @@
extends KinematicBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View file

@ -1,27 +0,0 @@
extends KinematicBody2D
var speed = 60
var gravity =500
const UP = Vector2(0, -1)
var velocity = Vector2()
func apply_gravity(delta, modifier = 1):
velocity.y += gravity * delta * modifier
func _physics_process(_delta):
if Globals.player != null:
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
else:
velocity.x = position.direction_to(Globals.player).normalized().x
apply_gravity(_delta)
velocity.x *= speed
velocity = move_and_slide(velocity, UP)
if is_on_wall() and is_on_floor():
velocity.y = -150

View file

@ -1,32 +0,0 @@
extends RigidBody2D
var speed = 45
var gravity = 500
const UP = Vector2(0, -1)
var is_grounded
var touching_wall = 0
var velocity = Vector2()
func apply_gravity(delta, modifier = 1):
velocity.y += gravity * delta * modifier
func _physics_process(_delta):
if Globals.player != null:
velocity.x = position.direction_to(Globals.player).normalized().x
apply_gravity(_delta)
velocity = move_and_slide(velocity * speed)
if is_on_wall():
if velocity.x > -1 and velocity.x < 1:
velocity.x = 0
var was_on_floor = is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
if !was_on_floor and is_on_floor():
emit_signal("grounded_updated", is_on_floor())
var was_grounded = is_grounded
is_grounded = is_on_floor()
if Vector2.ZERO == velocity:
velocity.y = -10

View file

@ -1,19 +1,33 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Skeleton Enemy.gd" type="Script" id=1]
[ext_resource path="res://art/unknown.png" type="Texture" id=2]
[ext_resource path="res://script/Skeleton Enemy.gd" type="Script" id=1]
[ext_resource path="res://art/Skeleton.png" type="Texture" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 5, 7 )
[sub_resource type="Animation" id=2]
resource_name = "Skeleton Jump"
length = 0.65
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Skeleton: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.1, 0.2, 0.3, 0.4, 0.5, 0.6 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 1, 2, 3, 4, 5, 6, 7 ]
}
[node name="Skeleton Enemy" type="KinematicBody2D"]
collision_layer = 4
collision_mask = 3
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
@ -26,3 +40,29 @@ collision_mask = 3
enabled = true
cast_to = Vector2( 80, 0 )
collision_mask = 3
[node name="RayCast2D3" type="RayCast2D" parent="."]
enabled = true
cast_to = Vector2( -80, -25 )
collision_mask = 3
[node name="RayCast2D4" type="RayCast2D" parent="."]
enabled = true
cast_to = Vector2( 80, -25 )
collision_mask = 3
[node name="ShootDelay" type="Timer" parent="."]
wait_time = 1.239
one_shot = true
[node name="Position2D" type="Position2D" parent="."]
[node name="Skeleton" type="Sprite" parent="."]
position = Vector2( 1, -1 )
texture = ExtResource( 3 )
hframes = 8
frame = 7
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "Skeleton Jump"
"anims/Skeleton Jump" = SubResource( 2 )

15
ai/SpinningBone.gd Normal file
View file

@ -0,0 +1,15 @@
extends Projectile
func launch_right():
velocity = (Vector2.RIGHT * speed)
func launch_left():
velocity = (Vector2.LEFT * speed)
func launch_upleft():
velocity = (Vector2(-1, -1).normalized() * speed)
func launch_upright():
velocity = (Vector2(1, -1).normalized() * speed)
func on_impact(collision):
if collision.collider.has_method("get_type"):
collision.collider.set_health(collision.collider.get_health() - 1)
queue_free()

46
ai/SpinningBone.tscn Normal file
View file

@ -0,0 +1,46 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://art/SpinningBone.png" type="Texture" id=1]
[ext_resource path="res://ai/SpinningBone.gd" type="Script" id=2]
[sub_resource type="Animation" id=1]
resource_name = "Bone Throw"
length = 0.5
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".: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.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ 0, 1 ]
}
[sub_resource type="CapsuleShape2D" id=2]
radius = 5.0
height = 0.0
[node name="KinematicBody2D" type="KinematicBody2D"]
collision_layer = 8
collision_mask = 3
script = ExtResource( 2 )
__meta__ = {
"_edit_group_": true
}
speed = 245
[node name="SpinningBone" type="Sprite" parent="."]
texture = ExtResource( 1 )
hframes = 2
frame = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="SpinningBone"]
autoplay = "Bone Throw"
"anims/Bone Throw" = SubResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 2 )

BIN
art/Skeleton.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

34
art/Skeleton.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Skeleton.png-3b80a3fffd84366a402cdde5a4883e3c.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://art/Skeleton.png"
dest_files=[ "res://.import/Skeleton.png-3b80a3fffd84366a402cdde5a4883e3c.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View file

@ -11,6 +11,10 @@
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( -7, 0, -7, -2, -6, -2, -6, -3, -5, -3, -5, -5, -6, -5, -6, -10, -7, -10, -7, -12, -6, -12, -6, -19, -4, -19, -4, -18, -3, -18, -3, -17, 1, -17, 1, -16, 3, -16, 3, -15, 4, -15, 4, -14, 5, -14, 5, -13, 6, -13, 6, -12, 7, -12, 7, -10, 6, -10, 6, -9, 5, -9, 5, -8, 6, -8, 6, -4, 5, -4, 5, 0, -7, 0 )
[sub_resource type="CapsuleShape2D" id=2]
radius = 6.0
height = 2.0
[sub_resource type="Animation" id=3]
resource_name = "Idle"
length = 0.8
@ -60,10 +64,6 @@ tracks/0/keys = {
"values": [ 4, 5, 6, 7 ]
}
[sub_resource type="CapsuleShape2D" id=6]
radius = 6.0
height = 4.0
[node name="Player" type="KinematicBody2D"]
collision_mask = 2
script = ExtResource( 1 )
@ -99,6 +99,11 @@ visible = false
position = Vector2( 0, 12 )
occluder = SubResource( 1 )
[node name="WorldCollision" type="CollisionShape2D" parent="."]
visible = false
position = Vector2( 0, -7 )
shape = SubResource( 2 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/Idle = SubResource( 3 )
anims/Jumping = SubResource( 4 )
@ -118,9 +123,5 @@ position = Vector2( 0, -7 )
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hitbox"]
visible = false
polygon = PoolVector2Array( -6, -12, -6, -5, -7, -5, -7, -3, -6, -3, -6, -0.52261, -6, 2, -5, 2, -5, 4, -6, 4, -6, 5, -7, 5, -7, 7, -3.9179, 7, 0.0151539, 7, 5, 7, 5, 5.0024, 5, 3, 6, 3, 6, 0.882053, 6, -1, 5, -1, 5, -2, 6, -2, 6, -3, 7, -3, 7, -5, 6, -5, 6, -6, 5, -6, 5, -7, 4, -7, 4, -8, 3, -8, 3, -9, 1, -9, 1, -10, -3, -10, -3, -11, -4, -11, -4, -12, -6, -12 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -8 )
shape = SubResource( 6 )
polygon = PoolVector2Array( -6, -12, -6, -5, -7, -5, -7, -3, -6, -3, -6, 2, -5, 2, -5, 4, -6, 4, -6, 5, -7, 5, -7, 7, 5, 7, 5, 3, 6, 3, 6, -1, 5, -1, 5, -2, 6, -2, 6, -3, 7, -3, 7, -5, 6, -5, 6, -6, 5, -6, 5, -7, 4, -7, 4, -8, 3, -8, 3, -9, 1, -9, 1, -10, -3, -10, -3, -11, -4, -11, -4, -12, -6, -12 )
[connection signal="grounded_updated" from="." to="Camera" method="_on_grounded_updated"]

View file

@ -9,46 +9,13 @@
[ext_resource path="res://art/Pedestal.png" type="Texture" id=7]
[ext_resource path="res://ai/Skeleton Enemy.tscn" type="PackedScene" id=8]
[sub_resource type="RectangleShape2D" id=8]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 169.977, 24.8286 )
[sub_resource type="DynamicFont" id=1]
[sub_resource type="DynamicFont" id=3]
font_data = ExtResource( 3 )
[sub_resource type="Animation" id=2]
resource_name = "Type Writer"
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0.2, 2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=3]
resource_name = "Type Writer"
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0.2, 2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=4]
resource_name = "Type Writer"
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
@ -64,7 +31,7 @@ tracks/0/keys = {
}
[sub_resource type="Animation" id=5]
resource_name = "Ok"
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
tracks/0/interp = 1
@ -72,10 +39,10 @@ tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"times": PoolRealArray( 0.2, 2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 0.0 ]
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=6]
@ -94,7 +61,35 @@ tracks/0/keys = {
}
[sub_resource type="Animation" id=7]
resource_name = "Type Writer"
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
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": 0,
"values": [ 0.0, 0.0 ]
}
[sub_resource type="Animation" id=8]
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0.2, 2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=9]
length = 2.0
tracks/0/type = "value"
tracks/0/path = NodePath("sample_text:percent_visible")
@ -128,17 +123,18 @@ __meta__ = {
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 8 )
shape = SubResource( 1 )
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
visible = false
modulate = Color( 0.635294, 0.635294, 0.635294, 1 )
motion_mirroring = Vector2( 490, 500 )
[node name="Sprite" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
modulate = Color( 0.419608, 0.411765, 0.411765, 1 )
position = Vector2( 519.223, 465.442 )
position = Vector2( 519.723, 465.442 )
scale = Vector2( 0.872628, 0.872628 )
texture = ExtResource( 6 )
centered = false
@ -148,6 +144,9 @@ offset = Vector2( -615.364, -675.27 )
position = Vector2( 954.711, 145.551 )
scale = Vector2( 1, 1.1044 )
texture = ExtResource( 7 )
__meta__ = {
"_edit_group_": true
}
[node name="Skeleton Enemy" parent="." instance=ExtResource( 8 )]
position = Vector2( 371.515, 139.784 )
@ -165,7 +164,7 @@ margin_left = 61.7179
margin_top = 35.9192
margin_right = 239.718
margin_bottom = 108.919
custom_fonts/font = SubResource( 1 )
custom_fonts/font = SubResource( 3 )
text = "AH! I see you finally came after like, forever!"
autowrap = true
__meta__ = {
@ -174,7 +173,7 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="text/Text"]
autoplay = "Type Writer"
"anims/Type Writer" = SubResource( 2 )
"anims/Type Writer" = SubResource( 4 )
[node name="Text4" type="Node" parent="text"]
@ -183,7 +182,7 @@ margin_left = 577.321
margin_top = 30.5355
margin_right = 742.321
margin_bottom = 103.536
custom_fonts/font = SubResource( 1 )
custom_fonts/font = SubResource( 3 )
text = "The wand is an extremely hard weapon to master"
autowrap = true
__meta__ = {
@ -192,7 +191,7 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="text/Text4"]
autoplay = "Type Writer"
"anims/Type Writer" = SubResource( 3 )
"anims/Type Writer" = SubResource( 5 )
[node name="Text5" type="Node" parent="text"]
@ -201,7 +200,7 @@ margin_left = 747.863
margin_top = 36.84
margin_right = 881.863
margin_bottom = 147.84
custom_fonts/font = SubResource( 1 )
custom_fonts/font = SubResource( 3 )
text = "Let me show you how to use it!"
autowrap = true
__meta__ = {
@ -210,7 +209,7 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="text/Text5"]
autoplay = "Type Writer"
"anims/Type Writer" = SubResource( 4 )
"anims/Type Writer" = SubResource( 6 )
[node name="Text2" type="Node" parent="text"]
script = ExtResource( 5 )
@ -220,7 +219,7 @@ margin_left = 327.0
margin_top = 23.0
margin_right = 518.0
margin_bottom = 96.0
custom_fonts/font = SubResource( 1 )
custom_fonts/font = SubResource( 3 )
text = "W and Space
Jump
@ -233,8 +232,8 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="text/Text2"]
autoplay = "Ok"
anims/Ok = SubResource( 5 )
"anims/Type Writer" = SubResource( 6 )
anims/Ok = SubResource( 7 )
"anims/Type Writer" = SubResource( 8 )
[node name="Text3" type="Node" parent="text"]
@ -243,7 +242,7 @@ margin_left = 67.5595
margin_top = 171.0
margin_right = 870.56
margin_bottom = 244.0
custom_fonts/font = SubResource( 1 )
custom_fonts/font = SubResource( 3 )
text = "<A and S> Walk also arrow keys work the same!
"
autowrap = true
@ -253,5 +252,5 @@ __meta__ = {
[node name="AnimationPlayer2" type="AnimationPlayer" parent="text/Text3"]
autoplay = "Type Writer"
"anims/Type Writer" = SubResource( 7 )
"anims/Type Writer" = SubResource( 9 )
[connection signal="body_entered" from="Area2D" to="text/Text2" method="_on_body_entered"]

View file

@ -10,7 +10,7 @@ texture = ExtResource( 1 )
script = ExtResource( 2 )
[node name="ProjectileSpawn" type="Position2D" parent="."]
position = Vector2( -6.11959e-007, -7 )
position = Vector2( -6.11959e-07, -7 )
[node name="ShootDelay" type="Timer" parent="."]
wait_time = 0.3

View file

@ -121,6 +121,11 @@ shoot={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}
inventory={
"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":69,"unicode":0,"echo":false,"script":null)
]
}
[layer_names]

View file

@ -8,6 +8,7 @@ func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision != null:
on_impact(collision)
print(collision)
func launch():
velocity = (Vector2(speed, 0)).rotated(rotation)

View file

@ -1,9 +1,15 @@
extends KinematicBody2D
var speed = 75
var gravity = 500
var Spinning_Bone = preload("res://ai/SpinningBone.tscn")
var speed = 60
var gravity =500
var health = 5
const UP = Vector2(0, -1)
onready var ShootDelay : Timer = $ShootDelay
onready var ProjectileSpawn: Node2D = $Position2D
var velocity = Vector2()
func apply_gravity(delta, modifier = 1):
@ -11,10 +17,53 @@ func apply_gravity(delta, modifier = 1):
func _physics_process(_delta):
if Globals.player != null:
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
if ShootDelay.is_stopped():
var temp = Spinning_Bone.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.launch_left()
ShootDelay.start()
elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
if ShootDelay.is_stopped():
var temp = Spinning_Bone.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.launch_right()
ShootDelay.start()
elif $RayCast2D3.get_collider() != null && $RayCast2D3.get_collider().has_method("get_type") and $RayCast2D3.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
if ShootDelay.is_stopped():
var temp = Spinning_Bone.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.launch_upleft()
ShootDelay.start()
elif $RayCast2D4.get_collider() != null && $RayCast2D4.get_collider().has_method("get_type") and $RayCast2D4.get_collider().get_type() == "player":
velocity = Vector2(0, 0)
if ShootDelay.is_stopped():
var temp = Spinning_Bone.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.launch_upright()
ShootDelay.start()
else:
velocity.x = position.direction_to(Globals.player).normalized().x
apply_gravity(_delta)
velocity = move_and_slide(velocity * speed)
if is_on_wall():
velocity.y = -50
velocity.x *= speed
velocity = move_and_slide(velocity, UP)
if velocity.x > 0:
$Skeleton.flip_h = false
elif velocity.x < 0:
$Skeleton.flip_h = true
if is_on_wall() and is_on_floor():
velocity.y = -150
func on_impact(collision):
if collision.collider.has_method("get_type"):
collision.collider.set_health(collision.collider.get_health() - 1)
queue_free()
if health == 0:
queue_free()

View file

@ -59,6 +59,8 @@ func _ready():
func _physics_process(delta):
Globals.player = position
emit_signal("grounded_updated", is_on_floor())
if get_health() <= 0:
get_tree().change_scene("res://levels/World.tscn")
func handle_move_input():
input_direction = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
@ -105,11 +107,5 @@ func get_movement_weight():
return 0.07
func _on_Area2D_body_entered(body):
pass