-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer1.gd
105 lines (84 loc) · 1.83 KB
/
Player1.gd
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
##var tm = 0
##onst GRAV = 14;
#const JUMP = 500 #230
#const SPEED = 200
#var dir = Vector2()
#
#func _physics_process(delta):
#
# if Input.is_action_pressed('ui_left'):
# dir.x = -1
# elif Input.is_action_pressed('ui_right'):
# dir.x = 1
# else:
# dir.x = 0
#
# if Input.is_action_just_pressed('ui_up'):
# dir.y = -1;
#
# else:
# dir.y = 0
#
#
# if Input.is_action_just_pressed('ui_down'):
# dir.y = 0.5;
#
#
# if dir.y:
# dir.y *= JUMP
# dir.y += 150;
#
# set_axis_velocity(dir)
# if dir.x:
# dir.x *= SPEED
# set_axis_velocity(dir)
#
extends "res://Character.gd"
# Grounded?
var grounded = false
# Jumping
var can_jump = false
var jump_time = 0
const TOP_JUMP_TIME = 0.1 # in seconds
# Start
func _ready():
# Set player properties
acceleration = 1000
top_move_speed = 200
top_jump_speed = 400
# Apply force
func apply_force(state):
# Move Left
if(Input.is_action_pressed("ui_left2")):
directional_force += DIRECTION.LEFT
# Move Right
if(Input.is_action_pressed("ui_right2")):
directional_force += DIRECTION.RIGHT
# Jump
if(Input.is_action_pressed("ui_up2") && jump_time < TOP_JUMP_TIME && can_jump):
directional_force += DIRECTION.UP
jump_time += state.get_step()
elif(Input.is_action_just_released("ui_up2")):
can_jump = false # Prevents the player from jumping more than once while in air
# Go down
if(Input.is_action_pressed("ui_down2")):
directional_force += DIRECTION.DOWN
# While on the ground
if(grounded):
can_jump = true
jump_time = 0
# Enter Ground
func _on_Player1_body_entered(body):
# Get groups
var groups = body.get_groups()
# If we are on a solid ground
if(groups.has("solid")):
grounded = true
# Exit Ground
# Get groups
func _on_Player1_body_exited(body):
# Get groups
var groups = body.get_groups()
# If we are on a solid ground
if(groups.has("solid")):
grounded = false