-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBird.java
121 lines (88 loc) · 2.57 KB
/
Bird.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.example.android.nextgame;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.PointF;
import android.util.Log;
/**
* Created by Vamsi Karnika on 6/30/2017.
*/
public class Bird {
private Point a;
private Point b;
private Point c;
private Point d;
private Point centre;
private int length = 5;
private int PixelsperMetreX ;
private int PixelsPerMetreY;
int sideX;
int sideY;
private int y;
Bitmap bitmap ;
int Bird_width ;
int Bird_height;
private float speed = 0;
private int gravity = 40;
Bird(Context context,String bitmapname,int screenX,int screenY){
PixelsperMetreX = screenX/90;
PixelsPerMetreY = screenY/55;
sideX = length*PixelsperMetreX;
sideY = length*PixelsPerMetreY;
gravity = PixelsPerMetreY*gravity;
y = screenY;
a = new Point();
b = new Point();
c = new Point();
d = new Point();
centre = new Point();
Log.d("Android:","In the bird");
centre.x = screenX/2;
centre.y = screenY/4;
a.x = centre.x - (sideX)/2;
a.y = centre.y + (sideY)/2;
b.x = centre.x + (sideX)/2;
b.y = centre.y + (sideY )/2;
c.x = centre.x + (sideX)/2;
c.y = centre.y - (sideY)/2;
d.x = centre.x - (sideX)/2;
d.y = centre.y - (sideY)/2;
int resId = context.getResources().getIdentifier(bitmapname,"drawable",context.getPackageName());
bitmap = BitmapFactory.decodeResource(context.getResources(),resId);
bitmap = Bitmap.createScaledBitmap(bitmap,sideX,sideY,true);
Bird_width = bitmap.getWidth();
Bird_height = bitmap.getHeight();
}
public Point getA(){
return a;
}
public Point getB(){
return b;
}
public Point getC(){
return c;
}
public Point getD(){
return d;
}
public void update(long fps){
speed = speed + gravity/fps;
centre.y += speed / fps;
if(centre.y - (sideY)/2 <= 0 ){
centre.y = sideY*3/4;
speed = 0;
}
a.x = centre.x - (sideX)/2;
a.y = centre.y + (sideY)/2;
b.x = centre.x + (sideX)/2;
b.y = centre.y + (sideY )/2;
c.x = centre.x + (sideX)/2;
c.y = centre.y - (sideY)/2;
d.x = centre.x - (sideX)/2;
d.y = centre.y - (sideY)/2;
}
public void onTouch(){
speed = -20*PixelsPerMetreY;
}
}