From e9d145235f3ad5b31f6e228d6fcd880bc289a1bc Mon Sep 17 00:00:00 2001 From: Zacchary Dempsey-Plante Date: Sun, 13 Jan 2019 23:52:19 -0500 Subject: [PATCH] Added Actor-specific isMouse...Here() methods, added a few missing World constructors, and made getWorld() return null instead of throwing an exception. --- distribution/Green-1.0/index.html | 2 +- .../Green-1.0/reference/Green/Actor.html | 165 ++++++++++++++---- .../Green-1.0/reference/Green/Green.html | 61 ++++++- .../Green-1.0/reference/Green/InputKey.html | 4 +- .../reference/Green/NoWorldException.html | 4 +- .../Green/SingleInstanceException.html | 4 +- .../Green/UnknownResizeFormatException.html | 4 +- .../Green-1.0/reference/Green/World.html | 71 +++++++- .../reference/Green/package-frame.html | 4 +- .../reference/Green/package-summary.html | 4 +- .../reference/Green/package-tree.html | 4 +- .../Green-1.0/reference/allclasses-frame.html | 4 +- .../reference/allclasses-noframe.html | 4 +- .../Green-1.0/reference/constant-values.html | 4 +- .../Green-1.0/reference/deprecated-list.html | 4 +- .../Green-1.0/reference/help-doc.html | 4 +- .../Green-1.0/reference/index-all.html | 40 ++++- distribution/Green-1.0/reference/index.html | 2 +- .../Green-1.0/reference/overview-tree.html | 4 +- .../Green-1.0/reference/serialized-form.html | 4 +- src/Green/Actor.java | 85 +++++++-- src/Green/Green.java | 25 ++- src/Green/World.java | 36 ++++ 23 files changed, 454 insertions(+), 89 deletions(-) diff --git a/distribution/Green-1.0/index.html b/distribution/Green-1.0/index.html index 8e4b9ab..73301e5 100644 --- a/distribution/Green-1.0/index.html +++ b/distribution/Green-1.0/index.html @@ -42,7 +42,7 @@

Green

Green

A Library by Zacchary Dempsey-Plante for the Processing programming environment.
- Last update, 2018-12-09. + Last update, 2019-01-13.

