-
- /*
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- if (!initialized) initialize();
-
- long currTime = System.currentTimeMillis();
-
- a = (float)(currTime - startTime) / (float)duration;
- if (a > (float)1.0) a = (float)1.0;
-
- x = Math.round(nextx*a + prevx*(1-a));
- y = Math.round(nexty*a + prevy*(1-a));
-
- if (a == (float)1.0) computeNextTarget();
-
- int bgWidth = bg.getWidth();
- int bgHeight = bg.getHeight();
- for (int i=0; i<height/bgHeight+1; i++) {
- for (int j=0; j<width/bgWidth+1; j++) {
- canvas.drawBitmap(bg, j*bgWidth, i*bgHeight, paint);
- }
- }
-
- canvas.drawBitmap(tile[randomtile], x, y, paint);
-
- repaint();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (event.getActionMasked()==MotionEvent.ACTION_DOWN) {
- //computeNextTarget();
- //nextx=Math.round(event.getX());
- //nexty=Math.round(event.getY());
- }
- return super.onTouchEvent(event);
- }
-
- private void initialize() {
- width = getWidth();
- height = getHeight();
-
- bg = BitmapFactory.decodeResource(getResources(), R.drawable.kshisen_bgnd);
- Bitmap tileset = BitmapFactory.decodeResource(getResources(), R.drawable.tileset);
-
- // The tile set has 4 rows x 9 columns
- tsrows = 4;
- tscols = 9;
- twidth = tileset.getWidth()/tscols;
- theight = tileset.getHeight()/tsrows;
- tile = new Bitmap[tsrows*tscols];
- int k=0;
- for (int i=0; i<tsrows; i++) {
- for (int j=0; j<tscols; j++) {
- tile[k] = Bitmap.createBitmap(tileset, j*twidth, i*theight, twidth, theight, null, false);
- k++;
- }
- }
-
- x = width/2;
- y = height/2;
-
- computeNextTarget();
-
- initialized = true;
- }
-
- private void computeNextTarget() {
- startTime = System.currentTimeMillis();
- prevx = x;
- prevy = y;
- nextx = (int) Math.floor(Math.random() * width);
- nexty = (int) Math.floor(Math.random() * height);
- randomtile = (int) Math.floor(Math.random() * tile.length);
-
- paint = new Paint();
- paint.setColor(Color.parseColor("#006666"));
- paint.setFlags(Paint.ANTI_ALIAS_FLAG);
- }
- */