-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.java
89 lines (74 loc) · 2.33 KB
/
Pipe.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
package com.example.android.nextgame;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.util.Log;
import java.util.ArrayList;
import java.util.Random;
import static java.lang.StrictMath.abs;
/**
* Created by Vamsi Karnika on 7/1/2017.
*/
public class Pipe {
boolean clipped = false;
private int block_size = 5;
private int blocks;
int xClip;
int heightTop;
float length ;
int heightBot;
Bitmap bitmap;
Bitmap reveresed;
private int screenWidth;
private int screenHeight;
int width = 10;
int gap = 14;
float speedY = 1;
private float shiftY = 0;
private int PixelsperMetreX;
private int PixelsperMetreY;
float s;
Pipe(Context context,String bitmapname,int screenX,int screenY,float speed){
PixelsperMetreX = screenX / 90;
PixelsperMetreY = screenY / 55;
screenWidth = screenX;
screenHeight = screenY;
s = speed;
int resid = context.getResources().getIdentifier(bitmapname,"drawable",context.getPackageName());
bitmap = BitmapFactory.decodeResource(context.getResources(),resid);
xClip = screenX;
blocks = 5;
Random rand = new Random();
length = random();
length = length*PixelsperMetreY;
heightTop = blocks*block_size*PixelsperMetreY;
width = width*PixelsperMetreX;
bitmap = Bitmap.createScaledBitmap(bitmap,width,heightTop,true);
Matrix matrix = new Matrix();
matrix.setScale(1,-1);
blocks = 5;
gap = gap*PixelsperMetreY;
heightBot = blocks*block_size*PixelsperMetreY;
reveresed = Bitmap.createBitmap(bitmap,0,0,width,heightBot,matrix,true);
}
public void update(long fps){
xClip -= s/fps;
if(xClip + width <= 0 ){
clipped = true;
}
/*shiftY -= speedY/fps;
length += shiftY;
Log.d("Android",String.valueOf(speedY));
if(abs(shiftY) >= 3 || (length <=0 || length >= screenHeight)){
//Log.d("Android",String.valueOf(shiftY));
speedY = -1*speedY;
shiftY = 0;
}*/
}
private int random(){
Random rand = new Random();
int result = (rand.nextInt(5)+1)*5;
return result;
}
}