Skip to content

Instantly share code, notes, and snippets.

@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
renderer.setView(camera);
renderer.render();
SpriteBatch batch = renderer.getSpriteBatch();
batch.begin();
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
renderer.setView(camera);
renderer.render();
}
private static final int WHITE = -1;
private static final int EMPTY = 0;
private static final int BLACK = 1;
public void play(int x, int y) {
if (board[x][y] == EMPTY) {
board[x][y] = currentPlayer;
currentPlayer *= -1;
}
}
@Override
public boolean tap(float x, float y, int count, int button) {
// where x and y are tap inputs
Vector3 touchPoint = new Vector3(x, y, 0);
camera.unproject(touchPoint);
game.play((int) touchPoint.x, (int) touchPoint.y);
return true;
}
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(new ZoomMoveKeyProcessor(camera));
multiplexer.addProcessor(new GestureDetector(new ZoomPanDetector(camera)));
multiplexer.addProcessor(new GestureDetector(new PutStoneDetector(this, camera)));
Gdx.input.setInputProcessor(multiplexer);
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
TiledMap map = new TmxMapLoader().load("data/goban19.tmx");
renderer = new OrthogonalTiledMapRenderer(map, unitScale);
camera = new OrthographicCamera();
camera.setToOrtho(true, w * unitScale, h * unitScale);
WIDTH = ((TiledMapTileLayer) map.getLayers().get(0)).getWidth();
@smaspe
smaspe / Storable.java
Created July 8, 2013 14:08
delete method
public boolean delete(Context context) {
boolean result = context.getContentResolver().delete(
getPath(getClass(), id), null, null) > 0;
if (result) {
id = -1;
}
return result;
}
public class TypeHandler {
public String getSQLType() {
return "TEXT";
}
public Object getSQLValue(Object object) {
return object;
}
public static <T extends Storable> T getById(Context context,
Class<T> clazz, long id) {
try {
T result = clazz.newInstance();
Cursor content = context.getContentResolver().query(
getPath(clazz, id), null, null, null, null);
if (content.moveToFirst()) {
result.loadCursor(content);
}
return result;
public void save(Context context) {
Map<String, Object> mapRepr = asMap();
Parcel p = Parcel.obtain();
p.writeMap(mapRepr);
p.setDataPosition(0);
ContentValues values = ContentValues.CREATOR.createFromParcel(p);
if (id == -1) {
Uri insertUri = context.getContentResolver().insert(
getPath(getClass()), values);
id = Long.parseLong(insertUri.getLastPathSegment());