-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUD.java
More file actions
57 lines (45 loc) · 1.42 KB
/
HUD.java
File metadata and controls
57 lines (45 loc) · 1.42 KB
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
package com.example.android.nextgame;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
import java.util.ArrayList;
/**
* Created by Vamsi Karnika on 7/2/2017.
*/
public class HUD {
Rect left;
Rect right;
public ArrayList<Rect> currentButtonList = new ArrayList<>();
HUD(int screenWidth,int screenHeight){
Log.d("Android:","HUD");
int buttonWidth = screenWidth / 8;
int buttonHeight = screenHeight / 7;
int buttonPadding = screenWidth / 80;
left = new Rect(screenWidth/2-200,
screenHeight/2,
screenWidth/2-50,
screenHeight/2+buttonHeight);
right = new Rect(screenWidth/2+50,
screenHeight/2,
screenWidth/2+200,
screenHeight/2 + buttonHeight);
currentButtonList.add(left);
currentButtonList.add(right);
}
public int handleInput(MotionEvent motionEvent){
int x = (int)motionEvent.getX(0);
int y = (int)motionEvent.getY(0);
int action = 0;
switch(motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
if(right.contains(x,y)){
action = 2;
}
else if(left.contains(x,y)){
action = 1;
}
break;
}
return action;
}
}