First_Person_Slapper/Player.gd
2022-10-11 15:20:45 -04:00

119 lines
2.9 KiB
GDScript

extends KinematicBody
export var speed = 40
export var h_acceleration = 6
export var air_acceleration = 1
export var normal_acceleration = 6
export var gravity = 100
export var jump = 30
export var slapkill = 0.8
var slap = 0.0
var chargeSlap = false
var isSlap = false;
export var mouse_sensitivity = 0.03
var bottom_boudaries = -20
var full_contact = false
var direction = Vector3()
var h_velocity = Vector3()
var movement = Vector3()
var gravity_vec = Vector3()
onready var head = $Head
onready var ground_check = $GroundCheck
onready var slap_gauge = $HUD/PlayerLayer/ActualHUD/SlapGauge
onready var slap_animator = $HandMovement
onready var Menu = $HUD/MenuLayer/Start
onready var AudioSlap = $AudioSlap
onready var AudioMegaSlap = $AudioMegaSlap
func _ready():
slap_animator.current_animation = "basic_slap"
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))
func _physics_process(delta):
if Input.is_action_just_pressed("escape"):
Menu.openMenu();
if global_transform.origin.y < bottom_boudaries:
global_transform.origin.x = 0
global_transform.origin.y = 10
global_transform.origin.z = 0
direction = Vector3()
full_contact = ground_check.is_colliding()
if not is_on_floor():
gravity_vec += Vector3.DOWN * gravity * delta
h_acceleration = air_acceleration
elif is_on_floor() and full_contact:
gravity_vec = -get_floor_normal() * gravity
h_acceleration = normal_acceleration
else:
gravity_vec = -get_floor_normal()
h_acceleration = normal_acceleration
if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()):
gravity_vec = Vector3.UP * jump
if Input.is_action_pressed("move_forward"):
direction -= transform.basis.z
elif Input.is_action_pressed("move_backward"):
direction += transform.basis.z
if Input.is_action_pressed("move_left"):
direction -= transform.basis.x
elif Input.is_action_pressed("move_right"):
direction += transform.basis.x
# Slappening
if Input.is_action_pressed("slap"):
if slap < 0.01:
chargeSlap = true;
elif Input.is_action_just_released("slap"):
if chargeSlap:
isSlap = true;
chargeSlap = false;
else:
isSlap = false;
if isSlap:
if slap >= slapkill:
AudioMegaSlap.play()
else:
AudioSlap.play()
if (chargeSlap):
slap += delta * 1.5;
else:
slap -= delta * 8.0;
slap = clamp(slap, 0.0, 1.0)
slap_gauge.fill = slap
slap_animator.seek(slap, true)
slap_gauge.fill = slap;
slap_gauge.kill = slapkill;
direction = direction.normalized()
h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
movement.z = h_velocity.z + gravity_vec.z
movement.x = h_velocity.x + gravity_vec.x
movement.y = gravity_vec.y
# warning-ignore:return_value_discarded
move_and_slide(movement, Vector3.UP)