Trying to write the correct formulas for drawing round hitboxes
This commit is contained in:
@ -1,15 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><objecttypes>
|
||||||
<objecttypes>
|
<objecttype color="#a0a0a4" name="misato">
|
||||||
<objecttype color="#a0a0a4" name="misato">
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
||||||
<property default="2 5 209 4 226 194 14 189 " name="drawbox" type="string"/>
|
<property default="Circle -10 20 40" name="hitbox" type="string"/></objecttype>
|
||||||
<property default="Circle 4 6 24" name="hitbox" type="string"/>
|
|
||||||
</objecttype>
|
|
||||||
<objecttype color="#a0a0a4" name="starlight">
|
<objecttype color="#a0a0a4" name="starlight">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="0 4 196 0 197 119 34 140 " name="drawbox" type="string"/>
|
<property default="0 4 196 0 197 119 34 140 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle -10 -3 61 55" name="hitbox" type="string"/>
|
<property default="Circle 11 -1 27" name="hitbox" type="string"/></objecttype>
|
||||||
</objecttype>
|
|
||||||
<objecttype color="#a0a0a4" name="tavern">
|
<objecttype color="#a0a0a4" name="tavern">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
||||||
@ -25,4 +22,4 @@
|
|||||||
<property default="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
|
<property default="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle -18 -678 217 161" name="hitbox" type="string"/>
|
<property default="Rectangle -18 -678 217 161" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
</objecttypes>
|
</objecttypes>
|
||||||
@ -1,5 +1,7 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@ -79,7 +81,14 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
|||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(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) {
|
if(entity != null) {
|
||||||
drawing((Graphics2D)g);
|
drawing((Graphics2D)g);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import events.EntityDrawboxChangedListener;
|
|||||||
import events.EntityHitboxChangedEvent;
|
import events.EntityHitboxChangedEvent;
|
||||||
import events.EntityHitboxChangedListener;
|
import events.EntityHitboxChangedListener;
|
||||||
import model.Hitbox;
|
import model.Hitbox;
|
||||||
|
import model.HitboxCircle;
|
||||||
import model.HitboxRectangle;
|
import model.HitboxRectangle;
|
||||||
import model.Point;
|
import model.Point;
|
||||||
import repository.Project;
|
import repository.Project;
|
||||||
@ -42,12 +43,14 @@ public class HitboxEditor extends Editable {
|
|||||||
|
|
||||||
changeInRectangleHitboxJButton.addActionListener((e)->{
|
changeInRectangleHitboxJButton.addActionListener((e)->{
|
||||||
functionClearHitboxJButton();
|
functionClearHitboxJButton();
|
||||||
//canvas.setHitboxRectengleRenderingFunction();
|
entity.setHitbox(new HitboxRectangle("Rectangle",entity));
|
||||||
|
canvas.setHitboxRectengleRenderingFunction();
|
||||||
//Сделать создание нового Hitbox формы Rectengle
|
//Сделать создание нового Hitbox формы Rectengle
|
||||||
});
|
});
|
||||||
changeInCircleHitboxJButton.addActionListener((e)->{
|
changeInCircleHitboxJButton.addActionListener((e)->{
|
||||||
functionClearHitboxJButton();
|
functionClearHitboxJButton();
|
||||||
//canvas.setHitboxCircleRenderingFunction();
|
entity.setHitbox(new HitboxCircle("Circle",entity));
|
||||||
|
canvas.setHitboxCircleRenderingFunction();
|
||||||
//Сделать создание нового Hitbox формы Circle
|
//Сделать создание нового Hitbox формы Circle
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
|||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||||
if(nowHitbox.getRadius()!=0) {
|
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) {
|
}else if(firstIsoPoint != null) {
|
||||||
currentRadius = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
currentRadius = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||||
g.drawOval((int)firstIsoPoint.x, (int)firstIsoPoint.y, currentRadius, currentRadius/2);
|
g.drawOval((int)firstIsoPoint.x, (int)firstIsoPoint.y, currentRadius, currentRadius/2);
|
||||||
@ -60,5 +60,6 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
|||||||
currentRadius = 0;
|
currentRadius = 0;
|
||||||
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
||||||
nowhitbox.setRadius(0);
|
nowhitbox.setRadius(0);
|
||||||
|
System.err.println("radius: "+nowhitbox.getRadius());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,8 +48,8 @@ public class Entity {
|
|||||||
thisDrawbox = outDrawbox;
|
thisDrawbox = outDrawbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
public void setHitbox(Hitbox outHitbox) {
|
public void setHitbox(Hitbox inputHitbox) {
|
||||||
thisHitbox = outHitbox;
|
thisHitbox = inputHitbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package model;
|
|||||||
|
|
||||||
public class HitboxCircle extends Hitbox {
|
public class HitboxCircle extends Hitbox {
|
||||||
private float radiusHitbox;
|
private float radiusHitbox;
|
||||||
|
Point cartesianCenterImagePoint= new Point(0,0);
|
||||||
private Point currentRefPoint= new Point(0,0);
|
private Point currentRefPoint= new Point(0,0);
|
||||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||||
super(dataHitbox[0]);
|
super(dataHitbox[0]);
|
||||||
@ -14,11 +15,14 @@ public class HitboxCircle extends Hitbox {
|
|||||||
radiusHitbox = 0;
|
radiusHitbox = 0;
|
||||||
}
|
}
|
||||||
private void parseStringToCircleHitbox(String[] informations) {
|
private void parseStringToCircleHitbox(String[] informations) {
|
||||||
|
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth(),owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||||
referencePoint.x = Float.parseFloat(informations[1]);
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
referencePoint.y = Float.parseFloat(informations[2]);
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
currentRefPoint.x = owner.getImage().getWidth()/2+referencePoint.x;
|
currentRefPoint = cartesianToIsometric(cartesianCenterImagePoint.x-referencePoint.x,cartesianCenterImagePoint.y-referencePoint.y,currentRefPoint);
|
||||||
currentRefPoint.y = owner.getImage().getHeight()+referencePoint.y;
|
float chisloPizdec = (float)Math.sqrt(2);
|
||||||
radiusHitbox = Float.parseFloat(informations[3]);
|
radiusHitbox = Float.parseFloat(informations[3])/chisloPizdec;
|
||||||
|
currentRefPoint.x -=radiusHitbox;
|
||||||
|
currentRefPoint.y -=radiusHitbox*2;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String listPointsToString() {
|
public String listPointsToString() {
|
||||||
|
|||||||
Reference in New Issue
Block a user