group1.model
Class Environment

java.lang.Object
  extended by group1.model.Environment

public class Environment
extends java.lang.Object

An environment, or a level, that contains a list of game objects. (Terrain, enemies, Jeff, etc.) In other words, the various areas in which the action will take place.

Note that this class and the GameObj classes technically store the data upside-down. Java treats the y-axis as top-to-bottom, which is too confusing for actual physics calculations. So, we make all calculations as though it's represented from bottom-to-top, then reverse the values later.


Constructor Summary
Environment()
          Default constructor.
Environment(java.util.List<GameObj> objs, Jeff jef, int w, int h)
          Constructor.
 
Method Summary
 void addObject(GameObj obj)
          Add an object.
 void addObject(GameObj obj, double x, double y)
          Add object, with the position explicitly defined by the caller.
 void addObject(GameObj obj, GameObj creatorObj)
          Add an object, with the position defined as being the position of the object that "created" or "threw" it.
 double getGravity()
          Get the gravity from the environment.
 XYPair getGroundVelocity(GameObj obj)
          Check whether or not an object is on ground that it can walk on, AND return the velocity of the ground if it's on ground.
 double getHeight()
          Return the "true" height of the Environment.
 XYPair getJeffsPosition()
          Get Jeff's position.
 GameObj getObject(int i)
          Return the specified object in the environment.
 java.util.List<GameObj> getObjectList()
          Return the full list of objects in the Environment.
 java.util.List<GameObj> getObjectListCopy()
          Return a copy of the list of objects in the Environment.\
 int getObjectListSize()
          Return the size of the list of all objects in the environment.
 double getWidth()
          Return the "true" width of the Environment.
 boolean isObjectNearLadder(GameObj obj)
          Check whether or not an object is close enough to a ladder to grab it.
 boolean isObjectOnGround(GameObj obj)
          Check whether or not an object is on ground that it can walk on.
 boolean removeObj(GameObj obj)
          Remove an object.
 void setGravity(double grav)
          Set the gravity.
 TimeClickReturn timeClick()
          Calculates and sets the positions and velocities of all objects in the environment, based upon the objects' own movements and hit detection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Environment

public Environment()
Default constructor.


Environment

public Environment(java.util.List<GameObj> objs,
                   Jeff jef,
                   int w,
                   int h)
Constructor.

Parameters:
objs - The list of GameObjs to initialize this environment with.
jef - The hero of the game. (The only object that carries over between environments.)
w - The width of the environment.
h - The height of the environment.
Method Detail

setGravity

public void setGravity(double grav)
Set the gravity. (Otherwise, uses a default value.)

Parameters:
grav - The gravity value. (Should be negative. Unless we're falling up or something...?)

timeClick

public TimeClickReturn timeClick()
Calculates and sets the positions and velocities of all objects in the environment, based upon the objects' own movements and hit detection. Returns a value to indicate if Jeff has died or completed the level.

This should be called by the Game class at each time click.

Returns:
An enum-type value representing the state of gameplay: JEFF_DIED, JEFF_WON, or CONTINUE_PLAYING.

getGroundVelocity

public XYPair getGroundVelocity(GameObj obj)
Check whether or not an object is on ground that it can walk on, AND return the velocity of the ground if it's on ground. Useful for objects that can stand on the ground, and want to conserve momentum and physics properly on platforms. (Due to time constraints, we might only truly implement this for Jeff, since each object has to handle the values themselves.) (And, I can't really figure out how to do it for objects generically at the moment.)

Parameters:
obj - The object in question.
Returns:
The velocity of the ground, or null if it is not standing on ground.

isObjectOnGround

public boolean isObjectOnGround(GameObj obj)
Check whether or not an object is on ground that it can walk on. Useful for objects that can stand on the ground.

Parameters:
obj - The object in question.
Returns:
Whether or not that object is on the ground.

isObjectNearLadder

public boolean isObjectNearLadder(GameObj obj)
Check whether or not an object is close enough to a ladder to grab it. (Currently not implemented, and returns false. Hopefully, to be implemented later.)

Parameters:
obj - The object in question.
Returns:
Whether or not the object is near a ladder.

getGravity

public double getGravity()
Get the gravity from the environment. (Generally assumed to be negative.) Useful for any object that is affected by gravity.

Returns:
The gravity value.

getJeffsPosition

public XYPair getJeffsPosition()
Get Jeff's position. Useful for enemy AI.

Returns:
Jeff's position as an XY pair.

getObjectList

public java.util.List<GameObj> getObjectList()
Return the full list of objects in the Environment.

Returns:
All the objects.

getObjectListCopy

public java.util.List<GameObj> getObjectListCopy()
Return a copy of the list of objects in the Environment.\

Returns:
All the objects (as a new list).

getObject

public GameObj getObject(int i)
Return the specified object in the environment. (Use with getObjectListSize().)

Parameters:
i - The index of the GameObj.
Returns:
The i'th game object in the list.

getObjectListSize

public int getObjectListSize()
Return the size of the list of all objects in the environment.

Returns:
The size of the list of game objects.

getHeight

public double getHeight()
Return the "true" height of the Environment.

Returns:
The height as a double value.

getWidth

public double getWidth()
Return the "true" width of the Environment.

Returns:
The width as a double value.

addObject

public void addObject(GameObj obj,
                      GameObj creatorObj)
Add an object, with the position defined as being the position of the object that "created" or "threw" it. Example: An enemy throws, oh, I don't know, a hammer. :) The hammer appears at the same position of the enemy that threw the hammer.

Parameters:
obj - The GameObj being added.
creatorObj - The object "creating" or "throwing" this object.

addObject

public void addObject(GameObj obj,
                      double x,
                      double y)
Add object, with the position explicitly defined by the caller.

Parameters:
obj - The GameObj being added.
x - The x-position of the object.
y - The x-position of the object.

addObject

public void addObject(GameObj obj)
Add an object. NOTE: To use this version safely, you must set the object's position, first! Otherwise, it will have a nonsense position.

Parameters:
obj - The GameObj being added.

removeObj

public boolean removeObj(GameObj obj)
Remove an object.

Parameters:
obj - The GameObj being removed.
Returns:
Whether or not the object was in the environment.