Merge branch 'alt-movement'
This commit is contained in:
commit
599dbb66e4
File diff suppressed because one or more lines are too long
|
@ -61,6 +61,18 @@ enum MapElemType {
|
||||||
OOB_LOWER,
|
OOB_LOWER,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ELEM_TYPE_SLOPE = [
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
]
|
||||||
|
|
||||||
enum SpriteClass {
|
enum SpriteClass {
|
||||||
IDLE,
|
IDLE,
|
||||||
WALK,
|
WALK,
|
||||||
|
@ -269,3 +281,27 @@ const SPAWN_DISTANCE = 20
|
||||||
|
|
||||||
# specialized constants
|
# specialized constants
|
||||||
const FLASH_CYCLE = 0.15
|
const FLASH_CYCLE = 0.15
|
||||||
|
|
||||||
|
const SLOPE_SPEED = [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
3.5,
|
||||||
|
7.3 * 1.118,
|
||||||
|
9.2 * 1.414,
|
||||||
|
]
|
||||||
|
|
||||||
|
const SLOPE_ACCEL = [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.2 * 1.118,
|
||||||
|
3.4 * 1.414,
|
||||||
|
]
|
||||||
|
|
||||||
|
const SLOPE_DECEL = [
|
||||||
|
5.0 * 1.414,
|
||||||
|
3.5 * 1.118,
|
||||||
|
0.3,
|
||||||
|
0.2,
|
||||||
|
0.1
|
||||||
|
]
|
||||||
|
|
|
@ -108,7 +108,7 @@ func _process(delta):
|
||||||
if !stage_finished:
|
if !stage_finished:
|
||||||
time_elapsed_in_race += delta
|
time_elapsed_in_race += delta
|
||||||
# 1 grid unit = 2ft, 1 grid unit / s = 1.36 mph
|
# 1 grid unit = 2ft, 1 grid unit / s = 1.36 mph
|
||||||
player_speed_mph = player.h_speed * 1.36
|
player_speed_mph = player.target_move_speed#player.h_speed * 1.36
|
||||||
|
|
||||||
if not race_over and player.pos.x >= finish_x_pos:
|
if not race_over and player.pos.x >= finish_x_pos:
|
||||||
race_over = true
|
race_over = true
|
||||||
|
@ -192,7 +192,7 @@ func handle_player_input():
|
||||||
|
|
||||||
if input_table[Constants.PlayerInput.GBA_A][I_T_PRESSED]:
|
if input_table[Constants.PlayerInput.GBA_A][I_T_PRESSED]:
|
||||||
if (player.get_current_action() == Constants.UnitCurrentAction.JUMPING
|
if (player.get_current_action() == Constants.UnitCurrentAction.JUMPING
|
||||||
or (player.get_current_action() == Constants.UnitCurrentAction.IDLE
|
or ((player.get_current_action() == Constants.UnitCurrentAction.IDLE)
|
||||||
and input_table[Constants.PlayerInput.GBA_A][I_T_JUST_PRESSED])):
|
and input_table[Constants.PlayerInput.GBA_A][I_T_JUST_PRESSED])):
|
||||||
if player.unit_conditions[Constants.UnitCondition.IS_ON_GROUND] or player.get_current_action() == Constants.UnitCurrentAction.JUMPING:
|
if player.unit_conditions[Constants.UnitCondition.IS_ON_GROUND] or player.get_current_action() == Constants.UnitCurrentAction.JUMPING:
|
||||||
player.set_action(Constants.ActionType.JUMP)
|
player.set_action(Constants.ActionType.JUMP)
|
||||||
|
|
|
@ -20,7 +20,8 @@ func _ready():
|
||||||
player.recorder = self
|
player.recorder = self
|
||||||
scene = player.get_parent()
|
scene = player.get_parent()
|
||||||
|
|
||||||
func _process(_delta):
|
func _physics_process(_delta):
|
||||||
|
print(_delta)
|
||||||
if this_frame:
|
if this_frame:
|
||||||
this_frame = false
|
this_frame = false
|
||||||
replay.positions.append(player.pos)
|
replay.positions.append(player.pos)
|
||||||
|
|
|
@ -160,10 +160,8 @@ func jump():
|
||||||
v_speed = max(Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], v_speed)
|
v_speed = max(Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], v_speed)
|
||||||
else:
|
else:
|
||||||
# airborne
|
# airborne
|
||||||
print("airjump")
|
|
||||||
print(v_speed)
|
|
||||||
v_speed = max(Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], move_toward(v_speed, Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], get_process_delta_time() * Constants.GRAVITY))
|
v_speed = max(Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], move_toward(v_speed, Constants.UNIT_TYPE_JUMP_SPEEDS[unit_type], get_process_delta_time() * Constants.GRAVITY))
|
||||||
print(v_speed)
|
|
||||||
set_unit_condition(Constants.UnitCondition.IS_ON_GROUND, false)
|
set_unit_condition(Constants.UnitCondition.IS_ON_GROUND, false)
|
||||||
if get_current_action() == Constants.UnitCurrentAction.JUMPING and v_speed > 0:
|
if get_current_action() == Constants.UnitCurrentAction.JUMPING and v_speed > 0:
|
||||||
set_sprite(Constants.SpriteClass.JUMP, 0)
|
set_sprite(Constants.SpriteClass.JUMP, 0)
|
||||||
|
|
|
@ -5,11 +5,13 @@ class_name DownhillAutoscrollerPlayer
|
||||||
export var min_speed : float = 3
|
export var min_speed : float = 3
|
||||||
export var max_speed : float = 11
|
export var max_speed : float = 11
|
||||||
export var player_initiated_acceleration : float = 5
|
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 last_contacted_map_elem_type : int = Constants.MapElemType.SQUARE
|
||||||
|
|
||||||
var boost : float = 0 # to movement speed
|
var boost : float = 0 # to movement speed
|
||||||
|
var boost_effect: float = 0
|
||||||
|
var instant_accel: bool = false
|
||||||
|
|
||||||
var respawn_pos : Vector2
|
var respawn_pos : Vector2
|
||||||
|
|
||||||
|
@ -94,76 +96,58 @@ func handle_idle():
|
||||||
if boost == 0:
|
if boost == 0:
|
||||||
.handle_idle()
|
.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):
|
func process_unit(delta, time_elapsed : float):
|
||||||
# always be movin'
|
# always be movin'
|
||||||
facing = Constants.Direction.RIGHT
|
facing = Constants.Direction.RIGHT
|
||||||
actions[Constants.ActionType.MOVE] = true
|
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)
|
.process_unit(delta, time_elapsed)
|
||||||
|
|
||||||
|
@ -204,8 +188,8 @@ func landed():
|
||||||
return
|
return
|
||||||
if boost > 0:
|
if boost > 0:
|
||||||
scene.find_node("CanvasLayer").flash_boost = true
|
scene.find_node("CanvasLayer").flash_boost = true
|
||||||
h_speed += boost
|
boost_effect += boost
|
||||||
target_move_speed = h_speed
|
target_move_speed += boost
|
||||||
boost = 0
|
boost = 0
|
||||||
|
|
||||||
func react(delta):
|
func react(delta):
|
||||||
|
@ -249,7 +233,13 @@ func react(delta):
|
||||||
|
|
||||||
func respawn_from_pit():
|
func respawn_from_pit():
|
||||||
pos = respawn_pos
|
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 = 0
|
||||||
|
boost_effect = 0
|
||||||
get_node("Camera2D").make_current()
|
get_node("Camera2D").make_current()
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ extents = Vector2( 9, 34 )
|
||||||
z_index = 1
|
z_index = 1
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
unit_type = 1
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2( 0, -36 )
|
position = Vector2( 0, -36 )
|
||||||
|
|
|
@ -14,6 +14,7 @@ extents = Vector2( 9, 34 )
|
||||||
z_index = 1
|
z_index = 1
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
unit_type = 1
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2( 0, -36 )
|
position = Vector2( 0, -36 )
|
||||||
|
|
Loading…
Reference in New Issue