Hi guys.
/edited due to no replies/
First Question :
I got that class below.
I need to know The (x;y) intersection of them ( the two Rectangles that im checking the collision), so when they do intersect , i can gen an explosion.How can i find the x;y intersection?
Second Question:
How do you guys do when you have a 2D game with several levels, how do you trade the GameView? i mean, the AppListener?
I mean, how do you manage several levels in your game?
Plus, if you could JUDGE my code, telling all the bad things of it so i can go research/learn how to improve it,i would be hAppY
Thanks guys, sorry for bothering you in any case :D.
package Collisions;
import Atlas.Explosion;
import Logic.GameUpdate;
import Models.EnemyPlane;
import Models.Missile;
import Models.Plane;
import java.awt.Rectangle;
import java.util.ArrayList;
/**
*
* @author André VinÃcius Lopes
*/
public class MainCollision {
private GameUpdate gameupdate;
//
private ArrayList<EnemyPlane> enemies;
private ArrayList<Missile> myMissiles;
private Plane plane;
private Rectangle ENEMIEPLANE_RECTANGLE;
private Rectangle MYMISSILE_RECTANGLE;
public MainCollision(GameUpdate g) {
gameupdate = g;
System.gc();
}
public void collision() {
enemies = gameupdate.getEnemies();
myMissiles = gameupdate.getMyMissiles();
plane = gameupdate.getShooterGame().getPlane();
for (int m = 0; m < myMissiles.size(); m++) {
Missile getMissileM = myMissiles.get(m);
//Detecta Colisao Entre Missel e inimigo.
MYMISSILE_RECTANGLE = getMissileM.getMissileRepresentativeRectangle();
for (int e = 0; e < enemies.size(); e++) {
EnemyPlane getEnemieE = enemies.get(e);
ENEMIEPLANE_RECTANGLE = getEnemieE.getEnemyPlaneRepresentativeRectangle();
if (ENEMIEPLANE_RECTANGLE.intersects(MYMISSILE_RECTANGLE))
{
int x;
int y;
gameupdate.removeMissile(m);
gameupdate.removeEnemyPlane(e);
//Create Explosion Based on (x;y) Intersection
//gameupdate.addNewExplosion(y, y);
//Adiciona novo inimigo casa haja colisao.//
gameupdate.addNewEnemy();
}
}
}
}
}