Merge branch 'main' of https://github.com/MarcEricMartel/FirstPersonSlapper
This commit is contained in:
52
Player.gd
52
Player.gd
@@ -12,6 +12,8 @@ var slap = 0.0
|
||||
var chargeSlap = false
|
||||
var isSlap = false
|
||||
var can_slap = true
|
||||
var isStep = false
|
||||
var stepAcc = 0
|
||||
|
||||
export var mouse_sensitivity = 0.03
|
||||
|
||||
@@ -34,8 +36,12 @@ onready var AudioSlap = $AudioSlap
|
||||
onready var AudioMegaSlap = $AudioMegaSlap
|
||||
onready var hitbox = $Head/Camera/HitBox
|
||||
onready var slap_cooldown = $SlapCooldown
|
||||
onready var AudioCharge = $AudioCharge
|
||||
onready var Steps = [ $Step1, $Step2, $Step3, $Step4 ]
|
||||
var rng = RandomNumberGenerator.new()
|
||||
|
||||
func _ready():
|
||||
rng.randomize()
|
||||
slap_animator.current_animation = "basic_slap"
|
||||
|
||||
|
||||
@@ -49,7 +55,7 @@ func _input(event):
|
||||
func _physics_process(delta):
|
||||
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
Menu.openMenu();
|
||||
Menu.openMenu();
|
||||
|
||||
if global_transform.origin.y < bottom_boudaries:
|
||||
global_transform.origin.x = 0
|
||||
@@ -66,9 +72,11 @@ func _physics_process(delta):
|
||||
elif is_on_floor() and full_contact:
|
||||
gravity_vec = -get_floor_normal() * gravity
|
||||
h_acceleration = normal_acceleration
|
||||
isStep = true
|
||||
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
|
||||
@@ -77,6 +85,7 @@ func _physics_process(delta):
|
||||
head.translate(Vector3.DOWN)
|
||||
if Input.is_action_just_released("crouch"):
|
||||
head.translate(Vector3.UP)
|
||||
isStep = false
|
||||
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
direction -= transform.basis.z
|
||||
@@ -87,17 +96,26 @@ func _physics_process(delta):
|
||||
elif Input.is_action_pressed("move_right"):
|
||||
direction += transform.basis.x
|
||||
|
||||
|
||||
# Slappening
|
||||
if can_slap:
|
||||
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;
|
||||
can_slap = false
|
||||
slap_cooldown.start(0.25)
|
||||
if Input.is_action_pressed("slap"):
|
||||
if !chargeSlap:
|
||||
AudioCharge.play();
|
||||
if slap < 0.01:
|
||||
chargeSlap = true;
|
||||
elif Input.is_action_just_released("slap"):
|
||||
if chargeSlap:
|
||||
isSlap = true;
|
||||
chargeSlap = false;
|
||||
can_slap = false
|
||||
slap_cooldown.start(0.25)
|
||||
AudioCharge.stop();
|
||||
else:
|
||||
isSlap = false;
|
||||
|
||||
if isSlap:
|
||||
if slap >= slapkill:
|
||||
AudioMegaSlap.play()
|
||||
else:
|
||||
isSlap = false;
|
||||
|
||||
@@ -120,9 +138,19 @@ func _physics_process(delta):
|
||||
slap_animator.seek(slap, true)
|
||||
slap_gauge.fill = slap;
|
||||
slap_gauge.kill = slapkill;
|
||||
|
||||
|
||||
|
||||
direction = direction.normalized()
|
||||
|
||||
if isStep:
|
||||
stepAcc += (abs(direction.x) + abs(direction.z)) * delta
|
||||
else:
|
||||
stepAcc = 0.0
|
||||
|
||||
if (stepAcc > 0.3):
|
||||
stepAcc -= 0.45
|
||||
Steps[rng.randi_range(0,3)].play();
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user