Parcourir la source

Use enumerations for player direction

DricomDragon il y a 5 ans
Parent
commit
baa134e399
1 fichiers modifiés avec 10 ajouts et 8 suppressions
  1. 10 8
      Player.gd

+ 10 - 8
Player.gd

@@ -14,10 +14,12 @@ var cell_half_size
 var alive = true
 
 # Enum
-const DIR_UP = 0
-const DIR_RIGHT = 1
-const DIR_DOWN = 2
-const DIR_LEFT = 3
+enum Direction {
+	DIR_UP = 0
+	DIR_RIGHT = 1
+	DIR_DOWN = 2
+	DIR_LEFT = 3
+}
 
 # Movement
 var posix
@@ -25,7 +27,7 @@ var posiy
 var dirx = 0
 var diry = 0
 
-export var dire = DIR_UP
+export var dire = Direction.DIR_UP
 var dire_delta = 0
 
 var is_moving = false
@@ -104,11 +106,11 @@ func _on_crash(b):
 func turn(dir:int):
 	dirx = 0
 	diry = 0
-	if dir == DIR_UP:
+	if dir == Direction.DIR_UP:
 		diry -= 1
-	elif dir == DIR_RIGHT:
+	elif dir == Direction.DIR_RIGHT:
 		dirx += 1
-	elif dir == DIR_DOWN:
+	elif dir == Direction.DIR_DOWN:
 		diry += 1
 	else:
 		dirx -= 1