Advertisement
Savta

Untitled

Jan 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package com.ancientslime.boombirds.Enemies;
  2.  
  3. import com.ancientslime.boombirds.Boombirds;
  4. import com.ancientslime.boombirds.GameScreen;
  5. import com.badlogic.gdx.Gdx;
  6. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  7. import com.badlogic.gdx.math.Vector2;
  8. import com.badlogic.gdx.physics.box2d.World;
  9. import com.badlogic.gdx.utils.Array;
  10.  
  11.  
  12. public class Bombs {
  13. private final GameScreen game;
  14. private final Explosions explosions;
  15. private final World world;
  16. private final Array<Bomb> bombList;
  17. private final Array<Bomb> bombsToRemove;
  18.  
  19.  
  20.  
  21. public Bombs(final GameScreen game,Explosions explosions, final World world){
  22. this.game = game;
  23. this.explosions = explosions;
  24. this.world = world;
  25. this.bombList = new Array<Bomb>();
  26. this.bombsToRemove = new Array<Bomb>();
  27.  
  28. }
  29.  
  30. public void newBomb(final Vector2 pos, boolean facingRight){
  31. Bomb bomb = new Bomb(game, this, world, pos, facingRight);
  32. bombList.add(bomb);
  33. }
  34.  
  35. public void collided(final Bomb bomb) {
  36.  
  37. bombsToRemove.add(bomb);
  38.  
  39. Gdx.app.postRunnable(new Runnable() {
  40. public void run() {
  41. explosions.newExp(new Vector2(bomb.body.getWorldCenter().x, bomb.body.getWorldCenter().y + 3.5f / Boombirds.PPM), false);
  42. }
  43. });
  44.  
  45. }
  46.  
  47.  
  48. public void update(float delta){
  49.  
  50. for (Bomb bomb : bombList) {
  51. bomb.update(delta);
  52. if (bombsToRemove.contains(bomb, true)){
  53. world.destroyBody(bomb.body);
  54. }
  55. }
  56.  
  57.  
  58. bombList.removeAll(bombsToRemove, true);
  59. bombsToRemove.clear();
  60.  
  61. }
  62.  
  63. public void draw(SpriteBatch batch){
  64. for (Bomb bomb : bombList){
  65. if (bomb != null) {
  66. bomb.draw(batch);
  67. }
  68. }
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement