AShadowWithoutLight/Player.gd

174 lines
4.0 KiB
GDScript3

extends KinematicBody
# Declare member variables here.
var MAX_SPEED = 7
var ACCEL = 3.5
var DEACCEL= 16
var MAX_SLOPE_ANGLE = 40
# The downward acceleration when in the air, in meters per second squared.
export var fall_acceleration = 75
export var jump_impulse = 22
var velocity = Vector3.ZERO
var rotation_helper
var MOUSE_SENSITIVITY = 0.05
onready var camera = $CameraPivot/Camera
var vel = Vector3()
var dir = Vector3()
#medicine
var moodStabilizer = 0
var antiDepressant = 0
var hud
func _process(_delta):
pass
func _physics_process(delta):
# We create a local variable to store the input direction.
dir = Vector3()
var cam_xform = camera.get_global_transform()
var input_movement_vector = Vector2()
# We check for each move input and update the direction accordingly.
if Input.is_action_pressed("move_right"):
input_movement_vector.x += 1
if Input.is_action_pressed("move_left"):
input_movement_vector.x -= 1
if Input.is_action_pressed("move_back"):
# Notice how we are working with the vector's x and z axes.
# In 3D, the XZ plane is the ground plane.
input_movement_vector.y -= 1
if Input.is_action_pressed("move_forward"):
input_movement_vector.y += 1
input_movement_vector = input_movement_vector.normalized()
dir += -cam_xform.basis.z.normalized() * input_movement_vector.y
dir += cam_xform.basis.x.normalized() * input_movement_vector.x
dir.y = 0
dir = dir.normalized()
var hvel = vel
hvel.y = 0
var target = dir
target *= MAX_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel * delta)
vel.x = hvel.x
vel.z = hvel.z
vel.y -= fall_acceleration * delta
if is_on_floor() and Input.is_action_just_pressed("jump"):
vel.y += jump_impulse
vel = move_and_slide(vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
rotation_helper.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))
var camera_rot = rotation_helper.rotation_degrees
camera_rot.x = clamp(camera_rot.x, -90, 90)
rotation_helper.rotation_degrees = camera_rot
func setManic(multiplyer):
MAX_SPEED = 12
ACCEL = 2.75 * multiplyer
DEACCEL= 4 * multiplyer
MAX_SLOPE_ANGLE = 40
fall_acceleration = 75
jump_impulse = 16 * multiplyer
MOUSE_SENSITIVITY = 0.2 * multiplyer
func setNormal():
MAX_SPEED = 7
ACCEL = 3.5
DEACCEL= 16
MAX_SLOPE_ANGLE = 40
fall_acceleration = 75
jump_impulse = 22
MOUSE_SENSITIVITY = 0.05
func setDepressed(multiplyer):
MAX_SPEED = 4 / multiplyer
ACCEL = 1 / multiplyer
DEACCEL= 64 / multiplyer
MAX_SLOPE_ANGLE = 40
fall_acceleration = 75
jump_impulse = 22 / multiplyer
MOUSE_SENSITIVITY = 0.02 / multiplyer
# Called when the node enters the scene tree for the first time.
func _ready():
rotation_helper = $CameraPivot
hud = get_node(@"../HUD")
func addMoodStabilizer():
moodStabilizer = moodStabilizer + 1
print("current mood stabilizer: ", moodStabilizer)
hud.showMoodStab(String(moodStabilizer))
func addAntiDepressant():
antiDepressant = antiDepressant + 1
print("current anti depressant: ", antiDepressant)
hud.showAntiDep(String(antiDepressant))
func takeMoodStabilizer():
if(moodStabilizer>0):
moodStabilizer = moodStabilizer - 1
print("current mood stabilizer: ", moodStabilizer)
hud.showMoodStab(String(moodStabilizer))
func takeAntiDepressant():
if(antiDepressant>0):
antiDepressant = antiDepressant - 1
print("current anti depressant: ", antiDepressant)
hud.showAntiDep(String(antiDepressant))
func getMoodStabilizer():
return moodStabilizer
func getAntiDepressant():
return antiDepressant
func unlimitedMeds():
antiDepressant = 9999
moodStabilizer = 9999
print("current mood stabilizer: ", moodStabilizer)
hud.showMoodStab(String(moodStabilizer))
print("current anti depressant: ", antiDepressant)
hud.showAntiDep(String(antiDepressant))