Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Enemy extends Actor {
- Rectangle bounds;
- public Enemy() {
- bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());
- }
- public Rectangle getBounds() {
- return bounds;
- }
- private void setXY(float pX,float pY) {
- setPosition(pX, pY);
- bounds.setX((int)pX);
- bounds.setY((int)pY);
- }
- }
- //init lists
- List<Enemy> enemies = new ArrayList<Enemy>();
- List<Bullet> bullets = new ArrayList<Bullet>();
- //add actors to lists
- enemies.Add(new Enemy());
- bullets.Add(new Bullet());
- for (int i = enemies.size() - 1; i >= 0; i--) {
- Enemy enemy = enemies[i];
- for (int j = bullets.size() - 1; j >= 0; j--) {
- Bullet bullet = bullets[j];
- if(enemy.getBounds().overlaps(bullet.getBounds())) {
- //handle collision
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement