Package eas.users.demos.rocketMan

Source Code of eas.users.demos.rocketMan.Phys3MasterC

/*
* File name:        Phys3Master.java (package eas.simulation.users.lukas.lukesPhysics3)
* Author(s):        aifb
* Java version:     6.0
* Generation date:  28.01.2011 (19:51:12)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.users.demos.rocketMan;

import eas.math.geometry.Vector2D;
import eas.plugins.masterScheduler.AbstractDefaultKeyEventMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.event.EASEvent;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.DistanceJoint;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.FixedJoint;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.Joint;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f;
import eas.startSetup.ParCollection;
import eas.users.demos.physics2DA.PhysicsAgent2;

/**
* @author aifb
*
*/
public class Phys3MasterC extends AbstractDefaultKeyEventMaster<Phys3Env> {
   
    /**
     *
     */
    private static final long serialVersionUID = -8868094822743667130L;

    public static final int STEPS_TILL_WIN = 100;
   
    private Joint j1, j2;
   
    @Override
    public Phys3Env[] generateRunnables(ParCollection params) {
        Phys3Env[] envs = new Phys3Env[1];
        final Phys3Env env = new Phys3Env(0, params, new Vector2f(0, 5), 1000);
        envs[0] = env;
       
        env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -5), 180);
        env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 1), 180);
        env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 1), 180);
        j1 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(1),
                new Vector2f(4, -5),
                new Vector2f(0, 0.9f),
                0);
        j2 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(2),
                new Vector2f(-4, -5),
                new Vector2f(0, 0.9f),
                0);
        j1 = new FixedJoint(
                env.getAgent(0),
                 env.getAgent(1));
        j2 = new FixedJoint(
                env.getAgent(0),
                env.getAgent(2));
        env.add(j1);
        env.add(j2);
       
        env.addAgent(new StaticObstacleLong(100, env, params), new Vector2D(10, 10), 0);
        env.addAgent(new StaticObstacleLong(102, env, params), new Vector2D(-60, -30), 90);
        env.addAgent(new StaticObstacleLong(104, env, params), new Vector2D(60, -30), 90);
        env.addAgent(new StaticObstacleShort(101, env, params), new Vector2D(-0, -80), 0);

        for (int i = 0; i < 7; i++) {
            env.addAgent(new StaticObstacleShortPassive(1000 + i, env, params), new Vector2D(-50 + i * 10, -70 + i * 5), 15);
        }
//        for (int i = 0; i < 3; i++) {
//            env.addAgent(new StaticObstacleShortPassive(10000 + i, env, params), new Vector2D(50 - i * 4, -50 - i * 5), -15);
//        }

        env.addAgent(new PhysicsAgent2(100000, env, 1000, params), new Vector2D(45, 3), 45);
        env.addAgent(new PhysicsAgent2(100001, env, 1000, params), new Vector2D(45, -30), 45);
        env.addAgent(new PhysicsAgent2(100002, env, 1000, params), new Vector2D(45, -63), 45);
       
        env.setPerfectFit(true);
       
        return envs;
    }

    @Override
    public synchronized void handleEvent(EASEvent e, Phys3Env env, Wink lastTick,
            ParCollection params) {
        super.handleEvent(e, env, lastTick, params);
       
        if (e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_IDENTIFIER + "r") && !((StaticObstacleShort) env.getAgent(101)).gesperrt) {
            env.remove(j1);
            env.remove(j2);
            env.removeAgent(0);
            env.removeAgent(1);
            env.removeAgent(2);
            env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -5), 180);
            env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 1), 180);
            env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 1), 180);
            j1 = new FixedJoint(
                    env.getAgent(0),
                    env.getAgent(1));
            j2 = new FixedJoint(
                    env.getAgent(0),
                    env.getAgent(2));
            env.add(j1);
            env.add(j2);
           
            env.setPerfectFit(true);
        }
    }
   
    @Override
    public void runDuringSimulation(Phys3Env umg, Wink simZyk,
            ParCollection params) {
        super.runDuringSimulation(umg, simZyk, params);
    }
   
    @Override
    public String id() {
        return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-rocketC";
    }
   
    @Override
    public boolean isTerminationRequested(Phys3Env runnable,
            Wink currentTime, ParCollection params) {
        return false;
    }
}
TOP

Related Classes of eas.users.demos.rocketMan.Phys3MasterC

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.