Java USES OGEngine to develop 2048

  • 2020-04-01 03:46:14
  • OfStack

Recently, there is a popular game 2048, this article will introduce the development of game 2048 using OGEngine game engine.

The OGEngine engine is open source, easy to find and easy to build, we just need to add the OGEngine jar or directly reference the source code under the Android project.

The source code download: (link: http://www.ogengine.com/download/resources.jsp)


    private void initView() {
        //Game background
        AnimatedSprite game_bg = new AnimatedSprite(0, 0, Res.GAME_BG,
                getVertexBufferObjectManager());
        this.attachChild(game_bg);
        //Intermediate game main part
        mGameGroup = new GameGroup(this);
        //Set the center of the Group to the center of the lens
        mGameGroup.setCentrePosition(this.getCameraCenterX(),
                this.getCameraCenterY());
        this.attachChild(mGameGroup);
 
        // 2048 LOGO
        AnimatedSprite game_logo = new AnimatedSprite(20, 20, Res.GAME_LOGO,
                getVertexBufferObjectManager());
        this.attachChild(game_logo);
 
        //Best scoring background
        bestScoreBg = new AnimatedSprite(0, 20, Res.GAME_SCORE_BG_BEST,
                getVertexBufferObjectManager());
        //Set the position of the x coordinate on the right of bestScoreBg to the position of minus 20 on the right of the lens
        bestScoreBg.setRightPositionX(this.getCameraRightX() - 20);
        this.attachChild(bestScoreBg);
 
        tBestScore = new Text(0, bestScoreBg.getY() + 50,
                FontRes.getFont(ConstantUtil.FONT_SCORE_NUM),
                SharedUtil.getBestScore(getActivity()) + "", 4,
                getVertexBufferObjectManager());
        //Set the midpoint on the X coordinate of tBestScore on the midpoint of the X coordinate of bestScoreBg
        tBestScore.setCentrePositionX(bestScoreBg.getCentreX());
        this.attachChild(tBestScore);
 
        //Current score background
        currScoreBg = new AnimatedSprite(0, bestScoreBg.getY(),
                Res.GAME_SCORE_BG_NOW, getVertexBufferObjectManager());
        //Set the x-coordinate point to the right of currScoreBg to the x-coordinate minus 20 to the left of bestScoreBg
        currScoreBg.setRightPositionX(bestScoreBg.getLeftX() - 20);
        this.attachChild(currScoreBg);
.....
    }

The above is all the content of this article, hope you can enjoy, can help you master Java.


Related articles: