Class PhysicsEngine
java.lang.Object
fr.r1r0r0.deltaengine.model.engines.PhysicsEngine
- All Implemented Interfaces:
Engine
,java.lang.Runnable
final class PhysicsEngine extends java.lang.Object implements Engine
A physical engine
-
Field Summary
Fields Modifier and Type Field Description private MapLevel
mapLevel
private long
maxRunDelta
private double
maxRunDeltaRatio
private int
physicalRate
private static CollisionPositions[]
POSITIONS_CHECK
Explication de la mise en place des collisions entre une source et une target : la source est une entitite qui posssede une liste de points de collision qui par defaut correspondent aux points : topleft, topright, botleft, botright, center, centerleft, centerright, centertop, centerbot puis on va tester l appartenance d un de ces points dans la hitbox de la cible qui correspond a un minX maxX minY maxYprivate long
previousRunTime
-
Constructor Summary
Constructors Constructor Description PhysicsEngine()
Constructor -
Method Summary
Modifier and Type Method Description private Coordinates<java.lang.Double>
calcNextPosition(Coordinates<java.lang.Double> topLeft, Direction direction, double speed, double timeRatio)
Return the next position of the object describe by a topLeft, a direction, a speed, and a delta of timeboolean
canGoToNextCell(Entity entity, Direction direction)
Return if the entity is able to move with the direction givenprivate java.util.Set<Event>
checkCollisions(java.util.ArrayList<Entity> entities)
Return a list of event providing from collisions between all entities in the collection given If there is a collision between 2 entity A and B, the list of event that will be return will contain the event from A to B and the event from B to A.void
clearMap()
Clear the current mapLevelprivate boolean
fitOnCell(Entity entity)
Return if the entity fit on a cellvoid
init()
Initializerboolean
isAvailableDirection(Entity entity, Direction direction)
Return if the entity can move with the direction given in argumentprivate boolean
isOnTarget(Coordinates<java.lang.Double> topLeft, Dimension dimension, Coordinates<java.lang.Integer> target)
private boolean
isValidNextPosition(Entity entity, Coordinates<java.lang.Double> nextPosition)
Returns if the next position of the entity is in a valid position in the mapLevelvoid
run()
Update the coordinate of all entity in the current mapLevelvoid
setMap(MapLevel mapLevel)
Replace the current mapLevel with anothervoid
setMaxRunDelta(int fps)
Setter for the attribute maxRunDelta The new value of the attribute is calc by using the number of fpsvoid
setPhysicalRate(int physicalRate)
Setter for the attribute physicalRateprivate void
updateCoordinates(java.util.Collection<Entity> entities, double timeRatio)
Update the coordinates of each entity in a collection of entity If the coordinates can not be update, because of an illegal movement, the direction of the entity is set to IDLEMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
POSITIONS_CHECK
Explication de la mise en place des collisions entre une source et une target : la source est une entitite qui posssede une liste de points de collision qui par defaut correspondent aux points : topleft, topright, botleft, botright, center, centerleft, centerright, centertop, centerbot puis on va tester l appartenance d un de ces points dans la hitbox de la cible qui correspond a un minX maxX minY maxY -
mapLevel
-
previousRunTime
private long previousRunTime -
maxRunDelta
private long maxRunDelta -
maxRunDeltaRatio
private double maxRunDeltaRatio -
physicalRate
private int physicalRate
-
-
Constructor Details
-
PhysicsEngine
public PhysicsEngine()Constructor
-
-
Method Details
-
init
public void init()Initializer -
run
public void run()Update the coordinate of all entity in the current mapLevel- Specified by:
run
in interfacejava.lang.Runnable
-
checkCollisions
Return a list of event providing from collisions between all entities in the collection given If there is a collision between 2 entity A and B, the list of event that will be return will contain the event from A to B and the event from B to A.- Parameters:
entities
- a collection of entity
-
updateCoordinates
Update the coordinates of each entity in a collection of entity If the coordinates can not be update, because of an illegal movement, the direction of the entity is set to IDLE- Parameters:
entities
- a collection of entitytimeRatio
- a ratio of time used to calc the movement
-
isOnTarget
private boolean isOnTarget(Coordinates<java.lang.Double> topLeft, Dimension dimension, Coordinates<java.lang.Integer> target) -
isAvailableDirection
Return if the entity can move with the direction given in argument- Parameters:
entity
- an entitydirection
- a direction- Returns:
- if the entity can move with the direction given
-
calcNextPosition
private Coordinates<java.lang.Double> calcNextPosition(Coordinates<java.lang.Double> topLeft, Direction direction, double speed, double timeRatio)Return the next position of the object describe by a topLeft, a direction, a speed, and a delta of time- Parameters:
topLeft
- a position topLeft of the objectdirection
- the direction of the objectspeed
- the speed of the objecttimeRatio
- a ratio of time- Returns:
- the next position of the object describe
-
canGoToNextCell
Return if the entity is able to move with the direction given- Parameters:
entity
- an entitydirection
- a direction- Returns:
- if the entity is able to move with the direction given
-
fitOnCell
Return if the entity fit on a cell- Parameters:
entity
- an entity- Returns:
- if the entity fit on a cell
-
isValidNextPosition
Returns if the next position of the entity is in a valid position in the mapLevel- Parameters:
entity
- an entitynextPosition
- the next position of the entity- Returns:
- if the position of the rectangle is valid in the mapLevel
-
setMap
Replace the current mapLevel with another- Parameters:
mapLevel
- a mapLevel
-
clearMap
public void clearMap()Clear the current mapLevel -
setMaxRunDelta
public void setMaxRunDelta(int fps)Setter for the attribute maxRunDelta The new value of the attribute is calc by using the number of fps- Parameters:
fps
- the number of fps
-
setPhysicalRate
public void setPhysicalRate(int physicalRate)Setter for the attribute physicalRate- Parameters:
physicalRate
- a physicalRate
-