Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. package com.mygdx.game;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.Color;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.OrthographicCamera;
  8. import com.badlogic.gdx.graphics.Texture;
  9. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  10. import com.badlogic.gdx.graphics.g2d.Sprite;
  11. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  12. import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
  13. import com.badlogic.gdx.math.Vector3;
  14. import com.mygdx.game.states.GameStateManager;
  15.  
  16.  
  17. public class MyGdxGame extends ApplicationAdapter {
  18.  
  19. //private OrthographicCamera cam;
  20. //private ShapeRenderer sr;
  21. private Vector3 pos;
  22.  
  23. //public static final int WIDTH= 400;
  24. //public static final int HEIGHT=800;
  25. public static final String TITLE= "Helikopter";
  26.  
  27. private GameStateManager gsm;
  28. private SpriteBatch batch;
  29. private Texture texture;
  30. private Sprite sprite;
  31. float speedX = 3f;
  32. float speedY = 3f;
  33. private String yourScoreName;
  34. BitmapFont yourBitmapFontName;
  35.  
  36.  
  37. @Override
  38. public void create () {
  39.  
  40. yourScoreName = "x: 0" + "y: 0" ;
  41. yourBitmapFontName = new BitmapFont();
  42.  
  43. //Gdx.gl.glClearColor(255, 255, 1,1);
  44.  
  45. batch = new SpriteBatch();
  46. texture = new Texture("heli1.png");
  47. sprite = new Sprite(texture);
  48. pos = new Vector3(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2, 0);
  49. sprite.flip(true,false);
  50. //cam= new OrthographicCamera();
  51.  
  52. //gsm = new GameStateManager();
  53. //cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  54. //cam.update();
  55. //gsm.push(new MenuState(gsm));
  56.  
  57. /*sr = new ShapeRenderer();
  58. cam = new OrthographicCamera();
  59. // størrelse på hvor mye man vil se av skjermen
  60. cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  61. pos = new Vector3(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2, 0);
  62. */
  63. }
  64.  
  65. @Override
  66. public void render () {
  67.  
  68.  
  69.  
  70. Gdx.gl.glClearColor(1, 0, 1, 1);
  71. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  72. //gsm.update(Gdx.graphics.getDeltaTime());
  73. //gsm.render(batch);
  74.  
  75.  
  76.  
  77. if (pos.x > Gdx.graphics.getWidth() - texture.getWidth() / 2 || pos.x < 0 + texture.getWidth() / 2) {
  78. sprite.flip(true, false);
  79. speedX = -speedX;
  80. }
  81.  
  82. if (pos.y > Gdx.graphics.getHeight() - texture.getHeight() / 2 || pos.y < 0 + texture.getHeight() / 2) {
  83.  
  84. speedY = -speedY;
  85. }
  86.  
  87. pos.x += speedX;
  88. pos.y += speedY;
  89.  
  90. yourScoreName = "x:" + pos.x + "y:" + pos.y;
  91. batch.begin();
  92. batch.draw(sprite,
  93. pos.x - sprite.getWidth() / 2,
  94. pos.y - sprite.getHeight()/2);
  95. yourBitmapFontName.setColor(1.0f, 1.0f, 1.0f, 1.0f);
  96. yourBitmapFontName.draw(batch, yourScoreName, 500, 450);
  97.  
  98. batch.end();
  99.  
  100. /*//Logic
  101. cam.update();
  102. if (Gdx.input.isTouched()){
  103. pos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
  104. cam.unproject(pos);
  105. }
  106.  
  107. // Drawing
  108. Gdx.gl.glClearColor(1,1,1,1);
  109. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  110. sr.begin(ShapeRenderer.ShapeType.Filled);
  111. sr.setColor(Color.PINK);
  112. sr.circle(pos.x, pos.y, 30);
  113. sr.end();
  114. */
  115. }
  116.  
  117. @Override
  118. public void dispose () {
  119.  
  120. batch.dispose();
  121.  
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement