tweaks to controller and savegames are stored by level
This commit is contained in:
@@ -22,6 +22,7 @@ var dead_player = preload("res://assets/dead_cam.tscn")
|
||||
const CLEARED_ANNOUNCE = preload("res://assets/cleared_announce.tscn")
|
||||
const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
|
||||
|
||||
var level_name
|
||||
var paused = false
|
||||
var health = start_health
|
||||
var pickups = []
|
||||
@@ -43,6 +44,8 @@ var engine_time_scale_cache : float = 1.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
level_name = self.get_name()
|
||||
print("LEVEL NAME ",level_name)
|
||||
#connect to signals
|
||||
SignalBus.enemy_count_changed.connect(enemy_count)
|
||||
|
||||
@@ -54,7 +57,10 @@ func _ready():
|
||||
GameGlobals.game_loaded = true
|
||||
SignalBus.emit_signal("game_loaded")
|
||||
else:
|
||||
SaveLoad.load_save_game_data()
|
||||
if SaveLoad.check_save_game_exists(level_name):
|
||||
SaveLoad.load_save_game_data(level_name)
|
||||
else:
|
||||
refresh_scene()
|
||||
|
||||
#Spawn Crown
|
||||
if SaveLoad.last_hit_path:
|
||||
@@ -209,5 +215,5 @@ func pause_menu():
|
||||
paused = !paused
|
||||
|
||||
func save_quit():
|
||||
SaveLoad.save_game_data()
|
||||
SaveLoad.save_game_data(level_name)
|
||||
get_tree().quit()
|
||||
|
||||
@@ -44,6 +44,7 @@ func _physics_process(delta):
|
||||
func picked_up():
|
||||
player.pickup_sound.pitch_scale = 1 + randf_range(-.3,.3)
|
||||
player.pickup_sound.play()
|
||||
Input.start_joy_vibration(0,.1,.1,.1)
|
||||
match pickupType:
|
||||
# Ammo
|
||||
0:
|
||||
|
||||
@@ -23,7 +23,9 @@ const ADS_POS = Vector3(0,-.05,-.45)
|
||||
#JOYSTICK SETTINGS
|
||||
const JOYSTICK_SENSITIVITY = .06
|
||||
var adj_sensitivity = JOYSTICK_SENSITIVITY
|
||||
const JOYSTICK_DEADZONE = 0.05
|
||||
const R_JOYSTICK_DEADZONE = 0.05
|
||||
const L_JOYSTICK_DEADZONE = .2
|
||||
const L_JOYSTICK_SENSITIVITY = .1
|
||||
|
||||
var speed
|
||||
var double_jump = true
|
||||
@@ -208,9 +210,18 @@ func _physics_process(delta):
|
||||
velocity.y += JUMP_VELOCITY
|
||||
double_jump = false
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
## HANDLE MOVEMENT DIRECTION
|
||||
var input_dir
|
||||
var direction
|
||||
#GetKB Input
|
||||
input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
#Get Joy Input
|
||||
input_dir += joypad_walk()
|
||||
if abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_X)) > L_JOYSTICK_SENSITIVITY or abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)) > L_JOYSTICK_SENSITIVITY:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y))
|
||||
else:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
# Handle Sprint
|
||||
if Input.is_action_just_pressed("sprint") and !is_on_floor():
|
||||
if air_dash > 0:
|
||||
@@ -287,6 +298,7 @@ func _physics_process(delta):
|
||||
var recoil_amount = Vector3(-.3,0,0)
|
||||
land_sound.volume_db = land_volume
|
||||
land_sound.play()
|
||||
Input.start_joy_vibration(0,.1,.1,.1)
|
||||
recoil.add_recoil(recoil_amount,10,10)
|
||||
moving_fast_top_speed = 0.0
|
||||
moving_fast = false
|
||||
@@ -414,15 +426,28 @@ func _physics_process(delta):
|
||||
weapon_sway(delta)
|
||||
weapon_bob(velocity.length(), delta)
|
||||
|
||||
func joypad_walk():
|
||||
# Joypad right stick look control
|
||||
var dir_out = Vector2(0,0)
|
||||
var xAxis = Input.get_joy_axis(0,JOY_AXIS_LEFT_X)
|
||||
var yAxis = Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)
|
||||
|
||||
if abs(xAxis) > L_JOYSTICK_DEADZONE:
|
||||
dir_out.x = xAxis
|
||||
if abs(yAxis) > L_JOYSTICK_DEADZONE:
|
||||
dir_out.y = yAxis
|
||||
|
||||
return dir_out
|
||||
|
||||
func joypad_look(delta):
|
||||
# Joypad right stick look control
|
||||
var xAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)
|
||||
var yAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)
|
||||
var aim_assist
|
||||
|
||||
if abs(xAxis) > JOYSTICK_DEADZONE:
|
||||
if abs(xAxis) > R_JOYSTICK_DEADZONE:
|
||||
self.rotate_y(-xAxis * JOYSTICK_SENSITIVITY * 1)
|
||||
if abs(yAxis) > JOYSTICK_DEADZONE:
|
||||
if abs(yAxis) > R_JOYSTICK_DEADZONE:
|
||||
head.rotate_x(-yAxis * JOYSTICK_SENSITIVITY * 1)
|
||||
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85))
|
||||
|
||||
@@ -471,7 +496,6 @@ func _on_pick_up_detection_body_entered(body):
|
||||
if body.is_in_group("pickup"):
|
||||
if body.pickupable:
|
||||
body.picked_up()
|
||||
Input.start_joy_vibration(0,.1,.1,.1)
|
||||
if body.is_in_group("weapon_pickup"):
|
||||
weapon_pickup_audio.play()
|
||||
Input.start_joy_vibration(0,.1,.1,.1)
|
||||
@@ -496,9 +520,11 @@ func weapon_tilt(input_x, delta):
|
||||
|
||||
func weapon_sway(delta):
|
||||
if !ads:
|
||||
var joy_input = Vector2(Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)*5,Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)*5)
|
||||
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_sway_amount, 5 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_sway_amount, 5 * delta)
|
||||
joy_input = lerp(joy_input,Vector2.ZERO,10 * delta)
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, (mouse_input.y + joy_input.y) * weapon_sway_amount, 5 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, (mouse_input.x + joy_input.x) * weapon_sway_amount, 5 * delta)
|
||||
|
||||
func weapon_bob(vel : float, delta):
|
||||
if weapon_holder:
|
||||
|
||||
@@ -158,6 +158,7 @@ func fire(delta):
|
||||
player.recoil.add_recoil(Vector3(0,recoil_amount.y,recoil_amount.z),10,recoil_speed_change)
|
||||
player.recoil.add_gun_recoil(recoil_amount.x)
|
||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||
Input.start_joy_vibration(0,.5,.9,.2)
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
|
||||
@@ -20,7 +20,6 @@ var reserve_ammo
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
var game_save_path = "user://gamesave.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
@@ -59,9 +58,10 @@ func load_persistent_data():
|
||||
enemies_killed = null
|
||||
|
||||
|
||||
func save_game_data():
|
||||
func save_game_data(level_name):
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
var file = FileAccess.open(game_save_path, FileAccess.WRITE)
|
||||
|
||||
#ASSIGN DATA TO VARIABLES
|
||||
@@ -115,10 +115,17 @@ func clear_persistent_data():
|
||||
print("PERSISTENT DATA CLEARED")
|
||||
file.close()
|
||||
|
||||
func load_save_game_data():
|
||||
func check_save_game_exists(level_name):
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
if FileAccess.file_exists(game_save_path):
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func load_save_game_data(level_name):
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
if FileAccess.file_exists(game_save_path):
|
||||
var file = FileAccess.open(game_save_path, FileAccess.READ)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user