public class GameObjectsMap {
public static final int HEIGHT = 7;
public static final int WIDTH = 13;
public static final float CELL_SIZE_X = 64f;
public static final float CELL_SIZE_Y = 64f;
public static final int LASER_LAYER = 0;
public static final int GAME_OBJECTS_LAYER = LASER_LAYER + 1;
private GameObject[][] mMap = new GameObject[WIDTH][HEIGHT];
private Textures mTextures;
GameObjectsMap(final Textures textures) {
mTextures = textures;
}
}
* This source code was highlighted with Source Code Highlighter .
public void add(Type type, final int posH, final int posW, final int angle) {
GameObject object = null ;
switch (type) {
case lasergun:
object = new LaserGun(posH, posW, angle, mTextures
.getLaserGun());
break ;
case mirror:
break ;
case target:
break ;
default :
break ;
}
mMap[posH][posW] = object ;
}
* This source code was highlighted with Source Code Highlighter .
public void addToScene(Scene scene) {
for ( int i = 0; i < mMap.length; i++) {
for ( int j = 0; j < mMap[i].length; j++) {
GameObject o = mMap[i][j];
if (o != null ) {
o.attachTo(scene);
}
}
}
}
* This source code was highlighted with Source Code Highlighter .
public void clear() {
for ( int i = 0; i < mMap.length; i++) {
Arrays.fill(mMap[i], null );
}
}
* This source code was highlighted with Source Code Highlighter .
public boolean onSceneTouchEvent(final Scene pScene, TouchEvent pSceneTouchEvent) {
if (pSceneTouchEvent.isActionDown()) {
float x = pSceneTouchEvent.getX();
float y = pSceneTouchEvent.getY();
int cellNumX = ( int ) ((x - x % GameObjectsMap.CELL_SIZE_X)
/ GameObjectsMap.CELL_SIZE_X);
int cellNumY = ( int ) ((y - y % GameObjectsMap.CELL_SIZE_X)
/ GameObjectsMap.CELL_SIZE_X);
DynamicGameObject object = (DynamicGameObject)mMap.getMap()[cellNumX][cellNumY];
if ( object != null ) {
//
}
}
return false ;
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/123367/
All Articles