Skip to content

Commit

Permalink
Improved Tail
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Apr 21, 2019
1 parent 0a99ecd commit fc72365
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 13 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/sma/rhythmtapper/framework/Graphics.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sma.rhythmtapper.framework;

import android.graphics.Paint;
import android.graphics.Path;

/**
* Created by Peter on 23.01.2017.
Expand All @@ -14,6 +15,8 @@ public static enum ImageFormat {

public void clearScreen(int color);

public void DrawPath(Path path);

public void drawLine(int x, int y, int x2, int y2, int color, int stroke);

public void drawLine(int x, int y, int x2, int y2, int color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,19 @@ public void clearScreen(int color) {
(color & 0xff));
}

@Override
public void DrawPath(Path path)
{
canvas.drawPath(path,paint);
}

@Override
public void drawLine(int x, int y, int x2, int y2, int color, int stroke) {
paint.setColor(color);
paint.setStrokeWidth(stroke);
canvas.drawLine(x, y, x2, y2, paint);
}


@Override
public void drawLine(int x, int y, int x2, int y2, int color) {
drawLine(x, y, x2, y2, color, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static List<Ball> Read(File file) throws FileNotFoundException, JSONExcep
Log.v(TAG,"connect "+id+" with"+prevMap.get(id));
Ball ba = id2Ball.get(id); //formar
ba.nextBall = id2Ball.get(prevMap.get(id)); //next
if(ba.isSlideNote()||ba.isLongNote())
if((ba.isSlideNote()||ba.isLongNote()) && (ba.nextBall.isSlideNote() || ba.nextBall.isLongNote()))
{
ba.connector= new Tail(ba, ba.nextBall);
} else{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sma.rhythmtapper.game.models;

import android.graphics.Color;
import android.util.Log;

import sma.rhythmtapper.framework.Impl.*;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void Paint(Graphics g) {
UpdateGhosts();
// }

g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y,ball1.color,40);
g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y, Color.LTGRAY,40);
/*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
2 changes: 1 addition & 1 deletion app/src/main/java/sma/rhythmtapper/game/models/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void Apply(GameStatusBundle bundle)
//how to apply combo bonus?
//score bonus?
int basicScore=totalAppeal/100;
//bundle.testResult = TestResult.PERFECT;
bundle.testResult = TestResult.PERFECT;
if(bundle.testResult.compareTo(TestResult.NICE)<=0)
bundle.continueCombo=false;
else
Expand Down
92 changes: 84 additions & 8 deletions app/src/main/java/sma/rhythmtapper/game/models/Tail.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,107 @@
package sma.rhythmtapper.game.models;
import android.graphics.Path;

import sma.rhythmtapper.framework.*;
import sma.rhythmtapper.game.*;
import static sma.rhythmtapper.game.EnvVar.SIZE_BALL;

public class Tail extends Connector
{
public Tail(Ball ball1,Ball ball2)
private final boolean optimized;
private boolean created = false;
public Tail(Ball ball1, Ball ball2)
{
super(ball1,ball2);
created = false;
if(ball1.startLine== ball2.startLine && ball1.endLine == ball2.endLine)
{
optimized = true;
} else {
optimized = false;
}
}
float[] tailxs;
transient Path path;// = new Path();
@Override
public void Paint(Graphics g) {
UpdateGhosts();
MakeTails();
if(path ==null)
path = new Path();
if(optimized)
{
if(!created)
{
// MakeTails();
}
//Draw optimized tail
int prevx=0, prevy = 0;
prevx = ghost2x;
prevy = ghost2y;
//path.moveTo(ghost2x, ghost2y);
int dy = ghost1y - ghost2y;
for(int y = ghost2y+EnvVar.speed; y < ghost1y; y += EnvVar.speed){
float tt = (ball1.t - ball2.t)/(ghost1y-ghost2y)*(y-ghost1y)+ball1.t;
int x = Ball.getXfromT(ball2.origx, ball1.endx, tt);
g.drawLine(prevx, prevy, x, y, ball1.color, 50);
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, 50);
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);
int x = Ball.getXfromT(ghost2x, ghost1x, tt);
g.drawLine(prevx, prevy, x, y, ball1.color, 50);
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, 50);
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++)
//for(int i=0;i<tailxs.length;i++)
{
//x = tailxs[i];
//y =
}
g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y,ball1.color,40);
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), SIZE_BALL * 2, SIZE_BALL * 2);
}
//g.drawLine(ghost1x, ghost1y, ghost2x, ghost2y,ball1.color,40);

return;
}
public void MakeTails()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit fc72365

Please sign in to comment.