Example #1
0
 public void printDistance(Point hitPoint) {
   for (int i = 0; i < nodes.size() - 1; i++) {
     Helper.println(
         "Distance from: (X,Y) ==>  ( " + nodes.get(i).getX() + ", " + nodes.get(i).getY() + " )");
     Helper.println(
         "To: (X,Y) ==>  ( " + nodes.get(i + 1).getX() + ", " + nodes.get(i + 1).getY() + " )");
     Helper.println(
         ""
             + Helper.pointToLineDistance(
                 nodes.get(i).getLocation(), nodes.get(i + 1).getLocation(), hitPoint));
   }
 }
Example #2
0
  /**
   * @param element Draws image using x, y, width, height of the passed ElementBase IF you need to
   *     have different render method for any element please write it in this class. By that, you
   *     would easily find what custom rendering did you need.
   */
  public void render(ElementBase element) {
    if (element.getImage() == null) {
      Helper.println("Renderer.java - Texture is null: " + element.getClass());
      return;
    }

    TextureRegion textureRegion = element.getImage();

    if (textureRegion == null) {
      // Helper.println("Renderer.java - Texture is null");
      return;
    }
    batch.draw(
        textureRegion.getTexture(),
        element.getX(),
        element.getY(),
        element.getWidth(),
        element.getHeight(),
        0,
        0,
        (int) textureRegion.getRegionWidth(),
        textureRegion.getRegionHeight(),
        false,
        false);

    //		batch.draw(textureRegion.getTexture(), Helper.getCameraX(), Helper.getCameraY(),
    //				element.getWidth(), element.getHeight(), 0, 0,
    //				(int) textureRegion.getRegionWidth(), textureRegion
    //						.getRegionHeight(), false, false);
  }
 @Override
 public void onTouch(Point p) {
   //		Helper.println("Checking hitpoint...");
   if (this.checkHit(p)) {
     Helper.println("classic game...");
     //			GlobalVars.ge.loadStage(new XLevel());
   }
 }
Example #4
0
	/**
	 * @param element
	 * This would add the element to the element list directly 
	 */
	public void addElementWithInit(ElementBase element)
	{
		Helper.println("Adding element: " + element.getClass());
		this.elements.add(element);
		if(element != null){
			element.init();
		}
	}
Example #5
0
 @Override
 public void onTouch(Point p) {
   if (this.checkHit(p)) {
     Helper.println("Button Pause Hit : " + p.toString());
     Helper.println(
         "Button Pause Hit : Current Game state : "
             + GlobalVars.ge.getCurrentStage().getGameState());
     if (GlobalVars.ge.getCurrentStage().getGameState() == GameState.PLAYING) {
       GlobalVars.ge.getCurrentStage().pause();
       this.image = imagePlay;
     } else if (GlobalVars.ge.getCurrentStage().getGameState() == GameState.PAUSED) {
       GlobalVars.ge.getCurrentStage().resume();
       this.image = imagePause;
     }
     Helper.println(
         "Button Pause Hit : Game state set: " + GlobalVars.ge.getCurrentStage().getGameState());
   }
 }
Example #6
0
  @Override
  public void onEvent(Point p) {
    //		Helper.println("Checking hitpoint...");
    if (this.checkHit(p)) {
      Helper.println("level pressed..." + level_id);

      if (is_level_visible()) GlobalVars.ge.loadStage(new BounceTest(level_id, res));
      //				GlobalVars.ge.loadStage(new XLevel(level_id, res));
    }
  }
  @Override
  public void onEvent(Point p) {
    if (this.checkHit(p)) {
      Helper.println("Button Restart Hit in game over screen: " + p.toString());

      //			GlobalVars.ge.getCurrentStage().setGameState(GameState.PLAYING);
      //			GlobalVars.ge.getCurrentStage().reload();

      if (res instanceof ResultBTRMAP)
        GlobalVars.ge.loadStage(new XLevel(level_id, new ResultBTRMAP()));
      else if (res instanceof ResultBTRClassic)
        GlobalVars.ge.loadStage(new XLevel(level_id, new ResultBTRClassic()));
      else if (res instanceof ResultBTRTime)
        GlobalVars.ge.loadStage(new XLevel(level_id, new ResultBTRTime()));
    }
  }
