Commit b5cb87e2 authored by Nils Hein's avatar Nils Hein
Browse files

PlayerArea hinzugefügt

parent 9ce8d047
......@@ -34,23 +34,24 @@ public class GameScreen implements Screen {
public int score = 0; //Punktestand
float timer = 0; //Zeit bis zum automatischen abschuss
boolean lower; //Zeigt an ob der Spieler oben oder unten ist
public Rectangle playArea; //Spielerbereich
}
Player p1 = new Player(); //Spieler 1
Player p2 = new Player(); //Spieler 2
List<Hexagon> removes; //Die aus dem Field zu entfernenden Bubbles
List<Hexagon> frozenHexagons; //Alle Frozen Bubbles
List<Bubble> fallingBubbles; //Alle fallende Bubbles
float bubbleRadius = 32; //Radius einer Bubble
HexagonalGrid map; //Hexagonal Grid
Map<Hexagon, Bubble> field; //Map der Bubbles auf dem Hexgrid
float CenterY, CenterX = 0; //Mittelpunkt des Screens
Sprite bg, bgOverlay; //Hintergrund
Sprite nextTop, nextTopOverlay, nextBottom, nextBottomOverlay; //Buttons der Gui
Vector2 mapOffset; //Offset für das Hexgrid
float wWidth, wHeight; //Screenbreite und Höhe
float timerDefault = 5; //Defaultzeit bis zum ablauf des Timers
private Rectangle m_Bounds; //Begrenzung der Spielfläche
private final Player p1 = new Player(); //Spieler 1
private final Player p2 = new Player(); //Spieler 2
private final List<Hexagon> removes; //Die aus dem Field zu entfernenden Bubbles
private final List<Hexagon> frozenHexagons; //Alle Frozen Bubbles
private final List<Bubble> fallingBubbles; //Alle fallende Bubbles
private float bubbleRadius = 32; //Radius einer Bubble
private final HexagonalGrid map; //Hexagonal Grid
private final Map<Hexagon, Bubble> field; //Map der Bubbles auf dem Hexgrid
private float CenterY, CenterX = 0; //Mittelpunkt des Screens
private final Sprite bg, bgOverlay; //Hintergrund
private final Sprite nextTop, nextTopOverlay, nextBottom, nextBottomOverlay; //Buttons der Gui
private final Vector2 mapOffset; //Offset für das Hexgrid
private float wWidth, wHeight; //Screenbreite und Höhe
private final float timerDefault = 5; //Defaultzeit bis zum ablauf des Timers
private final Rectangle m_Bounds; //Begrenzung der Spielfläche
public GameScreen() {
......@@ -123,6 +124,9 @@ public class GameScreen implements Screen {
p1.timer = timerDefault;
p2.timer = timerDefault;
p1.playArea = new Rectangle(0, 2*bubbleRadius, wWidth, (wHeight / 2)-(2*bubbleRadius));
p2.playArea = new Rectangle(0, CenterY, wWidth, (wHeight / 2)-(2*bubbleRadius));
}
//Liefert das Hexagon auf dem siech die Bubble befindet
......@@ -141,7 +145,7 @@ public class GameScreen implements Screen {
return new Vector2((float) hex.getCenterX() + mapOffset.x, (float) hex.getCenterY() + mapOffset.y);
}
private void sendFlying(Vector2 source, Vector2 target, Player p){
private void sendFlying(Vector2 source, Vector2 target, Player p) {
Vector2 speed = target.cpy().sub(source).nor();
p.active.isFlying = true;
p.timer = timerDefault;
......@@ -149,7 +153,8 @@ public class GameScreen implements Screen {
p.active.setForce(speed.scl(100));
FrozenNumbersGame.assets.get("snd/shot.mp3", Sound.class).play();
}
private void playerlogic(Player p, boolean lower) {
private void playerlogic(Player p) {
//Wenn die aktuelle Bubble in der Map gelandet ist neue Bubble erzeugen
if (p.active == null) {
p.active = new Bubble(p.sPos.cpy());
......@@ -169,11 +174,8 @@ public class GameScreen implements Screen {
float randomX = -0.2f * wWidth + (new Random().nextFloat() * 1.4f * wWidth);
touchPoint = new Vector2(randomX, (float) (wHeight / 2.0));
}
if (lower && touchPoint.y <= CenterY) {
sendFlying(p.sPos,touchPoint,p);
} else if (!lower && touchPoint.y >= CenterY) {
sendFlying(p.sPos,touchPoint,p);
if (p.playArea.contains(touchPoint)) {
sendFlying(p.sPos, touchPoint, p);
}
}
}
......@@ -192,16 +194,19 @@ public class GameScreen implements Screen {
}
}
}
if((p.active.getPos().y> (2*bubbleRadius)) && (p.active.getPos().y< (wHeight-(2*bubbleRadius)))) {
if (!p.playArea.contains(p.active.getPos().x, p.active.getPos().y)) {
if ((p.active.getPos().y > CenterY - bubbleRadius / 2.0 && lower) || (p.active.getPos().y < CenterY + bubbleRadius / 2.0 && !lower)) {
hit = true;
FrozenNumbersGame.assets.get("snd/hit.mp3", Sound.class).play();
}
hit = true;
if (p.active.getPos().x > m_Bounds.getWidth() - (bubbleRadius)
|| p.active.getPos().x < m_Bounds.getX() + (bubbleRadius)) {
p.active.setVel(p.active.getVel().scl(-1, 1));
FrozenNumbersGame.assets.get("snd/hit.mp3", Sound.class).play();
}
if (p.active.getPos().x > m_Bounds.getWidth() - (bubbleRadius)
|| p.active.getPos().x < m_Bounds.getX() + (bubbleRadius)) {
p.active.setVel(p.active.getVel().scl(-1, 1));
}
}
p.active.Update(0.1f);
if (hit) {
......@@ -231,16 +236,10 @@ public class GameScreen implements Screen {
//Scoring and deleting Bubble
int points = 5;
float y = b.getPos().y;
if (y < 3 * bubbleRadius && lower) {
p.score += points;
iterator.remove();
p2.timer = 0;
}
if (y > wHeight - 3 * bubbleRadius && !lower) {
if (p.playArea.contains(b.getPos().x, b.getPos().y)) {
p.score += points;
iterator.remove();
p1.timer = 0;
p.timer = 0;
}
}
}
......@@ -260,6 +259,7 @@ public class GameScreen implements Screen {
removes.add(h);
removes.addAll(map.getNeighborsOf(h));
}
active.setColor(Color.LIGHT_GRAY);
return (nei.size() + 1) * 10;
}
return 0;
......@@ -272,8 +272,8 @@ public class GameScreen implements Screen {
p1.timer -= delta;
p2.timer -= delta;
playerlogic(p1, true);
playerlogic(p2, false);
playerlogic(p1);
playerlogic(p2);
for (Hexagon h : field.keySet()) {
Bubble bu = field.get(h);
......@@ -466,7 +466,6 @@ public class GameScreen implements Screen {
botLabel.draw(FrozenNumbersGame.batch, 1);
}
// Aufruf sobald Screen dargestellt wird
@Override
public void show() {
FrozenNumbersGame.assets.get("snd/theme.ogg", Music.class).setVolume(0.1f);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment