Boss encounter

This commit is contained in:
Felipe M 2021-05-22 17:06:32 +02:00
parent bdd9f2ea2c
commit 2b90d087c4
Signed by: fmartingr
GPG key ID: 716BC147715E716F
6 changed files with 111 additions and 4 deletions

View file

@ -0,0 +1,37 @@
extends "res://Scenes/Enemies/Enemy.gd"
var MainInstances = ResourceLoader.MainInstances
const Bullet = preload("res://Scenes/Objects/EnemyBullet.tscn")
export (int) var ACCELERATION = 70
onready var rightWallCheck = $RightWallCheck
onready var leftWallCheck = $LeftWallCheck
func _process(delta):
chase_player(delta)
func chase_player(delta):
var player = MainInstances.Player
if player != null: # We not dead
var direction_to_move = sign(player.global_position.x - global_position.x)
motion.x += ACCELERATION * delta * direction_to_move
motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
global_position.x += motion.x * delta
rotation_degrees = lerp(rotation_degrees, (motion.x / MAX_SPEED) * 10, 0.3)
if rightWallCheck.is_colliding() and motion.x > 0:
motion.x *= -0.5
if rightWallCheck.is_colliding() and motion.x <= 0:
motion.x *= -0.5
func fire_bullet() -> void:
var bullet = Utils.instance_scene_on_main(Bullet, global_position)
var velocity = Vector2.DOWN * 50
velocity = velocity.rotated(deg2rad(rand_range(-30, 30)))
bullet.velocity = velocity
func _on_Timer_timeout():
fire_bullet()

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://Scenes/Enemies/Enemy.tscn" type="PackedScene" id=1]
[ext_resource path="res://Assets/Enemies/BossEnemyHead.png" type="Texture" id=2]
@ -8,6 +8,7 @@
[ext_resource path="res://Assets/Enemies/BossEnemyLeg1.png" type="Texture" id=6]
[ext_resource path="res://Assets/Enemies/BossEnemyLeg2.png" type="Texture" id=7]
[ext_resource path="res://Assets/Enemies/BossEnemyLeg3.png" type="Texture" id=8]
[ext_resource path="res://Scenes/Enemies/BossEnemy.gd" type="Script" id=9]
[sub_resource type="Animation" id=1]
resource_name = "Base"
@ -816,8 +817,11 @@ radius = 18.0
length = 16.0
[node name="BossEnemy" instance=ExtResource( 1 )]
script = ExtResource( 9 )
MAX_SPEED = 50
[node name="OnionLayer" type="Sprite" parent="." index="0"]
visible = false
modulate = Color( 1, 1, 1, 0.113725 )
position = Vector2( 0, -11 )
texture = ExtResource( 5 )
@ -1005,5 +1009,19 @@ shape = SubResource( 4 )
[node name="EnemyStats" parent="." index="6"]
max_health = 100
[node name="RightWallCheck" type="RayCast2D" parent="." index="7"]
cast_to = Vector2( 0, 16 )
collision_mask = 2
[node name="LeftWallCheck" type="RayCast2D" parent="." index="8"]
cast_to = Vector2( 0, -16 )
collision_mask = 2
[node name="Timer" type="Timer" parent="." index="9"]
wait_time = 0.3
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
[editable path="Hurtbox"]
[editable path="Hitbox"]

View file

@ -6,6 +6,8 @@ export (int) var MAX_SPEED = 15
onready var stats = $EnemyStats
signal died
var motion = Vector2.ZERO
func _on_Hurtbox_hit(damage):