-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
星屑集め #271
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
つよそう
public Background(){ | ||
mv = MainView.getInstance(); | ||
|
||
Path imagePath = Paths.get(".", "resource", "mini_game", "shonben_kozou", "background.jpg"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
background.jpg、アップロードされてなくないですか?
g.setColor(Color.WHITE); | ||
g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 25)); | ||
g.drawString("score " + model.getCircles().getScore(), mv.getWidth() - 150, 20); | ||
g.drawString(String.format("time %d.%02d",model.getGameTimer().getRemain()/100, model.getGameTimer().getRemain() % 100 ), 0, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
横に長いので
int timeRemaining = model.getGameTimer().getRemain();
String timerStr = String.format("%d.%02d", timeRemaining / 100, timeRemaining % 100);
g.drawString(timerStr, 0, 20);
とすると読みやすくなると思います!
this.model = model; | ||
mv = MainView.getInstance(); | ||
size = 20; | ||
vy = r.nextDouble()*36 - 17; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
実は Random#nextDouble()
と Math.random()
は完全に実装が同じなので、変数を増やさない意味では Math.random()
の方を使用した方が良いように思われます。
setX(getX() + vx); | ||
setY(getY() + vy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translate(vx, vy);
とも書けます
} | ||
|
||
public void addCircle(){ | ||
if(model.getGameTimer().getCount() >= 300 && model.getGameTimer().getCount() % 5 == 0 && model.getGameTimer().getCount() < 1300) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int count = model.getGameTimer().getCount();
とおいた方が
if(300 <= count && count < 1300 && count % 5 == 0) {
// do something
}
と短く書けるので楽そう
public void repulsion(){ | ||
if(getX() > mv.getWidth() - sizeX){ | ||
direction = 1; | ||
setX(2 * (double)mv.getWidth() - 3 * (double)sizeX - getX()); | ||
vx = -vx; | ||
} | ||
|
||
if(getX() < sizeX){ | ||
direction = -1; | ||
setX(3 * (double)sizeX - getX()); | ||
vx = -vx; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
似たようなコードを置くならSymbolを継承してrepulsionを持ったSymbolクラスを作ってそれをKozouが継承する、というようなことをすると後で管理しやすくなると思います。あと単純に共通化でコピペミス由来のバグを減らせます。
return p; | ||
} | ||
|
||
public int getdirection(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDirection
のミスに思われます
this.model = model; | ||
sizeX = 112; | ||
sizeY = 267; | ||
direction = -1; // -1のとき右向き。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これ、-1と1以外使わないならbooleanとかにした方が壊れなそうです。もしくは setAngleDegrees()
などを使い向きを指定、 Math.cos(getAngleRadians()) で値を得るなど
またはenumで
public enum FaceTo {
LEFT(1), RIGHT(-1)
private int dirVector;
private FaceTo(int dir) {
this.dirVector = dir;
}
public int getDirVector() {
return dirVector;
}
}
など
一通りできたので投げます。発表頑張ってください。