-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
144 lines (125 loc) · 3.29 KB
/
Copy pathPlayer.java
File metadata and controls
144 lines (125 loc) · 3.29 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.lud.root.jetfighter;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.util.Log;
public class Player {
private Bitmap bitmap;
//coordinates
private int x;
private int y;
private float speed ;
private boolean slowing, goingDown;
private int GRAVITY = -10; // For the gravity effect on the ship
//Boundaries
private int maxY;
private int minY;
private int screenY;
private float radius;
private final float MINRADIUS = 30;
private final float MAXRADIUS = 100;
private final int POSGRAVITY = +10;
private final int NEGGRAVITY = -10;
private final int SLOWPOSGRAVITY = +4;
private final int SLOWNEGGRAVITY = -4;
public Player(Context context, int screenX, int screenY){
x = 30; //initial x-position
y = 50; //initial y-position
speed = -4;
radius = MINRADIUS;
maxY = screenY - 30;
this.screenY = screenY;
minY = 30; //equal to initial radius
slowing = false; //initially slowing is false
goingDown = true;
}
public void startSlowing(){
slowing = true;
if(radius > MAXRADIUS)
radius = MAXRADIUS;
else radius += 1.5f;
if(goingDown)
{
speed = -0.3f;
GRAVITY = SLOWNEGGRAVITY;
}
else{
speed = 0.3f;
GRAVITY = SLOWPOSGRAVITY;
}
}
public void stopSlowing(){
slowing = false;
if(goingDown)
{
speed = -4.0f;
GRAVITY = NEGGRAVITY;
}
else{
speed = 4.0f;
GRAVITY = POSGRAVITY;
}
}
public void update(){
minY = (int) getRadius();
maxY = screenY - (int) getRadius();
if(!slowing)
if(radius < MINRADIUS)
radius = MINRADIUS;
else radius -= 0.5f;
if(slowing)
if(radius > MAXRADIUS)
radius = MAXRADIUS;
else radius += 0.5f;
// Moving the ball down
y -= speed + GRAVITY;
if(y < minY)
{
y = minY;
if(slowing)
{
speed = -0.3f;
GRAVITY = SLOWNEGGRAVITY;
}
else
{
speed = -4;
GRAVITY = NEGGRAVITY;
}
goingDown = true;
Log.d("down","Gravity : "+ GRAVITY + " Speed : "+speed+" y : "+y+" goingDown : "+goingDown);
}
if( y > maxY)
{
y = maxY;
if(slowing)
{
speed = 0.3f;
GRAVITY = SLOWPOSGRAVITY;
}
else
{
speed = 4;
GRAVITY = POSGRAVITY;
}
goingDown = false;
Log.d("down","Gravity : "+ GRAVITY + " Speed : "+speed+" y : "+y+" goingDown : "+goingDown);
}
}
public float getSpeed() {
return speed;
}
public int getY() {
return y;
}
public int getX() {
return (int) (getRadius());
}
public void setX(int x) {
this.x = x;
}
public float getRadius() {
return radius;
}
}