master
Jan Ehehalt 6 years ago
parent 828420c9e6
commit 4ffd5aed9e

@ -19,6 +19,9 @@ import model.Level;
import model.Projectile; import model.Projectile;
import view.Gamescreen; import view.Gamescreen;
import view.Levelscreen; import view.Levelscreen;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
@ -32,11 +35,11 @@ import view.Winscreen;
* @author Jan * @author Jan
*/ */
public class Controller extends ApplicationAdapter implements InputProcessor{ public class Controller extends ApplicationAdapter implements InputProcessor{
final float GAME_WORLD_WIDTH = 1600; final float GAME_WORLD_WIDTH = 1600;
final float GAME_WORLD_HEIGHT = 900; final float GAME_WORLD_HEIGHT = 900;
Titlescreen ts; Titlescreen ts;
Levelscreen ls; Levelscreen ls;
Gamescreen gs; Gamescreen gs;
@ -45,15 +48,15 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
SpriteBatch batch; SpriteBatch batch;
Timer stepTimer; Timer stepTimer;
Level level; Level level;
OrthographicCamera camera; OrthographicCamera camera;
Viewport viewport; Viewport viewport;
@Override @Override
public void create(){ public void create(){
ts = new Titlescreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT); ts = new Titlescreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
ls = null; ls = null;
gs = null; gs = null;
@ -61,10 +64,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
levelAmount = 10; levelAmount = 10;
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();
viewport = new ExtendViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT * aspectRatio, camera); viewport = new ExtendViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT * aspectRatio, camera);
viewport.apply(); viewport.apply();
@ -85,25 +88,34 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
gs = null; gs = null;
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, false); ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, false);
} }
else{ else{
gs.step(level);
level.step(); level.step();
gs.step(level);
for(Rectangle rect : gs.getGoalRects()){
if(Intersector.overlaps(gs.getProjectileCirc(), rect)){
if(rect.getHeight() == 1){
level.horizontalCollision();
}
else if(rect.getWidth() == 1){
level.verticalCollision();
}
break;
}
}
for(
} }
} }
} }
}, 0, 0.01f); }, 0, 0.01f);
stepTimer.stop(); stepTimer.stop();
} }
@Override @Override
public void resize(int width, int height){ public void resize(int width, int height){
viewport.update(width, height); viewport.update(width, height);
camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0); camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0);
} }
@Override @Override
public void render(){ public void render(){
Gdx.gl.glClearColor(1f, 1f, 1f, 1f); Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
@ -113,7 +125,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
if(ts != null) ts.render(batch); if(ts != null) ts.render(batch);
else if(ls != null) ls.render(batch); else if(ls != null) ls.render(batch);
else if(gs != null){ else if(gs != null){
gs.render(batch, level); gs.render(batch, level);
if(gs.getWin()){ if(gs.getWin()){
gs.dispose(); gs.dispose();
@ -125,12 +137,12 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
else if(ws != null) ws.render(batch); else if(ws != null) ws.render(batch);
batch.end(); batch.end();
} }
@Override @Override
public void dispose () { public void dispose () {
} }
@Override @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {
camera.translate(5f, 5f); camera.translate(5f, 5f);

@ -63,11 +63,11 @@ public class Level {
} }
public void horizontalCollision(){ public void horizontalCollision(){
this.projectile.setvY(-this.projectile.getvY); this.projectile.setvY(-this.projectile.getvY());
} }
public void verticalCollision(){ public void verticalCollision(){
this.projectile.setvX(-this.projectile.getvX); this.projectile.setvX(-this.projectile.getvX());
} }
public void step(){ public void step(){

@ -151,5 +151,12 @@ public class Gamescreen{
return win; return win;
} }
public Rectangle[] getGoalRects(){
return goalRects;
}
public Circle getProjectileCirc(){
return projectileCirc;
}
} }

Loading…
Cancel
Save