Skip to content

Commit f2e2d60

Browse files
authored
Merge pull request #92 from cbscribe/kcc_fixes
GDScript style fixes and other minor corrections
2 parents 49b0f87 + 4f6c514 commit f2e2d60

File tree

22 files changed

+237
-305
lines changed

22 files changed

+237
-305
lines changed

2d/hdr/beach_cave.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const CAVE_LIMIT = 1000
66

77

88
func _input(event):
9-
if (event is InputEventMouseMotion and event.button_mask&1):
9+
if event is InputEventMouseMotion and event.button_mask&1:
1010
var rel_x = event.relative.x
11-
var cavepos = get_node("cave").position
11+
var cavepos = $cave.position
1212
cavepos.x += rel_x
13-
if (cavepos.x < -CAVE_LIMIT):
13+
if cavepos.x < -CAVE_LIMIT:
1414
cavepos.x = -CAVE_LIMIT
15-
elif (cavepos.x > 0):
15+
elif cavepos.x > 0:
1616
cavepos.x = 0
17-
get_node("cave").position=cavepos
17+
$cave.position = cavepos

2d/hexagonal_map/troll.gd

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
21
extends KinematicBody2D
32

4-
# This is a simple collision demo showing how
5-
# the kinematic controller works.
6-
# move() will allow to move the node, and will
7-
# always move it to a non-colliding spot,
8-
# as long as it starts from a non-colliding spot too.
3+
# This is a demo showing how KinematicBody2D
4+
# move_and_slide works.
95

106
# Member variables
117
const MOTION_SPEED = 160 # Pixels/second
@@ -14,16 +10,15 @@ const MOTION_SPEED = 160 # Pixels/second
1410
func _physics_process(delta):
1511
var motion = Vector2()
1612

17-
if (Input.is_action_pressed("move_up")):
13+
if Input.is_action_pressed("move_up"):
1814
motion += Vector2(0, -1)
19-
if (Input.is_action_pressed("move_bottom")):
15+
if Input.is_action_pressed("move_bottom"):
2016
motion += Vector2(0, 1)
21-
if (Input.is_action_pressed("move_left")):
17+
if Input.is_action_pressed("move_left"):
2218
motion += Vector2(-1, 0)
23-
if (Input.is_action_pressed("move_right")):
19+
if Input.is_action_pressed("move_right"):
2420
motion += Vector2(1, 0)
2521

26-
motion = motion.normalized()*MOTION_SPEED
22+
motion = motion.normalized() * MOTION_SPEED
2723

2824
move_and_slide(motion)
29-

2d/isometric/troll.gd

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
21
extends KinematicBody2D
32

4-
# This is a simple collision demo showing how
5-
# the kinematic controller works.
6-
# move() will allow to move the node, and will
7-
# always move it to a non-colliding spot,
8-
# as long as it starts from a non-colliding spot too.
3+
# This is a demo showing how KinematicBody2D
4+
# move_and_slide works.
95

106
# Member variables
11-
const MOTION_SPEED = 160 # Pixels/seconds
7+
const MOTION_SPEED = 160 # Pixels/second
128

139

1410
func _physics_process(delta):
1511
var motion = Vector2()
1612

17-
if (Input.is_action_pressed("move_up")):
13+
if Input.is_action_pressed("move_up"):
1814
motion += Vector2(0, -1)
19-
if (Input.is_action_pressed("move_bottom")):
15+
if Input.is_action_pressed("move_bottom"):
2016
motion += Vector2(0, 1)
21-
if (Input.is_action_pressed("move_left")):
17+
if Input.is_action_pressed("move_left"):
2218
motion += Vector2(-1, 0)
23-
if (Input.is_action_pressed("move_right")):
19+
if Input.is_action_pressed("move_right"):
2420
motion += Vector2(1, 0)
2521

26-
motion = motion.normalized()*MOTION_SPEED
27-
# Make character slide nicely through the world
28-
move_and_slide( motion )
22+
motion = motion.normalized() * MOTION_SPEED
2923

24+
move_and_slide(motion)

2d/kinematic_character/colworld.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
extends Node2D
32

43

54
func _on_princess_body_enter(body):
65
# The name of this editor-generated callback is unfortunate
7-
if (body.get_name() == "player"):
8-
get_node("youwin").show()
6+
if body.get_name() == "player":
7+
$youwin.show()

2d/kinematic_character/player.gd

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
21
extends KinematicBody2D
32

4-
# This is a simple collision demo showing how
5-
# the kinematic controller works.
6-
# move() will allow to move the node, and will
7-
# always move it to a non-colliding spot,
8-
# as long as it starts from a non-colliding spot too.
3+
# This demo shows how to build a kinematic controller.
94

105
# Member variables
11-
const GRAVITY = 500.0 # Pixels/second
6+
const GRAVITY = 500.0 # pixels/second/second
127

138
# Angle in degrees towards either side that the player can consider "floor"
149
const FLOOR_ANGLE_TOLERANCE = 40
@@ -19,8 +14,8 @@ const STOP_FORCE = 1300
1914
const JUMP_SPEED = 200
2015
const JUMP_MAX_AIRBORNE_TIME = 0.2
2116

22-
const SLIDE_STOP_VELOCITY = 1.0 # One pixel per second
23-
const SLIDE_STOP_MIN_TRAVEL = 1.0 # One pixel
17+
const SLIDE_STOP_VELOCITY = 1.0 # one pixel/second
18+
const SLIDE_STOP_MIN_TRAVEL = 1.0 # one pixel
2419

2520
var velocity = Vector2()
2621
var on_air_time = 100
@@ -39,38 +34,38 @@ func _physics_process(delta):
3934

4035
var stop = true
4136

