-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShip.java
More file actions
196 lines (150 loc) · 4.61 KB
/
Ship.java
File metadata and controls
196 lines (150 loc) · 4.61 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.thrus.test;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public class Ship {
Sprite shipSprite;
Redemption redemption;
float w = Cnst.width;
float h = Cnst.height;
public float maxSpeed,accn,dccn,accTimer,rotSpeed,rad,dx,dy,x,y,spw=0,sph=0,pointRad;
public boolean up,down,left,right,isTouched;
thrust th;
newThrust nth;
float thrustVel;
public Ship(Redemption re){
// maxSpeed = 25;
accn = 1000;
dccn = 200;
rad = 3.1415f/2f;
rotSpeed = 4;
x = w/2;
y=h/2;
this.redemption = re;
th=new thrust(redemption);
nth=new newThrust();
shipSprite = new Sprite(redemption.loader.shipTex);
spw = shipSprite.getWidth()/2;
sph = shipSprite.getHeight()/2;
shipSprite.setScale(1/3f);
}
public void phy(float dt)
{
maxSpeed=1000f*pointRad;
if(isTouched){
dx+=MathUtils.cosDeg(shipSprite.getRotation()+90)*accn*dt;
dy+=MathUtils.sinDeg(shipSprite.getRotation()+90)*accn*dt;
thrustVel=pointRad*10;
//10f+((float) Math.sqrt(dx*dx + dy*dy)/50f);
}
else{thrustVel=0;}
//MathUtils.lerp(thrustVel,0,10*dt);}
float vec = (float) Math.sqrt(dx*dx + dy*dy);
if (vec>maxSpeed){
dx= (dx/vec)*maxSpeed;
dy= (dy/vec)*maxSpeed;
}
if (vec>0){
dx-=(dx/vec)*dccn*dt;
dy-=(dy/vec)*dccn*dt;
}
x+=dx*dt;
y+=dy*dt;
nth.setVel(thrustVel);
nth.setPoints(x,y,shipSprite.getRotation());
nth.update(1/60f);
shipSprite.setPosition(x-spw,y-sph);
// wrap();
}
public void move(float touchpadX, float touchpadY,boolean t) {
isTouched=t;
nth.moo(true);
// x = x+(touchpadX * maxSpeed);
// y =( y+(touchpadY * maxSpeed) );
pointRad=(float)Math.sqrt(Math.pow(touchpadX,2)+Math.pow(touchpadY,2));
//nth.setVel((float)Math.sqrt(Math.pow(touchpadX,2)+Math.pow(touchpadY,2)));
if (touchpadX != 0 && touchpadY != 0) {
//nth.moo(true);
float rotation = (float) Math.atan2(touchpadX, -touchpadY) * MathUtils.radiansToDegrees;
shipSprite.setRotation(rotation-180);
}
}
public float getX() {
return x-spw;
}
public float getY() {
return y-sph;
}
public void setLeft(boolean left) {
this.left = left;
}
public void setRight(boolean right) {
this.right = right;
}
public void setUp(boolean up) {
this.up = up;
}
public void drth(ShaderProgram s){
th.createThrust(s);
}
public void drawthrust(ShaderProgram s){
nth.drawThrust(s);
}
public void draw(SpriteBatch batch){
shipSprite.draw(batch);
// System.out.println(shipSprite.getRotation());
// Gdx.app.log("ang",);
}
public void update(float dt){
// th.setX(x);
// th.setY(y);
// if(left){
// rad+=rotSpeed*dt;
// } else if (right) {
// rad -=rotSpeed*dt;
// }
// if(up){
// nth.moo(true);
// dx+= MathUtils.cos(rad)*accn*dt;
// dy+= MathUtils.sin(rad)*accn*dt;
// accTimer+=dt;
// if (accTimer>0.1f){
// accTimer=0f;
// }
// } else {
// nth.moo(false);
// accTimer=0f;
// }
// //deccn
// float vec = (float) Math.sqrt(dx*dx + dy*dy);
// if (vec>0){
// dx-=(dx/vec)*dccn*dt;
// dy-=(dy/vec)*dccn*dt;
// }
// if (vec>maxSpeed){
// dx= (dx/vec)*maxSpeed;
// dy= (dy/vec)*maxSpeed;
// }
// //setpos
// x+=dx*dt;
// y+=dy*dt;
// shipSprite.setPosition(x-spw,y-sph);
// shipSprite.setRotation((MathUtils.radiansToDegrees*rad)-90);
// th.update(this.x,this.y,shipSprite.getRotation());
}
public float vx(){
return dx;
}
public float vy(){
return dy;
}
private void wrap() {
if (x<0) x = w;
if (x>w) x=0;
if (y<0) y=h;
if (y>h) y=0;
}
}