Skip to content

Commit a14736e

Browse files
committed
add method for setting the hitbox by using a varargs
1 parent 45f9203 commit a14736e

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

docs/en/archives/Halloween/package.bluej

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ editor.fx.0.height=0
1212
editor.fx.0.width=0
1313
editor.fx.0.x=0
1414
editor.fx.0.y=0
15-
objectbench.height=110
15+
objectbench.height=98
1616
objectbench.width=487
1717
package.divider.horizontal=0.5995145631067961
18-
package.divider.vertical=0.8765822784810127
19-
package.editor.height=824
18+
package.divider.vertical=0.8892405063291139
19+
package.editor.height=836
2020
package.editor.width=693
2121
package.editor.x=994
22-
package.editor.y=54
22+
package.editor.y=32
2323
package.frame.height=1048
2424
package.frame.width=844
2525
package.numDependencies=3

src/org/openpatch/scratch/Sprite.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ public void changeTint(float step) {
236236
costume.changeTint(step);
237237
}
238238
}
239+
public void changeTint(double step) {
240+
this.changeTint((float) step);
241+
}
239242

240243
/**
241244
* Sets the transparency of the sprite.
@@ -265,6 +268,9 @@ public void changeTransparency(float step) {
265268
costume.changeTransparency(step);
266269
}
267270
}
271+
public void changeTransparency(double step) {
272+
this.changeTransparency((float) step);
273+
}
268274

269275
/**
270276
* Hides the sprite. The pen is not effected.
@@ -312,7 +318,7 @@ public void setSize(double percentage) {
312318
}
313319

314320
/**
315-
*
321+
*
316322
* @param amount
317323
*/
318324
public void changeSize(float amount) {
@@ -464,6 +470,9 @@ public void setX(float x) {
464470
this.x = x;
465471
this.pen.setPosition(this.x, this.y);
466472
}
473+
public void setX(double x) {
474+
this.setX((float) x);
475+
}
467476

468477
/**
469478
* Changes x by a certain amount
@@ -474,6 +483,9 @@ public void changeX(float x) {
474483
this.x += x;
475484
this.pen.setPosition(this.x, this.y);
476485
}
486+
public void changeX(double x) {
487+
this.changeX((float) x);
488+
}
477489

478490
/**
479491
* Returns the y coordinate of the sprite
@@ -503,6 +515,9 @@ public void changeY(float y) {
503515
this.y += y;
504516
this.pen.setPosition(this.x, this.y);
505517
}
518+
public void changeY(double y) {
519+
this.changeY((float) y);
520+
}
506521

507522
/**
508523
* Return the width of the current costume or the pen size, when no costume is
@@ -703,6 +718,17 @@ public float distanceToSprite(Sprite sprite) {
703718
return (float) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
704719
}
705720

721+
public void setHitbox(int ...points) {
722+
int l = points.length / 2;
723+
int[] xPoints = new int[l];
724+
int[] yPoints = new int[l];
725+
for (int i = 0; i < points.length; i+=2) {
726+
xPoints[i/2] = points[i];
727+
yPoints[i/2] = points[i+1];
728+
}
729+
this.hitbox = new Hitbox(xPoints, yPoints);
730+
}
731+
706732
public void setHitbox(int[] xPoints, int[] yPoints) {
707733
this.hitbox = new Hitbox(xPoints, yPoints);
708734
}

0 commit comments

Comments
 (0)