Example #8
0
	public void init() {

		for(int i = 0; i < zSortedElements.size; i++)
		{
			a = zSortedElements.get(i);
//			Helper.println("A size: " + a.size);
			for(ElementBase element :a){
				element.init();
			}
		}
		for(ElementBase element: elements)
		{
			element.init();
		}
		this.setGameState(GameState.PLAYING);
		
		Helper.println("INit: gameState: " + this.getGameState());
	}	
Example #9
0
  /**
   * Starts traversing with given hit point and maxDistance from the hit. It returns closest point
   * on the closest segment.
   *
   * @param hitPoint Any point on the screen.
   * @param maxDistance Maximum distance from the hit-point to the landing point on the comparing
   *     path segment. Needed for detection.
   * @return Using the given hit-point, returns TraversePointInfo for the landing point on the Path
   */
  public TraversePointInfo startTraverse0(Point hitPoint, float maxDistance) {
    Helper.println("\n\n\nStarting: ");
    float distance, d;
    for (int i = 0; i < nodes.size() - 1; i++) {
      //			if(!insideCheck(nodes.get(i).getLocation(), nodes.get(i+1).getLocation(), hitPoint))
      //				continue;
      distance =
          (float)
              Helper.pointToLineDistance(
                  nodes.get(i).getLocation(), nodes.get(i + 1).getLocation(), hitPoint);
      //			Helper.printKeyVal("node: " + nodes.get(i)+ "  to  " + nodes.get(i+1), distance);

      if (distance <= maxDistance) {
        //				Helper.printKeyVal("Node selected: ", nodes.get(i).getLocation().toString());

        TraversePointInfo info = new TraversePointInfo();
        info.setPathNode(nodes.get(i));

        d = (float) Math.pow(info.getPathNode().getLocation().distancePoint2Point(hitPoint), 2);
        distance = distance * distance;
        //				Helper.printKeyVal("Distance measured: ", Math.sqrt(d-distance));
        distance = (float) Math.sqrt(d - distance);

        info.setTraverseLocation(info.getPathNode().getPointAtDistance(distance));
        //				Helper.printKeyVal("Point Set: ", info.getTraverseLocation().toString());

        info.setDistance(distance);
        //				Helper.printKeyVal("Distance Set: ", info.getDistance());

        for (int j = 0; j <= i; j++) {
          distance += nodes.get(j).getLeftDistance();
        }

        info.setTotalDistanceInPath(distance);
        //				Helper.printKeyVal("Total Distance Set: ", info.getTotalDistanceInPath());
        info.setPath(this);

        return info;
      }
    }
    return null;
  }
Example #10
0
  @Override
  public void onEvent(Point p) {
    //		Helper.println("Checking hitpoint...");
    if (this.checkHit(p)) {
      //			if(isInfoBack==true)
      //
      //	((ChoosePlayerandBall)GlobalVars.ge.getCurrentStage()).removeElement(((ChoosePlayerandBall)GlobalVars.ge.getCurrentStage()).buttonInfoBack);

      ((ChoosePlayerandBall) GlobalVars.ge.getCurrentStage()).showPlayerInfo();
      Helper.println("show player info");
      if (isTouched != false) {
        this.setImage(Helper.getImageFromAssets(AssetConstants.IMG_INFO));
        isTouched = false;
      } else if (isTouched == false) {
        this.setImage(Helper.getImageFromAssets(AssetConstants.IMG_INFO_PRESSED));

        isTouched = true;
      }
    }
  }
Example #11
0
	protected void updateStage(){
		if(this.gameState == GameState.RELOADING)
		{
			Helper.println("\n\nReloading...");
			
			for(int i = 0; i < zSortedElements.size; i++)
			{
				zSortedElements.get(i).clear();
			}
			zSortedElements.clear();
			
			this.elements.clear();
			this.interactions.clear();
			this.gameControlInteractions.clear();
			this.loadElements();
//			System.gc();
			this.init();			
			return;
		}		
	}