A library for Processing to emulate Greenfoot functionality.
diff --git a/distribution/Green-1.0/reference/Green/Actor.html b/distribution/Green-1.0/reference/Green/Actor.html index a44a752..2e0342e 100644 --- a/distribution/Green-1.0/reference/Green/Actor.html +++ b/distribution/Green-1.0/reference/Green/Actor.html @@ -2,9 +2,9 @@ - + Actor (Javadocs: Green) - + @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":6,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":9,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10,"i45":10,"i46":10}; +var methods = {"i0":6,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":9,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10,"i45":10,"i46":10,"i47":10,"i48":10,"i49":10,"i50":10,"i51":10}; var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -337,9 +337,7 @@

Method Summary

World -getWorld() -
Retrieves the current World this Actor is in, or null otherwise.
- +getWorld()  static <W extends World>
W
@@ -382,109 +380,140 @@

Method Summary

+boolean +isMouseButtonDownHere(int mouseButton) +
Retrieves whether or not a specific mouse button is currently down on this Actor.
+ + + +boolean +isMouseButtonDownThisFrameHere(int mouseButton) +
Retrieves whether or not a specific mouse button was pressed this frame on this Actor.
+ + + +boolean +isMouseButtonUpThisFrameHere(int mouseButton) +
Retrieves whether or not a specific mouse button was released this frame on this Actor.
+ + + +boolean +isMouseScrollingHere() +
Retrieves whether or not the mouse is currently scrolling on this Actor.
+ + + void move(float amount)
Moves the Actor amount units in the direction of the actor's rotation.
- + void moveGlobal(float x, float y)
Moves the Actor x units on the X-axis and y units on the Y-axis.
- + +boolean +pointInBounds(float pX, + float pY) +
Checks to see if a point defined by pX and pY is within the Actor's rotated rect.
+ + + void removedFromWorld(World world)
Called when the Actor is removed from any World.
- + void setDimensions(int w, int h)
Sets the width and height of the Actor.
- + void setHeight(int h)
Sets the height of the Actor.
- + void setImage(PImage image)
Sets the image of the Actor.
- + void setLocation(float x, float y)
Sets the X-axis and Y-axis positions of the Actor.
- + void setOpacity(float opacity)
Sets the opacity value (in the range 0 - 255) of the Actor.
- + void setResizeFormat(int format)
Sets the image resize format of the Actor.
- + void setRotation(float rotation)
Sets the rotation of the Actor in degrees.
- + void setWidth(int w)
Sets the width of the Actor.
- + void setX(float x)
Sets the X-axis position of the Actor.
- + void setY(float y)
Sets the Y-axis position of the Actor.
- + void setZ(float z)
Sets the Z-axis position of the Actor.
- + java.lang.String toString()  - + void turn(float degrees)
Rotates the Actor degrees amount in degrees.
- + void turnTowards(Actor obj)
Rotates the Actor to face it's right side towards another Actor.
- + void turnTowards(float x, float y) @@ -850,15 +879,7 @@

getResizeFormat

@@ -1116,6 +1137,24 @@

intersects

+
+ + + @@ -1362,6 +1401,68 @@

turnTowards

+ + + + + + + + + + + + + + + + diff --git a/distribution/Green-1.0/reference/Green/Green.html b/distribution/Green-1.0/reference/Green/Green.html index 4bd345c..033a085 100644 --- a/distribution/Green-1.0/reference/Green/Green.html +++ b/distribution/Green-1.0/reference/Green/Green.html @@ -2,9 +2,9 @@ - + Green (Javadocs: Green) - + @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":9,"i1":9,"i2":10,"i3":9,"i4":9,"i5":9,"i6":10,"i7":10,"i8":10,"i9":9,"i10":9,"i11":9,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":42,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":9,"i39":10}; +var methods = {"i0":9,"i1":9,"i2":10,"i3":9,"i4":9,"i5":9,"i6":10,"i7":10,"i8":10,"i9":9,"i10":9,"i11":9,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":42,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":9,"i38":10,"i39":9,"i40":10}; var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"],32:["t6","Deprecated Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -431,6 +431,21 @@

Method Summary

+static boolean +pointInRectangle(float pXx, + float pXy, + float pYx, + float pYy, + float pZx, + float pZy, + float pWx, + float pWy, + float pPx, + float pPy) +
Checks whether a point (pPx, pPy) is within the bounds of a rectangle ((pXx, pXy), (pYx, pYy), (pZx, pZy), (pWx, pWy)) where the points are provided in clockwise order.
+ + + PImage resizeNN(PImage src, int w, @@ -438,13 +453,13 @@

Method Summary

A nearest-neighbour resizing implementation.
- + static float sec(float angle)
Calculates the secant of angle in radians.
- + PImage tileImage(PImage src, int w, @@ -785,6 +800,42 @@

tileImage

+ + + +
    +
  • +

    pointInRectangle

    +
    public static boolean pointInRectangle(float pXx,
    +                                       float pXy,
    +                                       float pYx,
    +                                       float pYy,
    +                                       float pZx,
    +                                       float pZy,
    +                                       float pWx,
    +                                       float pWy,
    +                                       float pPx,
    +                                       float pPy)
    +
    Checks whether a point (pPx, pPy) is within the bounds of a rectangle ((pXx, pXy), (pYx, pYy), (pZx, pZy), (pWx, pWy)) where the points are provided in clockwise order.
    +
    +
    Parameters:
    +
    pXx - The X-axis position of the X point.
    +
    pXy - The Y-axis position of the X point.
    +
    pYx - The X-axis position of the Y point.
    +
    pYy - The Y-axis position of the Y point.
    +
    pZx - The X-axis position of the Z point.
    +
    pZy - The Y-axis position of the Z point.
    +
    pWx - The X-axis position of the W point.
    +
    pWy - The Y-axis position of the W point.
    +
    pPx - The X-axis position of the point to check.
    +
    pPy - The Y-axis position of the point to check.
    +
    Returns:
    +
    Whether the point to check is within the bounds of the provided rectangle.
    +
    See Also:
    +
    https://gamedev.stackexchange.com/a/110233
    +
    +
  • +
diff --git a/distribution/Green-1.0/reference/Green/InputKey.html b/distribution/Green-1.0/reference/Green/InputKey.html index 8a277b2..3517236 100644 --- a/distribution/Green-1.0/reference/Green/InputKey.html +++ b/distribution/Green-1.0/reference/Green/InputKey.html @@ -2,9 +2,9 @@ - + InputKey (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/NoWorldException.html b/distribution/Green-1.0/reference/Green/NoWorldException.html index 93389e5..e89849f 100644 --- a/distribution/Green-1.0/reference/Green/NoWorldException.html +++ b/distribution/Green-1.0/reference/Green/NoWorldException.html @@ -2,9 +2,9 @@ - + NoWorldException (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/SingleInstanceException.html b/distribution/Green-1.0/reference/Green/SingleInstanceException.html index 4909a25..512287a 100644 --- a/distribution/Green-1.0/reference/Green/SingleInstanceException.html +++ b/distribution/Green-1.0/reference/Green/SingleInstanceException.html @@ -2,9 +2,9 @@ - + SingleInstanceException (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/UnknownResizeFormatException.html b/distribution/Green-1.0/reference/Green/UnknownResizeFormatException.html index 4f3fe27..9d13e05 100644 --- a/distribution/Green-1.0/reference/Green/UnknownResizeFormatException.html +++ b/distribution/Green-1.0/reference/Green/UnknownResizeFormatException.html @@ -2,9 +2,9 @@ - + UnknownResizeFormatException (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/World.html b/distribution/Green-1.0/reference/Green/World.html index 6407daa..8667f09 100644 --- a/distribution/Green-1.0/reference/Green/World.html +++ b/distribution/Green-1.0/reference/Green/World.html @@ -2,9 +2,9 @@ - + World (Javadocs: Green) - + @@ -190,6 +190,15 @@

Constructor Summary

+World(int w, + int h, + int bgColor, + PImage bgImage, + boolean unbounded) +
Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise.
+ + + World(int w, int h, int bgColor, @@ -198,7 +207,7 @@

Constructor Summary

Creates a new world with defined dimensions and a background image with a background colour to draw underneath.
- + World(int w, int h, int bgColor, @@ -208,13 +217,21 @@

Constructor Summary

Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise.
- + World(int w, int h, PImage bgImage)
Creates a new world with defined dimensions and a background image.
+ +World(int w, + int h, + PImage bgImage, + boolean unbounded) +
Creates a new world with defined dimensions and a background image, set to be bounded or otherwise.
+ + World(int w, int h, @@ -786,6 +803,28 @@

World

+ + + +
    +
  • +

    World

    +
    public World(int w,
    +             int h,
    +             PImage bgImage,
    +             boolean unbounded)
    +
    Creates a new world with defined dimensions and a background image, set to be bounded or otherwise.
    +
    +
    Parameters:
    +
    w - The width to create the world with.
    +
    h - The height to create the world with.
    +
    bgImage - The background image.
    +
    unbounded - Whether or not Actor instances should be able to go out of bounds.
    +
    Throws:
    +
    UnknownResizeFormatException - Thrown when an unknown resize format is supplied.
    +
    +
  • +
@@ -810,6 +849,30 @@

World

+ + + +
    +
  • +

    World

    +
    public World(int w,
    +             int h,
    +             int bgColor,
    +             PImage bgImage,
    +             boolean unbounded)
    +
    Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise.
    +
    +
    Parameters:
    +
    w - The width to create the world with.
    +
    h - The height to create the world with.
    +
    bgColor - The background colour. Use the PApplet.color(int, int, int) method to define it.
    +
    bgImage - The background image.
    +
    unbounded - Whether or not Actor instances should be able to go out of bounds.
    +
    Throws:
    +
    UnknownResizeFormatException - Thrown when an unknown resize format is supplied.
    +
    +
  • +
diff --git a/distribution/Green-1.0/reference/Green/package-frame.html b/distribution/Green-1.0/reference/Green/package-frame.html index 90d3c39..11419da 100644 --- a/distribution/Green-1.0/reference/Green/package-frame.html +++ b/distribution/Green-1.0/reference/Green/package-frame.html @@ -2,9 +2,9 @@ - + Green (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/package-summary.html b/distribution/Green-1.0/reference/Green/package-summary.html index 1fdacf3..98634fd 100644 --- a/distribution/Green-1.0/reference/Green/package-summary.html +++ b/distribution/Green-1.0/reference/Green/package-summary.html @@ -2,9 +2,9 @@ - + Green (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/Green/package-tree.html b/distribution/Green-1.0/reference/Green/package-tree.html index 9141263..20ca5b5 100644 --- a/distribution/Green-1.0/reference/Green/package-tree.html +++ b/distribution/Green-1.0/reference/Green/package-tree.html @@ -2,9 +2,9 @@ - + Green Class Hierarchy (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/allclasses-frame.html b/distribution/Green-1.0/reference/allclasses-frame.html index 848641b..58ae968 100644 --- a/distribution/Green-1.0/reference/allclasses-frame.html +++ b/distribution/Green-1.0/reference/allclasses-frame.html @@ -2,9 +2,9 @@ - + All Classes (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/allclasses-noframe.html b/distribution/Green-1.0/reference/allclasses-noframe.html index 0ad6a64..c61edd3 100644 --- a/distribution/Green-1.0/reference/allclasses-noframe.html +++ b/distribution/Green-1.0/reference/allclasses-noframe.html @@ -2,9 +2,9 @@ - + All Classes (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/constant-values.html b/distribution/Green-1.0/reference/constant-values.html index 88027e2..066ee9c 100644 --- a/distribution/Green-1.0/reference/constant-values.html +++ b/distribution/Green-1.0/reference/constant-values.html @@ -2,9 +2,9 @@ - + Constant Field Values (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/deprecated-list.html b/distribution/Green-1.0/reference/deprecated-list.html index 40f6149..aa5bc57 100644 --- a/distribution/Green-1.0/reference/deprecated-list.html +++ b/distribution/Green-1.0/reference/deprecated-list.html @@ -2,9 +2,9 @@ - + Deprecated List (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/help-doc.html b/distribution/Green-1.0/reference/help-doc.html index 77651a2..71b7e25 100644 --- a/distribution/Green-1.0/reference/help-doc.html +++ b/distribution/Green-1.0/reference/help-doc.html @@ -2,9 +2,9 @@ - + API Help (Javadocs: Green) - + diff --git a/distribution/Green-1.0/reference/index-all.html b/distribution/Green-1.0/reference/index-all.html index 2fc0dc1..8d70eee 100644 --- a/distribution/Green-1.0/reference/index-all.html +++ b/distribution/Green-1.0/reference/index-all.html @@ -2,9 +2,9 @@ - + Index (Javadocs: Green) - + @@ -337,9 +337,7 @@

G

Retrieves the width of the World.
getWorld() - Method in class Green.Actor
-
-
Retrieves the current World this Actor is in, or null otherwise.
-
+
 
getWorld() - Static method in class Green.Green
Retrieves the currently-loaded World.
@@ -504,14 +502,26 @@

I

Retrieves whether or not a specific mouse button is currently down.
+
isMouseButtonDownHere(int) - Method in class Green.Actor
+
+
Retrieves whether or not a specific mouse button is currently down on this Actor.
+
isMouseButtonDownThisFrame(int) - Method in class Green.Green
Retrieves whether or not a specific mouse button was pressed this frame.
+
isMouseButtonDownThisFrameHere(int) - Method in class Green.Actor
+
+
Retrieves whether or not a specific mouse button was pressed this frame on this Actor.
+
isMouseButtonUpThisFrame(int) - Method in class Green.Green
Retrieves whether or not a specific mouse button was released this frame.
+
isMouseButtonUpThisFrameHere(int) - Method in class Green.Actor
+
+
Retrieves whether or not a specific mouse button was released this frame on this Actor.
+
isMouseMoving() - Method in class Green.Green
Retrieves whether or not the mouse has moved this frame.
@@ -520,6 +530,10 @@

I

Retrieves whether or not the mouse is currently scrolling.
+
isMouseScrollingHere() - Method in class Green.Actor
+
+
Retrieves whether or not the mouse is currently scrolling on this Actor.
+
@@ -566,6 +580,14 @@

N

P

+
pointInBounds(float, float) - Method in class Green.Actor
+
+
Checks to see if a point defined by pX and pY is within the Actor's rotated rect.
+
+
pointInRectangle(float, float, float, float, float, float, float, float, float, float) - Static method in class Green.Green
+
+
Checks whether a point (pPx, pPy) is within the bounds of a rectangle ((pXx, pXy), (pYx, pYy), (pZx, pZy), (pWx, pWy)) where the points are provided in clockwise order.
+
prepare() - Method in class Green.World
Called when the World is loaded via the Green.loadWorld(World) method.
@@ -814,10 +836,18 @@

W

Creates a new world with defined dimensions and a background colour, set to be bounded or otherwise.
+
World(int, int, PImage, boolean) - Constructor for class Green.World
+
+
Creates a new world with defined dimensions and a background image, set to be bounded or otherwise.
+
World(int, int, PImage, int, boolean) - Constructor for class Green.World
Creates a new world with defined dimensions and a background image, set to be bounded or otherwise.
+
World(int, int, int, PImage, boolean) - Constructor for class Green.World
+
+
Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise.
+
World(int, int, int, PImage, int, boolean) - Constructor for class Green.World
Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise.
diff --git a/distribution/Green-1.0/reference/index.html b/distribution/Green-1.0/reference/index.html index c6127e9..fb09128 100644 --- a/distribution/Green-1.0/reference/index.html +++ b/distribution/Green-1.0/reference/index.html @@ -2,7 +2,7 @@ - + Javadocs: Green diff --git a/distribution/Green-1.0/reference/serialized-form.html b/distribution/Green-1.0/reference/serialized-form.html index 384b7f1..c3c8e1a 100644 --- a/distribution/Green-1.0/reference/serialized-form.html +++ b/distribution/Green-1.0/reference/serialized-form.html @@ -2,9 +2,9 @@ - + Serialized Form (Javadocs: Green) - + diff --git a/src/Green/Actor.java b/src/Green/Actor.java index 9d41f39..87d8f82 100644 --- a/src/Green/Actor.java +++ b/src/Green/Actor.java @@ -292,14 +292,14 @@ public final int getResizeFormat() * @return The world this {@link Actor} is a part of that is currently loaded. * @throws NoWorldException Thrown when the method is called and the {@link Actor} is not part of a {@link World}. */ - public final World getWorld() throws NoWorldException + private final World getWorldUnsafe() throws NoWorldException { World currentWorld = Green.getWorld(); if(currentWorld.hasObject(this)) return currentWorld; throw new NoWorldException(); } - private final World getWorldSafe() + public final World getWorld() { World currentWorld = Green.getWorld(); if(currentWorld.hasObject(this)) @@ -328,7 +328,7 @@ public static W getWorldOfType(Class type) */ public final void setX(float x) { - World world = getWorldSafe(); + World world = getWorld(); if(world != null && !world.getUnbounded()) _x = Math.max(0, Math.min(world.getWidth(), x)); else @@ -340,7 +340,7 @@ public final void setX(float x) */ public final void setY(float y) { - World world = getWorldSafe(); + World world = getWorld(); if(world != null && !world.getUnbounded()) _y = Math.max(0, Math.min(world.getHeight(), y)); else @@ -361,7 +361,7 @@ public final void setZ(float z) */ public final void setLocation(float x, float y) { - World world = getWorldSafe(); + World world = getWorld(); if(world != null && !world.getUnbounded()) { _x = Math.max(0, Math.min(world.getWidth(), x)); @@ -474,7 +474,7 @@ public final void turn(float degrees) */ public final boolean isAtEdge() throws NoWorldException { - World world = getWorld(); + World world = getWorldUnsafe(); return (_x <= 0 || _x >= world.getWidth() || _y <= 0 || _y >= world.getHeight()); } /** @@ -534,6 +534,30 @@ public final boolean intersects(Actor actor) Green.getLinesIntersect(c1RUX, c1RUY, c1RDX, c1RDY, c2RUX, c2RUY, c2LUX, c2LUY) ); } + /** + * Checks to see if a point defined by {@code pX} and {@code pY} is within the {@link Actor}'s rotated rect. + * @param pX The X-axis coordinate of the point to check. + * @param pY The Y-axis coordinate of the point to check. + * @return Whether or not the point is within the bounds of the {@link Actor}. + */ + public final boolean pointInBounds(float pX, float pY) + { + float rotSin = sin(_rotation); + float rotCos = cos(_rotation); + float edgeX = _width / 2f; + float edgeY = _height / 2f; + + float cRDX = (edgeX * rotCos - edgeY * rotSin) + _x; + float cRDY = (edgeX * rotSin + edgeY * rotCos) + _y; + float cLDX = (-edgeX * rotCos - edgeY * rotSin) + _x; + float cLDY = (-edgeX * rotSin + edgeY * rotCos) + _y; + float cRUX = (edgeX * rotCos + edgeY * rotSin) + _x; + float cRUY = (edgeX * rotSin - edgeY * rotCos) + _y; + float cLUX = (-edgeX * rotCos + edgeY * rotSin) + _x; + float cLUY = (-edgeX * rotSin - edgeY * rotCos) + _y; + + return Green.pointInRectangle(cLUX, cLUY, cRUX, cRUY, cRDX, cRDY, cLDX, cLDY, pX, pY); + } /** * Retrieves a list of all objects matching {@code type} in the {@link World} that intersect with the {@link Actor}, using basic rect comparison. * @param The type of {@link Actor} to return if possible, as defined by {@code type}. @@ -543,7 +567,7 @@ public final boolean intersects(Actor actor) */ public final List getIntersectingObjects(Class type) throws NoWorldException //Compares rects of images { - World world = getWorld(); + World world = getWorldUnsafe(); List actors = world.getObjects(type); List retList = new ArrayList(); for(A actor : actors) @@ -560,7 +584,7 @@ public final List getIntersectingObjects(Class type) thr */ public final A getOneIntersectingObject(Class type) throws NoWorldException //Compares rects of images { - World world = getWorld(); + World world = getWorldUnsafe(); List actors = world.getObjects(type); for(A actor : actors) if(intersects(actor)) @@ -579,7 +603,7 @@ public final A getOneIntersectingObject(Class type) throws */ public final List getObjectsAtOffset(float oX, float oY, Class type, float range) throws NoWorldException { - World world = getWorld(); + World world = getWorldUnsafe(); if(world == null) return null; List actors = world.getObjects(type); List retList = new ArrayList(); @@ -615,7 +639,7 @@ public final List getObjectsAtOffset(float oX, float oY, Cl */ public final A getOneObjectAtOffset(float oX, float oY, Class type, float range) throws NoWorldException { - World world = getWorld(); + World world = getWorldUnsafe(); if(world == null) return null; List actors = world.getObjects(type); float tX = getX() + oX; @@ -648,7 +672,7 @@ public final A getOneObjectAtOffset(float oX, float oY, Class< */ public final List getObjectsInRange(float range, Class type) throws NoWorldException { - World world = getWorld(); + World world = getWorldUnsafe(); if(world == null) return null; List actors = world.getObjects(type); List retList = new ArrayList(); @@ -667,7 +691,7 @@ public final List getObjectsInRange(float range, Class t */ public final A getOneObjectInRange(float range, Class type) throws NoWorldException { - World world = getWorld(); + World world = getWorldUnsafe(); if(world == null) return null; List actors = world.getObjects(type); for(A actor : actors) @@ -708,6 +732,43 @@ public final void turnTowards(Actor obj) _rotation = atan2(obj.getY() - _y, obj.getX() - _x); } + //Mouse Methods + /** + * Retrieves whether or not a specific mouse button is currently down on this {@link Actor}. + * @param mouseButton The mouse button to check for - either {@link PConstants#LEFT}, {@link PConstants#CENTER}, or {@link PConstants#RIGHT}. + * @return Whether or not {@code mouseButton} is down. + */ + public final boolean isMouseButtonDownHere(int mouseButton) + { + return green.isMouseButtonDown(mouseButton) && pointInBounds(app.mouseX, app.mouseY); + } + /** + * Retrieves whether or not a specific mouse button was pressed this frame on this {@link Actor}. + * @param mouseButton The mouse button to check for - either {@link PConstants#LEFT}, {@link PConstants#CENTER}, or {@link PConstants#RIGHT}. + * @return Whether or not {@code mouseButton} was pressed in this frame. + */ + public final boolean isMouseButtonDownThisFrameHere(int mouseButton) + { + return green.isMouseButtonDownThisFrame(mouseButton) && pointInBounds(app.mouseX, app.mouseY); + } + /** + * Retrieves whether or not a specific mouse button was released this frame on this {@link Actor}. + * @param mouseButton The mouse button to check for - either {@link PConstants#LEFT}, {@link PConstants#CENTER}, or {@link PConstants#RIGHT}. + * @return Whether or not {@code mouseButton} was released in this frame. + */ + public final boolean isMouseButtonUpThisFrameHere(int mouseButton) + { + return green.isMouseButtonUpThisFrame(mouseButton) && pointInBounds(app.mouseX, app.mouseY); + } + /** + * Retrieves whether or not the mouse is currently scrolling on this {@link Actor}. + * @return Whether or not the mouse is currently scrolling. + */ + public final boolean isMouseScrollingHere() + { + return green.isMouseScrolling() && pointInBounds(app.mouseX, app.mouseY); + } + //Base Methods /** * Renders the {@link Actor} to the screen. By default, this method renders the {@link Actor} with it's image, position, rotation, and opacity taken into account, but it can be overridden for further use. diff --git a/src/Green/Green.java b/src/Green/Green.java index 8b9cf89..04b6d86 100644 --- a/src/Green/Green.java +++ b/src/Green/Green.java @@ -269,13 +269,36 @@ public PImage tileImage(PImage src, int w, int h) PImage img = parent.createImage(w, h, src.format); //Create a temporary image with the same pixel format as the source - int tW = (int) Math.ceil(w / src.width) + 1, tH = (int) Math.ceil(h / src.height) + 1; + int tW = (int) Math.ceil(w / src.width) + 1, tH = (int) Math.ceil((float) h / src.height) + 1; for (int y = 0; y < tH; y++) for (int x = 0; x < tW; x++) img.set(x * src.width, y * src.height, src); return img; } + private static float isLeft(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y) + { + return ((p1x - p0x) * (p2y - p0y) - (p2x - p0x) * (p1y - p0y)); + } + /** + * Checks whether a point ({@code pPx}, {@code pPy}) is within the bounds of a rectangle (({@code pXx}, {@code pXy}), ({@code pYx}, {@code pYy}), ({@code pZx}, {@code pZy}), ({@code pWx}, {@code pWy})) where the points are provided in clockwise order. + * @param pXx The X-axis position of the X point. + * @param pXy The Y-axis position of the X point. + * @param pYx The X-axis position of the Y point. + * @param pYy The Y-axis position of the Y point. + * @param pZx The X-axis position of the Z point. + * @param pZy The Y-axis position of the Z point. + * @param pWx The X-axis position of the W point. + * @param pWy The Y-axis position of the W point. + * @param pPx The X-axis position of the point to check. + * @param pPy The Y-axis position of the point to check. + * @return Whether the point to check is within the bounds of the provided rectangle. + * @see https://gamedev.stackexchange.com/a/110233 + */ + public static boolean pointInRectangle(float pXx, float pXy, float pYx, float pYy, float pZx, float pZy, float pWx, float pWy, float pPx, float pPy) + { + return (isLeft(pXx, pXy, pYx, pYy, pPx, pPy) > 0 && isLeft(pYx, pYy, pZx, pZy, pPx, pXy) > 0 && isLeft(pZx, pZy, pWx, pWy, pPx, pPy) > 0 && isLeft(pWx, pWy, pXx, pXy, pPx, pPy) > 0); + } //Base Methods /** diff --git a/src/Green/World.java b/src/Green/World.java index cc28afb..3d1eca1 100644 --- a/src/Green/World.java +++ b/src/Green/World.java @@ -248,6 +248,23 @@ public World(int w, int h, int bgColor, boolean unbounded) _backgroundColour = bgColor; _unbounded = unbounded; } + /** + * Creates a new world with defined dimensions and a background image, set to be bounded or otherwise. + * @param w The width to create the world with. + * @param h The height to create the world with. + * @param bgImage The background image. + * @param unbounded Whether or not {@link Actor} instances should be able to go out of bounds. + * @throws UnknownResizeFormatException Thrown when an unknown resize format is supplied. + */ + public World(int w, int h, PImage bgImage, boolean unbounded) + { + init(); + _width = w; + _height = h; + _sourceBackgroundImage = bgImage; + _unbounded = unbounded; + scaleBackgroundImage(_width, _height); + } /** * Creates a new world with defined dimensions and a background image, set to be bounded or otherwise. Also supplies a resizing format. * @param w The width to create the world with. @@ -267,6 +284,25 @@ public World(int w, int h, PImage bgImage, int resizeFormat, boolean unbounded) _unbounded = unbounded; scaleBackgroundImage(_width, _height); } + /** + * Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise. + * @param w The width to create the world with. + * @param h The height to create the world with. + * @param bgColor The background colour. Use the {@link processing.core.PApplet#color(int, int, int)} method to define it. + * @param bgImage The background image. + * @param unbounded Whether or not {@link Actor} instances should be able to go out of bounds. + * @throws UnknownResizeFormatException Thrown when an unknown resize format is supplied. + */ + public World(int w, int h, int bgColor, PImage bgImage, boolean unbounded) + { + init(); + _width = w; + _height = h; + _backgroundColour = bgColor; + _sourceBackgroundImage = bgImage; + _unbounded = unbounded; + scaleBackgroundImage(_width, _height); + } /** * Creates a new world with defined dimensions and a background image with a background colour to draw underneath, set to be bounded or otherwise. Also supplies a resizing format. * @param w The width to create the world with.