/* Copyright 2010, 2012-2013 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut. If not, see <http://www.gnu.org/licenses/>.
*/
package ponkOut.Menu;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
import ponkOut.State;
import ponkOut.StateChangeListener;
import ponkOut.Menu.MenuState.FlyingDirection;
import ponkOut.graphics.Camera;
import ponkOut.graphics.Color;
import ponkOut.graphics.GraphicsObjectsManager;
import ponkOut.graphics.Skybox;
import ponkOut.graphics.Sprite;
import ponkOut.graphics.WorldText;
import ponkOut.graphics.resources.TextureManager;
public class CreditsState extends State {
private GraphicsObjectsManager goManager;
private MenuState.FlyingDirection flying;
private float posZ;
private float destPosZ;
private float scrollPos;
private float textPosY, textPosZ;
public CreditsState(StateChangeListener listener, State previous) {
super(listener, previous);
goManager = new GraphicsObjectsManager();
scrollPos = 0.0f;
WorldText ponkOutText = new WorldText("PonkOut", 15.0f, new Color(0.8f, 0.8f, 1.0f, 0.8f), new Vector3f(0.0f,
0.0f, -150.0f), -45.0f, 0.0f, 0.0f, goManager);
ponkOutText.translate(-0.5f * ponkOutText.getWidth(), 0.0f, 0.0f);
textPosY = -40.0f;
textPosZ = -130.0f;
newCaption("PROGRAMMING");
newText("Christian Matt");
newCaption("GRAPHICS");
newText("Christian Matt");
moveText(30.0f);
new Sprite(TextureManager.getInstance().getTexture("logos.tga"), new Color(1.0f, 1.0f, 1.0f, 0.8f),
new Vector3f(-40.0f, textPosY, textPosZ), 80.0f, 40.0f, 0.0f, 1.0f, 0.5f, 1.0f, -45.0f, 0.0f, 0.0f,
goManager);
}
@Override
public void init() {
flying = MenuState.FlyingDirection.OUT;
posZ = -200.0f;
destPosZ = 0.0f;
Camera.init(new Vector3f(0.0f, 0.0f, posZ));
}
@Override
public void keyDown(int key) {
if (key == Keyboard.KEY_ESCAPE && flying == FlyingDirection.NONE) {
flying = FlyingDirection.IN;
destPosZ -= 200.0f;
}
}
@Override
public void update(float elapsedTime) {
if (scrollPos < 300.0f)
scrollPos += 20.0f * elapsedTime;
else if (flying == FlyingDirection.NONE) {
flying = FlyingDirection.IN;
destPosZ -= 200.0f;
}
switch (flying) {
case IN:
if (posZ > destPosZ)
posZ -= MenuState.getFlySpeed(posZ - destPosZ, 200.0f, false) * elapsedTime;
if (posZ <= destPosZ) {
posZ = destPosZ;
flying = FlyingDirection.NONE;
getListener().changeState(getPrevious());
return;
}
Camera.setPosition(new Vector3f(0.0f, 0.0f, posZ));
break;
case OUT:
if (posZ < destPosZ)
posZ += MenuState.getFlySpeed(destPosZ - posZ, 400.0f, true) * elapsedTime;
if (posZ >= destPosZ) {
posZ = destPosZ;
flying = FlyingDirection.NONE;
}
Camera.setPosition(new Vector3f(0.0f, 0.0f, posZ));
break;
case NONE:
break;
}
}
@Override
public void render() {
// clear screen
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
// update camera position
GL11.glLoadIdentity();
Camera.applyTransformation();
// draw sky box
Skybox.draw(false);
GL11.glPushMatrix();
GL11.glTranslatef(0.0f, scrollPos, -scrollPos);
// draw objects
goManager.drawScene();
GL11.glPopMatrix();
}
@Override
public void cleanup() {
}
private void moveText(float d) {
textPosY -= d;
textPosZ += d;
}
private void newCaption(String text) {
moveText(20.0f);
WorldText item = new WorldText(text, 8.0f, new Color(0.8f, 0.8f, 1.0f, 0.8f), new Vector3f(0.0f, textPosY,
textPosZ), -45.0f, 0.0f, 0.0f, goManager);
item.translate(-0.5f * item.getWidth(), 0.0f, 0.0f);
moveText(20.0f);
}
private void newText(String text) {
WorldText item = new WorldText(text, 5.0f, new Color(0.8f, 0.8f, 1.0f, 0.8f), new Vector3f(0.0f, textPosY,
textPosZ), -45.0f, 0.0f, 0.0f, goManager);
item.translate(-0.5f * item.getWidth(), 0.0f, 0.0f);
moveText(10.0f);
}
}