Added the function of drawing rectangular hitboxes, as well as the ability to erase and save the result. Drawing in any direction.

This commit is contained in:
2026-03-29 23:14:42 +03:00
parent 2686d036cf
commit 6665199d12
2 changed files with 15 additions and 7 deletions

View File

@ -2,13 +2,13 @@
<objecttypes>
<objecttype color="#a0a0a4" name="misato">
<property default="Solid" name="class" type="string"/>
<property default="9 3 214 11 220 190 15 185 " name="drawbox" type="string"/>
<property default="2 5 209 4 226 194 14 189 " name="drawbox" type="string"/>
<property default="Circle 4 6 24" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="starlight">
<property default="Solid" name="class" type="string"/>
<property default="11 1 196 0 181 141 26 131 " name="drawbox" type="string"/>
<property default="Rectangle 0 0 76 119" name="hitbox" 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"/>
</objecttype>
<objecttype color="#a0a0a4" name="tavern">
<property default="Solid" name="class" type="string"/>
@ -23,6 +23,6 @@
<objecttype color="000000" name="newtest">
<property default="solid" name="class" type="string"/>
<property default="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
<property default="Rectangle 80 -607 27 49" name="hitbox" type="string"/>
<property default="Rectangle -185 -822 189 99" name="hitbox" type="string"/>
</objecttype>
</objecttypes>

View File

@ -88,7 +88,7 @@ public class HitboxRectangle extends Hitbox {
}
@Override
public String listPointsToString() {
System.out.println("Данные");
System.out.println("Парсинг данных");
parseCartesianListPointsToWidthHeight();
calculationReferencePoint();
return "Rectangle "+(int)referencePoint.x+" "+(int)referencePoint.y+" "+(int)widthHitbox+" "+(int)heightHitbox;
@ -98,9 +98,17 @@ public class HitboxRectangle extends Hitbox {
widthHitbox = Math.abs(listPointsCartesian.get(0).x-listPointsCartesian.get(1).x);
heightHitbox = Math.abs(listPointsCartesian.get(1).y-listPointsCartesian.get(2).y);
}
@Override
public void calculationReferencePoint() {
referencePoint.x = listPointsIso.get(1).x-owner.getImage().getWidth()/2;
referencePoint.y = listPointsIso.get(1).y-owner.getImage().getHeight();
Point bottomPoint = new Point(0,0);
for(Point currentPoint: listPointsIso) {
if(bottomPoint.y<currentPoint.y) {
bottomPoint.x=currentPoint.x;
bottomPoint.y=currentPoint.y;
}
}
referencePoint.x = bottomPoint.x-owner.getImage().getWidth()/2;
referencePoint.y = bottomPoint.y-owner.getImage().getHeight();
}
}