158 lines
3.9 KiB
Plaintext
158 lines
3.9 KiB
Plaintext
|
[gd_scene load_steps=11 format=2]
|
||
|
|
||
|
[ext_resource path="res://Scripts/BaddieManager.gd" type="Script" id=1]
|
||
|
[ext_resource path="res://Art/Enemies/basic_enemy3.png" type="Texture" id=2]
|
||
|
[ext_resource path="res://Art/Enemies/basic_enemy1.png" type="Texture" id=3]
|
||
|
[ext_resource path="res://Art/Enemies/basic_enemy2.png" type="Texture" id=4]
|
||
|
[ext_resource path="res://Art/Enemies/basic_enemy4.png" type="Texture" id=5]
|
||
|
[ext_resource path="res://Art/light.png" type="Texture" id=6]
|
||
|
|
||
|
[sub_resource type="GDScript" id=1]
|
||
|
script/source = "extends KinematicBody2D
|
||
|
|
||
|
const UP = Vector2(0, -1)
|
||
|
const BASE_GRAVITY = 20
|
||
|
|
||
|
export var active_distance = 32
|
||
|
export var angry_distance = 100
|
||
|
|
||
|
export var speed = 25
|
||
|
|
||
|
export var attack_speed = 1
|
||
|
|
||
|
var angry = false
|
||
|
|
||
|
var knockback = 0
|
||
|
var player
|
||
|
|
||
|
const UPDATE_ANGRY_TIME = 0.25
|
||
|
|
||
|
var motion = Vector2(0, 0)
|
||
|
var TIMER
|
||
|
|
||
|
func _ready():
|
||
|
$AnimatedSprite.play(\"default\")
|
||
|
$Area2D.connect(\"body_entered\", self, \"collision_method\")
|
||
|
var alarmRoot = get_parent().get_parent()
|
||
|
if alarmRoot.has_node(\"BaddieAlarm\"):
|
||
|
for node in alarmRoot.get_children():
|
||
|
if node.name == \"BaddieAlarm\":
|
||
|
node.connect(\"timeout\", self, \"update_angry\")
|
||
|
TIMER = node
|
||
|
break
|
||
|
else:
|
||
|
var node = Timer.new()
|
||
|
node.name = \"BaddieAlarm\"
|
||
|
node.connect(\"timeout\", self, \"update_angry\")
|
||
|
alarmRoot.add_child(node)
|
||
|
node.start(UPDATE_ANGRY_TIME)
|
||
|
TIMER = node
|
||
|
|
||
|
func collision_method(body):
|
||
|
if body.has_method(\"deal_damage\"):
|
||
|
body.deal_damage()
|
||
|
knockback += 100
|
||
|
|
||
|
func take_damage(dmg):
|
||
|
knockback += 75 * dmg
|
||
|
get_parent().take_damage(dmg)
|
||
|
|
||
|
func update_angry():
|
||
|
if angry && global_position.distance_to(player.global_position) > angry_distance:
|
||
|
angry = false
|
||
|
elif global_position.distance_to(player.global_position) < active_distance:
|
||
|
angry = true
|
||
|
if(TIMER.wait_time <= 0):
|
||
|
TIMER.start(UPDATE_ANGRY_TIME)
|
||
|
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
#Implement the force of gravity!
|
||
|
motion.y += BASE_GRAVITY
|
||
|
|
||
|
if is_on_floor():
|
||
|
motion.y = 0
|
||
|
|
||
|
if knockback > 0:
|
||
|
motion.y -= knockback/2
|
||
|
if(player.global_position.x > global_position.x):
|
||
|
motion.x -= knockback
|
||
|
else:
|
||
|
motion.x += knockback
|
||
|
knockback -= 30
|
||
|
else:
|
||
|
if !player:
|
||
|
player = get_node(\"/root/World/Player\")
|
||
|
else:
|
||
|
|
||
|
|
||
|
if angry:
|
||
|
angry = true
|
||
|
if($AnimatedSprite.animation != \"run\"):
|
||
|
$AnimatedSprite.play(\"run\")
|
||
|
if player.global_position.distance_to(global_position) > 24:
|
||
|
if(player.global_position.x > global_position.x):
|
||
|
motion.x += speed
|
||
|
$AnimatedSprite.flip_h = false
|
||
|
$Area2D.rotation = 0
|
||
|
else:
|
||
|
motion.x -= speed
|
||
|
$AnimatedSprite.flip_h = true
|
||
|
$Area2D.rotation = PI
|
||
|
else:
|
||
|
knockback += 60
|
||
|
else:
|
||
|
$AnimatedSprite.play(\"default\")
|
||
|
|
||
|
motion = move_and_slide(motion, UP)"
|
||
|
|
||
|
[sub_resource type="SpriteFrames" id=2]
|
||
|
animations = [ {
|
||
|
"frames": [ ExtResource( 2 ) ],
|
||
|
"loop": true,
|
||
|
"name": "default",
|
||
|
"speed": 5.0
|
||
|
}, {
|
||
|
"frames": [ ExtResource( 3 ), ExtResource( 4 ), ExtResource( 2 ), ExtResource( 5 ) ],
|
||
|
"loop": true,
|
||
|
"name": "run",
|
||
|
"speed": 5.0
|
||
|
} ]
|
||
|
|
||
|
[sub_resource type="CapsuleShape2D" id=3]
|
||
|
|
||
|
[sub_resource type="RectangleShape2D" id=4]
|
||
|
|
||
|
[node name="Basic Enemy" type="Node2D"]
|
||
|
modulate = Color( 1, 1, 0, 1 )
|
||
|
script = ExtResource( 1 )
|
||
|
__meta__ = {
|
||
|
"_edit_group_": true
|
||
|
}
|
||
|
HP = 3
|
||
|
|
||
|
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
|
||
|
script = SubResource( 1 )
|
||
|
active_distance = 128
|
||
|
|
||
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="KinematicBody2D"]
|
||
|
frames = SubResource( 2 )
|
||
|
playing = true
|
||
|
|
||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicBody2D"]
|
||
|
scale = Vector2( 0.35, 0.45 )
|
||
|
shape = SubResource( 3 )
|
||
|
|
||
|
[node name="Area2D" type="Area2D" parent="KinematicBody2D"]
|
||
|
|
||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicBody2D/Area2D"]
|
||
|
position = Vector2( 5, -2 )
|
||
|
scale = Vector2( 0.5, 0.25 )
|
||
|
shape = SubResource( 4 )
|
||
|
one_way_collision_margin = 30.0
|
||
|
|
||
|
[node name="Light2D" type="Light2D" parent="KinematicBody2D"]
|
||
|
texture = ExtResource( 6 )
|
||
|
texture_scale = 1.5
|
||
|
energy = 0.25
|