Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shootthefacedontdie.game;
- import com.badlogic.gdx.Game;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.shootthefacedontdie.game.GameActors.Character;
- public class MainClass extends Game {
- int a=0;
- private Input userInput;
- private SpriteBatch batch;
- private Character actor, actor2;
- @Override
- public void create () {
- batch=new SpriteBatch();
- actor=new Character("Pictures/badlogic.jpg");
- actor2=new Character("Pictures/BallonWallpaper.jpg");
- userInput=new Input();
- Gdx.input.setInputProcessor(userInput);
- actor.getSprite().setSize(100,100);
- actor2.getSprite().setSize(200,300);
- actor2.x=Gdx.graphics.getWidth()/2 - actor2.getSprite().getWidth()/2;
- actor2.y=Gdx.graphics.getHeight()/2 - actor2.getSprite().getHeight()/2;
- actor.setSound("Sounds/Limp Bizkit - Loser.mp3");
- actor.width=actor.getTexture().getWidth();
- actor.height=actor.getTexture().getHeight();
- actor2.width=actor2.getTexture().getWidth();
- actor2.height=actor2.getTexture().getHeight();
- }
- @Override
- public void render()
- {
- update();
- batch.begin();
- Gdx.gl.glClearColor(0, 0, 0, 0);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- actor.getSprite().draw(batch);
- actor2.getSprite().draw(batch);
- batch.end();
- }
- void update()
- {
- if(Gdx.input.justTouched())
- {
- System.out.println("Screen has been touched");
- System.out.println("x position:"+userInput.getXposition()+" y position:"+userInput.getYposition());
- actor.x+=10;
- actor2.x-=10;
- actor.getSound().play();
- a++;
- }
- if(a>1)
- {
- actor.getSound().pause();
- a=0;
- }
- actor.getSprite().setPosition(actor.x,actor.y);
- actor2.getSprite().setPosition(actor2.x,actor2.y);
- if(actor.overlaps(actor2))
- {
- System.out.println("Colision Detected");
- }
- }
- @Override
- public void dispose ()
- {
- actor.getSound().dispose();
- actor2.getTexture().dispose();
- actor.getTexture().dispose();
- batch.dispose();
- }
- }
Add Comment
Please, Sign In to add comment