Guest User

Untitled

a guest
Jan 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package com.shootthefacedontdie.game;
  2.  
  3. import com.badlogic.gdx.Game;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.GL20;
  6. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  7. import com.shootthefacedontdie.game.GameActors.Character;
  8.  
  9. public class MainClass extends Game {
  10.     int a=0;
  11.     private Input userInput;
  12.     private SpriteBatch batch;
  13.     private Character actor, actor2;
  14.    
  15.     @Override
  16.     public void create () {
  17.         batch=new SpriteBatch();
  18.         actor=new Character("Pictures/badlogic.jpg");
  19.         actor2=new Character("Pictures/BallonWallpaper.jpg");
  20.         userInput=new Input();
  21.  
  22.         Gdx.input.setInputProcessor(userInput);
  23.  
  24.         actor.getSprite().setSize(100,100);
  25.         actor2.getSprite().setSize(200,300);
  26.  
  27.         actor2.x=Gdx.graphics.getWidth()/2 - actor2.getSprite().getWidth()/2;
  28.         actor2.y=Gdx.graphics.getHeight()/2 - actor2.getSprite().getHeight()/2;
  29.  
  30.         actor.setSound("Sounds/Limp Bizkit - Loser.mp3");
  31.  
  32.         actor.width=actor.getTexture().getWidth();
  33.         actor.height=actor.getTexture().getHeight();
  34.  
  35.         actor2.width=actor2.getTexture().getWidth();
  36.         actor2.height=actor2.getTexture().getHeight();
  37.     }
  38.  
  39.     @Override
  40.     public void render()
  41.     {
  42.         update();
  43.         batch.begin();
  44.         Gdx.gl.glClearColor(0, 0, 0, 0);
  45.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  46.         actor.getSprite().draw(batch);
  47.         actor2.getSprite().draw(batch);
  48.         batch.end();
  49.     }
  50.  
  51.     void update()
  52.     {
  53.         if(Gdx.input.justTouched())
  54.         {
  55.             System.out.println("Screen has been touched");
  56.             System.out.println("x position:"+userInput.getXposition()+" y position:"+userInput.getYposition());
  57.             actor.x+=10;
  58.             actor2.x-=10;
  59.             actor.getSound().play();
  60.             a++;
  61.         }
  62.         if(a>1)
  63.         {
  64.             actor.getSound().pause();
  65.             a=0;
  66.         }
  67.  
  68.  
  69.         actor.getSprite().setPosition(actor.x,actor.y);
  70.         actor2.getSprite().setPosition(actor2.x,actor2.y);
  71.  
  72.         if(actor.overlaps(actor2))
  73.         {
  74.             System.out.println("Colision Detected");
  75.         }
  76.     }
  77.    
  78.     @Override
  79.     public void dispose ()
  80.     {
  81.         actor.getSound().dispose();
  82.         actor2.getTexture().dispose();
  83.         actor.getTexture().dispose();
  84.         batch.dispose();
  85.     }
  86. }
Add Comment
Please, Sign In to add comment