Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


    public void initializeShoot(ElementBullet shoot) {


        shoot.owner=owner;
        Vec2 shootPos = getShootRelativePosition();
        Vec2 shootSpeed = getShootRelativeSpeed();

        shootPos.x+= owner.body.getWorldCenter().x;
        shootPos.y+= owner.body.getWorldCenter().y;
        Common.info(7,"shooting direction "+D());
        shootSpeed.x+=D().x*shoot.speed;
 
View Full Code Here



    public Vec2 D()
    {
        if(owner.directionX==0 &&  owner.directionY==0)
            return new Vec2(1,0);
        else {
            Vec2 d=  new Vec2(owner.directionX,owner.directionY);
            return d;
        }

    }
View Full Code Here

        }

    }

    public Vec2 getShootRelativePosition() {
        return new Vec2(
                   D().x * 2 * owner.getSize().x ,
                   D().y * 2 * owner.getSize().y
               );

    }
View Full Code Here

                   D().y * 2 * owner.getSize().y
               );

    }
    public Vec2 getShootRelativeSpeed() {
        return new Vec2(
                   0,0
               );

    }
View Full Code Here

        friction=10;

        jumpSpeed = 7f;
        runSpeed = 6f;

        reducedSize = new Vec2(0.3f, 0.35f);
        standardSize = new Vec2(0.3f, 0.7f);
        setBoxShape(standardSize.x, standardSize.y);
        fireTime=0.7f;
        ActionTimer at = new ActionTimer("",fireTime,0,true) {

            public Object force(Object o)
View Full Code Here

        */
        if (k.check(KeyFlag.LEFT))
        {
            //this.setSpeed(new Vec2(-hSpeed, generator.nextFloat() ));

            this.setSpeed(new Vec2(-hSpeed, 0f));
            if(!isJumping) this.applySpeed(new Vec2(0f, (generator.nextFloat()-0.5f) *0.5f));
      if(isRunning!=-1)            this.directionX=-1;
     
       isRunning = -1;
        }
        if (k.check(KeyFlag.RIGHT))
        {
            //this.setSpeed(new Vec2(hSpeed, generator.nextFloat()));

            this.setSpeed(new Vec2(hSpeed, 0f));
            if(!isJumping) this.applySpeed(new Vec2(0f,(generator.nextFloat()-0.5f)*0.5f ));
      if(isRunning!=1)            this.directionX=1;
   
      isRunning = 1;
        }



        if (k.check(KeyFlag.JUMP) && !isJumping)
            this.setSpeed(new Vec2(0, -jumpSpeed));
        ((ActionTimer)actions.getAction("jumptime")).active=true;

        if (k.check(KeyFlag.FIRE))
        {

            this.gl.get(currentGunIndex).fire();
            k.del(KeyFlag.FIRE);
            isFiring=true;
            ((ActionTimer)actions.getAction("firetime")).active=true;

        }
        if (k.check(KeyFlag.SPECIAL)) {
            specialMove(k);
        }
        if (k.check(KeyFlag.DOWN) && !isJumping ||(!k.check(KeyFlag.DOWN) && isBending)) {
            Vec2 oldPos = getPosition().clone();
            Vec2 oldSize = getSize().clone();
            Vec2 newPos =  new Vec2();
            Vec2 newSize = new Vec2();

            //  Common.info(1,"DOWN: oldPOS="+getPosition()+" oldSIZE="+getSize());
            PolygonShape newShape = new PolygonShape();

            //bodydef = new BodyDef();
            //level.delElement(this);
            if (isBending) {
                newPos = new Vec2(oldPos.x, oldPos.y + oldSize.y / 2f- standardSize.y / 2);
                newSize = new Vec2(standardSize.x, standardSize.y);
                isBending = false;
            } else {

                newPos = new Vec2(oldPos.x, oldPos.y + oldSize.y / 2f - reducedSize.y  / 2);
                newSize = new Vec2(reducedSize.x, reducedSize.y);
                isBending = true;

            }
            //  Common.info(1,"DOWN: oldPOS="+getPosition()+" oldSIZE="+getSize());


            body.setTransform(newPos,0f);

            body.destroyFixture(body.getFixtureList());
            //body.resetMassData();
            //FixtureDef fd = new FixtureDef();
            setBoxShape(newSize.x, newSize.y);
            //fd.shape=shape;
            //body.createFixture(fd);
            //setFixture(body.createFixture(fd));
            setBody(body);
            updateAABB();

            k.del(KeyFlag.DOWN);
        }

        if (k.number()!=0) {
            int n=k.number()-1;
            if(gl.get(n)!=null)      currentGunIndex=n;
        }


        if (k.Key == KeyFlag.NONE)
        {
            allKeysReleased();
            applySpeed(new Vec2(-getSpeed().x,0));
       isRunning = 0;
        }

        //Common.info(1,"bodu:"+body.isActive()+" mass:"+body.getMass()+ " waawakw"+body.isAwake());
    }
View Full Code Here

            fungoImg);
            //Common.info(1, "loaded: " + currentSprite.getFileName());
          } else
          Common.info(1, "il funghetto e' nul" + File.listRoots());
        }
        Vec2 scale = c.scale;
        Point position = new Point(
        (int) (se.position.x + (currentSprite.offsetx - currentSprite.sizex / 2)
        * scale.x),
        (int) (se.position.y + (currentSprite.offsety - currentSprite.sizey / 2)
        * scale.y));
 
View Full Code Here

  * remaining time from the end of the game
  */
  public long remaning=0;
  public Game() {
    screenResolution = new Point(800, 600);
    gameResolution = new Vec2(10f , 10f );
    chat = new ArrayList<String>();
    for (int i = 0; i < 10; i++)
    chat.add("");
    scale = new Vec2();
  }
View Full Code Here

  }
 
  public synchronized  void setResolution(float x,float y)
 
  {
    gameResolution = new Vec2(x,y);
  }
View Full Code Here

  /**
  * return the screen centered on currentPlayer
  */
  public synchronized ArrayList<ShownElement> getScreen(ElementPlayer currentPlayer) {
    if(currentPlayer==null) return new ArrayList<ShownElement>();
    Vec2 curpos = currentPlayer.getPosition();
    if(curpos==null) return new ArrayList<ShownElement>();
    Vec2 gameScreen = new Vec2();
    gameScreen.x = curpos.x - gameResolution.x / 2;
    gameScreen.y = curpos.y - gameResolution.y / 2;
    List insideL = level.getScreen(gameScreen, gameResolution);
    ArrayList<ShownElement> se = new ArrayList<ShownElement>();

View Full Code Here

TOP

Related Classes of org.jbox2d.common.Vec2

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.