After flappy bird scratch at previous post, we
will add more two bars to increase the difficulty.
Declare
one more variable name xbar34
Initial
two new bars.
bar3 = BitmapFactory.decodeResource(getResources(), R.drawable.kb);
bar4 = BitmapFactory.decodeResource(getResources(), R.drawable.kb);
Set their position next to old bars 200dp.
xbar34 = r+200;
We draw them near top edge to make them not straight with first
gap.
canvas.drawBitmap(bar3, xbar34, -40, null);
canvas.drawBitmap(bar4, xbar34, 320, null);
Make rect touch to get hit.
Rect touch3 = new Rect(xbar34, 0, xbar34 + bar.getWidth(),
bar.getHeight()-40);
Rect touch4 = new Rect(xbar34, 320, xbar34 + bar.getWidth(),
320
+ bar.getHeight());
Make the new bars run.
xbar34 = xbar34 - 7;
Make them return when go to left edge.
if (xbar34 < -bar.getWidth()) {
xbar34 = r;
}
In case MotionEvent.ACTION_DOWN: set position xthanh34 when game start
xbar34 = r+200;
Run to make sure we have two more bars run.
Add
these lines to get hit of bird and new bars.
if (Rect.intersects(touch, touch3)) {
hit = true;
soundPool.play(bump, 0.9f, 0.1f, 1, 0, 0.7f);
}
if (Rect.intersects(touch, touch4)) {
hit = true;
soundPool.play(bump, 0.9f, 0.1f, 1, 0, 0.7f);
}
Declare
one more variable xcount2 to count number times bird fly through second gap.
xcount2 = xbar34 - 200 + bar.getWidth() + bird.getWidth();
Add above
line in if (xbar34 < -bar.getWidth()) { to make it return and in case MotionEvent.ACTION_DOWN: to start game again.
Add this
lien to make it run parellel with bars.
xdem2 = xdem2 - 7;
Add this
lines to count number times bird fly through gap 2.
if (xdem2 < 0) {
xdem2 = r;
dem = dem + 1;
}
It’s done
now, we have second gap at higher position.
To add
three gap, you can do the same.
No comments:
Post a Comment