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)); } }
/** * @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); }
public Path() { nodes = new LinkedList<PathNode>(); renderNodes = new LinkedList<PathNode>(); // segmentPoints = new LinkedList<Point>(); pathRenderer = new PathRenderMethods(this); this.imageInActive = Helper.getImageFromAssets(AssetConstants.IMG_ROAD_WHITE); }
@Override public void onTouch(Point p) { // Helper.println("Checking hitpoint..."); if (this.checkHit(p)) { Helper.println("classic game..."); // GlobalVars.ge.loadStage(new XLevel()); } }
/** * @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(); } }
@Override public void onEvent(Point p) { if (this.checkHit(p)) { this.image = Helper.getImageFromAssets(imagePath_2); GlobalVars.ge.loadStage(new LevelMenuArnold()); } }
@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()); } }
@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)); } }
/** * 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; }
public void set_main_menu() { x = 0f; y = 0f; bg = new BackGroundUniversal( x, y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 1, AssetConstantsFruit.main_bg); this.elements.add(bg); x = Gdx.graphics.getWidth() / 2f - Helper.getImageFromAssets(AssetConstantsFruit.play_n).getRegionWidth() / 2f * AssetConstantsFruit.ratio_w; y = Gdx.graphics.getHeight() / 2f - 120 * AssetConstantsFruit.ratio_h - Helper.getImageFromAssets(AssetConstantsFruit.play_n).getRegionHeight() / 2f * AssetConstantsFruit.ratio_h; play = new ButtonStageLoad( x, y, Helper.getImageFromAssets(AssetConstantsFruit.play_n).getRegionWidth() * AssetConstantsFruit.ratio_w, Helper.getImageFromAssets(AssetConstantsFruit.play_n).getRegionHeight() * AssetConstantsFruit.ratio_h, 1, AssetConstantsFruit.play_n, new SelectVehicleMenuFruit()); this.elements.add(play); this.interaction_touch.subscribe(play); y = y - 1.5f * Helper.getImageFromAssets(AssetConstantsFruit.settings_n).getRegionHeight() * AssetConstantsFruit.ratio_h; settings = new ButtonStageLoad( x, y, Helper.getImageFromAssets(AssetConstantsFruit.settings_n).getRegionWidth() * AssetConstantsFruit.ratio_w, Helper.getImageFromAssets(AssetConstantsFruit.settings_n).getRegionHeight() * AssetConstantsFruit.ratio_h, 1, AssetConstantsFruit.settings_n, new SettingsMenuFruit()); this.elements.add(settings); this.interaction_touch.subscribe(settings); }
@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; } } }
public PathNode getPathNode(Point hitPoint, float maxDistance) { for (int i = 0; i < nodes.size() - 1; i++) { // Helper.printKeyVal("node: " + nodes.get(i)+ " to " + nodes.get(i+1), // Helper.pointToLineDistance(nodes.get(i).getLocation(), nodes // .get(i + 1).getLocation(), hitPoint)); if (Helper.pointToLineDistance( nodes.get(i).getLocation(), nodes.get(i + 1).getLocation(), hitPoint) <= maxDistance) return nodes.get(i); } return null; }
@Override public void onEvent(Point p) { if (this.checkHit(p)) { if (soundhandler.is_arnold_active()) { // soundhandler.set_music_active(false); soundhandler.set_arnold_active(false); this.setImage(Helper.getImageFromAssets(setImagePath(false))); SettingMenuArnold.is_arnold_sound_active = false; } else { // soundhandler.set_music_active(true); soundhandler.set_arnold_active(true); this.setImage(Helper.getImageFromAssets(setImagePath(true))); SettingMenuArnold.is_arnold_sound_active = true; } } }
@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())); } }
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()); }
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; } }
@Override public void init() { this.image = Helper.getImageFromAssets(imagePath); }
/** * @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); }
public ButtonSelectShot( float x, float y, float width, float height, int zIndex, String imagePath) { super(x, y, width, height, zIndex, imagePath); this.image = Helper.getImageFromAssets(imagePath); }
@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 }
@Override public void init() { super.init(); imagePlay = Helper.getImageFromAssets(AssetConstants.IMG_PLAY); imagePause = this.image; }
@Override public void init() { // this.imageelevator = Helper.getImageFromAssets(CSPConstants.TROPIC_CARPET); this.texturePathCarpet = Helper.getImageFromAssets(imagePathCarpet); this.texturePathTexture = Helper.getImageFromAssets(imagePathTexture); }
@Override public void render() { this.update(Gdx.graphics.getDeltaTime()); for (int i = 0; i < chains.size(); i++) { ct = chains.get(i); for (int j = 1; j <= ct.getChildCount(); j++) { ct.getVertex(j - 1, vertex); ct.getVertex(j, v); p.setLocation( PhysicsHelper.ConvertToWorld(vertex.x) * LevelInfo.ratioX, PhysicsHelper.ConvertToWorld(vertex.y) * LevelInfo.ratioX); q.setLocation( PhysicsHelper.ConvertToWorld(v.x) * LevelInfo.ratioX, PhysicsHelper.ConvertToWorld(v.y) * LevelInfo.ratioX); // if(Math.abs(p.getX() - GlobalVars.ge.getScreen().cam.position.x) > // Gdx.graphics.getWidth()) // continue; // if(Math.abs(p.getY() - GlobalVars.ge.getScreen().cam.position.y) > // Gdx.graphics.getHeight()) // continue; if (q.x < Helper.getCameraLeft() && p.x < Helper.getCameraLeft()) continue; else if (p.x > Helper.getCameraRight() && q.x > Helper.getCameraRight()) continue; // GlobalVars.ge.getScreen().getBatch() // .setColor(0.1f, 0.1f, 0.1f, 0.8f); // Helper.println("Angle: " + j + " -> " + Helper.getAngle(p, // q)); distance = p.distancePoint2Point(q); // Helper.println("\nP: " + p); // Helper.println("Q: " + q); // drawing road texture for (int k = 0; k < distance; k += 15 * LevelInfo.ratioX) { p.getPointAtDistance(p, Helper.getAngle(p, q) + 90, k, r); // Helper.println("R: " + r); // float f = GlobalVars.ge.getScreen().cam.position.y-Gdx.graphics.getHeight()/2f; float f = texturePathCarpet.getRegionHeight(); // float f = r.y - Helper.getCameraBottom(); // GlobalVars.ge.getRenderer().render(texturePathTexture, // r.x, r.y - f, // 15* LevelInfo.ratioX, f); GlobalVars.ge .getRenderer() .render( texturePathTexture, r.x, r.y - f, 15 * LevelInfo.ratioX, f, 0, texturePathTexture.getRegionHeight() - f, texturePathTexture.getRegionWidth(), f); } GlobalVars.ge .getRenderer() .render( texturePathCarpet, p.x, p.y - this.height / 2f, distance, /* GameMenuInfo.ratio_h* */ this.height * 2f, 0, this.height, Helper.getAngle(p, q) + 90, 1, 1); // GlobalVars.ge.getScreen().getBatch().setColor(1f, 1f, 1f, 1f); } } }
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); }