summaryrefslogtreecommitdiffstats
path: root/ps_forced.gd
blob: 4c4c3dcf2de766b186718a7983dbdfa796893d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class_name PlayerStateForced
extends PlayerState

var input_x: float
var jump_coef = 1.3

func initialize(p: Player, dir: String):
	if dir == "LEFT":
		input_x = -1.0
	elif dir == "JUMP_LEFT":
		p.velocity.y = -jump_coef * p.jump_strength
		input_x = -1.0
	elif dir == "RIGHT":
		input_x = 1.0
	elif dir == "JUMP_RIGHT":
		p.velocity.y = -jump_coef * p.jump_strength
		input_x = 1.0
	elif dir == "JUMP":
		p.velocity.y = -p.jump_strength
		input_x = 0.0
		p.gravity = 0.0
	elif dir == "DROP":
		input_x = 0.0

func _handle(p: Player, _delta: float):
	var as2d = p.get_node("AnimatedSprite2D")
	if p.velocity.x > 0:
		as2d.flip_h = false
	elif p.velocity.x < 0:
		as2d.flip_h = true
	
	if not p.is_on_floor():
		as2d.set_animation("jump")
	elif abs(p.velocity.x) > 0.0:
		as2d.set_animation("walk")
	else:
		as2d.set_animation("idle")

func _handle_physics(p: Player, delta: float):
	p.velocity.y += p.gravity * delta
	if p.velocity.y > p.jump_strength:
		p.velocity.y = p.jump_strength

	p.velocity.x = input_x * p.speed

	p.move_and_slide()