Package eas.users.demos.pacman

Source Code of eas.users.demos.pacman.PacmanMaster

/*
* Datei:            PacmanMaster.java
* Autor(en):        Lukas König
* Java-Version:     6.0
* Erstellt:         2010-10-27
*
* (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.pacman;

import java.util.Random;

import eas.math.geometry.Vector2D;
import eas.plugins.PluginProperties;
import eas.plugins.masterScheduler.AbstractDefaultKeyEventMaster;
import eas.plugins.standard.visualization.AllroundVideoPlugin;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.standardAgents.AbstractAgent2D;
import eas.simulation.spatial.sim2D.standardScenes.ObstacleRectangularScene;
import eas.simulation.spatial.sim2D.standardScenes.Scene2D;
import eas.startSetup.ParCollection;

/**
* @author Lukas König
*/
@PluginProperties(pluginIsHidden = false)
public class PacmanMaster extends AbstractDefaultKeyEventMaster<PacmanWorld> {

    /**
     *
     */
    private static final long serialVersionUID = -3686561854078113932L;

    @Override
    public PacmanWorld[] generateRunnables(ParCollection params) {
        Random rand = new Random();
        PacmanWorld world = new PacmanWorld(0, params);
        RealPacmanAgent agent = new RealPacmanAgent(0, world, params);
        Scene2D<AbstractAgent2D<?>> obstacleScene = new ObstacleRectangularScene(4, params, new Random(params.getSeed()));
       
        double breite = obstacleScene.getBoundingBox().getWidth();
        double hoehe = obstacleScene.getBoundingBox().getHeight();
       
        for (int i = 0; i < 7; i++) {
            obstacleScene.addCollidingAgent(
                    new PacmanGhostAgent(1, world, params),
                    new Vector2D(
                            rand.nextDouble() * breite - breite / 2,
                            rand.nextDouble() * hoehe - hoehe / 2),
                    rand.nextDouble() * 360,
                    new Vector2D(2.8, 2.8));
        }
       
        obstacleScene.scaleScene(0.05);
        obstacleScene.rotateScene(10);
        world.addCollidingAgent(agent, Vector2D.NULL_VECTOR, 0);
        world.addScene(obstacleScene);

        return new PacmanWorld[] {world};
    }

    @Override
    public String id() {
        return eas.simulation.ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-pacman";
    }
   
    @Override
    public void runDuringSimulation(PacmanWorld environment, Wink cyc,
        ParCollection params) {
      super.runDuringSimulation(environment, cyc, params);
     
      if (cyc.getLastTick() == 0) {
            params.setParValue(AllroundVideoPlugin.ROTATION_SPEED_PAR_NAME, 9.0);

            try {
        AllroundVideoPlugin vp = (AllroundVideoPlugin) environment.getSimTime().getPluginObject(new AllroundVideoPlugin().id());
        vp.setZoom2DPlus();
        vp.setZoom2DPlus();
        vp.setZoom2DPlus();
        vp.setZoom2DPlus();
        vp.setZoom2DPlus();
        vp.setZoom2DPlus();
        vp.setFollowAgent(true);
        Vector2D pos = environment.getPositionInVisualization(0);
        vp.setClickPosition((int) pos.x, (int) pos.y);
      } catch (Exception e) {
      }
      }
    }
}
TOP

Related Classes of eas.users.demos.pacman.PacmanMaster

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.