Add multiple Levels
This commit is contained in:
parent
9daa9af2e9
commit
027a18ac06
|
|
@ -5,9 +5,9 @@ public class Bird
|
||||||
private final Rectangle _rect;
|
private final Rectangle _rect;
|
||||||
private double _speed;
|
private double _speed;
|
||||||
|
|
||||||
public Bird(GameScreen game)
|
public Bird(GameScreen game, String color)
|
||||||
{
|
{
|
||||||
_rect = new Rectangle(20, 20, 20, 20, "cyan", true);
|
_rect = new Rectangle(20, 20, 20, 20, color, true);
|
||||||
game.addDrawable(_rect);
|
game.addDrawable(_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,6 +28,11 @@ public class Bird
|
||||||
_speed = -JUMP_SPEED;
|
_speed = -JUMP_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(String color)
|
||||||
|
{
|
||||||
|
_rect.setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
public Rectangle getRect()
|
public Rectangle getRect()
|
||||||
{
|
{
|
||||||
return _rect;
|
return _rect;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,32 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
class GameScreen implements LinearColorAnimator.AnimationListener
|
class GameScreen implements LinearColorAnimator.AnimationListener
|
||||||
{
|
{
|
||||||
|
private static class Level
|
||||||
|
{
|
||||||
|
public String birdColor, birdColorTransition;
|
||||||
|
public String obstacleColor, obstacleColorTransition;
|
||||||
|
public Color backgroundColor;
|
||||||
|
|
||||||
|
public Level(String bird, String birdTrans, String obst, String obstTrans, Color bg)
|
||||||
|
{
|
||||||
|
birdColor = bird;
|
||||||
|
birdColorTransition = birdTrans;
|
||||||
|
obstacleColor = obst;
|
||||||
|
obstacleColorTransition = obstTrans;
|
||||||
|
backgroundColor = bg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static ArrayList<Level> LEVELS = new ArrayList<Level>();
|
||||||
|
static
|
||||||
|
{
|
||||||
|
LEVELS.add(new Level("cyan", "cyan", "schwarz", "schwarz", Color.WHITE));
|
||||||
|
LEVELS.add(new Level("weiss", "grau", "weiss", "grau", Color.BLACK));
|
||||||
|
LEVELS.add(new Level("orange", "rot", "orange", "rot", Color.RED));
|
||||||
|
LEVELS.add(new Level("cyan", "orange", "cyan", "orange", Color.BLACK));
|
||||||
|
};
|
||||||
|
// Time in seconds until new level is reached
|
||||||
|
// You might wanna set that to 3 or so to enjoy more rapid color changes
|
||||||
private final static int LEVEL_TIME = 10;
|
private final static int LEVEL_TIME = 10;
|
||||||
|
|
||||||
private final List<Drawable> _drawables;
|
private final List<Drawable> _drawables;
|
||||||
|
|
@ -17,10 +43,11 @@ class GameScreen implements LinearColorAnimator.AnimationListener
|
||||||
public GameScreen()
|
public GameScreen()
|
||||||
{
|
{
|
||||||
_drawables = new ArrayList<Drawable>();
|
_drawables = new ArrayList<Drawable>();
|
||||||
_backgroundAnimator = new LinearColorAnimator(Color.BLACK, Color.WHITE, 1, this);
|
_backgroundAnimator = new LinearColorAnimator(Color.BLACK, LEVELS.get(0).backgroundColor, 1, this);
|
||||||
_backgroundAnimator.start();
|
_backgroundAnimator.start();
|
||||||
_bird = new Bird(this);
|
_bird = new Bird(this, LEVELS.get(0).birdColor);
|
||||||
_world = new World(this);
|
_world = new World(this);
|
||||||
|
_world.setObstacleColor(LEVELS.get(0).obstacleColor);
|
||||||
_totalTime = 0;
|
_totalTime = 0;
|
||||||
_try = 1;
|
_try = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -40,12 +67,12 @@ class GameScreen implements LinearColorAnimator.AnimationListener
|
||||||
if (_totalTime / (LEVEL_TIME * 1e3) > _level + 1)
|
if (_totalTime / (LEVEL_TIME * 1e3) > _level + 1)
|
||||||
{
|
{
|
||||||
++_level;
|
++_level;
|
||||||
// Would be nice to add some more levels with different colors
|
if (_level < LEVELS.size())
|
||||||
if (_level == 1)
|
|
||||||
{
|
{
|
||||||
_world.setObstacleColor("grau");
|
_world.setObstacleColor(LEVELS.get(_level).obstacleColorTransition);
|
||||||
_backgroundAnimator.setStart(Color.WHITE);
|
_bird.setColor(LEVELS.get(_level).birdColorTransition);
|
||||||
_backgroundAnimator.setEnd(Color.BLACK);
|
_backgroundAnimator.setStart(LEVELS.get(_level-1).backgroundColor);
|
||||||
|
_backgroundAnimator.setEnd(LEVELS.get(_level).backgroundColor);
|
||||||
_backgroundAnimator.start();
|
_backgroundAnimator.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,12 +87,13 @@ class GameScreen implements LinearColorAnimator.AnimationListener
|
||||||
_totalTime = _level = 0;
|
_totalTime = _level = 0;
|
||||||
_bird.reset();
|
_bird.reset();
|
||||||
_world.reset();
|
_world.reset();
|
||||||
|
_bird.setColor(LEVELS.get(0).birdColor);
|
||||||
|
|
||||||
// If the background is currently not white, smoothly animate it back
|
// If the background is currently not white, smoothly animate it back
|
||||||
if (_backgroundAnimator.getCurrentColor().getRGB() != Color.WHITE.getRGB())
|
if (_backgroundAnimator.getCurrentColor().getRGB() != Color.WHITE.getRGB())
|
||||||
{
|
{
|
||||||
_backgroundAnimator.setStart(_backgroundAnimator.getCurrentColor());
|
_backgroundAnimator.setStart(_backgroundAnimator.getCurrentColor());
|
||||||
_backgroundAnimator.setEnd(Color.WHITE);
|
_backgroundAnimator.setEnd(LEVELS.get(0).backgroundColor);
|
||||||
_backgroundAnimator.start();
|
_backgroundAnimator.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +101,10 @@ class GameScreen implements LinearColorAnimator.AnimationListener
|
||||||
|
|
||||||
public void onAnimationFinished()
|
public void onAnimationFinished()
|
||||||
{
|
{
|
||||||
if (_backgroundAnimator.getEnd().getRGB() == Color.BLACK.getRGB())
|
if (_level < LEVELS.size())
|
||||||
{
|
{
|
||||||
_world.setObstacleColor("weiss");
|
_world.setObstacleColor(LEVELS.get(_level).obstacleColor);
|
||||||
|
_bird.setColor(LEVELS.get(_level).birdColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user