New hitbox architecture. But need change function addListElement in class ListGUI and load in class Project
This commit is contained in:
@ -21,7 +21,7 @@ public class HitboxEditor extends Editable {
|
||||
|
||||
@Override
|
||||
public void drawing(Graphics2D g) {
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
/*Hitbox nowHitbox = entity.getHitbox();
|
||||
//if(firstIsoPoint != null) {
|
||||
int x1,y1,x2,y2;
|
||||
int size = nowHitbox.getListPointsIso().size();
|
||||
@ -38,7 +38,7 @@ public class HitboxEditor extends Editable {
|
||||
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
//}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,7 +69,7 @@ public class HitboxEditor extends Editable {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
currentIsoPoint.x = e.getX();
|
||||
/*currentIsoPoint.x = e.getX();
|
||||
currentIsoPoint.y = e.getY();
|
||||
if(entity!=null) {
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
@ -83,7 +83,7 @@ public class HitboxEditor extends Editable {
|
||||
nowHitbox.convertCartesianPointsToIso();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -89,13 +89,7 @@ public class ListGUI extends JPanel {
|
||||
|
||||
|
||||
public void addListElement(String name, String solid) throws DuplicateEntryException {
|
||||
|
||||
// плейсхолдеры для новых хитбоксов и дроубоксов, иначе всё валится с NPE
|
||||
Hitbox hitbox = new Hitbox();
|
||||
Drawbox drawbox = new Drawbox();
|
||||
|
||||
Entity e = new Entity(name, hitbox, drawbox);
|
||||
hitbox.setOwnerEntity(e);
|
||||
Entity e = new Entity(name);
|
||||
e.setType(solid);
|
||||
logger.finer("Entity \""+name+"\" was created.");
|
||||
Project.getInstance().addEntity(e);
|
||||
|
||||
@ -18,10 +18,10 @@ public class Entity {
|
||||
thisHitbox = new Hitbox(hitbox,this);
|
||||
}
|
||||
|
||||
public Entity(String name, Hitbox hitbox, Drawbox drawbox) {
|
||||
public Entity(String name) {
|
||||
this.thisName = name;
|
||||
this.thisHitbox = hitbox;
|
||||
this.thisDrawbox = drawbox;
|
||||
this.thisHitbox = new Hitbox();
|
||||
this.thisDrawbox = new Drawbox();
|
||||
thisHitbox.setOwnerEntity(this);
|
||||
}
|
||||
|
||||
|
||||
@ -4,99 +4,33 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Hitbox {
|
||||
private String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
||||
private List<Point> listPointsIso = new ArrayList<Point>();
|
||||
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
||||
private Point referencePoint = new Point(0, 0); //Точка отсчета хитбокса, от нее рассчитывается высота+ширина/радиус(при круге) хитбокса.
|
||||
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
||||
private float radiusHitbox = 0;
|
||||
private Entity owner;
|
||||
String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
||||
Point referencePoint = new Point(0, 0); //Точка отсчета хитбокса, от нее рассчитывается высота+ширина/радиус(при круге) хитбокса.
|
||||
Entity owner;
|
||||
|
||||
public Hitbox(){
|
||||
initListsPoints();
|
||||
}
|
||||
public Hitbox(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
||||
public Hitbox(String shape){
|
||||
this.shape = new String(shape);
|
||||
this.listPointsIso = listPointsIso;
|
||||
this.listPointsCartesian = listPointsCartesian;
|
||||
initListsPoints();
|
||||
}
|
||||
|
||||
//informationHitbox - default="Rectangle 0 0 96 98"
|
||||
public Hitbox(String informationHitbox, Entity owner){
|
||||
if(informationHitbox!= null) {
|
||||
setOwnerEntity(owner);
|
||||
initListsPoints();
|
||||
String[] informations = informationHitbox.split(" ");
|
||||
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||
shape = new String(informations[0]);
|
||||
if(shape.equals("Rectangle")) {
|
||||
parseStringToRectangleHitbox(informations);
|
||||
/*parseStringToRectangleHitbox(informations);
|
||||
createCartesianPointsFromWidthAndHeigh();
|
||||
convertCartesianPointsToIso();
|
||||
printToConsole();
|
||||
printToConsole();*/
|
||||
}else if(shape.equals("Circle")) {
|
||||
parseStringToCircleHitbox(informations);
|
||||
//parseStringToCircleHitbox(informations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initListsPoints() {
|
||||
if(listPointsIso.size()<1) {
|
||||
for(int i=0;i<4;i++) {
|
||||
listPointsIso.add(new Point(0,0));
|
||||
}
|
||||
}
|
||||
if(listPointsCartesian.size()<1) {
|
||||
for(int i=0;i<4;i++) {
|
||||
listPointsCartesian.add(new Point(0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void parseStringToRectangleHitbox(String[] informations) {
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
referencePoint.y = Float.parseFloat(informations[2]);
|
||||
widthHitbox = Float.parseFloat(informations[3]);
|
||||
heightHitbox = Float.parseFloat(informations[4]);
|
||||
|
||||
}
|
||||
|
||||
private void parseStringToCircleHitbox(String[] informations) {
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
referencePoint.y = Float.parseFloat(informations[2]);
|
||||
radiusHitbox = Float.parseFloat(informations[3]);
|
||||
}
|
||||
|
||||
|
||||
public void convertIsoPointsToCartesian() {
|
||||
Point isoPoint;
|
||||
for (int i = 0 ; i<4;i++) {
|
||||
isoPoint = listPointsIso.get(i);
|
||||
cartesianToIsometric(isoPoint.x,isoPoint.y,listPointsCartesian.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//+++++++
|
||||
public void convertCartesianPointsToIso() {
|
||||
Point cartesianPoint;
|
||||
for (int i = 0 ; i<4;i++) {
|
||||
cartesianPoint = listPointsCartesian.get(i);
|
||||
cartesianToIsometric(cartesianPoint.x,cartesianPoint.y,listPointsIso.get(i));
|
||||
}
|
||||
}
|
||||
//+++++++
|
||||
private void createCartesianPointsFromWidthAndHeigh(){
|
||||
Point refIsoPoint = new Point(owner.getWidth()/2+referencePoint.x,owner.getHeight()+referencePoint.y);
|
||||
Point refCartesianPoint = isometricToCartesian(refIsoPoint.x,refIsoPoint.y,new Point(0,0));
|
||||
listPointsCartesian.clear();
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y));
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y));
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param result - Point object to store the result
|
||||
* @return x and y converted to isometic coords
|
||||
@ -126,16 +60,11 @@ public class Hitbox {
|
||||
public String getShape() {
|
||||
return shape;
|
||||
}
|
||||
public List<Point> getListPointsIso() {
|
||||
return listPointsIso;
|
||||
}
|
||||
public List<Point> getListPointsCartesian() {
|
||||
return listPointsCartesian;
|
||||
}
|
||||
|
||||
|
||||
//not the same as toString()! the latter is for XML while printToConsole() is for console
|
||||
public void printToConsole() {
|
||||
System.out.println();
|
||||
/*System.out.println();
|
||||
System.out.println("|||Hitbox:");
|
||||
if(shape!=null&&listPointsCartesian!=null) {
|
||||
System.out.println("Shape: " + shape);
|
||||
@ -153,7 +82,7 @@ public class Hitbox {
|
||||
System.out.println(" ");
|
||||
}else {
|
||||
System.out.println("null");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
||||
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
||||
|
||||
@ -1,5 +1,16 @@
|
||||
package model;
|
||||
|
||||
public class HitboxCircle extends Hitbox {
|
||||
private float radiusHitbox = 0;
|
||||
private float radiusHitbox;
|
||||
|
||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||
super(dataHitbox[0]);
|
||||
parseStringToCircleHitbox(dataHitbox);
|
||||
}
|
||||
|
||||
private void parseStringToCircleHitbox(String[] informations) {
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
referencePoint.y = Float.parseFloat(informations[2]);
|
||||
radiusHitbox = Float.parseFloat(informations[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ public class HitboxRectangle extends Hitbox {
|
||||
private List<Point> listPointsIso = new ArrayList<Point>();
|
||||
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
||||
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
||||
/*
|
||||
|
||||
public HitboxRectangle(){
|
||||
initListsPoints();
|
||||
}
|
||||
@ -17,22 +17,17 @@ public class HitboxRectangle extends Hitbox {
|
||||
this.listPointsCartesian = listPointsCartesian;
|
||||
initListsPoints();
|
||||
}
|
||||
public HitboxRectangle(String informationHitbox, Entity owner){
|
||||
if(informationHitbox!= null) {
|
||||
setOwnerEntity(owner);
|
||||
initListsPoints();
|
||||
String[] informations = informationHitbox.split(" ");
|
||||
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||
shape = new String(informations[0]);
|
||||
if(shape.equals("Rectangle")) {
|
||||
parseStringToRectangleHitbox(informations);
|
||||
createCartesianPointsFromWidthAndHeigh();
|
||||
convertCartesianPointsToIso();
|
||||
printToConsole();
|
||||
}else if(shape.equals("Circle")) {
|
||||
parseStringToCircleHitbox(informations);
|
||||
}
|
||||
}
|
||||
|
||||
//informationHitbox - default="Rectangle 0 0 96 98"
|
||||
public HitboxRectangle(String[] dataHitbox, Entity owner){
|
||||
super(dataHitbox[0]);
|
||||
setOwnerEntity(owner);
|
||||
initListsPoints();
|
||||
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||
parseStringToRectangleHitbox(dataHitbox);
|
||||
createCartesianPointsFromWidthAndHeigh();
|
||||
convertCartesianPointsToIso();
|
||||
printToConsole();
|
||||
}
|
||||
|
||||
private void initListsPoints() {
|
||||
@ -48,14 +43,14 @@ public class HitboxRectangle extends Hitbox {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseStringToRectangleHitbox(String[] informations) {
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
referencePoint.y = Float.parseFloat(informations[2]);
|
||||
widthHitbox = Float.parseFloat(informations[3]);
|
||||
heightHitbox = Float.parseFloat(informations[4]);
|
||||
private void parseStringToRectangleHitbox(String[] dataHitbox) {
|
||||
referencePoint.x = Float.parseFloat(dataHitbox[1]);
|
||||
referencePoint.y = Float.parseFloat(dataHitbox[2]);
|
||||
widthHitbox = Float.parseFloat(dataHitbox[3]);
|
||||
heightHitbox = Float.parseFloat(dataHitbox[4]);
|
||||
|
||||
}
|
||||
|
||||
//тут не правильно реализована функция, т.к. до сих пор нигде не используется. Надо переделать будет.
|
||||
public void convertIsoPointsToCartesian() {
|
||||
Point isoPoint;
|
||||
for (int i = 0 ; i<4;i++) {
|
||||
@ -83,6 +78,11 @@ public class HitboxRectangle extends Hitbox {
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
||||
}
|
||||
*/
|
||||
|
||||
public List<Point> getListPointsIso() {
|
||||
return listPointsIso;
|
||||
}
|
||||
public List<Point> getListPointsCartesian() {
|
||||
return listPointsCartesian;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user