This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/Scripts/EnemySpricky.gd
2022-06-18 13:05:48 +02:00

131 lines
4.1 KiB
GDScript

######################
### Jessist Script ###
######################
# This script is part of Jessist
# Jessist is licensed under GNU GPLv3
#
# This script manages the enemy "Spricky"
# It handles animations, physics and movement
extends KinematicBody2D
class_name EnemySpricky
# 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","DEATH") var enemyAction = "STANDING"
export (String, "LEFT", "RIGHT") var enemyFacing = "LEFT"
var isDeathTimer = -10
export (bool) var activateMovement = true
func _ready():
gameController.logCall("EnemySpricky","_ready",null)
func _physics_process(delta):
gameController.logCall("EnemySpricky","_physics_process",delta)
if not isDeathTimer == -10:
if isDeathTimer == 10:
$EnemySprickySprite.animation = "Death"
$EnemySprickySprite.playing = false
$EnemySprickySprite.frame = 0
isDeathTimer -= 1
elif isDeathTimer == 0:
queue_free()
else:
isDeathTimer -= 1
return
if not gameController.gamePaused:
if activateMovement:
moveVector.x = 0
if is_on_ceiling() or is_on_floor():
gameController.logVelocity("EnemySpricky","_physics_process","EnemySpricky 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("EnemySpricky","_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("EnemySpricky","_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("EnemySpricky","_physics_process","Out of focus, removing")
queue_free()
if position.y < 0:
position.y = 0
if position.y > 1080:
position.y = 1080
else:
$EnemySprickySprite.playing = false
func animManager():
gameController.logCall("EnemySpricky","animManager",null)
if enemyAction == "WALKING":
$EnemySprickySprite.animation = "Walking"
$EnemySprickySprite.playing = true
elif enemyAction == "DEATH":
$EnemySprickySprite.animation = "Death"
$EnemySprickySprite.playing = true
elif enemyAction == "STANDING":
$EnemySprickySprite.animation = "Walking"
$EnemySprickySprite.frame = 0
$EnemySprickySprite.playing = false
if enemyFacing == "LEFT":
$EnemySprickySprite.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))
$EnemySprickySprite.material = shader
elif enemyFacing == "RIGHT":
$EnemySprickySprite.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))
$EnemySprickySprite.material = shader
func getKilled():
gameController.logCall("EnemySpricky","getKilled",null)
enemyAction = "DEATH"
isDeathTimer = 10
func playerHitZoneEntered(body):
gameController.logCall("EnemySpricky","playerHitZoneEntered",body)
if body.name == "Player" and isDeathTimer == -10:
print("=> playerHitZone entered")
body.event("death")
func enemyHitZoneEntered(body):
gameController.logCall("EnemySpricky","enemyHitZoneEntered",body)
if body.name == "Player":
print("=> enemyHitZone entered")
isDeathTimer = 10
enemyAction = "DEATH"
pass