Guest User

Untitled

a guest
Nov 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. @Override
  2. protected void onCreate (Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
  5. View gameView = initializeForView(new MyPipPioGame(this), config);
  6. setupAds();
  7.  
  8. RelativeLayout layout = new RelativeLayout(this);
  9. layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
  10. ViewGroup.LayoutParams.MATCH_PARENT);
  11.  
  12. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
  13. ViewGroup.LayoutParams.MATCH_PARENT,
  14. ViewGroup.LayoutParams.WRAP_CONTENT);
  15. params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  16. layout.addView(bannerAd, params);
  17.  
  18. setContentView(layout);
  19. }
  20.  
  21. public void setupAds() {
  22. bannerAd = new AdView(this);
  23. bannerAd.setVisibility(View.INVISIBLE);
  24. bannerAd.setBackgroundColor(0xff000000); // black
  25. bannerAd.setAdUnitId(BANNER_AD_UNIT_ID);
  26. bannerAd.setAdSize(AdSize.SMART_BANNER);
  27. }
  28.  
  29.  
  30. @Override
  31. public void showBannerAd() {
  32. runOnUiThread(new Runnable() {
  33. @Override
  34. public void run() {
  35. bannerAd.setVisibility(View.VISIBLE);
  36. AdRequest.Builder builder = new AdRequest.Builder();
  37. AdRequest ad = builder.build();
  38. bannerAd.loadAd(ad);
  39. }
  40. });
  41. }
  42.  
  43. @Override
  44. public void hideBannerAd() {
  45. runOnUiThread(new Runnable() {
  46. @Override
  47. public void run() {
  48. bannerAd.setVisibility(View.INVISIBLE);
  49. }
  50. });
  51.  
  52. }
  53. }
  54.  
  55. public class MyPipPioGame extends ApplicationAdapter {
  56.  
  57. public static final int WIDTH = 1100;
  58. public static final int HIGHT = 640;
  59. public static final String TITLE = "Pio Runner";
  60.  
  61. private GameStateManager gameStateManager;
  62. private SpriteBatch batch;
  63.  
  64. private AdsController adsController;
  65.  
  66. public MyPipPioGame(AdsController adsController){
  67. this.adsController = adsController;
  68. }
  69.  
  70.  
  71. @Override
  72. public void create () {
  73. gameStateManager = new GameStateManager();
  74. batch = new SpriteBatch();
  75. Gdx.gl.glClearColor(1, 0, 0, 1);
  76. gameStateManager.push(new MenuState(gameStateManager));
  77. HighScore.getInstance().load();
  78.  
  79. }
  80.  
  81. @Override
  82. public void resize(int width, int height) {
  83. super.resize(width, height);
  84.  
  85. }
  86.  
  87. @Override
  88. public void render () {
  89.  
  90. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  91. gameStateManager.update(Gdx.graphics.getDeltaTime());
  92. gameStateManager.render(batch);
  93. }
  94.  
  95. @Override
  96. public void dispose () {
  97. batch.dispose();
  98.  
  99. }
  100. }
  101.  
  102. public class GameOver extends state {
  103.  
  104. private Texture gameover;
  105. private Texture bg;
  106. private Texture tap;
  107. private BitmapFont font;
  108.  
  109.  
  110. protected GameOver(GameStateManager gameStateManager) {
  111. super(gameStateManager);
  112. camera.setToOrtho(false, MyPipPioGame.WIDTH / 2, MyPipPioGame.HIGHT / 2);
  113. gameover = new Texture("gameover.png");
  114. bg = new Texture("prueba2.png");
  115. tap = new Texture("tapto.png");
  116. font = new BitmapFont(Gdx.files.internal("font/tintin.fnt"), Gdx.files.internal("font/tintin_0.png"), false);
  117. }
  118.  
  119. @Override
  120. protected void handleImput() {
  121. if (Gdx.input.justTouched()){
  122. gameStateManager.set(new PlayState(gameStateManager));
  123. }
  124.  
  125. }
  126.  
  127. @Override
  128. public void update(float dt) {
  129. handleImput();
  130. }
  131.  
  132. @Override
  133. public void render(SpriteBatch spriteBatch) {
  134. spriteBatch.setProjectionMatrix(camera.combined);
  135. spriteBatch.begin();
  136. spriteBatch.draw(bg, camera.position.x - camera.viewportWidth , 0 );
  137. spriteBatch.draw(gameover, camera.position.x - gameover.getWidth() / 2, camera.position.y - gameover.getHeight() / 2 + 120);
  138. font.draw(spriteBatch, "High Score", camera.position.x - gameover.getWidth() / 2 + 20, camera.position.y - gameover.getHeight() / 2 + 100);
  139. font.draw(spriteBatch, "Best " + HighScore.getInstance().getHighscore(), camera.position.x - gameover.getWidth() / 2, camera.position.y - gameover.getHeight() / 2 + 60 );
  140. spriteBatch.draw(tap, camera.position.x - tap.getWidth() / 2 , camera.position.y - tap.getHeight() / 2 - 10);
  141. font.draw(spriteBatch, "Enjoying Pio Pop ?",camera.position.x - gameover.getWidth() / 2 - 20, camera.position.y - gameover.getHeight() / 2 - 20 );
  142. font.setColor(Color.RED);
  143. font.draw(spriteBatch, "RATE US ON PLAY STORE" , camera.position.x - gameover.getWidth() / 2 - 70 , camera.position.y - gameover.getHeight() / 2 - 60);
  144. spriteBatch.end();
  145. }
  146.  
  147. @Override
  148. public void dispose() {
  149. gameover.dispose();
  150. bg.dispose();
  151. font.dispose();
  152. tap.dispose();
  153. }
Add Comment
Please, Sign In to add comment