Ready to draw and save round hitboxes. It is necessary to complete the correct loading of round hitbox data
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><objecttypes>
|
||||
<objecttype color="#a0a0a4" name="misato">
|
||||
<property default="Solid" name="class" type="string"/>
|
||||
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
||||
<property default="Circle -10 20 40" name="hitbox" type="string"/></objecttype>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<objecttypes>
|
||||
<objecttype color="#a0a0a4" name="misato">
|
||||
<property default="Solid" name="class" type="string"/>
|
||||
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
||||
<property default="Rectangle 22 -1 63 67" name="hitbox" type="string"/>
|
||||
</objecttype>
|
||||
<objecttype color="#a0a0a4" name="starlight">
|
||||
<property default="Solid" name="class" type="string"/>
|
||||
<property default="0 4 196 0 197 119 34 140 " name="drawbox" type="string"/>
|
||||
<property default="Circle 11 -1 27" name="hitbox" type="string"/></objecttype>
|
||||
<property default="Circle 23 13 29" name="hitbox" type="string"/>
|
||||
</objecttype>
|
||||
<objecttype color="#a0a0a4" name="tavern">
|
||||
<property default="Solid" name="class" type="string"/>
|
||||
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
||||
|
||||
@ -34,6 +34,7 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
hitboxCircleRenderFunct = new HitboxCircleRenderingFunction();
|
||||
drawboxRectengleRenderFunct.subscribe(Project.getInstance()); // подписка: Project получит данные ввиде обьекта Event, содержащий данные drawbox при отрисовке последней точки из 4-х.
|
||||
hitboxRectengleRenderFunct.subscribe(Project.getInstance());
|
||||
hitboxCircleRenderFunct.subscribe(Project.getInstance());
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@ package model;
|
||||
|
||||
public class HitboxCircle extends Hitbox {
|
||||
private float radiusHitbox;
|
||||
private float diametrX,diametrY;
|
||||
Point cartesianCenterImagePoint= new Point(0,0);
|
||||
//currentRefPoint - точка хранящая изометрические(экранные) коорды, от которой рисуется овал
|
||||
private Point currentRefPoint= new Point(0,0);
|
||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||
super(dataHitbox[0]);
|
||||
@ -15,24 +17,37 @@ public class HitboxCircle extends Hitbox {
|
||||
radiusHitbox = 0;
|
||||
}
|
||||
private void parseStringToCircleHitbox(String[] informations) {
|
||||
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth(),owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
referencePoint.y = Float.parseFloat(informations[2]);
|
||||
currentRefPoint = cartesianToIsometric(cartesianCenterImagePoint.x-referencePoint.x,cartesianCenterImagePoint.y-referencePoint.y,currentRefPoint);
|
||||
float chisloPizdec = (float)Math.sqrt(2);
|
||||
radiusHitbox = Float.parseFloat(informations[3])/chisloPizdec;
|
||||
currentRefPoint.x -=radiusHitbox;
|
||||
currentRefPoint.y -=radiusHitbox*2;
|
||||
currentRefPoint.x = owner.getImage().getWidth()/2+referencePoint.x;
|
||||
currentRefPoint.y = owner.getImage().getHeight()+referencePoint.y;
|
||||
radiusHitbox = Float.parseFloat(informations[3]);
|
||||
}
|
||||
@Override
|
||||
public String listPointsToString() {
|
||||
return "Circle"+referencePoint.x+referencePoint.x+" "+referencePoint.y+" "+radiusHitbox;
|
||||
Point cartesianCenterRefPoint = new Point(0, 0);
|
||||
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth()/2,owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||
cartesianCenterRefPoint = isometricToCartesian(currentRefPoint.x+diametrY,currentRefPoint.y+(diametrY/2),cartesianCenterRefPoint);
|
||||
System.out.println("");
|
||||
referencePoint.x = (cartesianCenterRefPoint.x - cartesianCenterImagePoint.x) * (-1);
|
||||
referencePoint.y = (cartesianCenterRefPoint.y - cartesianCenterImagePoint.y) * (-1);
|
||||
return "Circle "+(int)referencePoint.x+" "+(int)referencePoint.y+" "+(int)radiusHitbox;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radiusHitbox;
|
||||
}
|
||||
public void setRadius(int radius) {
|
||||
public void setDiametrXY(float diametrX, float diametrY) {
|
||||
this.diametrX = diametrX;
|
||||
this.diametrY = diametrY;
|
||||
}
|
||||
public float getDiametrX() {
|
||||
return diametrX;
|
||||
}
|
||||
public float getDiametrY() {
|
||||
return diametrY;
|
||||
}
|
||||
public void setRadius(float radius) {
|
||||
radiusHitbox = radius;
|
||||
}
|
||||
public Point getCurrentRefPoint() {
|
||||
|
||||
Reference in New Issue
Block a user