Feature: Levelname wird bei Levelbeginn eingeblendet.

This commit is contained in:
Jan Philipp Timme 2014-12-09 15:01:35 +01:00
parent 9cd809b4a3
commit 130152aba0
2 changed files with 60 additions and 1 deletions

View File

@ -0,0 +1,56 @@
package de.teamteamteam.spacescooter.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.entity.Entity;
/**
* A headline that is being displayed at the beginning of each level,
* disappearing by fading out after 1-2 seconds.
*/
public class LevelHeadline extends Entity {
private int lifeTime;
private int lifeTimeCounter;
private String text;
public LevelHeadline(int x, int y, String text) {
super(x, y);
this.text = text;
this.lifeTime = 150;
this.lifeTimeCounter = this.lifeTime;
}
/**
* Make the headline stay for a while, then let it disappear.
*/
@Override
public void update() {
if(this.lifeTimeCounter > 0) {
this.lifeTimeCounter--;
}
if(lifeTime == 0) {
this.remove();
}
}
/**
* Draw the Headline
*/
public void paint(Graphics2D g) {
g.setFont(new Font("Monospace", 0, 60));
float alpha = (float) (this.lifeTimeCounter / (this.lifeTime * 1.0));
int textWidth = g.getFontMetrics().stringWidth(this.text);
int textHeight = g.getFontMetrics().getHeight();
int x = (GameConfig.gameScreenWidth/2 - textWidth/2);
int y = (int) (GameConfig.gameScreenHeight/2 - textHeight);
g.setColor(new Color(1.0F, 1.0F, 1.0F, alpha));
g.drawString(this.text, x, y);
}
}

View File

@ -17,6 +17,7 @@ import de.teamteamteam.spacescooter.entity.obstacle.Obstacle;
import de.teamteamteam.spacescooter.entity.obstacle.StoneOne; import de.teamteamteam.spacescooter.entity.obstacle.StoneOne;
import de.teamteamteam.spacescooter.entity.obstacle.StoneThree; import de.teamteamteam.spacescooter.entity.obstacle.StoneThree;
import de.teamteamteam.spacescooter.entity.obstacle.StoneTwo; import de.teamteamteam.spacescooter.entity.obstacle.StoneTwo;
import de.teamteamteam.spacescooter.gui.LevelHeadline;
import de.teamteamteam.spacescooter.screen.GameScreen; import de.teamteamteam.spacescooter.screen.GameScreen;
import de.teamteamteam.spacescooter.screen.Screen; import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.sound.SoundSystem;
@ -83,12 +84,14 @@ public final class Level {
} }
/** /**
* Initialize the level based on the LevelConfig attributes. * Initialize the level based on the LevelConfig attributes,
* show the level name in a LevelHeadline.
*/ */
public void doBuildUp() { public void doBuildUp() {
this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50); this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50);
GameScreen.setPlayer(new Player(200, 300)); GameScreen.setPlayer(new Player(200, 300));
this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic); this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic);
new LevelHeadline(100,100, this.config.name);
} }
/** /**