Skip to content

Commit

Permalink
🐛 Fix tail
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Oct 18, 2020
1 parent 40d5d63 commit 78e1960
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 106 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/sma/rhythmtapper/game/models/Ball.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public int getXfromT(float tt) {
return getXfromT(origx, endx, tt);
}

static final float alphaOfZ = 0.7f;//0.95f;
static final float alphaDepth = alphaOfZ * DEPTH;
public static final float alphaOfZ = 0.7f;//0.95f;
public static final float alphaDepth = alphaOfZ * DEPTH;

private void OnScreenMeasured() {
this.origx = (int) ((EnvVar.gameWidth * 0.8f / 5 / 2) * (2 * startLine - 1) + EnvVar.gameWidth * 0.1f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Paint(Graphics g) {
UpdateGhosts();
// }
if (ball1.alive)
g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y, Color.LTGRAY, (int) (40 * GameScreen.getSizeCoeff(ball1.t)));
g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y, Color.LTGRAY, (int) (50 * GameScreen.getSizeCoeff(ball1.t)));
/*if(ghost1y > EnvVar.HITBOX_CENTER && ghost2y <EnvVar.HITBOX_CENTER) {
int helperx = (GameScreen.HITBOX_CENTER - ghost1y) * (ghost2x - ghost1x) / (ghost2y - ghost1y) + ghost1x;
g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL)
Expand Down
255 changes: 152 additions & 103 deletions app/src/main/java/sma/rhythmtapper/game/models/Tail.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import sma.rhythmtapper.game.EnvVar;

import static sma.rhythmtapper.game.models.Ball.DEPTH;
import static sma.rhythmtapper.game.models.Ball.alphaDepth;

//ㅇㅁㅇㅁㅇㅁㅇㅁㅇ
public class Tail extends Connector {
private final boolean optimized;
private boolean created = false;
final int STROKE = 80;
final int STROKE = 60;

public Tail(Ball ball1, Ball ball2) {
super(ball1, ball2);
Expand All @@ -25,116 +26,164 @@ public Tail(Ball ball1, Ball ball2) {

final int numJoints = 6;

// @Override
// public void Paint(Graphics g) {
// //super.Paint(g);
// //각 관절마다 sizecoeff를 체크하여 그것을 넘지 못하면 그리지 않는다.
// //ball1과 ball2 사이를 보간하여 가상의 공들을 만들고 그 사이를 직선으로 잇는다.
// //ball1과 ball2 사이의 z들을 잘라서 그 z에 대해 좌표들을 계산하면 될 듯.
// int prevX, prevY;
// prevX = ball1.x;
// prevY = ball1.y;
// for (int k = 1; k < numJoints - 2; k++) {
// float alp = (float) k / (float) numJoints;
// float z = alp * ball1.z + (1 - alp) * ball2.z;
// int y;// = (int)(ball1.aOfZ*(z-Ball.alphaDepth)*(z-Ball.alphaDepth));
// //this.y = (int)(/*GameScreen.BALL_INITIAL_Y*/ EnvVar.HITBOX_CENTER+ ( EnvVar.currentTime-this.time)* EnvVar.speed *100);
// float t = 1 - ((float) z / DEPTH);//(float)EnvVar.HITBOX_CENTER;
// int x = (int) (alp * ball1.x + (1 - alp) * ball2.x);//Ball.getXfromT(ball2.x,0,t);
// y = (int) (alp * ball1.y + (1 - alp) * ball2.y);
// if (t < 0.3f || t > 1.0f)
// continue;
// g.drawLine(prevX, prevY, x, y, Color.WHITE, STROKE);
// prevX = x;
// prevY = y;
// }
// g.drawLine(prevX, prevY, ball2.x, ball2.y, Color.WHITE, STROKE);
//
//
//// UpdateGhosts();
////
//// if (path == null)
//// path = new Path();
// /*
// if (optimized) {
// if (!created) {
// // MakeTails();
// }
// //Draw optimized tail
// int prevx = 0, prevy = 0, prevz = 0;
// prevx = ghost2x;
// prevy = ghost2y;
// prevz = ball2.z;
//
// //path.moveTo(ghost2x, ghost2y);
// int dy = ghost1y - ghost2y;
// for (int y = ball2.z + EnvVar.speed; z < ball1.z; z += EnvVar.speed) {
// float tt = (ball1.t - ball2.t) / (ball1.z-ball2.z/*ghost1y - ghost2y* /) * (y - ghost1y) + ball1.t;
// int x = Ball.getXfromT(ball2.origx, ball1.endx, tt);
// g.drawLine(prevx, prevy, x, y, ball1.color, (int) (STROKE * GameScreen.getSizeCoeff(tt)));
// if (y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
// int helperx = (GameScreen.HITBOX_CENTER - y) * (prevx - x) / (prevy - y) + x;
// g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
// }
// prevx = x;
// prevy = y;
// }
// g.drawLine(prevx, prevy, ghost1x, ghost1y, ball1.color, STROKE);
// if (ghost1y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
// int helperx = (GameScreen.HITBOX_CENTER - ghost1y) * (prevx - ghost1x) / (prevy - ghost1y) + ghost1x;
// g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
// }
//
// //int starti = ghost2y
// //for(int i = starti; i < tailxs.length; i++) {
// // y += EnvVar.speed;
// // path.lineTo(tailxs[i], y);
// //}
// //path.close();
// //g.DrawPath(path);
// } else {
// //Create Dynamic tail
// //
// //path.reset();
// int prevx = 0, prevy = 0;
// prevx = ghost2x;
// prevy = ghost2y;
// int dy = ghost1y - ghost2y;
// for (int y = ghost2y + EnvVar.speed; y < ghost1y; y += EnvVar.speed) {
// float tt = (float) (y - ghost2y) / (float) (dy);
// float sizett = (ball1.t - ball2.t) / (ghost1y - ghost2y) * (y - ghost1y) + ball1.t;
// int x = Ball.getXfromTLinear(ghost2x, ghost1x, tt);
// g.drawLine(prevx, prevy, x, y, ball1.color, (int) (STROKE * GameScreen.getSizeCoeff(sizett)));
// if (y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
// int helperx = (GameScreen.HITBOX_CENTER - y) * (prevx - x) / (prevy - y) + x;
// g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
// }
// prevx = x;
// prevy = y;
// //path.lineTo(x,y);
// }
// g.drawLine(prevx, prevy, ghost1x, ghost1y, ball1.color, STROKE);
// if (ghost1y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
// int helperx = (GameScreen.HITBOX_CENTER - ghost1y) * (prevx - ghost1x) / (prevy - ghost1y) + ghost1x;
// g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
// }
//
// //path.lineTo(ghost1x,ghost1y);
// //path.close();
// //g.DrawPath(path);
// }
// int x = ghost2x;
// int y = ghost2y;
// //for(int i=0;i<tailxs.length;i++)
// {
// //x = tailxs[i];
// //y =
// }
// //g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y,ball1.color,40);
//
// return;
//
// */
// }

