Package com.aqpproject.worldmodel.game.entity

Source Code of com.aqpproject.worldmodel.game.entity.WEMissile

/*
* 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.Interpolation;
import com.aqpproject.tools.Vector2D;
import com.aqpproject.worldmodel.game.state.RaceGameState;
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 Clément
*/
public class WEMissile extends WorldPhysicEntity {

    public WEMissile(String name, Vector2D pos, float rotation, WECar emitter, RaceGameState state) {
        super(name, "missile", pos, rotation, new Vector2D(23, 14), 0, 0, 0, 1);
        m_emitter = emitter;
        Vector2D velocity = emitter.getLinearVelocity().translate(getDirection().scale(300.f));
        Singleton.getPhysics().setLinearVelocity(name, velocity);
        m_state = state;
        Singleton.getVisualisation().createParticleActor(m_name + "_smoke", "missile", m_position.x, m_position.y, true);
        try {
            Singleton.getAudioController().playSound("tirer", false);
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(WEMissile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void destroy() {
        super.destroy();
        Singleton.getVisualisation().deleteParticleActor(m_name + "_smoke", true);
    }

    @Override
    public void updateActorTransform() {
        super.updateActorTransform();
        Vector2D pos = getCenter();
        //pos.translate(getDirection().scale(-16));

        Singleton.getVisualisation().updateParticleActor(m_name + "_smoke", pos.x, pos.y, true);
    }

    @Override
    public void startContact(WorldPhysicEntity other, Vector2D normal, Vector2D point) {
        //if (other != m_emitter && !(other instanceof WEMissile)) {
        if (m_isActive) {
            m_isActive = false;
            m_state.getWorldEntities().put(m_name + "_Explosion", new WEExplosion(m_name + "_Explosion", getCenter()));
            Singleton.getPhysics().applyAngularForce(other.m_name, 2000.f * (float) Math.random());
            Singleton.getPhysics().applyLinearForce(other.m_name, getDirection().scale(100));
            try {
                Singleton.getAudioController().stopSound("tirer");
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEMissile.class.getName()).log(Level.SEVERE, null, ex);
            }

            try {
                Singleton.getAudioController().playSound("boom02", false);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEMissile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        //}
    }

    @Override
    public void stopContact(WorldPhysicEntity other, Vector2D normal, Vector2D point) {
    }

    @Override
    public void startStaticContact(Vector2D normal, Vector2D point) {
        if (m_isActive) {
            m_isActive = false;
            m_state.getWorldEntities().put(m_name + "_Explosion", new WEExplosion(m_name + "_Explosion", getCenter()));
            try {
                Singleton.getAudioController().stopSound("tirer");
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEMissile.class.getName()).log(Level.SEVERE, null, ex);
            }

            try {
                Singleton.getAudioController().playSound("boom02", false);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEMissile.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    @Override
    public void stopStaticContact(Vector2D normal, Vector2D point) {
    }

    public WorldEntity getEmitter() {
        return m_emitter;
    }
    private WorldEntity m_emitter;
    private RaceGameState m_state;
}
TOP

Related Classes of com.aqpproject.worldmodel.game.entity.WEMissile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.