java - Android Studio LibGDX Game problems -
i'm finishing writing game, however, when run game, android studio complains following errors: error:(103, 8) gradle: error: illegal start of expressionerror:(103, 15) gradle: error: illegal start of expressionerror:(103, 26) gradle: error: ';' expectederror:(103, 43) gradle: error: ';' expected
.
here's code gamescreen class:
package com.circlecrashavoider; import com.badlogic.gdx.gdx; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.math.mathutils; import com.badlogic.gdx.math.vector2; import com.badlogic.gdx.physics.box2d.contact; import com.badlogic.gdx.physics.box2d.contactimpulse; import com.badlogic.gdx.physics.box2d.contactlistener; import com.badlogic.gdx.physics.box2d.manifold; import com.badlogic.gdx.physics.box2d.world; import com.badlogic.gdx.scenes.scene2d.stage; import com.badlogic.gdx.utils.viewport.fitviewport; import com.circlecrashavoider.entities.floorentity; import com.circlecrashavoider.entities.obstacleentity; import com.circlecrashavoider.entities.obstacleentity2; import com.circlecrashavoider.entities.playerentity; import com.circlecrashavoider.scene2d.entityfactory; import java.util.arraylist; import java.util.list; import java.util.objects; import java.util.random; /** * created felipe on 2/22/2016. */ public class gamescreen extends basescreen { private stage stage; private world world; private playerentity player; private list<floorentity> floorlist = new arraylist<floorentity>(); private list<obstacleentity> obstaclelist = new arraylist<obstacleentity>(); private list<obstacleentity2> obstacle2list = new arraylist<obstacleentity2>(); public gamescreen(maingame game) { super(game); stage = new stage(new fitviewport(1024, 620)); world = new world(new vector2(0, -10), true); world.setcontactlistener(new contactlistener() { private boolean arecollided(contact contact, object usera, object userb) { return (contact.getfixturea().getuserdata().equals(usera) && contact.getfixtureb().getuserdata().equals(userb)) || (contact.getfixturea().getuserdata().equals(userb) && contact.getfixtureb().getuserdata().equals(usera)); } @override public void begincontact(contact contact) { if (arecollided(contact, "player", "floor")) { player.setjumping(false); if (gdx.input.istouched()) { player.setmustjump(true); } } if (arecollided(contact, "player", "obstacle")) { player.setalive(false); system.out.println("game over"); } if (arecollided(contact, "player", "obstacle2")) { player.setalive(false); system.out.println("game over"); } } @override public void endcontact(contact contact) { } @override public void presolve(contact contact, manifold oldmanifold) { } @override public void postsolve(contact contact, contactimpulse impulse) { } }); } private float spawntime = 4f; private float timer = 0; @override public void show() { public void update( float deltatime) { timer += deltatime; if (timer >= spawntime) { this.spawnentity(); spawntime = mathutils.random(2f, 4f); timer = 0; } } } private void spawnentity(){ texture floortexture = game.getmanager().get("floor.png"); texture overfloortexture = game.getmanager().get("overfloor.png"); texture overfloor2texture = game.getmanager().get("overfloor2.png"); texture obstacletexture = game.getmanager().get("obstacle.png"); texture obstacle2texture = game.getmanager().get("obstacle2.png"); //spawn object floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture, 0, 1000, 1)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,8, 10 ,5)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,10, 10 ,8)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,34 , 3 ,5)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,19 , 8 ,4)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,24 , 8 ,1.5f)); floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,27 , 5 , 2)); obstaclelist.add(new obstacleentity(world, obstacletexture, 6, 1)); stage.addactor(player); (floorentity floor: floorlist) { stage.addactor(floor); } (obstacleentity obstacle : obstaclelist) { stage.addactor(obstacle); } } @override public void render(float delta) { gdx.gl20.glclearcolor(0.5f, 0.6f, 1, 3f); gdx.gl20.glclear(gl20.gl_color_buffer_bit); stage.act(); world.step(delta, 6, 2); stage.draw(); } @override public void dispose() { stage.dispose(); world.dispose(); } }
the code maingame class:
package com.circlecrashavoider; import com.badlogic.gdx.game; import com.badlogic.gdx.assets.assetmanager; import com.badlogic.gdx.graphics.texture; import com.circlecrashavoider.scene2d.box2dscreen; import com.circlecrashavoider.scene2d.scene2dscreen; public class maingame extends game { private assetmanager manager; public assetmanager getmanager() { return manager; } @override public void create() { manager = new assetmanager(); manager.load("floor.png", texture.class); manager.load("overfloor.png", texture.class); manager.load("overfloor2.png", texture.class); manager.load("obstacle.png", texture.class); manager.load("obstacle2.png", texture.class); manager.load("crash.png", texture.class); manager.load("player.png", texture.class); manager.finishloading(); setscreen(new gamescreen(this)); } }
could give me assistance on fixing these errors? appreciate it!
you aren't allowed have methods in other methods or methods in constructor. move part of code looks outside constructor either above or below.
@override public void begincontact(contact contact) { if (arecollided(contact, "player", "floor")) { player.setjumping(false); if (gdx.input.istouched()) { player.setmustjump(true); } } if (arecollided(contact, "player", "obstacle")) { player.setalive(false); system.out.println("game over"); } if (arecollided(contact, "player", "obstacle2")) { player.setalive(false); system.out.println("game over"); } } @override public void endcontact(contact contact) { } @override public void presolve(contact contact, manifold oldmanifold) { } @override public void postsolve(contact contact, contactimpulse impulse) { } });
Comments
Post a Comment