forked from team-sg/hero-mark-2
spider implementation! death_blood_offset variable added to enemy.gd to facilitate
This commit is contained in:
parent
b1beffd97b
commit
bc4510a103
6 changed files with 128 additions and 3 deletions
BIN
graphics/enemy/spider.png
Normal file
BIN
graphics/enemy/spider.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 308 B |
35
graphics/enemy/spider.png.import
Normal file
35
graphics/enemy/spider.png.import
Normal file
|
@ -0,0 +1,35 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/spider.png-f700df811f96542b517031163b837e41.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://graphics/enemy/spider.png"
|
||||
dest_files=[ "res://.import/spider.png-f700df811f96542b517031163b837e41.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
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=9 format=2]
|
||||
[gd_scene load_steps=10 format=2]
|
||||
|
||||
[ext_resource path="res://objects/Camera2D.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://maps/map.gd" type="Script" id=2]
|
||||
|
@ -8,6 +8,7 @@
|
|||
[ext_resource path="res://objects/player/player.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://objects/hud/hud.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://objects/collectibles/arrow.tscn" type="PackedScene" id=8]
|
||||
[ext_resource path="res://objects/enemy/spider.tscn" type="PackedScene" id=9]
|
||||
|
||||
[node name="Map" type="Node2D" groups=["map"]]
|
||||
script = ExtResource( 2 )
|
||||
|
@ -23,7 +24,7 @@ texture = ExtResource( 3 )
|
|||
tile_set = ExtResource( 4 )
|
||||
cell_size = Vector2( 8, 8 )
|
||||
format = 1
|
||||
tile_data = PoolIntArray( 1441792, 0, 0, 1441793, 0, 0, 1441794, 0, 0, 1441795, 0, 0, 1441796, 0, 0, 1441797, 0, 0, 1441798, 0, 0, 1441799, 0, 0, 1441800, 0, 0, 1441801, 0, 0, 1441802, 0, 0, 1441803, 0, 0, 1441804, 0, 0, 1441805, 0, 0, 1441806, 0, 0, 1441807, 0, 0, 1441808, 0, 0, 1441809, 0, 0, 1441810, 0, 0, 1441811, 0, 0, 1441812, 0, 0, 1441813, 0, 0, 1441814, 0, 0, 1441815, 0, 0, 1441816, 0, 0, 1441817, 0, 0, 1441818, 0, 0, 1441819, 0, 0, 1441820, 0, 0, 1441821, 0, 0, 1441822, 0, 0, 1441823, 0, 0, 1507328, 0, 65537, 1507329, 0, 65537, 1507330, 0, 65537, 1507331, 0, 65537, 1507332, 0, 65537, 1507333, 0, 65537, 1507334, 0, 65537, 1507335, 0, 65537, 1507336, 0, 65537, 1507337, 0, 65537, 1507338, 0, 65537, 1507339, 0, 65537, 1507340, 0, 65537, 1507341, 0, 65537, 1507342, 0, 65537, 1507343, 0, 65537, 1507344, 0, 65537, 1507345, 0, 65537, 1507346, 0, 65537, 1507347, 0, 65537, 1507348, 0, 65537, 1507349, 0, 65537, 1507350, 0, 65537, 1507351, 0, 65537, 1507352, 0, 65537, 1507353, 0, 65537, 1507354, 0, 65537, 1507355, 0, 65537, 1507356, 0, 65537, 1507357, 0, 65537, 1507358, 0, 65537, 1507359, 0, 65537 )
|
||||
tile_data = PoolIntArray( 983050, 0, 65536, 983051, 0, 65537, 983052, 0, 65537, 983053, 0, 65537, 983054, 0, 65537, 983055, 0, 65537, 983056, 0, 65538, 1441792, 0, 0, 1441793, 0, 0, 1441794, 0, 0, 1441795, 0, 0, 1441796, 0, 0, 1441797, 0, 0, 1441798, 0, 0, 1441799, 0, 0, 1441800, 0, 0, 1441801, 0, 0, 1441802, 0, 0, 1441803, 0, 0, 1441804, 0, 0, 1441805, 0, 0, 1441806, 0, 0, 1441807, 0, 0, 1441808, 0, 0, 1441809, 0, 0, 1441810, 0, 0, 1441811, 0, 0, 1441812, 0, 0, 1441813, 0, 0, 1441814, 0, 0, 1441815, 0, 0, 1441816, 0, 0, 1441817, 0, 0, 1441818, 0, 0, 1441819, 0, 0, 1441820, 0, 0, 1441821, 0, 0, 1441822, 0, 0, 1441823, 0, 0, 1507328, 0, 65537, 1507329, 0, 65537, 1507330, 0, 65537, 1507331, 0, 65537, 1507332, 0, 65537, 1507333, 0, 65537, 1507334, 0, 65537, 1507335, 0, 65537, 1507336, 0, 65537, 1507337, 0, 65537, 1507338, 0, 65537, 1507339, 0, 65537, 1507340, 0, 65537, 1507341, 0, 65537, 1507342, 0, 65537, 1507343, 0, 65537, 1507344, 0, 65537, 1507345, 0, 65537, 1507346, 0, 65537, 1507347, 0, 65537, 1507348, 0, 65537, 1507349, 0, 65537, 1507350, 0, 65537, 1507351, 0, 65537, 1507352, 0, 65537, 1507353, 0, 65537, 1507354, 0, 65537, 1507355, 0, 65537, 1507356, 0, 65537, 1507357, 0, 65537, 1507358, 0, 65537, 1507359, 0, 65537 )
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 6 )]
|
||||
position = Vector2( 24, 166 )
|
||||
|
@ -35,3 +36,6 @@ position = Vector2( 70, 166 )
|
|||
|
||||
[node name="Arrow" parent="." instance=ExtResource( 8 )]
|
||||
position = Vector2( 43, 167 )
|
||||
|
||||
[node name="Spider" parent="." instance=ExtResource( 9 )]
|
||||
position = Vector2( 120, 144 )
|
||||
|
|
|
@ -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
34
objects/enemy/spider.gd
Normal 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
51
objects/enemy/spider.tscn
Normal 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"]
|
Loading…
Add table
Add a link
Reference in a new issue