Trying to write the correct formulas for drawing round hitboxes
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
@ -79,7 +81,14 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(image, 0, 0, this);
|
||||
if(image!=null) {
|
||||
g.drawImage(image, 0, 0, this);
|
||||
g.setColor(Color.darkGray);
|
||||
g.drawRect(0, 0, image.getWidth(), image.getHeight());
|
||||
g.setColor(Color.RED);
|
||||
g.fillOval(image.getWidth()/2, image.getHeight(), 2, 2);
|
||||
g.setColor(Color.green);
|
||||
}
|
||||
if(entity != null) {
|
||||
drawing((Graphics2D)g);
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import events.EntityDrawboxChangedListener;
|
||||
import events.EntityHitboxChangedEvent;
|
||||
import events.EntityHitboxChangedListener;
|
||||
import model.Hitbox;
|
||||
import model.HitboxCircle;
|
||||
import model.HitboxRectangle;
|
||||
import model.Point;
|
||||
import repository.Project;
|
||||
@ -42,12 +43,14 @@ public class HitboxEditor extends Editable {
|
||||
|
||||
changeInRectangleHitboxJButton.addActionListener((e)->{
|
||||
functionClearHitboxJButton();
|
||||
//canvas.setHitboxRectengleRenderingFunction();
|
||||
entity.setHitbox(new HitboxRectangle("Rectangle",entity));
|
||||
canvas.setHitboxRectengleRenderingFunction();
|
||||
//Сделать создание нового Hitbox формы Rectengle
|
||||
});
|
||||
changeInCircleHitboxJButton.addActionListener((e)->{
|
||||
functionClearHitboxJButton();
|
||||
//canvas.setHitboxCircleRenderingFunction();
|
||||
entity.setHitbox(new HitboxCircle("Circle",entity));
|
||||
canvas.setHitboxCircleRenderingFunction();
|
||||
//Сделать создание нового Hitbox формы Circle
|
||||
});
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ 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()*2, (int)nowHitbox.getRadius());
|
||||
g.drawOval((int)nowHitbox.getCurrentRefPoint().x, (int)nowHitbox.getCurrentRefPoint().y, (int)nowHitbox.getRadius()*4, (int)(nowHitbox.getRadius()*2));
|
||||
}else if(firstIsoPoint != null) {
|
||||
currentRadius = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||
g.drawOval((int)firstIsoPoint.x, (int)firstIsoPoint.y, currentRadius, currentRadius/2);
|
||||
@ -60,5 +60,6 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
currentRadius = 0;
|
||||
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
||||
nowhitbox.setRadius(0);
|
||||
System.err.println("radius: "+nowhitbox.getRadius());
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,8 +48,8 @@ public class Entity {
|
||||
thisDrawbox = outDrawbox;
|
||||
};
|
||||
|
||||
public void setHitbox(Hitbox outHitbox) {
|
||||
thisHitbox = outHitbox;
|
||||
public void setHitbox(Hitbox inputHitbox) {
|
||||
thisHitbox = inputHitbox;
|
||||
};
|
||||
|
||||
public String getName() {
|
||||
|
||||
@ -2,6 +2,7 @@ package model;
|
||||
|
||||
public class HitboxCircle extends Hitbox {
|
||||
private float radiusHitbox;
|
||||
Point cartesianCenterImagePoint= new Point(0,0);
|
||||
private Point currentRefPoint= new Point(0,0);
|
||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||
super(dataHitbox[0]);
|
||||
@ -14,11 +15,14 @@ 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.x = owner.getImage().getWidth()/2+referencePoint.x;
|
||||
currentRefPoint.y = owner.getImage().getHeight()+referencePoint.y;
|
||||
radiusHitbox = Float.parseFloat(informations[3]);
|
||||
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;
|
||||
}
|
||||
@Override
|
||||
public String listPointsToString() {
|
||||
|
||||
Reference in New Issue
Block a user