Fix hitbox. Nothing worked, now it is.
This commit is contained in:
@ -12,18 +12,17 @@ import model.Point;
|
||||
|
||||
public class HitboxRectangleEditor extends Editable {
|
||||
Point firstIsoPoint = null;
|
||||
Point currentIsoPoint = null;
|
||||
Point currentIsoPoint = new Point(0,0);
|
||||
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
|
||||
HitboxRectangleEditor(ListGUI listGUI) {
|
||||
super(listGUI);
|
||||
// TODO Auto-generated cons2tructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawing(Graphics2D g) {
|
||||
if(firstIsoPoint != null) {
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
//if(firstIsoPoint != null) {
|
||||
int x1,y1,x2,y2;
|
||||
int size = nowHitbox.getListPointsIso().size();
|
||||
for(int i = 0; i < size;i++) {
|
||||
@ -38,7 +37,7 @@ public class HitboxRectangleEditor extends Editable {
|
||||
x2 = (int)nowHitbox.getListPointsIso().get(3).x;
|
||||
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@ -53,6 +52,7 @@ public class HitboxRectangleEditor extends Editable {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(firstIsoPoint == null) {
|
||||
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
||||
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
||||
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
||||
}else{
|
||||
/*
|
||||
@ -71,14 +71,18 @@ public class HitboxRectangleEditor extends Editable {
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
currentIsoPoint.x = e.getX();
|
||||
currentIsoPoint.y = e.getY();
|
||||
if(firstIsoPoint != null) {
|
||||
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
||||
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
||||
nowHitbox.convertCartesianPointsToIso();
|
||||
repaint();
|
||||
if(entity!=null) {
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
if(firstIsoPoint != null) {
|
||||
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
||||
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
||||
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
||||
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
||||
nowHitbox.convertCartesianPointsToIso();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +92,7 @@ public class HitboxRectangleEditor extends Editable {
|
||||
if(parent.getSelectedComponent() == this){
|
||||
if(entity != null) {
|
||||
firstIsoPoint = null;
|
||||
currentIsoPoint = null;
|
||||
currentIsoPoint.setXY(0,0);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ public class Hitbox {
|
||||
parseStringToRectangleHitbox(informations);
|
||||
createCartesianPointsFromWidthAndHeigh();
|
||||
convertCartesianPointsToIso();
|
||||
printToConsole();
|
||||
}else if(shape.equals("Circle")) {
|
||||
parseStringToCircleHitbox(informations);
|
||||
}
|
||||
@ -136,15 +137,23 @@ public class Hitbox {
|
||||
public void printToConsole() {
|
||||
System.out.println();
|
||||
System.out.println("|||Hitbox:");
|
||||
/* if(shape!=null&&listPoints!=null) {
|
||||
System.out.println("shape: " + shape);
|
||||
for(Point point: listPoints) {
|
||||
if(shape!=null&&listPointsCartesian!=null) {
|
||||
System.out.println("Shape: " + shape);
|
||||
System.out.println("Cartesian: ");
|
||||
for(Point point: listPointsCartesian) {
|
||||
System.out.print("("+point.x+";"+point.y+") ");
|
||||
System.out.println("");
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("-----------");
|
||||
System.out.println("Iso: ");
|
||||
for(Point point: listPointsIso){
|
||||
System.out.print("("+point.x+";"+point.y+") ");
|
||||
System.out.println("");
|
||||
}
|
||||
System.out.println(" ");
|
||||
}else {
|
||||
System.out.println("null");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
||||
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
||||
|
||||
5
src/model/HitboxCircle.java
Normal file
5
src/model/HitboxCircle.java
Normal file
@ -0,0 +1,5 @@
|
||||
package model;
|
||||
|
||||
public class HitboxCircle extends Hitbox {
|
||||
private float radiusHitbox = 0;
|
||||
}
|
||||
88
src/model/HitboxRectangle.java
Normal file
88
src/model/HitboxRectangle.java
Normal file
@ -0,0 +1,88 @@
|
||||
package model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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();
|
||||
}
|
||||
public HitboxRectangle(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
||||
super(shape);
|
||||
this.listPointsIso = listPointsIso;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user