106 lines
3.4 KiB
GDScript3
106 lines
3.4 KiB
GDScript3
|
######################
|
||
|
### Jessist Script ###
|
||
|
######################
|
||
|
# This script is part of Jessist
|
||
|
# Jessist is licensed under GNU GPLv3
|
||
|
#
|
||
|
# This script manages the enemy "Elie"
|
||
|
# It handles animations, physics and movement
|
||
|
extends KinematicBody2D
|
||
|
|
||
|
class_name EnemyElie
|
||
|
|
||
|
# Enemy information
|
||
|
export (int) var enemyJump = 600
|
||
|
export (int) var enemySpeed = 175/2
|
||
|
export (int) var gravitySpeed = 600
|
||
|
var gravityVector = 0
|
||
|
var moveVector = Vector2(0,0)
|
||
|
export (int) var isHitTimer = 0
|
||
|
export (String, "STANDING","WALKING","HIT") var enemyAction = "STANDING"
|
||
|
export (String, "LEFT", "RIGHT") var enemyFacing = "LEFT"
|
||
|
export (bool) var activateMovement = true
|
||
|
|
||
|
func _ready():
|
||
|
gameController.logCall("EnemySpricky","_ready",null)
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
gameController.logCall("EnemySpricky","_physics_process",delta)
|
||
|
if not gameController.gamePaused:
|
||
|
if activateMovement:
|
||
|
moveVector.x = 0
|
||
|
if is_on_ceiling() or is_on_floor():
|
||
|
gameController.logVelocity("EnemyElie","_physics_process","EnemyElie is on ceiling or floor, resetting y movement and gravity")
|
||
|
moveVector.y = 0
|
||
|
gravityVector = 0
|
||
|
animManager()
|
||
|
if activateMovement:
|
||
|
gravityVector += gravitySpeed * delta
|
||
|
if gravityVector > 1600:
|
||
|
gravityVector = 1600
|
||
|
gameController.logVelocity("EnemyElie","_physics_process","gravityVector above 1600, throttling")
|
||
|
moveVector.y += gravityVector
|
||
|
if not isHitTimer == 0:
|
||
|
enemyAction = "HIT"
|
||
|
isHitTimer -= 1
|
||
|
if is_on_wall():
|
||
|
if enemyFacing == "LEFT":
|
||
|
enemyFacing = "RIGHT"
|
||
|
elif enemyFacing == "RIGHT":
|
||
|
enemyFacing = "LEFT"
|
||
|
if isHitTimer == 0:
|
||
|
if is_on_floor():
|
||
|
enemyAction = "WALKING"
|
||
|
if enemyFacing == "LEFT":
|
||
|
moveVector.x = -enemySpeed
|
||
|
elif enemyFacing == "RIGHT":
|
||
|
moveVector.x = enemySpeed
|
||
|
else:
|
||
|
enemyAction = "STANDING"
|
||
|
gameController.logVelocity("EnemyElie","_physics_process",moveVector)
|
||
|
move_and_slide(moveVector,Vector2(0,-1))
|
||
|
#if position.x < 0+32.5:
|
||
|
# position.x = 0+32.5
|
||
|
# enemyFacing = "RIGHT"
|
||
|
if position.x < -20:
|
||
|
gameController.logVelocity("EnemyElie","_physics_process","Out of focus, removing")
|
||
|
queue_free()
|
||
|
if position.y < 0:
|
||
|
position.y = 0
|
||
|
if position.y > 1080:
|
||
|
position.y = 1080
|
||
|
else:
|
||
|
$EnemyElieSprite.playing = false
|
||
|
|
||
|
func animManager():
|
||
|
gameController.logCall("EnemySpricky","animManager",null)
|
||
|
if enemyAction == "WALKING":
|
||
|
$EnemyElieSprite.animation = "Walking"
|
||
|
$EnemyElieSprite.playing = true
|
||
|
elif enemyAction == "HIT":
|
||
|
$EnemyElieSprite.animation = "Hit"
|
||
|
$EnemyElieSprite.playing = true
|
||
|
elif enemyAction == "STANDING":
|
||
|
$EnemyElieSprite.animation = "Walking"
|
||
|
$EnemyElieSprite.frame = 0
|
||
|
$EnemyElieSprite.playing = false
|
||
|
if enemyFacing == "LEFT":
|
||
|
$EnemyElieSprite.flip_h = false
|
||
|
var shader = ShaderMaterial.new()
|
||
|
shader.shader = load("res://Shaders/offsetshadow.shader")
|
||
|
shader.set_shader_param("modulate",Color8(0,0,0,102))
|
||
|
shader.set_shader_param("offset",Vector2(-1,1))
|
||
|
$EnemyElieSprite.material = shader
|
||
|
elif enemyFacing == "RIGHT":
|
||
|
$EnemyElieSprite.flip_h = true
|
||
|
var shader = ShaderMaterial.new()
|
||
|
shader.shader = load("res://Shaders/offsetshadow.shader")
|
||
|
shader.set_shader_param("modulate",Color8(0,0,0,102))
|
||
|
shader.set_shader_param("offset",Vector2(1,1))
|
||
|
$EnemyElieSprite.material = shader
|
||
|
|
||
|
func playerHitZoneEntered(body):
|
||
|
gameController.logCall("EnemySpricky","playerHitZoneEntered",body)
|
||
|
if body.name == "Player":
|
||
|
body.event("death")
|