|
|
|
@ -5,11 +5,13 @@ class_name DownhillAutoscrollerPlayer
|
|
|
|
|
export var min_speed : float = 3
|
|
|
|
|
export var max_speed : float = 11
|
|
|
|
|
export var player_initiated_acceleration : float = 5
|
|
|
|
|
export var boost_per_second : float = 6 / 1.36 # 6 mph
|
|
|
|
|
export var boost_per_second : float = 4 / 1.36 # 6 mph
|
|
|
|
|
|
|
|
|
|
var last_contacted_map_elem_type : int = Constants.MapElemType.SQUARE
|
|
|
|
|
|
|
|
|
|
var boost : float = 0 # to movement speed
|
|
|
|
|
var boost_effect: float = 0
|
|
|
|
|
var instant_accel: bool = false
|
|
|
|
|
|
|
|
|
|
var respawn_pos : Vector2
|
|
|
|
|
|
|
|
|
@ -94,77 +96,59 @@ func handle_idle():
|
|
|
|
|
if boost == 0:
|
|
|
|
|
.handle_idle()
|
|
|
|
|
|
|
|
|
|
func handle_speed(delta):
|
|
|
|
|
if get_current_action() == Constants.UnitCurrentAction.RECOILING:
|
|
|
|
|
target_move_speed = min_speed
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.LEFT][scene.I_T_PRESSED]:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, min_speed, player_initiated_acceleration * delta)
|
|
|
|
|
boost_effect = 0.0
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var slope: int = Constants.ELEM_TYPE_SLOPE[last_contacted_map_elem_type]
|
|
|
|
|
|
|
|
|
|
var speed_limit: float = Constants.SLOPE_SPEED[slope]
|
|
|
|
|
var accel: float = player_initiated_acceleration
|
|
|
|
|
|
|
|
|
|
if not get_condition(Constants.UnitCondition.IS_ON_GROUND, true):
|
|
|
|
|
speed_limit = target_move_speed
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED] and speed_limit < Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type]:
|
|
|
|
|
speed_limit = Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type]
|
|
|
|
|
|
|
|
|
|
speed_limit = max(min_speed, speed_limit)
|
|
|
|
|
|
|
|
|
|
if get_condition(Constants.UnitCondition.IS_ON_GROUND, true):
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED]:
|
|
|
|
|
speed_limit += 1.0
|
|
|
|
|
|
|
|
|
|
if boost_effect > 0:
|
|
|
|
|
speed_limit += boost_effect
|
|
|
|
|
|
|
|
|
|
if target_move_speed < boost_effect:
|
|
|
|
|
boost_effect = 0.0
|
|
|
|
|
|
|
|
|
|
elif slope < 2:
|
|
|
|
|
boost_effect -= delta
|
|
|
|
|
|
|
|
|
|
accel = (Constants.SLOPE_ACCEL if target_move_speed < speed_limit else Constants.SLOPE_DECEL)[slope]
|
|
|
|
|
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, speed_limit, accel * delta)
|
|
|
|
|
if target_move_speed > speed_limit + 4.0:
|
|
|
|
|
target_move_speed -= speed_limit
|
|
|
|
|
target_move_speed *= pow(0.5, delta)
|
|
|
|
|
target_move_speed += speed_limit
|
|
|
|
|
|
|
|
|
|
func process_unit(delta, time_elapsed : float):
|
|
|
|
|
# always be movin'
|
|
|
|
|
facing = Constants.Direction.RIGHT
|
|
|
|
|
actions[Constants.ActionType.MOVE] = true
|
|
|
|
|
|
|
|
|
|
# Fine tune the player's speed
|
|
|
|
|
handle_speed(delta)
|
|
|
|
|
|
|
|
|
|
print(last_contacted_map_elem_type)
|
|
|
|
|
if boost_effect > 0:
|
|
|
|
|
boost_effect -= delta
|
|
|
|
|
|
|
|
|
|
if get_current_action() == Constants.UnitCurrentAction.RECOILING:
|
|
|
|
|
target_move_speed = min_speed
|
|
|
|
|
else:
|
|
|
|
|
# override player input so that leftward movement is deceleration,
|
|
|
|
|
# right movement is acceleration
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.LEFT][scene.I_T_PRESSED]:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, min_speed, player_initiated_acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
if not get_condition(Constants.UnitCondition.IS_ON_GROUND, true):
|
|
|
|
|
if (target_move_speed < Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type]
|
|
|
|
|
and scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED]):
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type], player_initiated_acceleration * delta)
|
|
|
|
|
if target_move_speed > max_speed:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, max_speed, player_initiated_acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
# shallow slope: arctan(.5) = 27 degrees, sin(27) = 0.45
|
|
|
|
|
# steep slope: sin(45) = 0.71
|
|
|
|
|
var ground_influenced_acceleration = 0
|
|
|
|
|
var is_decel : bool = false
|
|
|
|
|
if (last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_RIGHT_1
|
|
|
|
|
or last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_RIGHT_2
|
|
|
|
|
or last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_LEFT_1
|
|
|
|
|
or last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_LEFT_2):
|
|
|
|
|
ground_influenced_acceleration = Constants.GRAVITY * 0.45
|
|
|
|
|
if (last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_LEFT_1
|
|
|
|
|
or last_contacted_map_elem_type == Constants.MapElemType.SMALL_SLOPE_LEFT_2):
|
|
|
|
|
is_decel = true
|
|
|
|
|
elif (last_contacted_map_elem_type == Constants.MapElemType.SLOPE_RIGHT
|
|
|
|
|
or last_contacted_map_elem_type == Constants.MapElemType.SLOPE_LEFT):
|
|
|
|
|
ground_influenced_acceleration = Constants.GRAVITY * 0.71
|
|
|
|
|
if last_contacted_map_elem_type == Constants.MapElemType.SLOPE_LEFT:
|
|
|
|
|
is_decel = true
|
|
|
|
|
if is_decel or ground_influenced_acceleration == 0:
|
|
|
|
|
var end_speed
|
|
|
|
|
if ground_influenced_acceleration == 0:
|
|
|
|
|
# flat ground
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED]:
|
|
|
|
|
end_speed = max(min(target_move_speed, max_speed), Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type])
|
|
|
|
|
else:
|
|
|
|
|
end_speed = min(target_move_speed, max_speed)
|
|
|
|
|
else:
|
|
|
|
|
# incline
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED]:
|
|
|
|
|
end_speed = Constants.UNIT_TYPE_MOVE_SPEEDS[unit_type]
|
|
|
|
|
else:
|
|
|
|
|
end_speed = min_speed
|
|
|
|
|
if target_move_speed < end_speed:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, end_speed, player_initiated_acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
if ground_influenced_acceleration > 0:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, end_speed, ground_influenced_acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, end_speed, player_initiated_acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
var acceleration = ground_influenced_acceleration
|
|
|
|
|
if scene.input_table[Constants.PlayerInput.RIGHT][scene.I_T_PRESSED]:
|
|
|
|
|
acceleration = max(acceleration, player_initiated_acceleration)
|
|
|
|
|
if target_move_speed < max_speed:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, max_speed, acceleration * delta)
|
|
|
|
|
else:
|
|
|
|
|
target_move_speed = move_toward(target_move_speed, max_speed, player_initiated_acceleration * delta)
|
|
|
|
|
|
|
|
|
|
.process_unit(delta, time_elapsed)
|
|
|
|
|
|
|
|
|
|
# treat all collisions as right-side collisions
|
|
|
|
@ -204,8 +188,8 @@ func landed():
|
|
|
|
|
return
|
|
|
|
|
if boost > 0:
|
|
|
|
|
scene.find_node("CanvasLayer").flash_boost = true
|
|
|
|
|
h_speed += boost
|
|
|
|
|
target_move_speed = h_speed
|
|
|
|
|
boost_effect += boost
|
|
|
|
|
target_move_speed += boost
|
|
|
|
|
boost = 0
|
|
|
|
|
|
|
|
|
|
func react(delta):
|
|
|
|
@ -249,7 +233,13 @@ func react(delta):
|
|
|
|
|
|
|
|
|
|
func respawn_from_pit():
|
|
|
|
|
pos = respawn_pos
|
|
|
|
|
hit(Constants.Direction.RIGHT)
|
|
|
|
|
#hit(Constants.Direction.RIGHT)
|
|
|
|
|
set_unit_condition_with_timer(Constants.UnitCondition.IS_INVINCIBLE)
|
|
|
|
|
start_flash()
|
|
|
|
|
get_node("SpinningSprite").visible = false
|
|
|
|
|
get_node("SpinningSprite").rotation = 0
|
|
|
|
|
hit_audiostream_player.play()
|
|
|
|
|
boost = 0
|
|
|
|
|
boost_effect = 0
|
|
|
|
|
get_node("Camera2D").make_current()
|
|
|
|
|
|
|
|
|
|