Jonathan Hager 6 years ago
parent cbd1d2f0c8
commit 66a06f231f

@ -43,6 +43,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
int levelAmount; int levelAmount;
SpriteBatch batch; SpriteBatch batch;
Timer stepTimer; Timer stepTimer;
boolean isColliding;
Level[] level; Level[] level;
int currentLevel; int currentLevel;
@ -63,7 +64,6 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
batch = new SpriteBatch(); batch = new SpriteBatch();
Gdx.input.setInputProcessor(this); Gdx.input.setInputProcessor(this);
float aspectRatio = (float)Gdx.graphics.getHeight() / (float)Gdx.graphics.getWidth(); float aspectRatio = (float)Gdx.graphics.getHeight() / (float)Gdx.graphics.getWidth();
camera = new OrthographicCamera(); camera = new OrthographicCamera();
@ -71,6 +71,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
viewport.apply(); viewport.apply();
camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0); camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0);
isColliding = false;
level = new Level[10]; level = new Level[10];
currentLevel = 0; currentLevel = 0;
level[0] = new Level(new Goal(500,200,450,100, 0.2f), new Projectile(0,0,0),200,200); level[0] = new Level(new Goal(500,200,450,100, 0.2f), new Projectile(0,0,0),200,200);
@ -91,17 +92,27 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
else{ else{
level[currentLevel].step(); level[currentLevel].step();
gs.step(level[currentLevel]); gs.step(level[currentLevel]);
boolean collision = false;
for(Rectangle rect : gs.getGoalRects()){ for(Rectangle rect : gs.getGoalRects()){
if(Intersector.overlaps(gs.getProjectileCirc(), rect)) { if(Intersector.overlaps(gs.getProjectileCirc(), rect)) {
collision = true;
if (!isColliding) {
if (rect.getHeight() == 1) { if (rect.getHeight() == 1) {
level[currentLevel].horizontalCollision(); level[currentLevel].horizontalCollision();
} } else if (rect.getWidth() == 1) {
else if(rect.getWidth() == 1){
level[currentLevel].verticalCollision(); level[currentLevel].verticalCollision();
} }
isColliding = true;
break; break;
} }
} }
}
if(!collision){
isColliding = false;
}
} }
} }

Loading…
Cancel
Save