Procházet zdrojové kódy

Memorize direction for crash guard

When there is a wall blocking rotation, auto enable rotation when there
is a hole in the desired side.
DricomDragon před 5 roky
rodič
revize
dfb12357dd
1 změnil soubory, kde provedl 15 přidání a 10 odebrání
  1. 15 10
      Player.gd

+ 15 - 10
Player.gd

@@ -82,33 +82,38 @@ func generate_wall():
 	grid.set_cell(posix - dirx, posiy - diry, 1)
 
 func turn(left_or_right:int):
-	var current_angle = dire * 90
+	var current_angle = (dire + dire_delta) * 90
+
+	dire_delta += left_or_right
+	if dire_delta > Side.RIGHT:
+		dire_delta = Side.RIGHT
+		return
+	elif dire_delta < Side.LEFT:
+		dire_delta = Side.LEFT
+		return
+
 	var aim_angle = current_angle + 90 * left_or_right
 
 	tween.rotate_char(self, current_angle, aim_angle)
 	tween.start()
 
-	dire_delta = left_or_right
-
 func move():
 	if !alive:
 		return
 
 	generate_wall()
 
-	if dire_delta == Side.LEFT and !has_block_on(Side.LEFT):
+	if dire_delta != 0 and !has_block_on(dire_delta):
 		# TODO Undo sprite turn if blocked
 		dire += dire_delta
+		dire_delta = 0
+
 		if dire < 0:
 			dire = 3
-
-	elif dire_delta == Side.RIGHT and !has_block_on(Side.RIGHT):
-		dire += dire_delta
-		if dire > 3:
+		elif dire > 3:
 			dire = 0
 
-	update_dirxy()
-	dire_delta = 0
+		update_dirxy()
 
 	posix += dirx
 	posiy += diry