summaryrefslogtreecommitdiff
path: root/Characters/Character.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Characters/Character.gd')
-rw-r--r--Characters/Character.gd68
1 files changed, 37 insertions, 31 deletions
diff --git a/Characters/Character.gd b/Characters/Character.gd
index 175094d..53260f2 100644
--- a/Characters/Character.gd
+++ b/Characters/Character.gd
@@ -1,11 +1,13 @@
-extends KinematicBody2D
+extends CharacterBody2D
-const SPEED = 130
+const SPEED = 450
const JUMPFORCE = -500
const GRAVITY = 20
+const RUNSPEED = SPEED * 2
+const WALLJUMPFORCE = JUMPFORCE * 0.75
+const WALLJUMPSPEED = SPEED * 10
-var velocity = Vector2()
var direction = Enum.DIRECTION.RIGHT
var canDoubleJump = false
@@ -13,45 +15,45 @@ var hasPlayedFallStop = false
var jumpHeightModifier = 0
-func _physics_process(_delta):
+func _physics_process(delta):
if Input.is_action_pressed("DIRECTION_LEFT"):
velocity.x = -SPEED
direction = Enum.DIRECTION.LEFT
- $Sprite.flip_h = true
+ $Sprite2D.flip_h = true
if self.is_running():
- velocity.x *= 2
- $Sprite.play("run")
- else:
- $Sprite.play("walk")
+ velocity.x = -RUNSPEED
elif Input.is_action_pressed("DIRECTION_RIGHT"):
velocity.x = SPEED
direction = Enum.DIRECTION.RIGHT
- $Sprite.flip_h = false
+ $Sprite2D.flip_h = false
if self.is_running():
- velocity.x *= 2
- $Sprite.play("run")
- else:
- $Sprite.play("walk")
- else:
- $Sprite.play("idle")
+ velocity.x = RUNSPEED
+
+ set_up_direction(Vector2.UP)
-
- velocity = move_and_slide(velocity, Vector2.UP)
+ if is_on_floor():
+ if Input.is_action_pressed("DIRECTION_LEFT") or Input.is_action_pressed("DIRECTION_RIGHT"):
+ if self.is_running():
+ $Sprite2D.play("run")
+ else:
+ $Sprite2D.play("walk")
+ else:
+ $Sprite2D.play("idle")
# jump and fall animation
if not is_on_floor():
- $Sprite.play("jump")
+ $Sprite2D.play("jump")
if has_node("CheckFallStop"):
if velocity.y > -JUMPFORCE:
$CheckFallLanding.set_enabled(true)
$CheckFallStop.set_enabled(true)
if $CheckFallLanding.is_colliding():
- $Sprite.play("fall_stop_landing")
+ $Sprite2D.play("fall_stop_landing")
elif $CheckFallStop.is_colliding():
- $Sprite.play("fall_stop")
+ $Sprite2D.play("fall_stop")
else:
- $Sprite.play("fall")
+ $Sprite2D.play("fall")
else:
$CheckFallLanding.set_enabled(false)
$CheckFallStop.set_enabled(true)
@@ -80,28 +82,32 @@ func _physics_process(_delta):
if is_on_wall():
velocity.y *= 0.8
- $Sprite.play("wall")
+ $Sprite2D.play("wall")
if Input.is_action_just_pressed("JUMP"):
- velocity.y = JUMPFORCE * 0.75
+ velocity.y = WALLJUMPFORCE
if direction == Enum.DIRECTION.LEFT:
- Input.action_release("DIRECTION_LEFT")
- velocity.x = 2000
- $Sprite.flip_h = false
+ velocity.x = WALLJUMPSPEED
+ $Sprite2D.flip_h = false
elif direction == Enum.DIRECTION.RIGHT:
- Input.action_release("DIRECTION_RIGHT")
- velocity.x = -2000
- $Sprite.flip_h = true
+ velocity.x = -WALLJUMPSPEED
+ $Sprite2D.flip_h = true
# stop
- velocity.x = lerp(velocity.x, 0, 0.7)
+ velocity = velocity.lerp(Vector2(0, velocity.y), 0.7)
+
+ move_and_slide()
func is_running():
return Input.is_action_pressed("RUN") and is_on_floor()
+func canWallJump():
+ return self.wallJumpGraceTimer < 0.1
+
+
func check_flag():
# $Sprite.play("dance anim")
print("FLAG CHECKED")