Package group24.escaperoom.entities
Class Item
java.lang.Object
group24.escaperoom.entities.Item
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable,Drawable
-
Field Summary
FieldsModifier and TypeFieldDescriptioncom.badlogic.gdx.graphics.Colorcoloris the color applied to this batch before drawing this itembooleanflippedrepresents whether or not an item is rotated in such a way that it's width and height are "flipped".intitemis the effectively final size of the item in world units, as if no transformations have occured.A reference to the MapScreen that this item is current on.booleanWhether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV)booleanWhether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV)occupiedSizeis the dynamically adjusted size of this item that changes with rotationsintThe render priority of this item.booleanWhether this item is currently selected -
Constructor Summary
ConstructorsConstructorDescriptionItem()Empty constructor forJson.SerializablecompatabilityItem(ObjectTypeData typeData) Construct an item fromObjectTypeData -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProperty(ItemProperty<? extends ItemPropertyValue> property) Add a property to this itemvoidadjustTextureRegion(int x, int y, int width, int height) Set the region of the underlying texture for this itemOptional<com.badlogic.gdx.math.Rectangle>clone()Get an exact clone of this item, copying all attributes exceptidclone(boolean preserveID) Get an exact clone of this itemcopy()voidDecrease this item's render priorityvoiddraw(com.badlogic.gdx.graphics.g2d.Batch batch) Draw this Drawable on theBatchbooleanvoidflip()This function swaps the item's occuped with and height, toggling itsflippedstatefloatgetAlpha()floatDraw rotation versus logical rotation is relevant forSpinnablePropertyitems The draw rotation for a spinnable item is always 0;draw(com.badlogic.gdx.graphics.g2d.Batch)intintgetID()com.badlogic.gdx.math.RectangleThis is different than theblockingRegion()in that every object must have an occupied region, but not all objects must block the player.com.badlogic.gdx.utils.Array<PlayerAction>Collection<ItemProperty<? extends ItemPropertyValue>>com.badlogic.gdx.utils.Array<ItemProperty<? extends ItemPropertyValue>>getProperties(PropertyType... types) Optional<ItemProperty<? extends ItemPropertyValue>>getProperty(PropertyType type) <T extends ItemPropertyValue,P extends ItemProperty<T>>
Optional<P>getProperty(PropertyType type, Class<P> expectedClass) intcom.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegionintgetType()intgetWidth()intgetX()intgetY()booleanhasProperty(PropertyType type) voidIncrease this item's render priorityvoidinitItem(ObjectTypeData typeData) booleanvoidSet whether this item's texture is mirrored horizontallyvoidSet whether this item's texture is mirrored veritcallyvoidmoveTo(int x, int y) Move the item.com.badlogic.gdx.math.Vector2position()voidread(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonData) Read item json to initialize this itemvoidForce an item to reload its texturevoidremove()Remove this item from the mapvoidremove(boolean temporary) Remove this item from the mapvoidremoveProperty(PropertyType type) remove a property to from itemintvoidrotateBy(int degrees) Adddegreesto this item's logical rotationvoidsetAlpha(float alpha) Convience method to set the alpha component of this items'sColorvoidsetBlocksPlayer(boolean blocksPlayer) Set if this object should block player movement The region that is blocked is assumed to be the region defined byvoidsetBlocksPlayer(float offsetX, float offsetY, float blockWidth, float blockHeight) Set if this object should block player movementvoidsetColor(float r, float b, float g, float a) voidsetColor(com.badlogic.gdx.graphics.Color color) voidsetContained(boolean isContained) voidsetDimmed(boolean dimmed) voidsetFocus(boolean isFocused) Set whether this item is currently focused by thePlayervoidsetHeight(int height) Set height - This is the original height of the item, not the currently occupied heightvoidsetHighlighed(boolean highlighted) voidsetPosition(int x, int y) Set the position of this itemvoidSet the position of this itemvoidsetRenderPriority(int priority) Set the render priority of this itemvoidsetRotation(int degrees) Set the logical rotation of this itemvoidsetSelected(boolean isSelected) Set whether this object is selected in theLevelEditorScreenvoidsetTexture(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion region) Set the texture of this item.voidsetWidth(int width) Set width - This is the original width of the item, not the currently occupied widthtoString()voidupdate(float delta) Update item statevoidwrite(com.badlogic.gdx.utils.Json json) Write our this items json tojson
-
Field Details
-
map
A reference to the MapScreen that this item is current on. -
id
public int id -
position
-
renderPriority
public int renderPriorityThe render priority of this item. This is how "high up" the item is in the world. -
selected
public boolean selectedWhether this item is currently selected -
flipped
public boolean flippedflippedrepresents whether or not an item is rotated in such a way that it's width and height are "flipped". This is only relevant for items with widths and heigts that are not equal e.g. _______ | | ------- -
mirrorH
public boolean mirrorHWhether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV) -
mirrorV
public boolean mirrorVWhether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV) -
color
public com.badlogic.gdx.graphics.Color colorcoloris the color applied to this batch before drawing this item -
occupiedSize
occupiedSizeis the dynamically adjusted size of this item that changes with rotations -
itemSize
itemis the effectively final size of the item in world units, as if no transformations have occured.
-
-
Constructor Details
-
Item
public Item()Empty constructor forJson.Serializablecompatability -
Item
Construct an item fromObjectTypeData- Parameters:
typeData- to construct from
-
-
Method Details
-
initItem
-
write
public void write(com.badlogic.gdx.utils.Json json) Write our this items json tojson- Specified by:
writein interfacecom.badlogic.gdx.utils.Json.Serializable
-
read
public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonData) Read item json to initialize this item- Specified by:
readin interfacecom.badlogic.gdx.utils.Json.Serializable
-
printString
-
update
public void update(float delta) Update item state- Parameters:
delta- amount of time since the last call
-
reloadTexture
public void reloadTexture()Force an item to reload its texture -
clone
Get an exact clone of this item, copying all attributes exceptid -
clone
Get an exact clone of this item- Parameters:
preserveID- whether or not to assign a new id to the newly created item- Returns:
- A clone of this item
-
copy
- Returns:
- a copy of this item, respecting any property values
that are non-copyable (like
ItemContainsItem)
-
getItemName
- Returns:
- the User-facing String describing this Item
- This includes an optional style prefix followed by the name spcecified by
ObjectTypeData.name
-
getPlayerActions
- Parameters:
ctx- theGameContext- Returns:
- the available
PlayerActions for this item
-
adjustTextureRegion
public void adjustTextureRegion(int x, int y, int width, int height) Set the region of the underlying texture for this item- Parameters:
x- region-local offset in the x-directiony- region-local offset in the y-directionwidth- new widthheight- new height
-
toString
-
equals
-
remove
public void remove(boolean temporary) Remove this item from the map- Parameters:
temporary- whether or not this removal is temporary this param signals to the map that this item will likely soon be replaced
-
remove
public void remove()Remove this item from the map- See Also:
-
addProperty
Add a property to this item- Parameters:
property- to add
-
removeProperty
remove a property to from item- Parameters:
type- to remove
-
hasProperty
- Parameters:
type- to query- Returns:
- whether this item has a certain property
-
getProperties
-
getProperty
-
getProperty
public <T extends ItemPropertyValue,P extends ItemProperty<T>> Optional<P> getProperty(PropertyType type, Class<P> expectedClass) -
getProperties
public com.badlogic.gdx.utils.Array<ItemProperty<? extends ItemPropertyValue>> getProperties(PropertyType... types) -
mirrorHorizontal
public void mirrorHorizontal()Set whether this item's texture is mirrored horizontally -
setRenderPriority
public void setRenderPriority(int priority) Set the render priority of this item- Parameters:
priority- new value
-
setWidth
public void setWidth(int width) Set width - This is the original width of the item, not the currently occupied width- Parameters:
width- new value
-
setHeight
public void setHeight(int height) Set height - This is the original height of the item, not the currently occupied height- Parameters:
height- new value
-
increaseRenderPriotity
public void increaseRenderPriotity()Increase this item's render priority -
decreaseRenderPriotity
public void decreaseRenderPriotity()Decrease this item's render priority -
mirrorVertical
public void mirrorVertical()Set whether this item's texture is mirrored veritcally -
setHighlighed
public void setHighlighed(boolean highlighted) -
setDimmed
public void setDimmed(boolean dimmed) -
setPosition
Set the position of this item- Parameters:
pos- new value- See Also:
-
setPosition
public void setPosition(int x, int y) Set the position of this item- Parameters:
x- new x coordy- new y coord- See Also:
-
moveTo
public void moveTo(int x, int y) Move the item. This differs fromsetPosition(int,int)in it updates various properties that depend on position. e.g.TiledBrushableitems need to refresh their adjacency- Parameters:
x- new x coordy- new y coord
-
setBlocksPlayer
public void setBlocksPlayer(float offsetX, float offsetY, float blockWidth, float blockHeight) Set if this object should block player movement- Parameters:
offsetX- from the bottom left corner for the start of the blocking regionoffsetY- from the bottom left corner for the start of the blocking regionblockWidth- width of the blocking regionblockHeight- height of the blocking region
-
setTexture
public void setTexture(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion region) Set the texture of this item.- Parameters:
region- new region
-
setFocus
public void setFocus(boolean isFocused) Set whether this item is currently focused by thePlayer- Parameters:
isFocused- whether or not is focused
-
setContained
public void setContained(boolean isContained) -
setBlocksPlayer
public void setBlocksPlayer(boolean blocksPlayer) Set if this object should block player movement The region that is blocked is assumed to be the region defined bynew Rectangle(getX(), getY(), getWidth(), getHeight());
Unless a different region was specifiedsetBlocksPlayer(int,int,int,int)- Parameters:
blocksPlayer- whether or not the entire item blocks the player
-
setSelected
public void setSelected(boolean isSelected) Set whether this object is selected in theLevelEditorScreen- Parameters:
isSelected- whether or not the item is selected
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color color) - Parameters:
color- new color
-
setColor
public void setColor(float r, float b, float g, float a) - Parameters:
r- red componentg- green componentb- blue componenta- alpha component
-
setAlpha
public void setAlpha(float alpha) Convience method to set the alpha component of this items'sColor- Parameters:
alpha- new alpha
-
getAlpha
public float getAlpha() -
setRotation
public void setRotation(int degrees) Set the logical rotation of this item- Parameters:
degrees- new value
-
rotateBy
public void rotateBy(int degrees) Adddegreesto this item's logical rotation- Parameters:
degrees- amount to add
-
flip
public void flip()This function swaps the item's occuped with and height, toggling itsflippedstate -
getX
public int getX()- Returns:
- x coordinate of the lower left corner of this item
-
getY
public int getY()- Returns:
- y coordinate of the lower left corner of this item
-
blockingRegion
- Returns:
- an
Optionalregion where this object should block player movement IfOptional.empty()is returned, this object should not block player movement - See Also:
-
getTexture
public com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion getTexture()- Returns:
- this item's texture
-
getOccupiedRegion
public com.badlogic.gdx.math.Rectangle getOccupiedRegion()This is different than theblockingRegion()in that every object must have an occupied region, but not all objects must block the player. For objects which block the player, it need not be that the blocking region == occupied region- Returns:
- the items occupied region
-
getPosition
- Returns:
- the lower left corner of this item
-
getType
- Returns:
- the
ObjectTypeDatadescribing this item
-
getOccupiedSize
- Returns:
- the occupied size of this item.
- See Also:
-
getID
public int getID() -
getHeight
public int getHeight()- Returns:
- ths items height
getOccupiedSize()
-
getWidth
public int getWidth()- Returns:
- ths items width
getOccupiedSize()
-
isContained
public boolean isContained()- Returns:
- whether or not this item is contained
-
getRotation
public int getRotation()- Returns:
- the logical rotation of this item
-
getDrawRotation
public float getDrawRotation()Draw rotation versus logical rotation is relevant forSpinnablePropertyitems The draw rotation for a spinnable item is always 0;draw(com.badlogic.gdx.graphics.g2d.Batch)- Returns:
- the draw rotation
-
renderPriority
public int renderPriority()- Specified by:
renderPriorityin interfaceDrawable- Returns:
- the renderPriority of this Drawable
-
position
public com.badlogic.gdx.math.Vector2 position() -
getTileDepth
public int getTileDepth()- Specified by:
getTileDepthin interfaceDrawable- Returns:
- the tile depth of this Drawable
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch) Description copied from interface:DrawableDraw this Drawable on theBatch
-