Package com.aqpproject.worldmodel.game.entity

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

/*
* 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 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 WEBomb extends WorldPhysicEntity {

    public WEBomb(String name, Vector2D pos, float rotation, WECar emitter, RaceGameState state) {
        super(name, "bomb", pos, rotation, new Vector2D(32, 32), 0, 0, 0, 1);
        m_emitter = emitter;
        m_lastVelocity = emitter.getLinearVelocity().translate(getDirection().scale(300.f));
        Singleton.getPhysics().setLinearVelocity(name, m_lastVelocity);
        m_state = state;
        m_boundsCount = 0;
        Singleton.getVisualisation().createParticleActor(m_name + "_smoke", "bomb", m_position.x, m_position.y, true);
        try {
            Singleton.getAudioController().playSound("balle", false);
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(WEBomb.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_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, other.getDirection().scale(-1));
            m_isActive = false;
            try {
                Singleton.getAudioController().stopSound("balle");
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEBomb.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Singleton.getAudioController().playSound("boom02", false);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEBomb.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        //}
        // m_speed = Singleton.getPhysics().getLinearVelocity(m_name).length();
    }

    @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()));
//        }
//        System.out.println("Normal: "+normal.x + "     "+normal.y);

        if (m_isActive) {
//            m_lastVelocity = m_lastVelocity.reflection(new Vector2D(normal.y, normal.x));
            //Singleton.getPhysics().setLinearVelocity(m_name, m_lastVelocity);

            m_lastVelocity = m_lastVelocity.reflection(new Vector2D(normal.y, normal.x));
            Vector2D back = m_lastVelocity.normalize().scale(-10);

            Singleton.getPhysics().resetBody(m_name, m_position.translate(back), m_lastVelocity.scale(100), m_rotation);


            m_boundsCount++;
            if (m_boundsCount > 10) {
                m_isActive = false;
                m_state.getWorldEntities().put(m_name + "_Explosion", new WEExplosion(m_name + "_Explosion", getCenter()));
            }
            try {
                Singleton.getAudioController().playSound("boing", false);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEBomb.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    public WorldEntity getEmitter() {
        return m_emitter;
    }

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

    public void explode() {
        if (m_isActive) {
            m_isActive = false;
            m_state.getWorldEntities().put(m_name + "_Explosion", new WEExplosion(m_name + "_Explosion", getCenter()));
            try {
                Singleton.getAudioController().stopSound("balle");
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEBomb.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Singleton.getAudioController().playSound("boom02", false);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(WEBomb.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    public void setNbBounds(int i) {
        m_boundsCount = i;
    }
    private WorldEntity m_emitter;
    private RaceGameState m_state;
    private Vector2D m_lastVelocity;
    private int m_boundsCount;
}
TOP

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

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.