class_name BaseMob
extends KinematicBody2D

var gravity = 300.0
export var speed = 10
export var base_max_velocity = 100.0
var max_velocity = 100.0
var jump_strength = 0.65
var jump_burst = 210.0
var velocity = Vector2()
var previous_real_velocity = Vector2()
var real_velocity = Vector2()
var lives = 1
export var frozen = true

func read_input(_delta):
	pass

func fundamental_forces(delta):
	velocity.y += delta * gravity * 2
	
	if abs(velocity.x) > max_velocity:
		velocity.x = sign(velocity.x) * max_velocity

func apply_movement(_delta):
	previous_real_velocity = real_velocity
	real_velocity = move_and_slide(velocity, Vector2(0.0, -1.0))
	
func stairs(_delta):
	pass
	
func post_movement(_delta):
	pass
	
func animate(_delta):
	pass
	
func finalize(_delta):
	pass
	
func strike():
	velocity = Vector2(0, 0)
	
func watch_for_death(delta):
	if lives < 1:
		set_scale(Vector2(1.0, get_scale().y - delta * 5.0))
		frozen = true
		if get_scale().y < 0.0:
			queue_free()

func _process(delta):
	watch_for_death(delta)
	if frozen:
		return
	if lives > 0:
		read_input(delta)
	fundamental_forces(delta)
	stairs(delta)
	apply_movement(delta)
	post_movement(delta)
	animate(delta)
	finalize(delta)
