Boss encounter
This commit is contained in:
parent
bdd9f2ea2c
commit
2b90d087c4
6 changed files with 111 additions and 4 deletions
37
metroidvania/Scenes/Enemies/BossEnemy.gd
Normal file
37
metroidvania/Scenes/Enemies/BossEnemy.gd
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue