Advertisement
Nairo05

Peng.java

Jan 11th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import com.badlogic.gdx.Gdx;
  2. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  3. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  4. public class Peng extends GameObjekt {
  5.  
  6.     private TextureRegion bird;
  7.     private float x, y;
  8.     private boolean directionup = true;
  9.  
  10.     public float getX() {
  11.         return x;
  12.     }
  13.  
  14.     public float getY() {
  15.         return y;
  16.     }
  17.  
  18.     public Peng(TextureRegion region) {
  19.         this.bird = region;
  20.     }
  21.  
  22.     @Override
  23.     public void load() {
  24.         x = Gdx.graphics.getWidth()/2 - bird.getRegionWidth() /2;
  25.         y = 0;
  26.  
  27.     }
  28.  
  29.     @Override
  30.     public void update(float delta) {
  31.         if (directionup){
  32.             y = y + 60.0f*delta;
  33.             if (y >= Gdx.graphics.getHeight()){
  34.                 directionup = false;
  35.             }
  36.         } else {
  37.             y = y - 60.0f*delta;
  38.             if (y <= 0){
  39.                 directionup = true;
  40.             }
  41.         }
  42.     }
  43.  
  44.     @Override
  45.     public void render(SpriteBatch batch) {
  46.         batch.draw(bird, x, y);
  47.     }
  48.  
  49.     @Override
  50.     public void dispose() {
  51.         this.dispose();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement