Commit 85590716 authored by Bastian's avatar Bastian
Browse files

Unconnected Bubbles fall and score points

parent b57f344f
......@@ -30,6 +30,7 @@ public class Bubble extends Sprite {
private float frozen_s = 0;
public boolean isDamped = false;
public boolean isFlying = false;
public boolean falling = false;
public int getValue() {
return value;
......@@ -124,4 +125,10 @@ public class Bubble extends Sprite {
return (frozen_s <= 0);
}
public void setFalling() {
this.setColor(Color.GRAY);
falling = true;
}
}
......@@ -23,6 +23,7 @@ import org.milderjoghurt.frozennumbers.model.Bubble;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
......@@ -45,6 +46,7 @@ public class GameScreen implements Screen {
Player p2 = new Player();
List<Hexagon> removes;
List<Hexagon> frozenHexagons;
List<Bubble> fallingBubbles;
float bubblradius = 32;
String lastpoint = "";
HexagonalGrid map;
......@@ -70,6 +72,7 @@ public class GameScreen implements Screen {
nachbarn = new HashMap<Hexagon, Bubble>();
removes = new ArrayList<Hexagon>();
frozenHexagons = new ArrayList<Hexagon>();
fallingBubbles = new ArrayList<Bubble>();
HexagonalGridBuilder hexbulder = new HexagonalGridBuilder();
bubblradius = wWidth / 14;
......@@ -208,7 +211,7 @@ public class GameScreen implements Screen {
}
if (p.active != null)
if ((p.active.getPos().y > bound && lower) || (p.active.getPos().y < bound && !lower)) {
if ((p.active.getPos().y > bound-bubblradius/2.0 && lower) || (p.active.getPos().y < bound+bubblradius/2.0 && !lower)) {
p.active.isFlying = false;
p.active.setVel(new Vector2(0, 0));
if (!nachbarn.containsKey(point))
......@@ -228,6 +231,30 @@ public class GameScreen implements Screen {
}
}
//Moving falling Bubbles
for (Iterator<Bubble> iterator = fallingBubbles.iterator(); iterator.hasNext(); ) {
Bubble b = iterator.next();
Vector2 speed = new Vector2(0,(float) -(wHeight/2.0 - b.getPos().y)).nor();
b.setVel(speed.cpy().scl(25.0f));
b.setForce(speed.scl(25));
b.isFlying = true;
b.Update(0.1f);
//Scoring and deleting Bubble
int points = 25;
float y = b.getPos().y;
if(y < 3*bubblradius && lower)
{
p.score+=points;
iterator.remove();
}
if(y > wHeight - 3*bubblradius && !lower)
{
p.score+=points;
iterator.remove();
}
}
}
@Override
......@@ -293,9 +320,11 @@ public class GameScreen implements Screen {
FrozenNumbersGame.assets.get("snd/pop.mp3", Sound.class).play();
nachbarn.remove(hex);
iterator.remove();
checkLooseBubbles();
}
if(b == null){
iterator.remove();
checkLooseBubbles();
}
}
......@@ -304,13 +333,14 @@ public class GameScreen implements Screen {
if(nachbarn.get(h)!=null)
{
double y = h.getCenterY();
if(y > wHeight-2*bubblradius || y < 4*bubblradius)
if(y > wHeight-3*bubblradius || y < 4*bubblradius)
{
FrozenNumbersGame.m_Screens.put("GameOverScreen", new GameOverScreen(p1.score, p2.score));
FrozenNumbersGame.game.setScreen(FrozenNumbersGame.m_Screens.get("GameOverScreen"));
}
}
}
FrozenNumbersGame.viewport.apply(true);
......@@ -340,6 +370,11 @@ public class GameScreen implements Screen {
bubble.draw(batch);
drawTextCentered(String.valueOf(bubble.getValue()), bubble.getPos().x, bubble.getPos().y, bubble.getColor());
}
for (Bubble bubble : fallingBubbles) {
bubble.draw(batch);
drawTextCentered(String.valueOf(bubble.getValue()), bubble.getPos().x, bubble.getPos().y, bubble.getColor());
}
FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class).draw(batch, lastpoint, 10, 40);
FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class).draw(batch, "Score " + String.valueOf(p1.score), wWidth - 140, 40);
......@@ -352,6 +387,50 @@ public class GameScreen implements Screen {
container.draw(batch, 1);
batch.end();
}
private void checkLooseBubbles() {
LinkedList<Hexagon> middleHexagons = new LinkedList<Hexagon>();
ArrayList<Hexagon> connectedHexagons = new ArrayList<Hexagon>();
// visitedHexagon
Rectangle MiddleRectangle = new Rectangle(0,(float) (wHeight/2.0 - 2*bubblradius),wWidth,4*bubblradius);
// Getting hexagons with bubbles connected to the middle
for (Hexagon h : nachbarn.keySet()) {
Bubble b = (nachbarn.get(h));
if (b != null && MiddleRectangle.contains(b.getPos())) {
middleHexagons.push(h);
}
}
//Adding Neighbors of Bubbles near the middle
while(!middleHexagons.isEmpty()){
Hexagon hex = middleHexagons.pop();
for(Hexagon h : map.getNeighborsOf(hex))
{
if(nachbarn.get(h)!=null && !connectedHexagons.contains(h))
{
middleHexagons.push(h);
}
}
connectedHexagons.add(hex);
}
//Marking and removing unconnected Bubbles from nachbarn adden zu fallingBubbles
for (Iterator<Hexagon> iterator = nachbarn.keySet().iterator(); iterator.hasNext(); ) {
Hexagon hex = iterator.next();
Bubble b = (nachbarn.get(hex));
if (b != null && !b.isFrozen() && !connectedHexagons.contains(hex)) {
Vector2 speed = new Vector2(0,(float) -(wHeight/2.0 - b.getPos().y)).nor();
b.setVel(speed.cpy().scl(50.0f));
b.setForce(speed.scl(50));
b.isFlying = true;
b.setFalling();
fallingBubbles.add(b);
iterator.remove();
}
}
}
private void drawTextCentered(String text, float x, float y, Color c) {
Actor rotaater;
......
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