master
Jan Ehehalt 6 years ago
parent 0939c3bb7c
commit 9745412044

@ -78,12 +78,16 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
public void run() { public void run() {
if(gs != null){ if(gs != null){
if(level.getProjectile().getxPos() > Gdx.graphics.getWidth() || level.getProjectile().getxPos() < 0 || level.getProjectile().getyPos() < 0){ if(level.getProjectile().getxPos() > Gdx.graphics.getWidth() || level.getProjectile().getxPos() < 0 || level.getProjectile().getyPos() < 0){
gs.step(level);
level.reset(); level.reset();
gs.dispose(); gs.dispose();
stepTimer.stop();
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();
} }
} }
@ -111,6 +115,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
gs.render(batch, level); gs.render(batch, level);
if(gs.getWin()){ if(gs.getWin()){
gs.dispose(); gs.dispose();
stepTimer.stop();
gs = null; gs = null;
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true); ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true);
} }
@ -159,6 +164,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
else{ else{
ls.dispose(); ls.dispose();
ls = null; ls = null;
level = new Level(new Goal(500,200,150,50, 0.2f), new Projectile(0,0,0),200,200);
gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
stepTimer.start(); stepTimer.start();
} }
@ -173,10 +179,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
ls = new Levelscreen(levelAmount, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT); ls = new Levelscreen(levelAmount, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
} }
else if(x < Gdx.graphics.getWidth() * 0.66){ else if(x < Gdx.graphics.getWidth() * 0.66){
level = new Level(new Goal(500,200,150,50, 0.2f), new Projectile(0,0,0),200,200);
gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
stepTimer.start();
} }
else{ else{
level = new Level(new Goal(500,200,150,50, 0.2f), new Projectile(0,0,0),200,200);
gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); gs = new Gamescreen(level, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
stepTimer.start();
} }
ws = null; ws = null;
} }

@ -10,6 +10,8 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -40,7 +42,9 @@ public class Gamescreen{
int pivotX; int pivotX;
int pivotY; int pivotY;
Rectangle[] goalRects; Rectangle[] goalRects;
Rectangle goalRect;
Circle projectileCirc;
// 0: Left, 1: LeftTop, 2: CenterLeft, 3: CenterBottom, 4: CenterRight, 5: RightTop, 6: Right, 7: Bottom // 0: Left, 1: LeftTop, 2: CenterLeft, 3: CenterBottom, 4: CenterRight, 5: RightTop, 6: Right, 7: Bottom
float GAME_WORLD_WIDTH; float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT; float GAME_WORLD_HEIGHT;
@ -73,7 +77,10 @@ public class Gamescreen{
goalRects[5] = new Rectangle(x + th*4 * w ,y + h - 1f ,w *th ,1 ); goalRects[5] = new Rectangle(x + th*4 * w ,y + h - 1f ,w *th ,1 );
goalRects[6] = new Rectangle(x + w-1 ,y ,1 ,h ); goalRects[6] = new Rectangle(x + w-1 ,y ,1 ,h );
goalRects[7] = new Rectangle(x ,y ,w ,1 ); goalRects[7] = new Rectangle(x ,y ,w ,1 );
goalRect = new Rectangle(x + w*th, y + h*th, w * th * 3, h * 0.1f);
projectileCirc = new Circle((float)level.getProjectile().getxPos(), (float)level.getProjectile().getyPos(), level.getProjectile().getRadius());
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(matrix); shapeRenderer.setProjectionMatrix(matrix);
@ -85,7 +92,8 @@ public class Gamescreen{
pivotX = level.getPivotX(); pivotX = level.getPivotX();
pivotY = level.getPivotY(); pivotY = level.getPivotY();
g = level.getGoal(); g = level.getGoal();
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK); shapeRenderer.setColor(Color.BLACK);
@ -107,26 +115,41 @@ public class Gamescreen{
shapeRenderer.rect(x + th *w + th*3 * w, y, th * w,h); shapeRenderer.rect(x + th *w + th*3 * w, y, th * w,h);
shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius()); shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius());
shapeRenderer.setColor(Color.RED); shapeRenderer.setColor(Color.RED);
/*
//goal hitboxes
for(int i = 0; i < goalRects.length; i++){ for(int i = 0; i < goalRects.length; i++){
shapeRenderer.rect(goalRects[i].getX(), goalRects[i].getY(), goalRects[i].getWidth(), goalRects[i].getHeight()); shapeRenderer.rect(goalRects[i].getX(), goalRects[i].getY(), goalRects[i].getWidth(), goalRects[i].getHeight());
} }
// projectile hitbox
//shapeRenderer.rect(g.getxPos(), g.getyPos(), g.getSizeX(), g.getSizeY()); shapeRenderer.circle(projectileCirc.x, projectileCirc.y, projectileCirc.radius);*/
// goal hitbox
shapeRenderer.setColor(Color.GREEN);
shapeRenderer.rect(goalRect.getX(), goalRect.getY(), goalRect.getWidth(), goalRect.getHeight());/*
// full goal size hitbox;
shapeRenderer.rect(g.getxPos(), g.getyPos(), g.getSizeX(), g.getSizeY());
*/
shapeRenderer.setColor(Color.GRAY); shapeRenderer.setColor(Color.GRAY);
shapeRenderer.circle(pivotX, pivotY, 5); shapeRenderer.circle(pivotX, pivotY, 5);
shapeRenderer.end(); shapeRenderer.end();
if(p.getxPos() > x + w*th && p.getxPos() < x+w*4*th && p.getyPos() > y + h * th && p.getyPos() < y + h ){
win = true;
}
} }
public void dispose() { public void dispose() {
} }
public void step(Level level){
projectileCirc = new Circle((float)level.getProjectile().getxPos(), (float)level.getProjectile().getyPos(), level.getProjectile().getRadius());
if(Intersector.overlaps(projectileCirc, goalRect)) win = true;
}
public boolean getWin(){ public boolean getWin(){
return win; return win;
} }
} }

Loading…
Cancel
Save