SUPERSLIMES
This commit is contained in:
parent
3b835b78f1
commit
8f2b42f968
3 changed files with 149 additions and 4 deletions
85
objects/enemy/super_slime.gd
Normal file
85
objects/enemy/super_slime.gd
Normal file
|
@ -0,0 +1,85 @@
|
|||
tool
|
||||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
|
||||
export var left_boundary: float = 0.0
|
||||
export var right_boundary: float = 0.0
|
||||
export var direction: float = 1.0
|
||||
export var speed: float = 50.0
|
||||
export var jump_distance: float = 0.0
|
||||
export var jump_speed: float = 50.0
|
||||
|
||||
var _jumping: bool = false
|
||||
var _jump_direction: float = -1.0
|
||||
|
||||
onready var hitbox: Area2D = $Hitbox
|
||||
onready var sprite: AnimatedSprite = $Hitbox/Sprite
|
||||
onready var detect_player_cast: RayCast2D = $"%DetectPlayerCast"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if Engine.editor_hint:
|
||||
return
|
||||
left_boundary *= 8.0
|
||||
right_boundary *= 8.0
|
||||
jump_distance *= 8.0
|
||||
detect_player_cast.cast_to = Vector2(0.0, -jump_distance)
|
||||
speed *= Game.enemy_speed_factor
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if Engine.editor_hint:
|
||||
return
|
||||
# check for player and jump
|
||||
if detect_player_cast.is_colliding():
|
||||
_jumping = true
|
||||
# move if not jumping
|
||||
if _jumping:
|
||||
hitbox.position.y += _jump_direction * jump_speed * delta
|
||||
if hitbox.position.y >= 8.0:
|
||||
hitbox.position.y = 0.0
|
||||
_jump_direction = -1.0
|
||||
hitbox.scale.y = 1.0
|
||||
_jumping = false
|
||||
elif hitbox.position.y <= -jump_distance - 8.0:
|
||||
hitbox.position.y = -jump_distance
|
||||
_jump_direction = 1.0
|
||||
hitbox.scale.y = -1.0
|
||||
_jumping = false
|
||||
else:
|
||||
hitbox.position.x += direction * speed * delta
|
||||
if hitbox.position.x >= right_boundary:
|
||||
hitbox.position.x = right_boundary
|
||||
direction = -1.0
|
||||
sprite.flip_h = true
|
||||
elif hitbox.position.x <= -left_boundary:
|
||||
hitbox.position.x = -left_boundary
|
||||
direction = 1.0
|
||||
sprite.flip_h = false
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Engine.editor_hint and Engine.get_frames_drawn() % 10 == 0:
|
||||
update()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if Engine.editor_hint:
|
||||
# bottom travel zone
|
||||
draw_line(
|
||||
Vector2(-left_boundary * 8.0, 4.0),
|
||||
Vector2(right_boundary * 8.0 + 8.0, 4.0),
|
||||
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
)
|
||||
# top travel zone
|
||||
draw_line(
|
||||
Vector2(-left_boundary * 8.0, -jump_distance * 8.0 - 4.0),
|
||||
Vector2(right_boundary * 8.0 + 8.0, -jump_distance * 8.0 - 4.0),
|
||||
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
)
|
||||
# jump line
|
||||
draw_line(
|
||||
Vector2(4.0, 4.0),
|
||||
Vector2(4.0, -jump_distance * 8.0 - 4.0),
|
||||
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
)
|
57
objects/enemy/super_slime.tscn
Normal file
57
objects/enemy/super_slime.tscn
Normal file
|
@ -0,0 +1,57 @@
|
|||
[gd_scene load_steps=10 format=2]
|
||||
|
||||
[ext_resource path="res://objects/enemy/super_slime.gd" type="Script" id=1]
|
||||
[ext_resource path="res://shaders/recolor_border.shader" type="Shader" id=2]
|
||||
[ext_resource path="res://graphics/enemy/pal_slime_purple.png" type="Texture" id=3]
|
||||
[ext_resource path="res://graphics/enemy/slime.png" type="Texture" id=4]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=4]
|
||||
shader = ExtResource( 2 )
|
||||
shader_param/border_color = Color( 0, 0, 0, 1 )
|
||||
shader_param/border_corners = false
|
||||
shader_param/palette = ExtResource( 3 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 4 )
|
||||
region = Rect2( 0, 0, 13, 13 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 4 )
|
||||
region = Rect2( 13, 0, 13, 13 )
|
||||
|
||||
[sub_resource type="SpriteFrames" id=5]
|
||||
animations = [ {
|
||||
"frames": [ SubResource( 2 ), SubResource( 3 ) ],
|
||||
"loop": true,
|
||||
"name": "default",
|
||||
"speed": 7.0
|
||||
} ]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=6]
|
||||
extents = Vector2( 4, 4 )
|
||||
|
||||
[node name="SuperSlime" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
blood = false
|
||||
jump_speed = 100.0
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="."]
|
||||
|
||||
[node name="Sprite" type="AnimatedSprite" parent="Hitbox"]
|
||||
material = SubResource( 4 )
|
||||
position = Vector2( 4, 3 )
|
||||
frames = SubResource( 5 )
|
||||
playing = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
position = Vector2( 4, 4 )
|
||||
shape = SubResource( 6 )
|
||||
|
||||
[node name="DetectPlayerCast" type="RayCast2D" parent="Hitbox"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2( 4, 0 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, -16 )
|
||||
collision_mask = 128
|
||||
|
||||
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
|
Loading…
Add table
Add a link
Reference in a new issue