Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate (Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- View gameView = initializeForView(new MyPipPioGame(this), config);
- setupAds();
- RelativeLayout layout = new RelativeLayout(this);
- layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- layout.addView(bannerAd, params);
- setContentView(layout);
- }
- public void setupAds() {
- bannerAd = new AdView(this);
- bannerAd.setVisibility(View.INVISIBLE);
- bannerAd.setBackgroundColor(0xff000000); // black
- bannerAd.setAdUnitId(BANNER_AD_UNIT_ID);
- bannerAd.setAdSize(AdSize.SMART_BANNER);
- }
- @Override
- public void showBannerAd() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- bannerAd.setVisibility(View.VISIBLE);
- AdRequest.Builder builder = new AdRequest.Builder();
- AdRequest ad = builder.build();
- bannerAd.loadAd(ad);
- }
- });
- }
- @Override
- public void hideBannerAd() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- bannerAd.setVisibility(View.INVISIBLE);
- }
- });
- }
- }
- public class MyPipPioGame extends ApplicationAdapter {
- public static final int WIDTH = 1100;
- public static final int HIGHT = 640;
- public static final String TITLE = "Pio Runner";
- private GameStateManager gameStateManager;
- private SpriteBatch batch;
- private AdsController adsController;
- public MyPipPioGame(AdsController adsController){
- this.adsController = adsController;
- }
- @Override
- public void create () {
- gameStateManager = new GameStateManager();
- batch = new SpriteBatch();
- Gdx.gl.glClearColor(1, 0, 0, 1);
- gameStateManager.push(new MenuState(gameStateManager));
- HighScore.getInstance().load();
- }
- @Override
- public void resize(int width, int height) {
- super.resize(width, height);
- }
- @Override
- public void render () {
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- gameStateManager.update(Gdx.graphics.getDeltaTime());
- gameStateManager.render(batch);
- }
- @Override
- public void dispose () {
- batch.dispose();
- }
- }
- public class GameOver extends state {
- private Texture gameover;
- private Texture bg;
- private Texture tap;
- private BitmapFont font;
- protected GameOver(GameStateManager gameStateManager) {
- super(gameStateManager);
- camera.setToOrtho(false, MyPipPioGame.WIDTH / 2, MyPipPioGame.HIGHT / 2);
- gameover = new Texture("gameover.png");
- bg = new Texture("prueba2.png");
- tap = new Texture("tapto.png");
- font = new BitmapFont(Gdx.files.internal("font/tintin.fnt"), Gdx.files.internal("font/tintin_0.png"), false);
- }
- @Override
- protected void handleImput() {
- if (Gdx.input.justTouched()){
- gameStateManager.set(new PlayState(gameStateManager));
- }
- }
- @Override
- public void update(float dt) {
- handleImput();
- }
- @Override
- public void render(SpriteBatch spriteBatch) {
- spriteBatch.setProjectionMatrix(camera.combined);
- spriteBatch.begin();
- spriteBatch.draw(bg, camera.position.x - camera.viewportWidth , 0 );
- spriteBatch.draw(gameover, camera.position.x - gameover.getWidth() / 2, camera.position.y - gameover.getHeight() / 2 + 120);
- font.draw(spriteBatch, "High Score", camera.position.x - gameover.getWidth() / 2 + 20, camera.position.y - gameover.getHeight() / 2 + 100);
- font.draw(spriteBatch, "Best " + HighScore.getInstance().getHighscore(), camera.position.x - gameover.getWidth() / 2, camera.position.y - gameover.getHeight() / 2 + 60 );
- spriteBatch.draw(tap, camera.position.x - tap.getWidth() / 2 , camera.position.y - tap.getHeight() / 2 - 10);
- font.draw(spriteBatch, "Enjoying Pio Pop ?",camera.position.x - gameover.getWidth() / 2 - 20, camera.position.y - gameover.getHeight() / 2 - 20 );
- font.setColor(Color.RED);
- font.draw(spriteBatch, "RATE US ON PLAY STORE" , camera.position.x - gameover.getWidth() / 2 - 70 , camera.position.y - gameover.getHeight() / 2 - 60);
- spriteBatch.end();
- }
- @Override
- public void dispose() {
- gameover.dispose();
- bg.dispose();
- font.dispose();
- tap.dispose();
- }
Add Comment
Please, Sign In to add comment