@Override
public void Paint(Graphics g) {
//super.Paint(g);
//각 관절마다 sizecoeff를 체크하여 그것을 넘지 못하면 그리지 않는다.
//ball1과 ball2 사이를 보간하여 가상의 공들을 만들고 그 사이를 직선으로 잇는다.
//ball1과 ball2 사이의 z들을 잘라서 그 z에 대해 좌표들을 계산하면 될 듯.
int prevX, prevY;
prevX = ball1.x;
prevY = ball1.y;
for (int k = 1; k < numJoints - 2; k++) {
float alp = (float) k / (float) numJoints;
float z = alp * ball1.z + (1 - alp) * ball2.z;
int y;// = (int)(ball1.aOfZ*(z-Ball.alphaDepth)*(z-Ball.alphaDepth));
//this.y = (int)(/*GameScreen.BALL_INITIAL_Y*/ EnvVar.HITBOX_CENTER+ ( EnvVar.currentTime-this.time)* EnvVar.speed *100);
float t = 1 - ((float) z / DEPTH);//(float)EnvVar.HITBOX_CENTER;
int x = (int) (alp * ball1.x + (1 - alp) * ball2.x);//Ball.getXfromT(ball2.x,0,t);
y = (int) (alp * ball1.y + (1 - alp) * ball2.y);
if (t < 0.3f || t > 1.0f)
float m1 = ball1.origx;
float n1 = ball1.endx;
float m2 = ball2.origx;
float n2 = ball2.endx;
float timeDelta = ball2.time - ball1.time;
final float dt = 0.05f;
float prevX = ball1.x;
float prevY = ball1.y;
// m1...n1
// ...
// m2...n2
// 사이를 일정 시간 간격으로 보간
// 가상의 ball 들을 만든다.
// 현재에 맞는 t들을 생성해야 한다.
// 먼저 이 가상 점들이 생성될 시간을 계산해야 한다.
float aOfZ = EnvVar.HITBOX_CENTER / (alphaDepth * alphaDepth);
float time;
for (time = ball1.time; time <= ball2.time; time += dt) {
// time : 가상 점들이 도착하는 시간
// m, n: 가상 점들의 시작점과 끝점
// t: 현재 시간에서 도착까지 남은 시간 (초)의 음수
float t = EnvVar.currentTime - time + 1;
if (t <= 0)
continue;
g.drawLine(prevX, prevY, x, y, Color.WHITE, 30);
prevX = x;
prevY = y;
}
g.drawLine(prevX, prevY, ball2.x, ball2.y, Color.WHITE, 30);

float factor = (time - ball1.time) / timeDelta;
float m = m2 * factor + m1 * (1 - factor); // m1, m2를 배분
float n = n2 * factor + n1 * (1 - factor); // m1, m2를 배분
float x = mn2x(m, n, t);
float z = (int) (DEPTH * (time - EnvVar.currentTime) * EnvVar.speed / 50);
float y = (int) (aOfZ * (z - alphaDepth) * (z - alphaDepth));

// UpdateGhosts();
//
// if (path == null)
// path = new Path();
/*
if (optimized) {
if (!created) {
// MakeTails();
}
//Draw optimized tail
int prevx = 0, prevy = 0, prevz = 0;
prevx = ghost2x;
prevy = ghost2y;
prevz = ball2.z;
g.drawLine((int) prevX, (int) prevY, (int) x, (int) y, Color.WHITE, STROKE);

//path.moveTo(ghost2x, ghost2y);
int dy = ghost1y - ghost2y;
for (int y = ball2.z + EnvVar.speed; z < ball1.z; z += EnvVar.speed) {
float tt = (ball1.t - ball2.t) / (ball1.z-ball2.z/*ghost1y - ghost2y* /) * (y - ghost1y) + ball1.t;
int x = Ball.getXfromT(ball2.origx, ball1.endx, tt);
g.drawLine(prevx, prevy, x, y, ball1.color, (int) (STROKE * GameScreen.getSizeCoeff(tt)));
if (y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
int helperx = (GameScreen.HITBOX_CENTER - y) * (prevx - x) / (prevy - y) + x;
g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
}
prevx = x;
prevy = y;
}
g.drawLine(prevx, prevy, ghost1x, ghost1y, ball1.color, STROKE);
if (ghost1y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
int helperx = (GameScreen.HITBOX_CENTER - ghost1y) * (prevx - ghost1x) / (prevy - ghost1y) + ghost1x;
g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
}
//int starti = ghost2y
//for(int i = starti; i < tailxs.length; i++) {
// y += EnvVar.speed;
// path.lineTo(tailxs[i], y);
//}
//path.close();
//g.DrawPath(path);
} else {
//Create Dynamic tail
//
//path.reset();
int prevx = 0, prevy = 0;
prevx = ghost2x;
prevy = ghost2y;
int dy = ghost1y - ghost2y;
for (int y = ghost2y + EnvVar.speed; y < ghost1y; y += EnvVar.speed) {
float tt = (float) (y - ghost2y) / (float) (dy);
float sizett = (ball1.t - ball2.t) / (ghost1y - ghost2y) * (y - ghost1y) + ball1.t;
int x = Ball.getXfromTLinear(ghost2x, ghost1x, tt);
g.drawLine(prevx, prevy, x, y, ball1.color, (int) (STROKE * GameScreen.getSizeCoeff(sizett)));
if (y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
int helperx = (GameScreen.HITBOX_CENTER - y) * (prevx - x) / (prevy - y) + x;
g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
}
prevx = x;
prevy = y;
//path.lineTo(x,y);
}
g.drawLine(prevx, prevy, ghost1x, ghost1y, ball1.color, STROKE);
if (ghost1y > EnvVar.HITBOX_CENTER && prevy < EnvVar.HITBOX_CENTER) {
int helperx = (GameScreen.HITBOX_CENTER - ghost1y) * (prevx - ghost1x) / (prevy - ghost1y) + ghost1x;
g.drawImage(Assets.ballHitpoint, (int) (helperx - SIZE_BALL), (int) (EnvVar.HITBOX_CENTER - SIZE_BALL), SIZE_BALL * 2, SIZE_BALL * 2);
}
prevX = x;
prevY = y;

//path.lineTo(ghost1x,ghost1y);
//path.close();
//g.DrawPath(path);
}
int x = ghost2x;
int y = ghost2y;
//for(int i=0;i<tailxs.length;i++)
{
//x = tailxs[i];
//y =
}
//g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y,ball1.color,40);
return;
// if(time < ball2.time)
if(ball2.y <= prevY)
g.drawLine((int) prevX, (int) prevY, ball2.x, ball2.y, Color.WHITE, STROKE);
}

*/
public float mn2x(float m, float n, float t) {
return n * t + m * (1.0f - t);
}

public void MakeTails() {
Expand Down

0 comments on commit 78e1960

Please sign in to comment.