Ready to draw and save round hitboxes. It is necessary to complete the correct loading of round hitbox data
This commit is contained in:
@ -2,7 +2,11 @@ package gui.render;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import events.EntityHitboxChangedEvent;
|
||||
import events.EntityHitboxChangedListener;
|
||||
import model.Entity;
|
||||
import model.HitboxCircle;
|
||||
import model.Point;
|
||||
@ -10,8 +14,9 @@ import model.Point;
|
||||
public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
Point firstIsoPoint = null;
|
||||
Point currentIsoPoint = new Point(0,0);
|
||||
int currentRadius=0;
|
||||
int currentDiametrX=0;
|
||||
Entity entity;
|
||||
private List<EntityHitboxChangedListener> listeners = new ArrayList<>();
|
||||
|
||||
public void setEntityInHitboxCircle(Entity e) {
|
||||
entity = e;
|
||||
@ -21,12 +26,11 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
public void drawing(Graphics2D g) {
|
||||
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||
if(nowHitbox.getRadius()!=0) {
|
||||
g.drawOval((int)nowHitbox.getCurrentRefPoint().x, (int)nowHitbox.getCurrentRefPoint().y, (int)nowHitbox.getRadius()*4, (int)(nowHitbox.getRadius()*2));
|
||||
g.drawOval((int)nowHitbox.getCurrentRefPoint().x, (int)(nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2)), (int)nowHitbox.getDiametrX(), (int)(nowHitbox.getDiametrY()));
|
||||
}else if(firstIsoPoint != null) {
|
||||
currentRadius = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||
g.drawOval((int)firstIsoPoint.x, (int)firstIsoPoint.y, currentRadius, currentRadius/2);
|
||||
currentDiametrX = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||
g.drawOval((int)firstIsoPoint.x, (int)(firstIsoPoint.y-currentDiametrX/4), currentDiametrX, currentDiametrX/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,9 +39,16 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
if(nowHitbox.getRadius()==0 && firstIsoPoint == null) {
|
||||
firstIsoPoint = new Point(e.getX(), e.getY());
|
||||
}else if(nowHitbox.getRadius()==0 && firstIsoPoint != null) {
|
||||
//Формула высчитывания радиуса из диаметров circle.
|
||||
nowHitbox.getCurrentRefPoint().setXY(firstIsoPoint.x, firstIsoPoint.y);
|
||||
nowHitbox.setDiametrXY(Math.abs(firstIsoPoint.x-e.getX()),Math.abs((firstIsoPoint.x-e.getX())/2));
|
||||
System.out.println("X = "+nowHitbox.getDiametrX()+ "Y = "+nowHitbox.getDiametrY());
|
||||
float temp = (float)Math.sqrt(2);
|
||||
nowHitbox.setRadius((nowHitbox.getDiametrY()/2)*temp);
|
||||
// высчитываем в параметры хитбокссеркла нужный радиус и текущую реф поинт.
|
||||
// Не забываем высчитать реф поинт хитбокса относительно текущей.
|
||||
// после чего вызываем listPointsToString и нотифай, который отправляет данные на сохранение
|
||||
notifySubscribers();
|
||||
}
|
||||
|
||||
}
|
||||
@ -50,16 +61,32 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
|
||||
public void functionClearHitboxJButton() {
|
||||
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void functionClearJButton() {
|
||||
firstIsoPoint = null;
|
||||
currentIsoPoint = new Point(0,0);
|
||||
currentRadius = 0;
|
||||
currentDiametrX = 0;
|
||||
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
||||
nowhitbox.setRadius(0);
|
||||
System.err.println("radius: "+nowhitbox.getRadius());
|
||||
}
|
||||
|
||||
public void subscribe(EntityHitboxChangedListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void unsubscribe(EntityHitboxChangedListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifySubscribers() {
|
||||
for (EntityHitboxChangedListener listener : listeners) {
|
||||
listener.hitboxChanged(
|
||||
new EntityHitboxChangedEvent(entity.getHitbox(), entity)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user