Package com.aqpproject.tools

Examples of com.aqpproject.tools.Vector2D


    public IAController(String playerName) {
        m_playerName = playerName;
        m_fireTime = -1;
        m_lastMovingTime = Singleton.getWorldModel().getTime();
        m_lastResetTime = 0;
        m_lastValidPosition = new Vector2D();
    }
View Full Code Here


    public void update() {
        if (Singleton.getWorldModel().isRaceStarted()) {
            if (m_lastResetTime == 0) {
                m_lastMovingTime = m_lastResetTime = Singleton.getWorldModel().getTime();
            }
            Vector2D pos = Singleton.getWorldModel().getEntityPosition(m_playerName);

            float rotation = Singleton.getWorldModel().getEntityRotation(m_playerName);
            rotation = rotation % 360;
            rotation = rotation >= 180 ? rotation - 360 : rotation;
            rotation = rotation <= 180 ? rotation : rotation + 360;
View Full Code Here

            perfectRotation -= (alpha / Math.abs(alpha)) * 360;
        }



        Vector2D vel = Singleton.getWorldModel().getEntityVelocity(m_playerName);

        if (currentRotation != perfectRotation) {
            if (currentRotation < perfectRotation) {
                Singleton.getWorldModel().control(Control.Q, m_playerName);
            } else {
                Singleton.getWorldModel().control(Control.D, m_playerName);
            }
        }

        float bias = Math.abs(alpha);
        bias = Math.abs((bias > 180) ? (bias - 360) : (bias));

        if (bias > ROTATION_CRITIC && vel.length() > 5) {
            Singleton.getWorldModel().control(Control.SHIFT_LEFT, m_playerName);
        } else {
            Singleton.getWorldModel().control(Control.Z, m_playerName);
        }

        //Singleton.getWorldModel().control(Control.Z, m_playerName);

        // System.out.println("C:"+currentRotation+"  /  P:"+perfectRotation);

        if (m_fireTime != -1 && m_fireTime < Singleton.getWorldModel().getTime()) {
            Singleton.getWorldModel().control(Control.SPACE, m_playerName);
        }

        if (m_fireTime == -1 && Singleton.getWorldModel().getEntityHasItem(m_playerName)) {
            m_fireTime = (float) (Singleton.getWorldModel().getTime() + (Math.random() * 10000.f) + 3000.f);
        }

        //CHECK RESET

//        System.out.println(vel.length());
        if (vel.length() > 5 || Singleton.getWorldModel().getTime() < m_lastResetTime + 3000) {
            m_lastMovingTime = Singleton.getWorldModel().getTime();
        }

        //RESET


        if (Singleton.getWorldModel().getTime() > m_lastMovingTime + 1000) {

            Vector2D pos = m_lastValidPosition.scale(1 / 64.f);
            m_lastValidPosition.x = Math.round(m_lastValidPosition.x);
            m_lastValidPosition.y = Math.round(m_lastValidPosition.y);
            m_lastValidPosition = m_lastValidPosition.scale(64);
            m_lastValidPosition = m_lastValidPosition.translate(32, 32);
            int code = Singleton.getVisualisation().getTile(Visualisation.MAP_LAYER.IA, pos);
View Full Code Here

         */
        PolygonShape shape = new PolygonShape();
        Vector2 pos = new Vector2(size.x / (2.f * PIXELS_PER_METERS), size.y / (2.f * PIXELS_PER_METERS));
        shape.setAsBox(size.x / (2.f * PIXELS_PER_METERS), size.y / (2.f * PIXELS_PER_METERS), pos, 0);

        m_bodiesSizes.put(name, new Vector2D(size));

        /*
         * Body Creation
         */
        body.createFixture(shape, density);
View Full Code Here

    public void createMapBodies() {

        for (int x = 0; x < Singleton.getVisualisation().getMapWidth(); x++) {
            for (int y = 0; y < Singleton.getVisualisation().getMapHeight(); y++) {

                int id = Singleton.getVisualisation().getTile(Visualisation.MAP_LAYER.STATIC_OBJECTS, new Vector2D(x * 64, y * 64));
                String code = "" + id;

                if (m_segments.containsKey(code)) {
                    ArrayList<Segment2D> segments = m_segments.get(code);

                    for (Segment2D seg : segments) {

                        /*
                         * BodyDef Creation
                         */
                        BodyDef bodydef = new BodyDef();
                        bodydef.type = BodyDef.BodyType.StaticBody;
                        Body body = m_world.createBody(bodydef);
                        body.setUserData("StaticBody");

                        /*
                         * Shape creation
                         */
                        EdgeShape shape = new EdgeShape();
                        Vector2 first = toVector2(new Vector2D(seg.getFirst()).translate((x) * 64, (y) * 64).scale(1.f / PIXELS_PER_METERS));
                        Vector2 second = toVector2(new Vector2D(seg.getSecond()).translate((x) * 64, (y) * 64).scale(1.f / PIXELS_PER_METERS));
                        shape.set(first, second);

                        /*
                         * Body Creation
                         */
                        body.createFixture(shape, 0);
                        shape.dispose();

                        m_debugSegments.add(new Segment2D(new Vector2D(seg.getFirst()).translate((x) * 64, (y) * 64), new Vector2D(seg.getSecond()).translate((x) * 64, (y) * 64)));


                        m_mapBodies.add(body);
                    }

View Full Code Here

        }
    }

    @Override
    public void applyLinearForce(String name, Vector2D vel) {
        m_bodies.get(name).applyForceToCenter(toVector2(new Vector2D(vel).scale(1.f / PIXELS_PER_METERS)));
    }
View Full Code Here

        return toVector2D(m_bodies.get(name).getPosition()).scale(PIXELS_PER_METERS);
    }

    @Override
    public void setBodyPosition(String name, Vector2D position) {
        Vector2 pos = toVector2(new Vector2D(position).scale(1.f / PIXELS_PER_METERS));
        float rotation = m_bodies.get(name).getAngle();
        m_bodies.get(name).setTransform(pos, rotation);
    }
View Full Code Here

    }

    private void updateBodyPosition() {
        while (!m_positionsToModify.isEmpty()) {
            String name = m_positionsToModify.keySet().iterator().next();
            Vector2D position = m_positionsToModify.remove(name);
            Vector2D velocity = m_velocitiesToModify.remove(name);
            float rotation = m_rotationToModify.remove(name);
            if (m_bodies.containsKey(name)) {
                Vector2 pos = toVector2(new Vector2D(position).scale(1.f / PIXELS_PER_METERS));
//                float rotation = m_bodies.get(name).getAngle();
                m_bodies.get(name).setTransform(pos, rotation);
                m_bodies.get(name).setLinearVelocity(toVector2(new Vector2D(velocity).scale(1.f / PIXELS_PER_METERS)));
            }
        }
    }
View Full Code Here

    }

    @Override
    public Vector2D getBodyCenter(String name) {
        Body body = m_bodies.get(name);
        Vector2D size = m_bodiesSizes.get(name);
        return toVector2D(body.getTransform().mul(new Vector2(size.x / (PIXELS_PER_METERS * 2.f), size.y / (PIXELS_PER_METERS * 2.f)))).scale(PIXELS_PER_METERS);
    }
View Full Code Here

        return toVector2D(m_bodies.get(name).getLinearVelocity()).scale(PIXELS_PER_METERS);
    }

    @Override
    public void setLinearVelocity(String name, Vector2D velocity) {
        m_bodies.get(name).setLinearVelocity(toVector2(new Vector2D(velocity).scale(1.f / PIXELS_PER_METERS)));
    }
View Full Code Here

TOP

Related Classes of com.aqpproject.tools.Vector2D

Copyright © 2018 www.massapicom. 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.