From 97454120445957dfcbf7c606fbbc1a930b50bc15 Mon Sep 17 00:00:00 2001 From: Jan Ehehalt Date: Thu, 18 Jun 2020 10:57:08 +0200 Subject: [PATCH] EHRE --- core/src/controller/Controller.java | 10 +++++++ core/src/view/Gamescreen.java | 43 ++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/core/src/controller/Controller.java b/core/src/controller/Controller.java index 87e15d8..9c9a170 100644 --- a/core/src/controller/Controller.java +++ b/core/src/controller/Controller.java @@ -78,12 +78,16 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ public void run() { if(gs != null){ if(level.getProjectile().getxPos() > Gdx.graphics.getWidth() || level.getProjectile().getxPos() < 0 || level.getProjectile().getyPos() < 0){ + gs.step(level); level.reset(); gs.dispose(); + stepTimer.stop(); gs = null; ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, false); } + else{ + gs.step(level); level.step(); } } @@ -111,6 +115,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ gs.render(batch, level); if(gs.getWin()){ gs.dispose(); + stepTimer.stop(); gs = null; ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true); } @@ -159,6 +164,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ else{ ls.dispose(); 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); stepTimer.start(); } @@ -173,10 +179,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ ls = new Levelscreen(levelAmount, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT); } 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); + stepTimer.start(); } 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); + stepTimer.start(); } ws = null; } diff --git a/core/src/view/Gamescreen.java b/core/src/view/Gamescreen.java index 7afb187..68cd295 100644 --- a/core/src/view/Gamescreen.java +++ b/core/src/view/Gamescreen.java @@ -10,6 +10,8 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; 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.Rectangle; import com.badlogic.gdx.math.Vector2; @@ -40,7 +42,9 @@ public class Gamescreen{ int pivotX; 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 float GAME_WORLD_WIDTH; 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[6] = new Rectangle(x + w-1 ,y ,1 ,h ); 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.setProjectionMatrix(matrix); @@ -85,7 +92,8 @@ public class Gamescreen{ pivotX = level.getPivotX(); pivotY = level.getPivotY(); g = level.getGoal(); - + + shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(Color.BLACK); @@ -107,26 +115,41 @@ public class Gamescreen{ shapeRenderer.rect(x + th *w + th*3 * w, y, th * w,h); shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius()); shapeRenderer.setColor(Color.RED); + + /* + //goal hitboxes for(int i = 0; i < goalRects.length; i++){ shapeRenderer.rect(goalRects[i].getX(), goalRects[i].getY(), goalRects[i].getWidth(), goalRects[i].getHeight()); } - - //shapeRenderer.rect(g.getxPos(), g.getyPos(), g.getSizeX(), g.getSizeY()); + // projectile hitbox + 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.circle(pivotX, pivotY, 5); 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 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(){ return win; } + }