Example #12
0
  private void createElevetors() {
    // TODO Auto-generated method stub
    BodyDef bodyDef = new BodyDef();
    for (int i = 0; i < XMLReader.ropes.size; i++) {

      // if(XMLReader.ropes.get(i).pathType == "path")
      Helper.println("pathtype" + XMLReader.ropes.get(i).pathType);
      XMLReader.ropes.get(i).pathType = XMLReader.ropes.get(i).pathType.toLowerCase();
      // if(true)
      if (!XMLReader.ropes.get(i).pathType.contains("lift")) {
        Vector2 vs[] = new Vector2[XMLReader.ropes.get(i).getNodes().size()];
        // for (int vertexCount
        // =0;vertexCount<XMLReader.ropes.get(i).getNodes().size();vertexCount++)
        // {
        // vs[vertexCount] = new Vector2();
        // }
        for (int vertexCount = 0;
            vertexCount < XMLReader.ropes.get(i).getNodes().size();
            vertexCount++) {

          if (XMLReader.ropes.get(i).getNodes().get(vertexCount).getY() < fallY)
            fallY = XMLReader.ropes.get(i).getNodes().get(vertexCount).getY();
          Helper.println("fallY::" + fallY);
          //					 Helper.println("vertex count::"+ vertexCount);
          // vs[vertexCount] = new Vector2(vs[vertexCount-1].x +
          // elevetorWidth, vs[vertexCount-1].y * 1.10f);
          // Helper.println("vertex position in
          // pixel:::"+PhysicsHelper.ConvertToWorld((vs[vertexCount-1].x)
          // ));
          // Helper.println("value of i:::"+i+"value of certexCpunt::"+vertexCount);
          try {
            // Helper.println("xml reader given rope no::::;"+XMLReader.ropes.get(i)+"xml reader
            // given rope nodes
            // ate::::;"+XMLReader.ropes.get(i).getNodes().get(vertexCount).getX());
            vs[vertexCount] =
                new Vector2(
                    PhysicsHelper.ConvertToBox(
                        XMLReader.ropes.get(i).getNodes().get(vertexCount).getX()),
                    PhysicsHelper.ConvertToBox(
                        XMLReader.ropes.get(i).getNodes().get(vertexCount).getY()));

            // Helper.println("rope  no:"+i+"rope node no:"+vertexCount+"rope node
            // position"+PhysicsHelper.ConvertToWorld(vs[vertexCount].x)+"rope node
            // position"+PhysicsHelper.ConvertToWorld(vs[vertexCount].y));
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }

        ChainShape chain = new ChainShape();
        // chain.setPrevVertex(new Vector2(vs[0].x - elevetorWidth,
        // vs[0].y));
        //
        // chain.setNextVertex(new Vector2(vs[vs.length-1].x +
        // elevetorWidth, vs[vs.length-1].y * 1.05f));
        chain.createChain(vs);
        // chain.setRadius(.625f);
        FixtureDef chainShepDef = new FixtureDef();
        chainShepDef.friction = friction;
        chainShepDef.shape = chain;
        chainShepDef.density = 0f;
        chainShepDef.restitution = 0f;
        // chainShepDef.filter.groupIndex = 1;
        chainShepDef.filter.categoryBits = 11;
        chainShepDef.filter.maskBits = 14 | 13 | 4 | 5 | 6 | 7 | 1;

        chains.add(chain);

        // bodyDef.position = anchor.add(new Vector2(0, i * 0.25f));
        // anchor.add(new Vector2(i*.25f, 0));
        // anchor.set(new Vector2(i*0f, i*0.55f));
        // anchor.add(PhysicsHelper.ConvertToBox(startPoint.x),
        // PhysicsHelper.ConvertToBox(startPoint.y));
        // anchor.add(startPoint);
        // calculatedAngle = Helper.getAngle(p, q);
        // bodyDef.angle = MathUtils.degreesToRadians*calculatedAngle;

        elevetor = world.createBody(bodyDef);
        elevetor.setUserData("elevator");
        elevetor.createFixture(chainShepDef);
        elevetor.setType(BodyType.StaticBody);
        elevators.add(elevetor);
        Helper.println("body angle is :::" + elevetor.getAngle());

      } else if (XMLReader.ropes.get(i).pathType.contains("lift")) {
        Vector2 vs1[] = new Vector2[XMLReader.ropes.get(i).getNodes().size()];
        // for (int vertexCount
        // =0;vertexCount<XMLReader.ropes.get(i).getNodes().size();vertexCount++)
        // {
        // vs1[vertexCount] = new Vector2();
        // }

        for (int vertexCount = 0;
            vertexCount < XMLReader.ropes.get(i).getNodes().size();
            vertexCount++) {
          //					if (XMLReader.ropes.get(i).getNodes().get(vertexCount)
          //							.getY() < fallY)
          //						fallY = XMLReader.ropes.get(i).getNodes()
          //								.get(vertexCount).getY();
          // Helper.println("value of i:::"+i+"value of certexCpunt::"+vertexCount);
          vs1[vertexCount] =
              new Vector2(
                  PhysicsHelper.ConvertToBox(
                      XMLReader.ropes.get(i).getNodes().get(vertexCount).getX()),
                  PhysicsHelper.ConvertToBox(
                      XMLReader.ropes.get(i).getNodes().get(vertexCount).getY()));
          if (vertexCount == XMLReader.ropes.get(i).getNodes().size() - 1)
            liftWidth =
                PhysicsHelper.ConvertToWorld(
                    (float) Helper.pointToPointDistance(vs1[vertexCount], vs1[0]));
          Helper.println("lift width ::" + liftWidth);
        }

        boolean b = XMLReader.ropes.get(i).pathType.contains("up");
        Helper.println("\n\n\n\n\n*****************************\nLift rope number :::" + i);
        Lift lift =
            new Lift(
                new Vector2(
                    PhysicsHelper.ConvertToWorld(vs1[0].x), PhysicsHelper.ConvertToWorld(vs1[0].y)),
                null,
                null,
                null,
                1,
                world,
                true,
                liftWidth,
                7 * LevelInfo.ratioY,
                b);
        // lift.getBody().setTransform(lift.getBody().getPosition(),
        // (float) (lift.getBody().getAngle()+ Math.PI/2));
        GlobalVars.ge.getCurrentStage().addElement(lift);
        // elevators.add(lift.getBody());
        // elevators.add(elevetor);
      }

      // elevators.add(i, elevetor);
    }

    ((BikeLevel) GlobalVars.ge.getCurrentStage())
        .setElevatorInfo(XMLReader.ropes.get(XMLReader.ropes.size - 1).getNodes().getLast(), fallY);
  }
Example #13
0
  @Override
  public void loadElements() {
    Helper.println("Now i'm in mainmenu");
    this.interactions.add(new InteractionTouch());
    this.gameControlInteractions.add(new InteractionTouch());
    this.elements.add(
        new Background(
            0,
            0,
            Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight(),
            1,
            AssetConstants.IMG_BKG_MAIN));
    //		Helper.println(""+Helper.getImageFromAssets(AssetConstants.IMG_EXIT).getRegionWidth());
    x = 180 * GameMenuInfo.ratio_w;
    y = 70 * GameMenuInfo.ratio_h;
    w = 147 * GameMenuInfo.ratio_w;
    h = 67 * GameMenuInfo.ratio_h;
    ButtonChoosePlayerandBall buttonChoosePlayerandBall =
        new ButtonChoosePlayerandBall(x, y, w, h, 1, AssetConstants.IMG_PLAY_TEXT);
    this.elements.add(buttonChoosePlayerandBall);
    subscribeToControllingInteraction(buttonChoosePlayerandBall, InteractionTouch.class);

    x = 180 * GameMenuInfo.ratio_w;
    y = 20 * GameMenuInfo.ratio_h;
    w = 147 * GameMenuInfo.ratio_w;
    h = 67 * GameMenuInfo.ratio_h;
    ButtonInstruction buttonInstruction =
        new ButtonInstruction(x, y, w, h, 1, AssetConstants.IMG_INS);
    this.elements.add(buttonInstruction);
    subscribeToControllingInteraction(buttonInstruction, InteractionTouch.class);
    // music
    //		x = 05;
    //		y = 290;
    x = 10 * GameMenuInfo.ratio_w;
    y = 280 * GameMenuInfo.ratio_h;
    w = 42 * GameMenuInfo.ratio_w;
    h = 36 * GameMenuInfo.ratio_h;

    ButtonMusicControl buttonMusic =
        new ButtonMusicControl(x, y, w, h, 1, AssetConstants.IMG_MUSIC_ON);
    this.elements.add(buttonMusic);
    subscribeToControllingInteraction(buttonMusic, InteractionTouch.class);

    // sound
    //		x= 40;
    //		y = 290;
    x = 50 * GameMenuInfo.ratio_w;
    y = 280 * GameMenuInfo.ratio_h;
    w = 42 * GameMenuInfo.ratio_w;
    h = 36 * GameMenuInfo.ratio_h;

    ButtonSoundControl buttonSound =
        new ButtonSoundControl(x, y, w, h, 1, AssetConstants.IMG_SOUND_ON);
    this.elements.add(buttonSound);
    subscribeToControllingInteraction(buttonSound, InteractionTouch.class);

    // exit
    //		x= 450;
    //		y= 290;
    x = 440 * GameMenuInfo.ratio_w;
    y = 280 * GameMenuInfo.ratio_h;
    w = 42 * GameMenuInfo.ratio_w;
    h = 36 * GameMenuInfo.ratio_h;
    ButtonExitGame buttonExitgame =
        new ButtonExitGame(x, y, w, h, 1, AssetConstants.IMG_EXIT, true);
    this.elements.add(buttonExitgame);
    subscribeToControllingInteraction(buttonExitgame, InteractionTouch.class);
    // start game
    //		x=150;
    //		y=250;
    //		ButtonEnterGameMenu buttonEntergame = new ButtonEnterGameMenu(x,y,140,60, 1,
    // AssetConstants.IMG_PLAY_MENU);
    //		this.elements.add(buttonEntergame);
    //		subscribeToControllingInteraction(buttonEntergame, InteractionTouch.class);
    // buttonChoosePlayerandBall
    //		y = 70;
    //		ButtonPlayerInfo buttonPlayerInfo = new ButtonPlayerInfo(x, y, 150, 60,1,
    // AssetConstants.IMG_CS);
    //		this.elements.add(buttonPlayerInfo);
    //		subscribeToControllingInteraction(buttonPlayerInfo, InteractionTouch.class);
    //		//option
    //		ButtonOptionGameMenu buttonOption = new ButtonOptionGameMenu(150,200, 60,40,1,
    // AssetConstants.IMG_OPTIONS);
    //		this.elements.add(buttonOption);
    //		subscribeToControllingInteraction(buttonOption, InteractionTouch.class);
    // ButtonChooseLocation
    //		x=150;
    //		y = 170;
    //		ButtonChooseLocation buttonChooseLocation = new ButtonChooseLocation(x, y, 150, 60,1,
    // AssetConstants.IMG_CL);
    //		this.elements.add(buttonChooseLocation);
    //		subscribeToControllingInteraction(buttonChooseLocation, InteractionTouch.class);
    // Choose Shhot/level
    //		x= 150;
    //		y = 130;
    //		ButtonChooseLevel buttonChooseLevel = new ButtonChooseLevel(x, y, 150, 60,1,
    // AssetConstants.IMG_PLAY_MENU);
    //		this.elements.add(buttonChooseLevel);
    //		subscribeToControllingInteraction(buttonChooseLevel, InteractionTouch.class);
    // ButtonInstruction

  }
Example #14
0
	/**
	 * @param element
	 * This would add the element to the element list directly 
	 */
	public void addElement(ElementBase element)
	{
		Helper.println("Adding element: " + element.getClass());
		this.elements.add(element);
	}