示例#1
0
  public void update() {
    System.out.println("asdsadsdasaddsasda " + handler.countOfObject(ID.BasicEnemy));

    r = new Random();
    road.update();
    handler.tick();
    if (System.currentTimeMillis() - timer > 5000) {

      // System.out.println("asdasdasdasd" + );
      if (enemyCounter < 4) {
        handler.addObject(
            new BasicEnemy(this, enemy, r.nextInt(getWidth() - 100), -450, ID.BasicEnemy, handler));
        // handler.addObject(new BasicEnemy(this, enemy2, r.nextInt(getWidth() -100), -450,
        // ID.BasicEnemy, handler));

        enemyCounter++;
        this.road.setMy(road.getMy() + 1);
      }

      timer += 5000;
    }
    if (System.currentTimeMillis() - timer2 > 10000) {
      try {
        //  gameThread.setRunning(false);
        this.road.setMy(road.getMy() - 1);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    //            //System.out.println("asdasdasdasd" + );
    //            if(enemyCounter <10){
    //                handler.addObject(new BasicEnemy(this, enemy, r.nextInt(getWidth() -100),
    // -450, ID.BasicEnemy, handler));
    //                // handler.addObject(new BasicEnemy(this, enemy2, r.nextInt(getWidth() -100),
    // -450, ID.BasicEnemy, handler));
    //
    //
    //                enemyCounter++;
    //                this.road.setMy(road.getMy()+2);
    //            }
    //
    //            timer+= 5000;
    //        }
  }
示例#2
0
 @Override
 protected void onDraw(Canvas canvas) {
   //        int x = getWidth()-bmpRight.getWidth();
   //        int y = (getHeight()/2)-(bmpRight.getHeight()/2);
   road.onDraw(canvas);
   // canvas.drawBitmap(background , -55 ,30 ,null);
   // canvas.drawBitmap(bmpRight, x,y, null);
   // canvas.drawBitmap(bmpLeft, 0, y, null);
   // myPlayer.onDraw(canvas);
   handler.render(canvas);
 }
示例#3
0
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public GamePlay(Context context) {
    super(context);
    holder = getHolder();
    gameThread = new GameThread(this);
    holder.addCallback(
        new SurfaceHolder.Callback() {

          @SuppressLint("WrongCall")
          @Override
          public void surfaceCreated(SurfaceHolder surfaceHolder) {
            gameThread.startGame(true);
            gameThread.start();
          }

          @Override
          public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {}

          @Override
          public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
            try {
              gameThread.join();
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        });

    handler = new GameObjectHandler();
    player = BitmapFactory.decodeResource(getResources(), R.drawable.scar5);

    enemy = BitmapFactory.decodeResource(getResources(), R.drawable.struck);
    enemy2 = BitmapFactory.decodeResource(getResources(), R.drawable.struck);

    //  bmpLeft = BitmapFactory.decodeResource(getResources(), R.drawable.left);
    //  bmpRight = BitmapFactory.decodeResource(getResources(), R.drawable.right);
    background = BitmapFactory.decodeResource(getResources(), R.drawable.road3);

    road = new Road(this, background, -55, 0);
    //       try {
    //           background.setWidth(getWidth());
    //           background.setHeight(getHeight());
    //       }catch (Exception e){
    //           e.printStackTrace();
    //       }

    handler.addObject(new PlayerSprite(this, player, 0, 0, ID.Player, handler));
  }