spider implementation! death_blood_offset variable added to enemy.gd to facilitate

This commit is contained in:
Haze Weathers 2023-01-21 01:36:57 -05:00
parent b1beffd97b
commit bc4510a103
6 changed files with 128 additions and 3 deletions

View file

@ -20,6 +20,7 @@ export var score_for_killing = 0
export var blood = true
var death_sound = Game.a_die
var death_blood_offset = Vector2.ZERO
func _on_Hitbox_area_entered(area):
#Kill player
@ -29,7 +30,7 @@ func _on_Hitbox_area_entered(area):
func die():
if blood:
var death_particles = DeathParticles.instance()
death_particles.global_position = global_position
death_particles.global_position = global_position + death_blood_offset
death_particles.emitting = true
get_parent().add_child(death_particles)

34
objects/enemy/spider.gd Normal file
View file

@ -0,0 +1,34 @@
extends "res://objects/enemy/enemy.gd"
export var speed = 0.0
export var direction = 1.0
onready var line = $Line2D
onready var hitbox = $Hitbox
var floor_y = 0.0
func _ready():
var raycast = $RayCast2D
# detect ceiling
raycast.force_raycast_update()
var old_y = hitbox.global_position.y
global_position.y = raycast.get_collision_point().y
hitbox.global_position.y = old_y
line.points[1].y = hitbox.position.y
# detect floor
raycast.cast_to = Vector2(0.0, 192.0)
raycast.force_raycast_update()
floor_y = to_local(raycast.get_collision_point()).y - 3
raycast.queue_free()
func _physics_process(delta):
hitbox.position.y += direction * speed * delta
if hitbox.position.y < 5.0:
hitbox.position.y = 5.0
direction = 1.0
if hitbox.position.y > floor_y:
hitbox.position.y = floor_y
direction = -1.0
line.points[1].y = hitbox.position.y
death_blood_offset = hitbox.position

51
objects/enemy/spider.tscn Normal file
View file

@ -0,0 +1,51 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://graphics/enemy/spider.png" type="Texture" id=1]
[ext_resource path="res://objects/enemy/spider.gd" type="Script" id=2]
[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 15, 14 )
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 15, 0, 15, 14 )
[sub_resource type="SpriteFrames" id=3]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ) ],
"loop": true,
"name": "default",
"speed": 7.0
} ]
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 4.5, 4 )
[node name="Spider" type="Node2D" groups=["enemy"]]
script = ExtResource( 2 )
speed = 30.0
[node name="Line2D" type="Line2D" parent="."]
position = Vector2( 4.5, 0 )
points = PoolVector2Array( 0, 0, 0, 0 )
width = 1.0
default_color = Color( 1, 1, 1, 1 )
[node name="RayCast2D" type="RayCast2D" parent="."]
position = Vector2( 4.5, 4 )
cast_to = Vector2( 0, -192 )
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
position = Vector2( 5, 5 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="Hitbox"]
frames = SubResource( 3 )
frame = 1
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2( -0.5, -1 )
shape = SubResource( 4 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]