18
18
import java .util .HashMap ;
19
19
20
20
import com .badlogic .gdx .math .Vector2 ;
21
+ import com .bladecoder .engine .util .EngineLogger ;
21
22
22
23
public class AnimationDesc {
23
24
public final static String BACK = "back" ;
@@ -28,44 +29,43 @@ public class AnimationDesc {
28
29
public final static String BACKLEFT = "backleft" ;
29
30
public final static String FRONTRIGHT = "frontright" ;
30
31
public final static String FRONTLEFT = "frontleft" ;
31
-
32
- public String id ;
33
- public String source ;
34
- public float duration ;
35
- public float delay ;
36
- public Vector2 inD ;
37
- public Vector2 outD ;
38
- public Tween .Type animationType ;
39
- public int count ;
40
-
32
+
33
+ public String id ;
34
+ public String source ;
35
+ public float duration ;
36
+ public float delay ;
37
+ public Vector2 inD ;
38
+ public Vector2 outD ;
39
+ public Tween .Type animationType ;
40
+ public int count ;
41
+
41
42
public String sound ;
42
-
43
+
43
44
public boolean preload ;
44
45
public boolean disposeWhenPlayed ;
45
-
46
+
46
47
public AnimationDesc () {
47
-
48
+
48
49
}
49
-
50
- public void set (String id , String source , float duration ,
51
- float delay , int count , Tween .Type animationType , String sound ,
52
- Vector2 inD , Vector2 outD , boolean preload , boolean disposeWhenPlayed ) {
50
+
51
+ public void set (String id , String source , float duration , float delay , int count , Tween .Type animationType ,
52
+ String sound , Vector2 inD , Vector2 outD , boolean preload , boolean disposeWhenPlayed ) {
53
53
this .id = id ;
54
54
this .duration = duration ;
55
55
this .delay = delay ;
56
56
this .animationType = animationType ;
57
57
this .count = count ;
58
-
58
+
59
59
this .source = source ;
60
60
this .sound = sound ;
61
-
61
+
62
62
this .inD = inD ;
63
63
this .outD = outD ;
64
-
64
+
65
65
this .preload = preload ;
66
66
this .disposeWhenPlayed = disposeWhenPlayed ;
67
67
}
68
-
68
+
69
69
public static String getFlipId (String id ) {
70
70
StringBuilder sb = new StringBuilder ();
71
71
@@ -79,15 +79,15 @@ public static String getFlipId(String id) {
79
79
80
80
return sb .toString ();
81
81
}
82
-
83
- private final static float DIRECTION_ASPECT_TOLERANCE = 2.5f ;
82
+
83
+ private final static float DIRECTION_ASPECT_TOLERANCE = 3f ;
84
84
private final static float DIRECTION_ASPECT_TOLERANCE_2 = 3f ;
85
85
86
86
public static String getDirectionString (Vector2 p0 , Vector2 pf , int numDirs ) {
87
-
88
- if (numDirs == 0 || numDirs == -1 )
87
+
88
+ if (numDirs == 0 || numDirs == -1 )
89
89
return null ;
90
-
90
+
91
91
float dx = pf .x - p0 .x ;
92
92
float dy = pf .y - p0 .y ;
93
93
float ratio = Math .abs (dx / dy );
@@ -96,11 +96,10 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
96
96
if (ratio2 < 1.0 )
97
97
ratio2 = 1.0f / ratio ;
98
98
99
- // EngineLogger.debug("P0: " + p0 + " PF: " + pf + " dx: " + dx +
100
- // " dy: "
101
- // + dy + " RATIO: " + ratio);
99
+ EngineLogger .debug ("P0: " + p0 + " PF: " + pf + " dx: " + dx + " dy: " + dy + " RATIO: " + ratio );
102
100
103
- if (ratio2 < DIRECTION_ASPECT_TOLERANCE && numDirs > 4 ) { // DIAGONAL MOVEMENT
101
+ if (ratio2 < DIRECTION_ASPECT_TOLERANCE && numDirs > 4 ) { // DIAGONAL
102
+ // MOVEMENT
104
103
if (dy > 0 ) { // UP. MOVEMENT
105
104
if (dx > 0 ) { // TO THE RIGHT
106
105
return BACKRIGHT ;
@@ -116,7 +115,8 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
116
115
}
117
116
}
118
117
} else { // HOR OR VERT MOVEMENT
119
- if (ratio > DIRECTION_ASPECT_TOLERANCE_2 || numDirs < 4 ) { // HOR. MOVEMENT
118
+ if (ratio > DIRECTION_ASPECT_TOLERANCE_2 || numDirs < 4 ) { // HOR.
119
+ // MOVEMENT
120
120
if (dx > 0 ) { // TO THE RIGHT
121
121
return RIGHT ;
122
122
} else { // TO THE LEFT
@@ -133,35 +133,35 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
133
133
}
134
134
}
135
135
136
-
137
136
/**
138
137
* Returns:
139
138
*
140
- * 8 -> when 8 dir animation mode (RIGHT, LEFT, FRONT, BACK, BACKRIGHT, BACKLEFT, FRONTRIGHT, FRONTLEFT)
141
- * 4 -> when 4 dir animation mode (RIGHT, LEFT, FRONT, BACK)
142
- * 2 -> when 2 dir animation mode (RIGHT, LEFT)
143
- * 0 -> when no dirs availables for the base animation
144
- * -1 -> when base animation doesn't exists
139
+ * 8 -> when 8 dir animation mode (RIGHT, LEFT, FRONT, BACK, BACKRIGHT,
140
+ * BACKLEFT, FRONTRIGHT, FRONTLEFT) 4 -> when 4 dir animation mode (RIGHT,
141
+ * LEFT, FRONT, BACK) 2 -> when 2 dir animation mode (RIGHT, LEFT) 0 -> when
142
+ * no dirs availables for the base animation -1 -> when base animation
143
+ * doesn't exists
145
144
*
146
- * @param base Base animation
145
+ * @param base
146
+ * Base animation
147
147
* @param fanims
148
148
* @return -1, 0, 2, 4 or 8
149
149
*/
150
150
public static int getDirs (String base , HashMap <String , AnimationDesc > fanims ) {
151
151
String basePoint = base + "." ;
152
-
153
- if (fanims .containsKey ( basePoint + FRONTRIGHT ) || fanims .containsKey (basePoint + FRONTLEFT ))
154
- return 8 ;
155
152
156
- if (fanims .containsKey ( basePoint + BACK ))
153
+ if (fanims .containsKey (basePoint + FRONTRIGHT ) || fanims .containsKey (basePoint + FRONTLEFT ))
154
+ return 8 ;
155
+
156
+ if (fanims .containsKey (basePoint + BACK ))
157
157
return 4 ;
158
-
159
- if (fanims .containsKey ( basePoint + LEFT ) || fanims .containsKey (basePoint + RIGHT ))
158
+
159
+ if (fanims .containsKey (basePoint + LEFT ) || fanims .containsKey (basePoint + RIGHT ))
160
160
return 2 ;
161
-
162
- if (fanims .containsKey (base ))
161
+
162
+ if (fanims .containsKey (base ))
163
163
return 0 ;
164
-
164
+
165
165
return -1 ;
166
- }
166
+ }
167
167
}
0 commit comments