From 78309426d35e6fbeaf6aa70e349c43c9ee672ec1 Mon Sep 17 00:00:00 2001 From: timeo <timeo.jacquier@gmail.com> Date: Fri, 19 Nov 2021 16:57:20 +0100 Subject: [PATCH] =?UTF-8?q?Panneau=20g=C3=A9n=C3=A9rable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/generateStruct/Panneau.java | 40 +++++++++++++++++++ core/src/com/platventure/game/worldPerso.java | 10 +++-- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 core/src/com/platventure/game/generateStruct/Panneau.java diff --git a/core/src/com/platventure/game/generateStruct/Panneau.java b/core/src/com/platventure/game/generateStruct/Panneau.java new file mode 100644 index 0000000..46cb54d --- /dev/null +++ b/core/src/com/platventure/game/generateStruct/Panneau.java @@ -0,0 +1,40 @@ +package com.platventure.game.generateStruct; + +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 Panneau { + + PolygonShape shapeStruct; + Vector2[] ptsStruct; + public Panneau(int x, int y, float tailleUnite, World world) { + BodyDef bodyDef = new BodyDef(); + bodyDef.type = BodyDef.BodyType.StaticBody; + bodyDef.position.set(0f, 0f); + + Body structBody = world.createBody(bodyDef); + + FixtureDef fixtureDefStruct = new FixtureDef(); + shapeStruct = new PolygonShape(); + + float newX = x * tailleUnite; + float newY = (y-1) * tailleUnite; + + ptsStruct = new Vector2[]{new Vector2(newX, newY), new Vector2(newX+tailleUnite, newY), new Vector2(newX+tailleUnite, newY+tailleUnite), new Vector2(newX, newY+tailleUnite)}; + shapeStruct.set(ptsStruct); + + fixtureDefStruct.shape = shapeStruct; + fixtureDefStruct.restitution = 0.6f; + fixtureDefStruct.density = 1f; + fixtureDefStruct.friction = 0.25f; + fixtureDefStruct.isSensor = true; + + + structBody.createFixture(fixtureDefStruct); + shapeStruct.dispose(); + } +} diff --git a/core/src/com/platventure/game/worldPerso.java b/core/src/com/platventure/game/worldPerso.java index 3c99703..43c6257 100644 --- a/core/src/com/platventure/game/worldPerso.java +++ b/core/src/com/platventure/game/worldPerso.java @@ -10,6 +10,7 @@ import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; import com.platventure.game.generateStruct.Joyau; +import com.platventure.game.generateStruct.Panneau; import com.platventure.game.generateStruct.Platform; import com.platventure.game.generateStruct.Water; @@ -129,13 +130,13 @@ public class worldPerso { System.out.print(current); switch (current){ case 'J': - new Platform(j, i-1, FabriqueUnite.getUnite(), "bord_gauche", world); + new Platform(j, i, FabriqueUnite.getUnite(), "bord_gauche", world); break; case 'K': - new Platform(j, i-1, FabriqueUnite.getUnite(), "rectangle", world); + new Platform(j, i, FabriqueUnite.getUnite(), "rectangle", world); break; case 'L': - new Platform(j, i-1, FabriqueUnite.getUnite(), "bord_droit", world); + new Platform(j, i, FabriqueUnite.getUnite(), "bord_droit", world); break; case 'A': case 'B': @@ -151,6 +152,9 @@ public class worldPerso { case 'W': new Water(j, i, FabriqueUnite.getUnite(), world); break; + case 'Z': + new Panneau(j, i, FabriqueUnite.getUnite(), world); + break; case '1': case '2': new Joyau(j, i, FabriqueUnite.getUnite(), world); -- GitLab