Class SelectableComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.friendlyunits.SelectableComponent
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(float inside, float from, float to) boolean
containsUs
(int startX, int startY, int endX, int endY) Called when player wishes to select units in a certain area on the screen and checks if this unit is in that areavoid
create()
Called when the entity is created and registered.boolean
boolean
isIn
(int xCoordinate, int yCoordinate) Called when a single click form the player happens.boolean
void
moveLocation
(int screenX, int screenY) void
multipleHover
(int startX, int startY, int endX, int endY) void
multipleSelect
(int startX, int startY, int endX, int endY) com.badlogic.gdx.math.Vector2
screenToWorldPosition
(int screenX, int screenY) Turns a selected screen position to the world positionvoid
singleHover
(int xCoordinate, int yCoordinate) void
singleSelect
(int xCoordinate, int yCoordinate) void
unselect()
Methods inherited from class com.deco2800.game.components.Component
dispose, earlyUpdate, getEntity, isAnimationRenderComponent, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
SelectableComponent
public SelectableComponent()initializes component with unit not being selected
-
-
Method Details
-
unselect
public void unselect() -
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
singleHover
public void singleHover(int xCoordinate, int yCoordinate) -
multipleHover
public void multipleHover(int startX, int startY, int endX, int endY) -
singleSelect
public void singleSelect(int xCoordinate, int yCoordinate) -
multipleSelect
public void multipleSelect(int startX, int startY, int endX, int endY) -
isIn
public boolean isIn(int xCoordinate, int yCoordinate) Called when a single click form the player happens. Checks if the hitbox of current entity is inside that click If it is, this unit is selected and if it's not, then do nothing- Parameters:
xCoordinate
- The x coordinate of the mouseyCoordinate
- The y coordinate of the mouse- Returns:
-
containsUs
public boolean containsUs(int startX, int startY, int endX, int endY) Called when player wishes to select units in a certain area on the screen and checks if this unit is in that area- Parameters:
startX
- start of x coordinate of boxstartY
- start of y coordinate of boxendX
- end of x coordinate of boxendY
- end of y coordinate of box
-
contains
public boolean contains(float inside, float from, float to) - Parameters:
inside
- position to checkfrom
- one bound to checkto
- other bounch to check- Returns:
- true if inside is between from and to
-
screenToWorldPosition
public com.badlogic.gdx.math.Vector2 screenToWorldPosition(int screenX, int screenY) Turns a selected screen position to the world position- Parameters:
screenX
- screen position of xscreenY
- screen position of y- Returns:
- (x,y) in vector form in the world
-
moveLocation
public void moveLocation(int screenX, int screenY) -
isSelected
public boolean isSelected()- Returns:
- if the unit is selected to function with other components
-
isHovered
public boolean isHovered()
-