|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectActivity
android.gameengine.icadroids.engine.GameEngine
public abstract class GameEngine
GameEngine is the core of the game. Extending this class is required to make use of the GameEngine. It contains many methods for GameObjects, Alarms, Sensors, Tiles, etc.
Field Summary | |
---|---|
LinearLayout |
dashboard
The game dashboard. |
java.util.ArrayList<LinearLayout> |
dashboards
It is possible to have multiple dashboards, stacked on top of each other. this.dashboard always holds the top level dashboard. |
static java.util.Vector<Alarm> |
gameAlarms
A vectorlist that holds all the active alarms. |
static GameTiles |
gameTiles
|
static java.util.Vector<GameObject> |
items
A vectorlist that holds all the active GameObjects. |
static java.util.Vector<GameObject> |
newItems
A vectorlist that holds all the newly created GameObjects during this cycle of the game loop. |
static boolean |
printDebugInfo
|
Constructor Summary | |
---|---|
GameEngine()
The GameEngine forms the core of the game by controlling the gameloop and the render operations. |
Method Summary | ||
---|---|---|
static void |
addAlarm(Alarm a)
Add an Alarm to the list of alarms in the GameEngine. |
|
void |
addDashboard()
Add a new dashboard. |
|
void |
addGameObject(GameObject gameObject)
Add a GameObject to the game. |
|
void |
addGameObject(GameObject gameObject,
float layerposition)
Add a GameObject to the game. |
|
void |
addGameObject(GameObject gameObject,
int x,
int y)
Add a GameObject to the game. |
|
void |
addGameObject(GameObject gameObject,
int x,
int y,
float layerposition)
Add a GameObject to the game. |
|
void |
addListOfObject(java.util.Collection<GameObject> objectList)
Add a collection of GameObjects. |
|
void |
addToDashboard(LinearLayout dashboard,
View v)
Add an item to a specific dashboard. |
|
void |
addToDashboard(View v)
Add an item to the dashboard that's currently on top. |
|
void |
clearBackgroundImage()
Clears the background Image so only the background color will show |
|
void |
deleteAlarm(Alarm a)
Remove an alarm from the GameEngine. |
|
void |
deleteAllAlarms()
Removes all alarm instances |
|
void |
deleteAllGameObjects()
Delete all GameObjects from the game |
|
|
deleteAllGameObjectsOfType(java.lang.Class<T> type)
Remove all GameObject instances of given class type. |
|
void |
deleteGameObject(GameObject gameObject)
Delete a GameObject from the game. |
|
protected void |
endGame()
End the game and close the application. |
|
java.util.Vector<GameObject> |
findItemAt(Rect rectangle)
This function finds gameObjects inside a given rectangle. |
|
static Context |
getAppContext()
Get Interface to global information about an application environment. |
|
static View |
getAppView()
DO NOT CALL THIS METHOD |
|
GameObject |
getGameObjectAtTouchPosition(int touchSize)
Get the first (rendered) object that is touched. |
|
|
getItemsOfType(java.lang.Class<T> type)
Get all instances of the specified type that are currently in the game |
|
int |
getMapHeight()
Get the height of the game world |
|
int |
getMapWidth()
Get the width of the game world |
|
MoveableGameObject |
getPlayer()
Return the player instance. |
|
int |
getRandomX(int width)
Get random x between left edge of world and right edge minus the specified width. |
|
int |
getRandomY(int height)
Get random y between top edge of world and bottom edge minus the specified height. |
|
static int |
getScreenHeight()
Gets the screen height of the telephone this value may change when flipping the telephone. |
|
static int |
getScreenWidth()
Gets the screen Width of the telephone this value may change when flipping the telephone. |
|
protected abstract void |
initialize()
This method is like a 'postponed constructor'. |
|
protected void |
initializeGameEngine()
Don't override this method, use initialize() instead This method is called by the GameView to notify the gameEngine to start initializing. |
|
void |
intializeInput()
Initialize the touch and/or the onScreenButtons |
|
boolean |
isTileBasedMap()
Ask whether this game has a tilemap |
|
void |
onAccuracyChanged(Sensor sensor,
int accuracy)
DO NOT CALL THIS METHOD This method is part of the Android sensor mechanism. |
|
protected void |
onCreate(Bundle savedInstanceState)
Do NOT call this method. |
|
protected void |
onDestroy()
DO NOT CALL THIS METHOD This method is part of the Android Activity lifecycle which is managed by GameEngine itself. |
|
protected void |
onPause()
DO NOT CALL THIS METHOD This method is part of the Android Activity lifecycle which is managed by GameEngine itself. |
|
protected void |
onResume()
DO NOT CALL THIS METHOD This method is part of the Android Activity lifecycle which is managed by GameEngine itself. |
|
void |
onSensorChanged(SensorEvent event)
DO NOT CALL THIS METHOD This method is part of the Android sensor mechanism. |
|
void |
pause()
Pause the game (stop the gamethread) |
|
static void |
printDebugInfo(java.lang.String tag,
java.lang.String msg)
Print information into the Logcat, for debugging purposes. |
|
void |
resume()
Resume the game when it had been paused. |
|
void |
setBackground(java.lang.String backgroundImage)
Sets the background image of the current view. |
|
void |
setBackground(java.lang.String backgroundImage,
boolean backgroundFit)
Sets the background image of the current view. |
|
void |
setBackgroundColor(int backgroundColor)
Set the background color. |
|
void |
setMapDimensions(int mapWidth,
int mapHeight)
Set the dimensions of the game world. |
|
void |
setPlayer(MoveableGameObject player)
Name a GameObject in the role of the Player object. |
|
void |
setPlayerPositionOnScreen(int hpositioning,
int vpositioning)
When using a viewport, set the position of the player on the screen. |
|
void |
setPlayerPositionTolerance(double ht,
double vt)
Set the tolerance of the positioning of the player. |
|
void |
setScreenLandscape(boolean landscape)
Set landscape mode or normal mode on android device |
|
protected void |
setTileMap(GameTiles gameTiles)
Set a GameTiles object as the current GameTile map. |
|
void |
setZoomFactor(float zoomFactor)
Set the zoom factor for the viewport. |
|
void |
showKeyboard()
Shows the onscreen keyboard. |
|
Point |
translateToGamePosition(float x,
float y)
Translates a given screen position to a position in the game world, taking into consideration the viewport location and the zoom factor. |
|
void |
update()
Allows the game to run logic such as updating the world, gathering input and playing audio. |
|
protected void |
updateGame()
Do NOT call this method. |
|
void |
vibrate(int milliseconds)
vibrates the phone for the amount of milliseconds specified. |
|
void |
vibrate(long[] pattern)
Vibrates the phone in the specified pattern. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean printDebugInfo
public static java.util.Vector<GameObject> items
public static java.util.Vector<GameObject> newItems
public static java.util.Vector<Alarm> gameAlarms
public static GameTiles gameTiles
public LinearLayout dashboard
public java.util.ArrayList<LinearLayout> dashboards
Constructor Detail |
---|
public GameEngine()
initialize()
Method Detail |
---|
protected final void onCreate(Bundle savedInstanceState)
Called when activity is started. Initialise GameEngine objects and set
options to be used by the GameEngine.
This method is part of the Android Activity lifecycle which is managed by
GameEngine itself.
savedInstanceState
- protected void initializeGameEngine()
protected abstract void initialize()
public void intializeInput()
protected final void updateGame()
Call the update for every GameObject added to the list.
public final void onAccuracyChanged(Sensor sensor, int accuracy)
This method is part of the Android sensor mechanism. It is used by GameEngine itself.
public void onSensorChanged(SensorEvent event)
This method is part of the Android sensor mechanism. It is used by GameEngine itself.
public void update()
Override this method inside your game base class that extends from GameEngine. Every pass of the game loop this method is called once.
GameObjects that were added to the game (by either addPlayer or addGameObject) should NOT be updated here. Classes that extend from GameObject or MovableGameObject have their own update() that should be overwritten.
MoveableGameObject
,
GameObject
public static void addAlarm(Alarm a)
a
- The alarm to be added.public void deleteAlarm(Alarm a)
a
- The alarm to be deleted.public void deleteAllAlarms()
public final void deleteGameObject(GameObject gameObject)
gameObject
- The GameObject instance to be removedpublic final void deleteAllGameObjects()
public <T> void deleteAllGameObjectsOfType(java.lang.Class<T> type)
type
- De class type of the instances to be removedprotected final void onResume()
This method is part of the Android Activity lifecycle which is managed by GameEngine itself.
protected final void onDestroy()
This method is part of the Android Activity lifecycle which is managed by GameEngine itself.
protected final void onPause()
This method is part of the Android Activity lifecycle which is managed by GameEngine itself.
protected final void endGame()
public final void addGameObject(GameObject gameObject, int x, int y)
gameObject
- The GameObject that will be added to the game. Should have
either GameObject or MovableGameObject as it's parent.x
- The X spawnlocation when this object is createdy
- The Y spawnlocation when this object is createdpublic final void addGameObject(GameObject gameObject, int x, int y, float layerposition)
gameObject
- The GameObject that will be added to the game. Should have
either GameObject or MovableGameObject as it's parent.x
- The X spawnlocation when this object is createdy
- The Y spawnlocation when this object is createdlayerposition
- The layerposition when this object is drawed. Between 0 and
1 (float). 1 front, 0 backpublic final void addGameObject(GameObject gameObject, float layerposition)
gameObject
- The GameObject that will be added to the game. Should have
either GameObject or MovableGameObject as it's parent.layerposition
- The layerposition when this object is drawed. Between 0 and
1 (float). 1 front, 0 backpublic final void addGameObject(GameObject gameObject)
gameObject
- The GameObject that will be added to the game. Should have either
GameObject or MovableGameObject as it's parent.public final void addListOfObject(java.util.Collection<GameObject> objectList)
objectList
- protected void setTileMap(GameTiles gameTiles)
gameTiles
- the current gameTiles object.public boolean isTileBasedMap()
public final void vibrate(long[] pattern)
pattern
- the pattern is an array of milliseconds. the first value in
the pattern is the amount of time to wait before turning the
vibration on the second value is how long it should actually
vibrate this is repeated trough out:
gap-vibration-gap-vibration etc.. example SOS: long[] pattern
= {200,500,200,800,200,500,200}; in this number 200 is
represented as a short gap.public final void vibrate(int milliseconds)
milliseconds
- the amount of millisecondspublic final MoveableGameObject getPlayer()
public final void setPlayer(MoveableGameObject player)
player
- The player that should be added to the game. The location of
this player is used by the viewport.public final void setBackground(java.lang.String backgroundImage, boolean backgroundFit)
backgroundImage
- The name of the background image that will be set.backgroundFit
- boolean, indicating if the image must be scaled to fit.public final void setBackground(java.lang.String backgroundImage)
backgroundImage
- The name of the background image that will be setpublic final void setZoomFactor(float zoomFactor)
zoomFactor
- a float, the factor by which the view must be enlarged.public final void setPlayerPositionOnScreen(int hpositioning, int vpositioning)
hpositioning
- the horizontal postioning, or Viewport.PLAYER_NOADJUST if there is no horizontal
adjustment of the viewportvpositioning
- the vertical postioning, or Viewport.PLAYER_NOADJUST if there is no vertical
adjustment of the viewportpublic final void setPlayerPositionTolerance(double ht, double vt)
ht
- horizontal tolerance, a value between 0 and 1vt
- vertical tolerance, a value between 0 and 1public Point translateToGamePosition(float x, float y)
x
- the screen xy
- the screen y
public final void clearBackgroundImage()
public final <T> java.util.Vector<GameObject> getItemsOfType(java.lang.Class<T> type)
type
- the class name with .class behind it.
public final java.util.Vector<GameObject> findItemAt(Rect rectangle)
rectangle
- the rectangle specified in a left, top to bottom,right
location
public int getMapWidth()
public int getMapHeight()
public void setMapDimensions(int mapWidth, int mapHeight)
mapWidth
- an int specifying the width of the game worldmapHeight
- an int specifying the height of the game worldpublic static final int getScreenWidth()
public static final int getScreenHeight()
public final void setScreenLandscape(boolean landscape)
landscape
- true if landscape screen is required, false if notpublic static Context getAppContext()
public static View getAppView()
public void setBackgroundColor(int backgroundColor)
backgroundColor
- public void pause()
public void resume()
public void showKeyboard()
public static void printDebugInfo(java.lang.String tag, java.lang.String msg)
tag
- The tag (shown in Logcat)msg
- The message you want to be displayedpublic final GameObject getGameObjectAtTouchPosition(int touchSize)
touchSize
- The size (rectangle) around the finger that will be checked
for objects.
public int getRandomX(int width)
width
-
public int getRandomY(int height)
height
-
public void addDashboard()
public void addToDashboard(View v)
v
- the view to add to the dashboard.public void addToDashboard(LinearLayout dashboard, View v)
dashboard
- v
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |