Skip to content
Snippets Groups Projects
Commit 18e22f86 authored by jez04's avatar jez04
Browse files

Add Box2D

parent 6ab20cbd
No related merge requests found
package cz.vsb.kp;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
public class Bucket {
private Sprite sprite;
private Body body;
private Texture img;
private float centerX;
private float centerY;
private World world;
public Bucket(Texture img, float centerX, float centerY, World world) {
this.img = img;
sprite = new Sprite(img);
sprite.setOriginBasedPosition(img.getWidth()/2, img.getHeight()/2);
sprite.setOrigin(0, 0);
this.centerX = centerX;
this.centerY = centerY;
this.world = world;
createBody();
}
private void createBody() {
int vyskaUchaKbeliku = 100;
PolygonShape dno = new PolygonShape();
dno.setAsBox(img.getWidth()/2.0f, 2, new Vector2(0, -img.getHeight()/2.0f), 0);
PolygonShape stenaPrava = new PolygonShape();
stenaPrava.setAsBox(2, (img.getHeight()-vyskaUchaKbeliku)/2.0f, new Vector2(img.getWidth()/2.0f, -vyskaUchaKbeliku/2), 0);
PolygonShape stenaLeva = new PolygonShape();
stenaLeva.setAsBox(2, (img.getHeight()-vyskaUchaKbeliku)/2.0f, new Vector2(-img.getWidth()/2.0f, -vyskaUchaKbeliku/2), 0);
PolygonShape vnitrek = new PolygonShape();
vnitrek.setAsBox((img.getWidth()-8)/2.0f,
((img.getHeight()-vyskaUchaKbeliku)/4.0f), new Vector2(0, -vyskaUchaKbeliku/2-(img.getHeight()-vyskaUchaKbeliku)/4.0f+4 ), 0);
FixtureDef detekceObsahu = new FixtureDef();
detekceObsahu.isSensor = true;
detekceObsahu.shape = vnitrek;
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.KinematicBody;
body = world.createBody(def);
body.createFixture(dno, 0);
body.createFixture(stenaPrava, 0);
body.createFixture(stenaLeva, 0);
body.createFixture(detekceObsahu);
body.setTransform(centerX, centerY, 0);
dno.dispose();
stenaLeva.dispose();
stenaPrava.dispose();
vnitrek.dispose();
}
public float getX(){
return body.getPosition().x;
}
public float getY(){
return body.getPosition().y;
}
public float getWidth(){
return img.getWidth();
}
public float getHeigh(){
return img.getHeight();
}
public void setVelocity(float v) {
body.setLinearVelocity(v, 0);
}
public float getVelocity() {
return body.getLinearVelocity().x;
}
public void draw(SpriteBatch batch) {
sprite.setCenter(body.getPosition().x, body.getPosition().y);
sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
sprite.setRotation((float)(180/Math.PI * body.getAngle()));
sprite.draw(batch);
// batch.draw(img, getX()-getWidth()/2, getY()-getHeigh()/2);
}
public void draw(ShapeRenderer shapeRenderer) {
// Color c = new Color(0, 1, 0, 0.5f);
// shapeRenderer.setColor(c);
// shapeRenderer.rect(body.getPosition().x-getWidth()/2, body.getPosition().y - getHeigh()/2, getWidth(), getHeigh());
// Color c1 = new Color(1, 1, 0, 0.5f);
// shapeRenderer.setColor(c1);
// shapeRenderer.rect(body.getPosition().x-getWidth()/2 + 10, body.getPosition().y - getHeigh()/2 + 10, getWidth() - 20, getHeigh() - 20);
}
}
package cz.vsb.kp;
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;
public class ContactDetector implements ContactListener {
@Override
public void beginContact(Contact contact) {
Drop kapka = isDropInContactWithSenzor(contact);
if(kapka != null) {
kapka.setZmensovani(true);
}
}
private Drop isDropInContactWithSenzor(Contact contact) {
if (contact.getFixtureA().isSensor() || contact.getFixtureB().isSensor()) {
if(contact.getFixtureA().getBody().getUserData() instanceof Drop) {
return (Drop)contact.getFixtureA().getBody().getUserData();
}
if(contact.getFixtureB().getBody().getUserData() instanceof Drop) {
return (Drop)contact.getFixtureB().getBody().getUserData();
}
System.out.println("kontak");
}
return null;
}
@Override
public void endContact(Contact contact) {
Drop kapka = isDropInContactWithSenzor(contact);
if(kapka != null) {
kapka.setZmensovani(false);
}
}
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
// TODO Auto-generated method stub
}
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
// TODO Auto-generated method stub
}
}
package cz.vsb.kp;
import java.util.ArrayList;
import java.util.Random;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
public class Drop {
private static final Random random = new Random();
private Body body;
private Texture dropImg;
private Sprite sprite;
private float centerX;
private float centerY;
private World world;
private float radius;
private boolean zmensovani = false;
public Drop(Texture dropImg, float centerX, float centerY, World world) {
this.dropImg = dropImg;
radius = dropImg.getWidth() / 2;
sprite = new Sprite(dropImg);
sprite.setOriginBasedPosition(dropImg.getWidth() / 2, dropImg.getHeight() / 2);
sprite.setOrigin(0, 0);
this.centerX = centerX;
this.centerY = centerY;
this.world = world;
createBody();
body.setLinearVelocity(50 - random.nextFloat() * 100, random.nextFloat() * (-150));
}
private void createBody() {
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.DynamicBody;
body = world.createBody(def);
createNewBodyFixture(radius);
body.setTransform(centerX, centerY, 0);
body.setUserData(this);
}
private void createNewBodyFixture(float radius) {
CircleShape poly = new CircleShape();
poly.setRadius(radius);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = poly;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.8f;
fixtureDef.restitution = 0.2f; // Make it bounce a little bit
body.createFixture(fixtureDef);
poly.dispose();
}
public void update() {
if(zmensovani) {
zmensi();
}
}
public boolean isZmensovani() {
return zmensovani;
}
public void setZmensovani(boolean zmensovani) {
this.zmensovani = zmensovani;
}
public void zmensi() {
for (Fixture fixture : body.getFixtureList()) {
body.destroyFixture(fixture);
}
radius = radius - 0.05f;
if (radius > 1) {
createNewBodyFixture(radius);
}
}
public float getX() {
return body.getPosition().x;
}
public float getY() {
return body.getPosition().y;
}
public float getWidth() {
return dropImg.getWidth();
}
public float getHeigh() {
return dropImg.getHeight();
}
public void draw(SpriteBatch batch) {
sprite.setCenter(body.getPosition().x, body.getPosition().y);
sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
sprite.setRotation((float) (180 / Math.PI * body.getAngle()));
sprite.draw(batch);
// batch.draw(dropImg, getX() - getWidth()/2, getY() - getHeigh()/2);
}
}
package cz.vsb.kp;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;
public class DropGame extends Game {
SpriteBatch batch;
BitmapFont font;
ShapeRenderer shapeRenderer;
@Override
public void create() {
font = new BitmapFont();
font.getData().scale(2);
batch = new SpriteBatch();
setScreen(new MainMenuScreen(this));
shapeRenderer = new ShapeRenderer();
}
@Override
public void render() {
super.render();
}
@Override
public void dispose() {
batch.dispose();
font.dispose();
}
}
package cz.vsb.kp;
import java.util.Iterator;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.TimeUtils;
public class Game extends ApplicationAdapter {
private SpriteBatch batch;
private OrthographicCamera camera;
private Texture bucketImg;
private Texture dropImg;
private Texture gardenImg;
private Rectangle bucket;
private Array<Rectangle> raindrops;
private long lastDropTime;
private ShapeRenderer shapeRenderer;
static private boolean projectionMatrixSet;
@Override
public void create() {
batch = new SpriteBatch();
bucketImg = new Texture("bucket.png");
dropImg = new Texture("drop.png");
gardenImg = new Texture("garden.png");
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
bucket = new Rectangle();
bucket.x = 800 / 2 - 161 / 2;
bucket.y = 20;
bucket.width = 161;
bucket.height = 268/2;
raindrops = new Array<Rectangle>();
spawnRaindrop();
// Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
shapeRenderer = new ShapeRenderer();
projectionMatrixSet = false;
}
@Override
public void render() {
ScreenUtils.clear(1, 0, 0, 1);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(gardenImg,0, 0 );
batch.draw(bucketImg, bucket.x, bucket.y);
for (Rectangle raindrop : raindrops) {
batch.draw(dropImg, raindrop.x, raindrop.y);
}
// batch.draw(img, 0, 0);
batch.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
if(!projectionMatrixSet){
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
}
shapeRenderer.begin(ShapeType.Filled);
Color c = new Color(0, 1, 0, 0.5f);
shapeRenderer.setColor(c);
shapeRenderer.rect(bucket.x, bucket.y, bucket.width, bucket.height);
Color c1 = new Color(1, 1, 0, 0.5f);
shapeRenderer.setColor(c1);
shapeRenderer.rect(bucket.x+10, bucket.y+10, bucket.width-20, bucket.height-20);
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
bucket.x = touchPos.x - 161/2;
}
if (Gdx.input.isKeyPressed(Input.Keys.LEFT))
bucket.x -= 200 * Gdx.graphics.getDeltaTime();
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT))
bucket.x += 200 * Gdx.graphics.getDeltaTime();
if (bucket.x < 0)
bucket.x = 0;
if (bucket.x > 800 - 161)
bucket.x = 800 - 161;
if (TimeUtils.nanoTime() - lastDropTime > 1000000000)
spawnRaindrop();
for (Iterator<Rectangle> iter = raindrops.iterator(); iter.hasNext();) {
Rectangle raindrop = iter.next();
raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
if (raindrop.y + 161 < 0)
iter.remove();
if(raindrop.overlaps(bucket)) {
// dropSound.play();
iter.remove();
}
}
if (Gdx.input.isKeyJustPressed(Input.Keys.F)) {
if(!Gdx.graphics.isFullscreen()) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(800, 600);
}
}
}
private void spawnRaindrop() {
Rectangle raindrop = new Rectangle();
raindrop.x = MathUtils.random(0, 800 - 64);
raindrop.y = 480;
raindrop.width = 64;
raindrop.height = 64;
raindrops.add(raindrop);
lastDropTime = TimeUtils.nanoTime();
}
@Override
public void dispose() {
batch.dispose();
bucketImg.dispose();
dropImg.dispose();
}
}
package cz.vsb.kp;
import java.util.Iterator;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.TimeUtils;
public class GardenScreen implements Screen {
private final DropGame dropGame;
private OrthographicCamera camera;
private Texture bucketImg;
private Texture dropImg;
private Texture gardenImg;
private Array<Drop> raindrops;
private long lastDropTime;
private Bucket bucket;
static private boolean projectionMatrixSet;
World world;
Box2DDebugRenderer debugRenderer;
public GardenScreen(final DropGame dropGame) {
this.dropGame = dropGame;
projectionMatrixSet = false;
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
world = new World(new Vector2(0, -10), true);
world.setContactListener(new ContactDetector());
debugRenderer = new Box2DDebugRenderer();
bucketImg = new Texture("bucket.png");
dropImg = new Texture("drop.png");
gardenImg = new Texture("garden.png");
bucket = new Bucket(bucketImg, (int) (camera.viewportWidth / 2 - bucketImg.getWidth() / 20), 135, world);
dropGame.shapeRenderer.setProjectionMatrix(dropGame.batch.getProjectionMatrix());
raindrops = new Array<>();
spawnRaindrop();
}
@Override
public void show() {
}
@Override
public void render(float delta) {
ScreenUtils.clear(1, 0, 0, 1);
camera.update();
dropGame.batch.setProjectionMatrix(camera.combined);
myRender();
debugRenderer.render(world, camera.combined);
world.step(1 / 60f, 6, 2);
if (TimeUtils.nanoTime() - lastDropTime > 1000000000) {
spawnRaindrop();
}
}
private void myRender() {
dropGame.batch.begin();
dropGame.batch.draw(gardenImg, 0, 0);
bucket.draw(dropGame.batch);
for (Drop raindrop : raindrops) {
raindrop.update();
raindrop.draw(dropGame.batch);
}
dropGame.batch.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
if (!projectionMatrixSet) {
dropGame.shapeRenderer.setProjectionMatrix(dropGame.batch.getProjectionMatrix());
}
dropGame.shapeRenderer.begin(ShapeType.Filled);
bucket.draw(dropGame.shapeRenderer);
dropGame.shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
bucket.setVelocity(bucket.getVelocity() - 5);
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
bucket.setVelocity(bucket.getVelocity() + 5);
}
if (bucket.getX() < bucket.getWidth()/2 && bucket.getVelocity() < 0) {
bucket.setVelocity(0);
}
if (bucket.getX() > 800 - bucket.getWidth()/2 && bucket.getVelocity() > 0) {
bucket.setVelocity(0);
}
if (TimeUtils.nanoTime() - lastDropTime > 1000000000) {
spawnRaindrop();
}
// System.out.println(bucket.getVelocity());
// for (Iterator<Drop> iter = raindrops.iterator(); iter.hasNext();) {
// Drop raindrop = iter.next();
// raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
// if (raindrop.y + 161 < 0)
// iter.remove();
// if (raindrop.overlaps(bucket)) {
// iter.remove();
// }
// }
if (Gdx.input.isKeyJustPressed(Input.Keys.F)) {
if (!Gdx.graphics.isFullscreen()) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(800, 600);
}
}
}
private void spawnRaindrop() {
Drop raindrop = new Drop(dropImg, MathUtils.random(0, 800 - 64), 550, world);
raindrops.add(raindrop);
lastDropTime = TimeUtils.nanoTime();
}
@Override
public void resize(int width, int height) {
/* nothing to do */
}
@Override
public void pause() {
/* nothing to do */
}
@Override
public void resume() {
/* nothing to do */
}
@Override
public void hide() {
/* nothing to do */
}
@Override
public void dispose() {
dropImg.dispose();
bucketImg.dispose();
gardenImg.dispose();
world.dispose();
debugRenderer.dispose();
}
}
package cz.vsb.kp;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.ScreenUtils;
public class MainMenuScreen implements Screen {
private final DropGame dropGame;
private OrthographicCamera camera;
private Texture gardenImg;
public MainMenuScreen(final DropGame dropGame) {
this.dropGame = dropGame;
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
gardenImg = new Texture("garden.png");
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void render(float delta) {
ScreenUtils.clear(0, 0, 0.2f, 1);
camera.update();
dropGame.batch.setProjectionMatrix(camera.combined);
dropGame.batch.begin();
dropGame.batch.draw(gardenImg, 0, 0);
dropGame.font.draw(dropGame.batch, "Welcome to Drop!!! ", 100, 150);
dropGame.font.draw(dropGame.batch, "Tap anywhere to begin!", 100, 100);
dropGame.batch.end();
if (Gdx.input.isTouched()) {
dropGame.setScreen(new GardenScreen(dropGame));
dispose();
}
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
gardenImg.dispose();
}
}
package cz.vsb.kp;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.EdgeShape;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
public class PhysicsGame extends ApplicationAdapter {
World world;
OrthographicCamera camera;
Box2DDebugRenderer debugRenderer;
@Override
public void create () {
world = new World(new Vector2(0, -10), true);
camera = new OrthographicCamera(50, 25);
debugRenderer = new Box2DDebugRenderer();
// ground
createEdge(BodyDef.BodyType.StaticBody, -20, -10f, 20, -10f, 0);
// left wall
createEdge(BodyDef.BodyType.StaticBody, -20, -10, -20, 10, 0);
// right wall
createEdge(BodyDef.BodyType.StaticBody, 20, -10, 20, 10, 0);
createCircle(BodyDef.BodyType.DynamicBody, 0, 0, 1, 3);
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean touchDown (int x, int y, int pointer, int button) {
Vector3 touchedPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchedPoint);
if(MathUtils.randomBoolean()) {
createBox(BodyDef.BodyType.DynamicBody, touchedPoint.x, touchedPoint.y, 1, 1, 1);
}
else{
createCircle(BodyDef.BodyType.DynamicBody, touchedPoint.x, touchedPoint.y, 1, 3);
}
return true;
}
});
}
@Override
public void render () {
Gdx.gl.glClearColor(.125f, .125f, .125f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
debugRenderer.render(world, camera.combined);
world.step(1 / 60f, 6, 2);
}
@Override
public void dispose () {
world.dispose();
debugRenderer.dispose();
}
private Body createBox(BodyDef.BodyType type, float x, float y, float width, float height, float density) {
PolygonShape poly = new PolygonShape();
poly.setAsBox(width, height);
BodyDef def = new BodyDef();
def.type = type;
Body body = world.createBody(def);
body.createFixture(poly, density);
body.setTransform(x, y, 0);
poly.dispose();
return body;
}
private Body createEdge(BodyDef.BodyType type, float x1, float y1, float x2, float y2, float density) {
EdgeShape poly = new EdgeShape();
poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
BodyDef def = new BodyDef();
def.type = type;
Body body = world.createBody(def);
body.createFixture(poly, density);
body.setTransform(x1, y1, 0);
poly.dispose();
return body;
}
private Body createCircle(BodyDef.BodyType type, float x, float y, float radius, float density) {
CircleShape poly = new CircleShape();
poly.setRadius(radius);
BodyDef def = new BodyDef();
def.type = type;
Body body = world.createBody(def);
body.createFixture(poly, density);
body.setTransform(x, y, 0);
poly.dispose();
return body;
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package cz.vsb.kp;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import cz.vsb.kp.Game;
import cz.vsb.kp.DropGame;
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
public class DesktopLauncher {
......@@ -10,6 +10,6 @@ public class DesktopLauncher {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setForegroundFPS(60);
config.setTitle("My First Game");
new Lwjgl3Application(new Game(), config);
new Lwjgl3Application(new DropGame(), config);
}
}
......@@ -3,7 +3,7 @@ package cz.vsb.kp.client;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
import cz.vsb.kp.Game;
import cz.vsb.kp.DropGame;
public class HtmlLauncher extends GwtApplication {
......@@ -17,6 +17,6 @@ public class HtmlLauncher extends GwtApplication {
@Override
public ApplicationListener createApplicationListener () {
return new Game();
return new DropGame();
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment