Even more changes.
This commit is contained in:
Executable → Regular
+38
-32
@@ -6,15 +6,24 @@ extends CharacterBody2D
|
||||
|
||||
signal state_change(old: States, new: States)
|
||||
|
||||
enum States {IDLE, RUN_START, RUN, ROLL, JUMP_START, JUMP, FALL, LAND, DAMAGE, RAGDOLL, BOUNCE, LAY, SHOOT, JAB, STRAIGHT, KICK, POUND}
|
||||
enum States {NULL, IDLE, RUN_START, RUN, ROLL, JUMP_START, JUMP, FALL, LAND, DAMAGE, RAGDOLL, BOUNCE, LAY, SHOOT, JAB, STRAIGHT, KICK, POUND, POUND_FALL}
|
||||
|
||||
const STATES_IMMOBILE = [States.ROLL, States.DAMAGE, States.RAGDOLL, States.BOUNCE, States.LAY, States.SHOOT, States.JAB, States.STRAIGHT, States.KICK, States.POUND]
|
||||
const STATES_IMMOBILE = [States.ROLL, States.DAMAGE, States.RAGDOLL, States.BOUNCE, States.LAY, States.SHOOT, States.JAB, States.STRAIGHT, States.KICK, States.POUND, States.POUND_FALL]
|
||||
const STATES_MOVEMENT = [States.RUN_START, States.RUN, States.JUMP_START, States.JUMP, States.FALL]
|
||||
const STATES_ATTACK = [States.JAB, States.STRAIGHT, States.KICK, States.POUND]
|
||||
const STATES_AIRBORNE = [States.JUMP_START, States.JUMP, States.FALL]
|
||||
|
||||
# FX
|
||||
const ROLL_DUST = preload("uid://botc600n5fcgt")
|
||||
const JUMP_DUST = preload("uid://c4h1cj75b5sry")
|
||||
|
||||
# Sounds
|
||||
const JUMP_SOUND = preload("uid://d1hwunwdel6sy")
|
||||
const HIT_GROUND = preload("uid://ciglwfq0vua8i")
|
||||
const POUND_SOUND = preload("uid://css0nv2dxb52w")
|
||||
|
||||
# Projectiles
|
||||
const POUND_BULLET = preload("uid://5uiinhmeyov0")
|
||||
|
||||
const SPEED = 90.0
|
||||
const ACCEL = 450
|
||||
@@ -22,20 +31,9 @@ const JUMP_VELOCITY = -312.0
|
||||
const ROLL_VELOCITY = 150.0
|
||||
const ROLL_DECEL = 1080
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
var state: States = States.IDLE: set = _set_state
|
||||
|
||||
var state_buffer: States = States.NULL
|
||||
var direction: float
|
||||
var grounded: bool
|
||||
var running: bool
|
||||
var rolling: bool
|
||||
var ragdoll: bool
|
||||
var bounce: bool
|
||||
var lay: bool
|
||||
var shooting: bool
|
||||
var melee: bool
|
||||
|
||||
func _set_state(s: States):
|
||||
state_change.emit(state, s)
|
||||
@@ -47,7 +45,7 @@ func _process(_delta: float) -> void:
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Jumping
|
||||
if state not in STATES_IMMOBILE and state not in STATES_AIRBORNE and Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
@@ -61,16 +59,17 @@ func _physics_process(delta):
|
||||
add_sibling(jump_dust)
|
||||
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
|
||||
# Short hops
|
||||
if Input.is_action_just_released("jump") && !is_on_floor():
|
||||
if state in [States.JUMP_START, States.JUMP] and Input.is_action_just_released("jump") and !is_on_floor():
|
||||
velocity.y = velocity.y / 2
|
||||
|
||||
# Falling
|
||||
if state not in [States.ROLL, States.RAGDOLL, States.BOUNCE] and velocity.y > 0:
|
||||
if state in [States.IDLE] + STATES_MOVEMENT and velocity.y > 0:
|
||||
state = States.FALL
|
||||
|
||||
if state in [States.FALL] and is_zero_approx(velocity.y):
|
||||
# Landing
|
||||
if state in [States.FALL] and is_on_floor():
|
||||
if direction:
|
||||
state = States.RUN
|
||||
else:
|
||||
@@ -78,7 +77,7 @@ func _physics_process(delta):
|
||||
|
||||
# Rolls
|
||||
if state not in STATES_IMMOBILE and state != States.ROLL and \
|
||||
(Input.is_action_just_pressed("roll_jump") or Input.is_action_just_pressed("roll")):
|
||||
(Input.is_action_just_pressed("roll_jump") or (Input.is_action_just_pressed("roll") and direction)):
|
||||
state = States.ROLL
|
||||
|
||||
if is_on_floor():
|
||||
@@ -94,20 +93,27 @@ func _physics_process(delta):
|
||||
|
||||
if velocity.y >= 0 && Input.is_action_just_pressed("roll_jump"):
|
||||
velocity.y = -120
|
||||
|
||||
|
||||
# Melee
|
||||
if state not in STATES_IMMOBILE and Input.is_action_just_pressed("melee"):
|
||||
state = States.MELEE
|
||||
if Input.is_action_pressed("roll"):
|
||||
# Pound
|
||||
pass
|
||||
state = States.POUND
|
||||
velocity.x = 0
|
||||
elif state in STATES_AIRBORNE:
|
||||
state = States.KICK
|
||||
else:
|
||||
state = States.JAB
|
||||
|
||||
# Pound
|
||||
if state in [States.POUND_FALL] and is_on_floor():
|
||||
state = States.POUND
|
||||
|
||||
# Shooting
|
||||
if state not in STATES_IMMOBILE and Input.is_action_just_pressed("shoot"):
|
||||
state = States.SHOOT
|
||||
match global.save.projectile:
|
||||
global.save.Projectile.BLAST:
|
||||
pass
|
||||
#if state not in STATES_IMMOBILE and Input.is_action_just_pressed("shoot"):
|
||||
#state = States.SHOOT
|
||||
#match global.save.projectile:
|
||||
#global.save.Projectile.BLAST:
|
||||
#pass
|
||||
|
||||
# Ragdoll
|
||||
if state not in [States.RAGDOLL, States.BOUNCE, States.LAY] and Input.is_action_just_pressed("ragdoll"):
|
||||
@@ -139,14 +145,14 @@ func _physics_process(delta):
|
||||
if state == States.ROLL and sprite.frame > 7:
|
||||
# Slow down if in the later roll frames.
|
||||
velocity.x = move_toward(velocity.x, 0, ROLL_DECEL * delta)
|
||||
elif state not in [States.ROLL, States.DAMAGE, States.RAGDOLL, States.BOUNCE, States.LAY, States.SHOOT, States.MELEE]:
|
||||
elif state not in STATES_IMMOBILE:
|
||||
# Apply velocity changes if not in a restricted movement state.
|
||||
velocity.x = move_toward(velocity.x, direction * SPEED, ACCEL * delta)
|
||||
if direction:
|
||||
if state not in [States.JUMP_START, States.JUMP, States.FALL, States.RUN_START, States.RUN]:
|
||||
if state not in STATES_MOVEMENT:
|
||||
state = States.RUN_START
|
||||
else:
|
||||
if state not in [States.JUMP_START, States.JUMP, States.FALL, States.LAND]:
|
||||
if state not in (STATES_AIRBORNE + [States.LAND]):
|
||||
state = States.IDLE
|
||||
|
||||
move_and_slide()
|
||||
|
||||
Reference in New Issue
Block a user