Ejemplo n.º 1
0
 public GameCountView(MainActivity mainActivity) {
   super(mainActivity);
   this.mainActivity = mainActivity;
   getHolder().addCallback(this);
   background = BitmapFactory.decodeResource(getResources(), R.drawable.background);
   backgroundRect = new Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
   magicCloud.initMagicCloud();
   // 绘制文本的画笔
   textPaint = new Paint();
   textPaint.setAntiAlias(true);
   // 绘制背景矩形的画笔
   rectPaint = new Paint();
   rectPaint.setAlpha(100);
   rectPaint.setColor(Color.WHITE);
   // 绘制底部点击屏幕开始游戏画笔
   bottomPaint = new Paint();
   bottomPaint.setColor(Color.BLUE);
   bottomPaint.setTextSize(30);
   bottomPaint.setStyle(Style.STROKE);
   bottomPaint.setTextAlign(Align.CENTER);
   bottomAlpha = 255;
   bottomPaint.setAntiAlias(true);
   gameCountViewDrawThread = new GameCountViewDrawThread(this, getHolder());
 }
Ejemplo n.º 2
0
 @Override
 public void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawBitmap(background, null, backgroundRect, textPaint);
   magicCloud.doDraw(canvas);
   Rect rect =
       new Rect(
           (int) (SCREEN_WIDTH * 0.1),
           (int) (SCREEN_HEIGHT * 0.2),
           (int) (SCREEN_WIDTH * 0.9),
           (int) (SCREEN_HEIGHT * 0.8));
   // 绘制矩形
   canvas.drawRect(rect, rectPaint);
   // 绘制文本内容
   textPaint.setTextSize(16);
   textPaint.setColor(Color.GREEN);
   textPaint.setTextAlign(Align.RIGHT);
   canvas.drawText("时间:", (int) (SCREEN_WIDTH * 0.4), (int) (SCREEN_HEIGHT * 0.33), textPaint);
   canvas.drawText("分数:", (int) (SCREEN_WIDTH * 0.4), (int) (SCREEN_HEIGHT * 0.40), textPaint);
   canvas.drawText("最高连击:", (int) (SCREEN_WIDTH * 0.4), (int) (SCREEN_HEIGHT * 0.47), textPaint);
   canvas.drawText("最长连接:", (int) (SCREEN_WIDTH * 0.4), (int) (SCREEN_HEIGHT * 0.54), textPaint);
   canvas.drawText("错误次数:", (int) (SCREEN_WIDTH * 0.4), (int) (SCREEN_HEIGHT * 0.61), textPaint);
   textPaint.setTextSize(28);
   textPaint.setTextAlign(Align.CENTER);
   textPaint.setColor(Color.RED);
   canvas.drawText(
       "第" + mainActivity.gameView.level.getLevel() + "关完成",
       (int) (SCREEN_WIDTH * 0.5),
       (int) (SCREEN_HEIGHT * 0.26),
       textPaint);
   if (mainActivity.gameCount != null) {
     textPaint.setTextAlign(Align.LEFT);
     textPaint.setTextSize(16);
     textPaint.setColor(Color.GREEN);
     canvas.drawText(
         mainActivity.gameCount.getGameTime(),
         (int) (SCREEN_WIDTH * 0.42),
         (int) (SCREEN_HEIGHT * 0.33),
         textPaint);
     canvas.drawText(
         String.valueOf(mainActivity.gameCount.getScore()),
         (int) (SCREEN_WIDTH * 0.42),
         (int) (SCREEN_HEIGHT * 0.40),
         textPaint);
     canvas.drawText(
         String.valueOf(mainActivity.gameCount.getMaxHitCount()),
         (int) (SCREEN_WIDTH * 0.42),
         (int) (SCREEN_HEIGHT * 0.47),
         textPaint);
     canvas.drawText(
         String.valueOf(mainActivity.gameCount.getMaxLinkLength()),
         (int) (SCREEN_WIDTH * 0.42),
         (int) (SCREEN_HEIGHT * 0.54),
         textPaint);
     canvas.drawText(
         String.valueOf(mainActivity.gameCount.getWrongCount()),
         (int) (SCREEN_WIDTH * 0.42),
         (int) (SCREEN_HEIGHT * 0.61),
         textPaint);
   }
   // 绘制点击屏幕开始游戏文字
   bottomPaint.setAlpha(bottomAlpha);
   canvas.drawText(
       "点击屏幕开始游戏", (int) (SCREEN_WIDTH * 0.5), (int) (SCREEN_HEIGHT * 0.9), bottomPaint);
   if (bottomAlphaGrow) {
     bottomAlpha += 20;
     if (bottomAlpha >= 255) {
       bottomAlphaGrow = false;
     }
   } else {
     bottomAlpha -= 20;
     if (bottomAlpha <= 0) {
       bottomAlphaGrow = true;
     }
   }
 }