@@ -28,14 +28,12 @@ public class MainActivity extends AppCompatActivity {
28
28
29
29
private boolean isGameStarted = false ;
30
30
31
- // private final ArrayList<Integer> backgrounds = new ArrayList<>();
31
+ private final ArrayList <Integer > backgrounds = new ArrayList <>();
32
32
33
- private final ArrayList <Integer > colors = new ArrayList <>();
34
33
private int selectedBackgroundNumber = 0 ;
35
34
36
35
private void changeBackground (int index ){
37
- binding .backgroundOfActivity .setBackgroundColor (colors .get (index ));
38
- // binding.backgroundOfActivity.setBackgroundResource(backgrounds.get(index));
36
+ binding .backgroundOfActivity .setBackgroundResource (backgrounds .get (index ));
39
37
}
40
38
41
39
private int score = 0 ;
@@ -59,8 +57,6 @@ private enum Directions{
59
57
DOWN_RIGHT ,
60
58
LEFT ,
61
59
RIGHT ,
62
- CEILING ,
63
- BOTTOM
64
60
}
65
61
66
62
private final DisplayMetrics metrics = new DisplayMetrics ();
@@ -83,25 +79,25 @@ private int getRandom(int from , int to){
83
79
private Directions getCurrentDirection () {
84
80
85
81
if (velocity > 0 && horizontalVelocity >= 0 ){
86
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .up_right )); //***
82
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .left_up )); //***
87
83
return Directions .UP_RIGHT ;
88
84
}else if (velocity < 0 && horizontalVelocity >= 0 ){
89
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .down_right )); //***
85
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .right_down )); //***
90
86
return Directions .DOWN_RIGHT ;
91
87
}else if (velocity < 0 && horizontalVelocity <= 0 ){
92
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .down_left )); //***
88
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .left_down )); //***
93
89
return Directions .DOWN_LEFT ;
94
90
}else if (velocity > 0 && horizontalVelocity <= 0 ){
95
91
//THIS IS JUST ON THE LEFT DIRECTION.!!
96
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .up_left )); //***
92
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .right_up )); //***
97
93
return Directions .UP_LEFT ;
98
94
}else {
99
95
//velocity == 0
100
96
if (horizontalVelocity <= 0 ){
101
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .up_left ));
97
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .left ));
102
98
return Directions .LEFT ;
103
99
}else {
104
- binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .up_right ));
100
+ binding .movingObject .setImageDrawable ( ContextCompat .getDrawable (this ,R .drawable .right ));
105
101
return Directions .RIGHT ;
106
102
}
107
103
}
@@ -143,16 +139,15 @@ public void run() {
143
139
}else {
144
140
if (targetY > getScreenHeight ){
145
141
146
- currentDirection = Directions . BOTTOM ;
147
- binding .movingObject .setImageDrawable (ContextCompat .getDrawable (MainActivity .this ,R .drawable .up_right ));
142
+
143
+ binding .movingObject .setImageDrawable (ContextCompat .getDrawable (MainActivity .this ,R .drawable .right_up ));
148
144
149
145
binding .movingObject .setY (getScreenHeight - 1f );
150
146
velocity = getRandom (getScreenHeight /50 ,getScreenHeight /35 );
151
147
152
148
}else if (targetY < 0 ){
153
149
154
- currentDirection = Directions .CEILING ;
155
- binding .movingObject .setImageDrawable (ContextCompat .getDrawable (MainActivity .this ,R .drawable .up_left ));
150
+ binding .movingObject .setImageDrawable (ContextCompat .getDrawable (MainActivity .this ,R .drawable .left_up ));
156
151
157
152
binding .movingObject .setY (0.1f );
158
153
velocity = - getRandom (getScreenHeight /50 ,getScreenHeight /35 );
@@ -181,23 +176,12 @@ private void theWayOfMovement() {
181
176
//INITILIZATION PROCESS
182
177
private void definition (){
183
178
184
- colors .add (ContextCompat .getColor (this ,R .color .first_bg_color ));
185
- colors .add (ContextCompat .getColor (this ,R .color .second_bg_color ));
186
- colors .add (ContextCompat .getColor (this ,R .color .third_bg_color ));
187
- colors .add (ContextCompat .getColor (this ,R .color .fourth_bg_color ));
188
179
189
- /*
190
180
backgrounds .add (R .drawable .background1 );
191
181
backgrounds .add (R .drawable .background2 );
192
182
backgrounds .add (R .drawable .background3 );
193
183
backgrounds .add (R .drawable .background4 );
194
184
backgrounds .add (R .drawable .background5 );
195
- backgrounds.add(R.drawable.background6);
196
- backgrounds.add(R.drawable.background7);
197
- backgrounds.add(R.drawable.background8);
198
- backgrounds.add(R.drawable.background9);
199
- */
200
-
201
185
202
186
getWindowManager ().getDefaultDisplay ().getMetrics (metrics );
203
187
@@ -219,7 +203,7 @@ private void definition(){
219
203
binding .startGameButton .setOnClickListener (new View .OnClickListener () {
220
204
@ Override
221
205
public void onClick (View view ) {
222
- startGame (30 );
206
+ startGame (60 );
223
207
}
224
208
});
225
209
@@ -236,7 +220,7 @@ public void onClick(View view) {
236
220
if (selectedBackgroundNumber > 0 ){
237
221
selectedBackgroundNumber --;
238
222
}else {
239
- selectedBackgroundNumber = colors .size () - 1 ;
223
+ selectedBackgroundNumber = backgrounds .size () - 1 ;
240
224
}
241
225
changeBackground (selectedBackgroundNumber );
242
226
}
@@ -245,7 +229,7 @@ public void onClick(View view) {
245
229
binding .arrowRightButton .setOnClickListener (new View .OnClickListener () {
246
230
@ Override
247
231
public void onClick (View view ) {
248
- if (selectedBackgroundNumber < colors .size () - 1 ){
232
+ if (selectedBackgroundNumber < backgrounds .size () - 1 ){
249
233
selectedBackgroundNumber ++;
250
234
}else {
251
235
selectedBackgroundNumber = 0 ;
0 commit comments