42-
if (walk_left):
43-
if (velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
37+
if walk_left:
38+
if velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED:
4439
force.x -= WALK_FORCE
4540
stop = false
46-
elif (walk_right):
47-
if (velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
41+
elif walk_right:
42+
if velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED:
4843
force.x += WALK_FORCE
4944
stop = false
5045

51-
if (stop):
46+
if stop:
5247
var vsign = sign(velocity.x)
5348
var vlen = abs(velocity.x)
5449

55-
vlen -= STOP_FORCE*delta
56-
if (vlen < 0):
50+
vlen -= STOP_FORCE * delta
51+
if vlen < 0:
5752
vlen = 0
5853

59-
velocity.x = vlen*vsign
54+
velocity.x = vlen * vsign
6055

6156
# Integrate forces to velocity
62-
velocity += force*delta
57+
velocity += force * delta
6358
# Integrate velocity into motion and move
64-
velocity = move_and_slide(velocity,Vector2(0,-1))
59+
velocity = move_and_slide(velocity, Vector2(0, -1))
6560

66-
if (is_on_floor()):
67-
on_air_time=0
61+
if is_on_floor():
62+
on_air_time = 0
6863

69-
if (jumping and velocity.y > 0):
64+
if jumping and velocity.y > 0:
7065
# If falling, no longer jumping
7166
jumping = false
7267

73-
if (on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping):
68+
if on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping:
7469
# Jump must also be allowed to happen if the character left the floor a little bit ago.
7570
# Makes controls more snappy.
7671
velocity.y = -JUMP_SPEED

2d/kinematic_collision/player.gd

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
21
extends KinematicBody2D
32

4-
# This is a simple collision demo showing how
5-
# the kinematic controller works.
6-
# move() will allow to move the node, and will
7-
# always move it to a non-colliding spot,
8-
# as long as it starts from a non-colliding spot too.
3+
# This is a demo showing how KinematicBody2D
4+
# move_and_slide works.
95

106
# Member variables
117
const MOTION_SPEED = 160 # Pixels/second
@@ -14,14 +10,15 @@ const MOTION_SPEED = 160 # Pixels/second
1410
func _physics_process(delta):
1511
var motion = Vector2()
1612

17-
if (Input.is_action_pressed("move_up")):
13+
if Input.is_action_pressed("move_up"):
1814
motion += Vector2(0, -1)
19-
if (Input.is_action_pressed("move_bottom")):
15+
if Input.is_action_pressed("move_bottom"):
2016
motion += Vector2(0, 1)
21-
if (Input.is_action_pressed("move_left")):
17+
if Input.is_action_pressed("move_left"):
2218
motion += Vector2(-1, 0)
23-
if (Input.is_action_pressed("move_right")):
19+
if Input.is_action_pressed("move_right"):
2420
motion += Vector2(1, 0)
2521

26-
motion = motion.normalized()*MOTION_SPEED
22+
motion = motion.normalized() * MOTION_SPEED
23+
2724
move_and_slide(motion)

2d/navigation/navigation.gd

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extends Navigation2D
32

43
# Member variables
@@ -10,23 +9,23 @@ var path = []
109

1110

1211
func _process(delta):
13-
if (path.size() > 1):
14-
var to_walk = delta*SPEED
15-
while(to_walk > 0 and path.size() >= 2):
12+
if path.size() > 1:
13+
var to_walk = delta * SPEED
14+
while to_walk > 0 and path.size() >= 2:
1615
var pfrom = path[path.size() - 1]
1716
var pto = path[path.size() - 2]
1817
var d = pfrom.distance_to(pto)
19-
if (d <= to_walk):
18+
if d <= to_walk:
2019
path.remove(path.size() - 1)
2120
to_walk -= d
2221
else:
2322
path[path.size() - 1] = pfrom.linear_interpolate(pto, to_walk/d)
2423
to_walk = 0
2524

2625
var atpos = path[path.size() - 1]
27-
get_node("agent").position=atpos
26+
$agent.position = atpos
2827

29-
if (path.size() < 2):
28+
if path.size() < 2:
3029
path = []
3130
set_process(false)
3231
else:
@@ -35,16 +34,15 @@ func _process(delta):
3534

3635
func _update_path():
3736
var p = get_simple_path(begin, end, true)
38-
path = Array(p) # Vector2array too complex to use, convert to regular array
37+
path = Array(p) # PoolVector2Array too complex to use, convert to regular array
3938
path.invert()
4039

4140
set_process(true)
4241

4342

4443
func _input(event):
45-
if (event is InputEventMouseButton and event.pressed and event.button_index == 1):
46-
begin = get_node("agent").position
44+
if event is InputEventMouseButton and event.pressed and event.button_index == 1:
45+
begin = $agent.position
4746
# Mouse to local navigation coordinates
4847
end = event.position - position
4948
_update_path()
50-

2d/physics_platformer/bullet.gd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
21
extends RigidBody2D
32

43
# Member variables
54
var disabled = false
65

76

87
func disable():
9-
if (disabled):
8+
if disabled:
109
return
11-
get_node("anim").play("shutdown")
10+
$anim.play("shutdown")
1211
disabled = true
1312

1413

1514
func _ready():
16-
get_node("Timer").start()
15+
$Timer.start()

2d/physics_platformer/coin.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
extends Area2D
32

43
# Member variables
54
var taken = false
65

76

87
func _on_body_enter( body ):
9-
if (not taken and body is preload("res://player.gd")):
10-
get_node("anim").play("taken")
8+
if not taken and body is preload("res://player.gd"):
9+
$anim.play("taken")
1110
taken = true
1211

1312

0 commit comments

Comments
 (0)