/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.worldmodel.game.entity;
import com.aqpproject.game.Singleton;
import com.aqpproject.tools.Vector2D;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
/**
*
* @author Clement
*/
public class WECountdown extends WorldEntity {
public WECountdown() {
super("Countdown", "Countdown", new Vector2D(), 0, 1, true, true);
m_started = false;
m_finished = false;
m_raceStarted = false;
m_c1 = true;
m_c2 = true;
m_cgo = true;
Vector2D size = new Vector2D(Singleton.getVisualisation().getSpriteSize(m_spriteName));
m_position = new Vector2D(Singleton.getVisualisation().getResolution()).scale(0.5f);
m_position.translate(-size.x / 2f, -size.y / 2f);
Singleton.getVisualisation().updateActor(m_name, m_position.x, m_position.y, 0);
try {
Singleton.getAudioController().playSound("c3", false);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(WECountdown.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void update(long time) {
if (m_started && !m_finished) {
long t = time - m_startTime;
float alpha = 1.f - ((t % 1000) / 1000.f);
Singleton.getVisualisation().setActorAlpha(m_name, alpha);
Singleton.getVisualisation().setActorScale(m_name, 1 + 1 - alpha);
if (t >= 4000) {
m_finished = true;
Singleton.getVisualisation().deleteActor(m_name, m_isAMenu);
} else if (t >= 3000) {
m_raceStarted = true;
Singleton.getVisualisation().updateActorFrame(m_name, 4);
if (m_cgo) {
try {
Singleton.getAudioController().playSound("cgo", false);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(WECountdown.class.getName()).log(Level.SEVERE, null, ex);
}
m_cgo = false;
}
} else if (t >= 2000) {
Singleton.getVisualisation().updateActorFrame(m_name, 3);
if (m_c1) {
try {
Singleton.getAudioController().playSound("c1", false);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(WECountdown.class.getName()).log(Level.SEVERE, null, ex);
}
m_c1 = false;
}
} else if (t >= 1000) {
Singleton.getVisualisation().updateActorFrame(m_name, 2);
if (m_c2) {
try {
Singleton.getAudioController().playSound("c2", false);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(WECountdown.class.getName()).log(Level.SEVERE, null, ex);
}
m_c2 = false;
}
}
}
}
/**
* Destroy the entity
*/
@Override
public void destroy() {
if (!m_finished) {
Singleton.getVisualisation().deleteActor(m_name, m_isAMenu);
}
}
public void start() {
m_started = true;
m_startTime = Singleton.getWorldModel().getTime();
}
public boolean isStarted() {
return m_started;
}
public boolean isFinished() {
return m_finished;
}
public boolean isRaceStarted() {
return m_raceStarted;
}
private boolean m_started;
private boolean m_finished;
private boolean m_raceStarted;
private long m_startTime;
private boolean m_c1;
private boolean m_c2;
private boolean m_cgo;
}