summaryrefslogtreecommitdiff
path: root/same-android/src/main/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-18 14:46:18 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-18 14:46:18 +0100
commit6965ac2e1c471238c6c394a75dc07d19fc33703c (patch)
treee85b992d3cd2135dfbb537f21ecb314afc5972fa /same-android/src/main/java/com/orbekk
parent3ea9b7b394e3d8a6e9ae726d0de190b5bd938a7d (diff)
Implement circle location and controls.
The circle can be controlled with touch events.
Diffstat (limited to 'same-android/src/main/java/com/orbekk')
-rw-r--r--same-android/src/main/java/com/orbekk/GameView.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/same-android/src/main/java/com/orbekk/GameView.java b/same-android/src/main/java/com/orbekk/GameView.java
index 047955a..4accd7a 100644
--- a/same-android/src/main/java/com/orbekk/GameView.java
+++ b/same-android/src/main/java/com/orbekk/GameView.java
@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
+import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@@ -16,18 +17,23 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
static class GameThread extends Thread {
private int height = 0;
private int width = 0;
- private int posX;
- private int posY;
+ private float posX;
+ private float posY;
private SurfaceHolder holder;
private Context context;
+ private Paint background;
private Paint paint;
public GameThread(SurfaceHolder holder, Context context) {
this.holder = holder;
this.context = context;
+ posX = 100;
+ posY = 100;
paint = new Paint();
paint.setAntiAlias(true);
paint.setARGB(255, 255, 0, 0);
+ background = new Paint();
+ background.setARGB(255, 0, 0, 0);
}
public void setSize(int width, int height) {
@@ -38,7 +44,8 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
}
private void doDraw(Canvas c) {
- c.drawCircle(100.0f, 50.0f, 20.0f, paint);
+ c.drawRect(0.0f, 0.0f, width+1.0f, height+1.0f, background);
+ c.drawCircle(posX, posY, 20.0f, paint);
}
@Override public void run() {
@@ -52,6 +59,12 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
holder.unlockCanvasAndPost(c);
}
}
+
+ private void setPosition(float x, float y) {
+ posX = x;
+ posY = y;
+ run();
+ }
}
public GameView(Context context) {
@@ -85,5 +98,11 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
logger.info("SurfaceDestroyed()");
// TODO: Stop thread.
}
+
+ @Override
+ public boolean onTouchEvent(MotionEvent e) {
+ thread.setPosition(e.getX(), e.getY());
+ return true;
+ }
}