diff --git a/.gradle/2.14.1/taskArtifacts/cache.properties b/.gradle/2.14.1/taskArtifacts/cache.properties index b1e623c..3419220 100644 --- a/.gradle/2.14.1/taskArtifacts/cache.properties +++ b/.gradle/2.14.1/taskArtifacts/cache.properties @@ -1 +1 @@ -#Fri Oct 13 19:03:57 CEST 2017 +#Tue Oct 17 00:48:27 CEST 2017 diff --git a/.gradle/2.14.1/taskArtifacts/cache.properties.lock b/.gradle/2.14.1/taskArtifacts/cache.properties.lock index bb7ec30..b38f1b8 100644 Binary files a/.gradle/2.14.1/taskArtifacts/cache.properties.lock and b/.gradle/2.14.1/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/2.14.1/taskArtifacts/fileHashes.bin b/.gradle/2.14.1/taskArtifacts/fileHashes.bin index ca8eab7..41fd3a1 100644 Binary files a/.gradle/2.14.1/taskArtifacts/fileHashes.bin and b/.gradle/2.14.1/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin b/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin index 555047c..664bc8c 100644 Binary files a/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin and b/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin b/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin index b03189c..3cda9f8 100644 Binary files a/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin and b/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin differ diff --git a/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin b/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin index 3fa8d15..2a66cd2 100644 Binary files a/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin and b/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin differ diff --git a/core/assets/desert-001.png b/core/assets/desert-001.png index 079a16e..0b25854 100644 Binary files a/core/assets/desert-001.png and b/core/assets/desert-001.png differ diff --git a/core/assets/logo.png b/core/assets/logo.png new file mode 100644 index 0000000..3fbcb7a Binary files /dev/null and b/core/assets/logo.png differ diff --git a/core/src/com/darkrp2d/DarkRP2D.java b/core/src/com/darkrp2d/DarkRP2D.java index 3cbac34..c531302 100755 --- a/core/src/com/darkrp2d/DarkRP2D.java +++ b/core/src/com/darkrp2d/DarkRP2D.java @@ -1,44 +1,70 @@ package com.darkrp2d; +import com.darkrp2d.entitySystems.RenderSystem; import com.badlogic.ashley.core.Engine; +import com.badlogic.ashley.core.Family; + import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.utils.TimeUtils; + +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; +import com.badlogic.gdx.physics.box2d.World; + +import com.darkrp2d.entities.components.TextureComponent; +import com.darkrp2d.entities.entityListeners.DisposeListener; +import com.darkrp2d.entitySystems.MovementSystem; import com.darkrp2d.input.CommandStream; import com.darkrp2d.input.InputHandler; import com.darkrp2d.input.commands.Command; +import com.darkrp2d.physics.Box2DUtils; public class DarkRP2D extends Game { public BitmapFont font; public SpriteBatch batch; - private Engine engine; + public Engine engine; + public World world; + private OrthographicCamera camera; + private Box2DDebugRenderer b2dbr; + private Matrix4 debugMatrix; + @Override public void create () { font = new BitmapFont(); batch = new SpriteBatch(); + world = new World(new Vector2(0.f,0.f),true); engine = new Engine(); + engine.addSystem(new RenderSystem()); + engine.addSystem(new MovementSystem()); + engine.addEntityListener(Family.all(TextureComponent.class).get(), 0, new DisposeListener()); + camera = new OrthographicCamera(); + camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + b2dbr = new Box2DDebugRenderer(); + + //must be before input registration or no character found + engine.addEntity(com.darkrp2d.entities.Character.create(this)); //Sets inputs Gdx.input.setInputProcessor(new InputHandler(this)); } + //GameLoop and debug private double lag = 0.; - private static final double MS_PER_UPDATE = 16.66; - - private int ups = 0; - private double timer = 0.; + private static final int UPDATES_PER_SECOND = 60; + private static final double MS_PER_UPDATE = 1e3/UPDATES_PER_SECOND; @Override // GameLoop public void render () { - lag += Gdx.graphics.getDeltaTime() * 1e3; //Seconds to milliseconds - timer += Gdx.graphics.getDeltaTime(); + lag += Gdx.graphics.getRawDeltaTime() * 1e3; //Seconds to milliseconds //Process Input Command currentCommand = CommandStream.pollCommand(); @@ -48,22 +74,16 @@ public class DarkRP2D extends Game { //Update Stuff while(lag >= MS_PER_UPDATE) { - update(); - ups++; + update(1.f/UPDATES_PER_SECOND); lag -= MS_PER_UPDATE; } - if(timer >= 1) { - System.out.println(ups); - ups = 0; - timer = 0.; - } - trueRender(); } - public void update() { - + public void update(float deltaTime) { + world.step(deltaTime, 6, 2); + engine.update(deltaTime); } public void trueRender() { @@ -73,14 +93,36 @@ public class DarkRP2D extends Game { //Render current Screen super.render(); + //Debug + camera.update(); + batch.setProjectionMatrix(camera.combined); + // Scale down the sprite batches projection matrix to box2D size + debugMatrix = batch.getProjectionMatrix().cpy().scale(Box2DUtils.PIXEL_PER_METER, + Box2DUtils.PIXEL_PER_METER, 0); + b2dbr.render(world, debugMatrix); + + //TODO: will be later moved to Gamescreen + engine.getSystem(RenderSystem.class).render(batch); + + //some testdrawing batch.begin(); GlyphLayout layout = new GlyphLayout(font, "Hello World"); font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2); batch.end(); } + + @Override + public void resize (int width, int height) { + //camera.setToOrtho(false, width, height); + } @Override public void dispose () { + b2dbr.dispose(); + engine.removeAllEntities(); + font.dispose(); + batch.dispose(); + world.dispose(); } diff --git a/core/src/com/darkrp2d/entities/Character.java b/core/src/com/darkrp2d/entities/Character.java index 8694db5..bfa27b1 100644 --- a/core/src/com/darkrp2d/entities/Character.java +++ b/core/src/com/darkrp2d/entities/Character.java @@ -6,7 +6,16 @@ package com.darkrp2d.entities; import com.badlogic.ashley.core.Entity; -import com.darkrp2d.entities.components.PositionComponent; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.physics.box2d.BodyDef; +import com.badlogic.gdx.physics.box2d.FixtureDef; +import com.badlogic.gdx.physics.box2d.PolygonShape; +import com.darkrp2d.DarkRP2D; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.PhysicComponent; +import com.darkrp2d.entities.components.TextureComponent; +import com.darkrp2d.physics.Box2DUtils; /** * @@ -16,10 +25,25 @@ public class Character { //Singletone private static Entity character; - public static Entity create() { + public static Entity create(DarkRP2D game) { if(character == null) { + float movementSpeed = 10.f; character = new Entity(); - character.add(new PositionComponent()); + BodyDef bodyDef = new BodyDef(); + bodyDef.type = BodyDef.BodyType.DynamicBody; + bodyDef.position.set(0 , 0); + + PolygonShape shape = new PolygonShape(); + shape.setAsBox(Box2DUtils.screenToWorld(32.f), Box2DUtils.screenToWorld(32.f)); + + FixtureDef fixtureDef = new FixtureDef(); + fixtureDef.shape = shape; + fixtureDef.density = 1f; + + character.add(new PhysicComponent(game,bodyDef, fixtureDef)); + shape.dispose(); + character.add(new TextureComponent(new Texture(Gdx.files.internal("police_officer.png")))); + character.add(new ControllableComponent(movementSpeed)); } return character; } diff --git a/core/src/com/darkrp2d/entities/components/ControllableComponent.java b/core/src/com/darkrp2d/entities/components/ControllableComponent.java new file mode 100644 index 0000000..6a4ecaa --- /dev/null +++ b/core/src/com/darkrp2d/entities/components/ControllableComponent.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entities.components; + +import com.badlogic.ashley.core.Component; + +/** + * + * @author Julian + */ +public class ControllableComponent implements Component { + + public boolean up = false; + public boolean down = false; + public boolean right = false; + public boolean left = false; + + public float speed; + + public ControllableComponent(float speed) { + this.speed = speed; + } +} diff --git a/core/src/com/darkrp2d/entities/components/Mappers.java b/core/src/com/darkrp2d/entities/components/Mappers.java new file mode 100644 index 0000000..027cf46 --- /dev/null +++ b/core/src/com/darkrp2d/entities/components/Mappers.java @@ -0,0 +1,20 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entities.components; + +import com.badlogic.ashley.core.ComponentMapper; + +/** + * + * @author Julian + */ +public class Mappers { + + public static final ComponentMapper physicComponentMapper = ComponentMapper.getFor(PhysicComponent.class); + public static final ComponentMapper textureComponentMapper = ComponentMapper.getFor(TextureComponent.class); + public static final ComponentMapper controllableComponentMapper = ComponentMapper.getFor(ControllableComponent.class); + +} diff --git a/core/src/com/darkrp2d/entities/components/PhysicComponent.java b/core/src/com/darkrp2d/entities/components/PhysicComponent.java new file mode 100644 index 0000000..2b1ffb6 --- /dev/null +++ b/core/src/com/darkrp2d/entities/components/PhysicComponent.java @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entities.components; + +import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.physics.box2d.Body; +import com.badlogic.gdx.physics.box2d.BodyDef; +import com.badlogic.gdx.physics.box2d.FixtureDef; +import com.darkrp2d.DarkRP2D; + +/** + * + * @author Julian + */ +public class PhysicComponent implements Component { + public BodyDef bodyDef; + public FixtureDef fixtureDef; + public Body body; + + public PhysicComponent(DarkRP2D game, BodyDef bodyDef, FixtureDef fixtureDef) { + this.bodyDef = bodyDef; + this.fixtureDef = fixtureDef; + body = game.world.createBody(bodyDef); + body.createFixture(fixtureDef); + + } + + public void dispose() { + } +} diff --git a/core/src/com/darkrp2d/entities/components/PositionComponent.java b/core/src/com/darkrp2d/entities/components/TextureComponent.java similarity index 52% rename from core/src/com/darkrp2d/entities/components/PositionComponent.java rename to core/src/com/darkrp2d/entities/components/TextureComponent.java index d08ad1a..6350a96 100644 --- a/core/src/com/darkrp2d/entities/components/PositionComponent.java +++ b/core/src/com/darkrp2d/entities/components/TextureComponent.java @@ -4,14 +4,23 @@ * and open the template in the editor. */ package com.darkrp2d.entities.components; - import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.graphics.Texture; /** * * @author Julian */ -public class PositionComponent implements Component { - public float x = 0.f; - public float y = 0.f; +public class TextureComponent implements Component { + + public Texture tex; + + public TextureComponent(Texture tex) { + this.tex = tex; + } + + public void dispose() { + tex.dispose(); + } + } diff --git a/core/src/com/darkrp2d/entities/entityListeners/DisposeListener.java b/core/src/com/darkrp2d/entities/entityListeners/DisposeListener.java new file mode 100644 index 0000000..d65e731 --- /dev/null +++ b/core/src/com/darkrp2d/entities/entityListeners/DisposeListener.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entities.entityListeners; + +import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.EntityListener; +import com.darkrp2d.entities.components.Mappers; + +/** + * + * @author Julian + */ +public class DisposeListener implements EntityListener { + + @Override + public void entityAdded(Entity entity) { + } + + @Override + public void entityRemoved(Entity entity) { + Mappers.textureComponentMapper.get(entity).dispose(); + } + +} diff --git a/core/src/com/darkrp2d/entitySystems/MovementSystem.java b/core/src/com/darkrp2d/entitySystems/MovementSystem.java new file mode 100644 index 0000000..a93ce23 --- /dev/null +++ b/core/src/com/darkrp2d/entitySystems/MovementSystem.java @@ -0,0 +1,61 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entitySystems; + +import com.badlogic.ashley.core.Engine; +import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.EntitySystem; +import com.badlogic.ashley.core.Family; +import com.badlogic.ashley.utils.ImmutableArray; +import com.badlogic.gdx.math.Vector2; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.entities.components.PhysicComponent; + +/** + * + * @author Julian + */ +public class MovementSystem extends EntitySystem { + + private ImmutableArray entities; + + public MovementSystem() { + + } + + @Override + public void addedToEngine(Engine engine) { + entities = engine.getEntitiesFor(Family.all(PhysicComponent.class, ControllableComponent.class).get()); + } + + @Override + public void update(float deltaTime) { + for (int i = 0; i < entities.size(); ++i) { + Entity entity = entities.get(i); + ControllableComponent controller = Mappers.controllableComponentMapper.get(entity); + PhysicComponent physic = Mappers.physicComponentMapper.get(entity); + Vector2 dir = new Vector2(0,0); + + if(controller.down) { + dir.y += -1; + } + if(controller.up) { + dir.y += 1; + } + if(controller.left) { + dir.x += -1; + } + if(controller.right) { + dir.x += 1; + } + + physic.body.setLinearVelocity(dir.nor().setLength(controller.speed)); + + } + } + +} diff --git a/core/src/com/darkrp2d/entitySystems/RenderSystem.java b/core/src/com/darkrp2d/entitySystems/RenderSystem.java new file mode 100644 index 0000000..bbedad3 --- /dev/null +++ b/core/src/com/darkrp2d/entitySystems/RenderSystem.java @@ -0,0 +1,47 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.entitySystems; + +import com.badlogic.ashley.core.Engine; +import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.EntitySystem; +import com.badlogic.ashley.core.Family; +import com.badlogic.ashley.utils.ImmutableArray; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; + +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.entities.components.PhysicComponent; +import com.darkrp2d.entities.components.TextureComponent; +import com.darkrp2d.physics.Box2DUtils; + +/** + * + * @author Julian + */ +public class RenderSystem extends EntitySystem { + + private ImmutableArray entities; + + + public RenderSystem() {} + + @Override + public void addedToEngine(Engine engine) { + entities = engine.getEntitiesFor(Family.all(TextureComponent.class, PhysicComponent.class).get()); + } + + public void render(SpriteBatch batch) { + batch.begin(); + for (int i = 0; i < entities.size(); ++i) { + Entity entity = entities.get(i); + PhysicComponent physics = Mappers.physicComponentMapper.get(entity); + TextureComponent texture = Mappers.textureComponentMapper.get(entity); + + batch.draw(texture.tex, Box2DUtils.worldToScreen(physics.body.getPosition().x) - texture.tex.getWidth() / 2, Box2DUtils.worldToScreen(physics.body.getPosition().y) - texture.tex.getHeight()/2); + } + batch.end(); + } +} diff --git a/core/src/com/darkrp2d/input/InputHandler.java b/core/src/com/darkrp2d/input/InputHandler.java index a15d125..46ea7ae 100644 --- a/core/src/com/darkrp2d/input/InputHandler.java +++ b/core/src/com/darkrp2d/input/InputHandler.java @@ -5,10 +5,15 @@ */ package com.darkrp2d.input; +import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.Family; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; import com.darkrp2d.DarkRP2D; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.PhysicComponent; import com.darkrp2d.input.commands.*; +import com.darkrp2d.input.commands.moveCommands.*; import com.darkrp2d.scenes.menu.MenuScreen; /** @@ -20,24 +25,70 @@ public class InputHandler implements InputProcessor { Command testCommand; Command menuCommand; + //MovementCommands + Command upCommand; + Command downCommand; + Command leftCommand; + Command rightCommand; + public InputHandler(DarkRP2D game) { testCommand = new TestCommand(); this.menuCommand = new MenuCommand(game, new MenuScreen(game)); + + //Inputs auf erstes bedienbares entity + Entity character = game.engine.getEntitiesFor(Family.all(ControllableComponent.class, PhysicComponent.class).get()).first(); + this.upCommand = new UpCommand(character); + this.downCommand = new DownCommand(character); + this.leftCommand = new LeftCommand(character); + this.rightCommand = new RightCommand(character); } @Override public boolean keyDown(int keycode) { - if(keycode == Input.Keys.Q) { - CommandStream.registerCommand(testCommand); - } else if(keycode == Input.Keys.C) { - CommandStream.registerCommand(menuCommand); + switch (keycode) { + case Input.Keys.Q: + CommandStream.registerCommand(testCommand); + break; + case Input.Keys.C: + CommandStream.registerCommand(menuCommand); + break; + case Input.Keys.W: + CommandStream.registerCommand(upCommand); + break; + case Input.Keys.S: + CommandStream.registerCommand(downCommand); + break; + case Input.Keys.A: + CommandStream.registerCommand(leftCommand); + break; + case Input.Keys.D: + CommandStream.registerCommand(rightCommand); + break; + default: + break; } return true; } @Override public boolean keyUp(int keycode) { - return false; + switch (keycode) { + case Input.Keys.W: + CommandStream.registerCommand(upCommand); + break; + case Input.Keys.S: + CommandStream.registerCommand(downCommand); + break; + case Input.Keys.A: + CommandStream.registerCommand(leftCommand); + break; + case Input.Keys.D: + CommandStream.registerCommand(rightCommand); + break; + default: + break; + } + return true; } @Override diff --git a/core/src/com/darkrp2d/input/commands/moveCommands/DownCommand.java b/core/src/com/darkrp2d/input/commands/moveCommands/DownCommand.java new file mode 100644 index 0000000..5d2b7c7 --- /dev/null +++ b/core/src/com/darkrp2d/input/commands/moveCommands/DownCommand.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.input.commands.moveCommands; + +import com.badlogic.ashley.core.Entity; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.input.commands.Command; + +/** + * + * @author Julian + */ +public class DownCommand implements Command{ + + Entity ent; + private boolean toggle = false; + + public DownCommand(Entity ent) { + this.ent = ent; + } + + @Override + public void execute() { + ControllableComponent controller = Mappers.controllableComponentMapper.get(ent); + if(!toggle) { + controller.down = true; + toggle = true; + } else { + controller.down = false; + toggle = false; + } + } + +} diff --git a/core/src/com/darkrp2d/input/commands/moveCommands/LeftCommand.java b/core/src/com/darkrp2d/input/commands/moveCommands/LeftCommand.java new file mode 100644 index 0000000..2d5121a --- /dev/null +++ b/core/src/com/darkrp2d/input/commands/moveCommands/LeftCommand.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.input.commands.moveCommands; + +import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.physics.box2d.Body; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.input.commands.Command; + +/** + * + * @author Julian + */ +public class LeftCommand implements Command { + + Entity ent; + private boolean toggle = false; + + public LeftCommand(Entity ent) { + this.ent = ent; + } + + @Override + public void execute() { + ControllableComponent controller = Mappers.controllableComponentMapper.get(ent); + if(!toggle) { + controller.left = true; + toggle = true; + } else { + controller.left = false; + toggle = false; + } + } +} diff --git a/core/src/com/darkrp2d/input/commands/moveCommands/RightCommand.java b/core/src/com/darkrp2d/input/commands/moveCommands/RightCommand.java new file mode 100644 index 0000000..82e35e9 --- /dev/null +++ b/core/src/com/darkrp2d/input/commands/moveCommands/RightCommand.java @@ -0,0 +1,40 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.input.commands.moveCommands; + +import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.physics.box2d.Body; +import com.darkrp2d.entities.components.ControllableComponent; +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.input.commands.Command; + +/** + * + * @author Julian + */ +public class RightCommand implements Command { + + Entity ent; + private boolean toggle = false; + + public RightCommand(Entity ent) { + this.ent = ent; + } + + @Override + public void execute() { + ControllableComponent controller = Mappers.controllableComponentMapper.get(ent); + if(!toggle) { + controller.right = true; + toggle = true; + } else { + controller.right = false; + toggle = false; + } + } + +} diff --git a/core/src/com/darkrp2d/input/commands/moveCommands/UpCommand.java b/core/src/com/darkrp2d/input/commands/moveCommands/UpCommand.java new file mode 100644 index 0000000..ddae17e --- /dev/null +++ b/core/src/com/darkrp2d/input/commands/moveCommands/UpCommand.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.input.commands.moveCommands; + +import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.physics.box2d.Body; +import com.darkrp2d.entities.components.Mappers; +import com.darkrp2d.input.commands.Command; +import com.badlogic.gdx.math.Vector2; +import com.darkrp2d.entities.components.ControllableComponent; + +/** + * + * @author Julian + */ +public class UpCommand implements Command { + + Entity ent; + private boolean toggle = false; + + public UpCommand(Entity ent) { + this.ent = ent; + } + + @Override + public void execute() { + ControllableComponent controller = Mappers.controllableComponentMapper.get(ent); + if(!toggle) { + controller.up = true; + toggle = true; + } else { + controller.up = false; + toggle = false; + } + + } + +} diff --git a/core/src/com/darkrp2d/physics/Box2DUtils.java b/core/src/com/darkrp2d/physics/Box2DUtils.java new file mode 100644 index 0000000..725c0a0 --- /dev/null +++ b/core/src/com/darkrp2d/physics/Box2DUtils.java @@ -0,0 +1,25 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.physics; + +/** + * + * @author Julian + */ +public class Box2DUtils { + + public static final float PIXEL_PER_METER = 32; + + public static float screenToWorld(float value) { + return value / PIXEL_PER_METER; + } + + public static float worldToScreen(float value) { + return value * PIXEL_PER_METER; + } + + +} diff --git a/core/src/com/darkrp2d/scenes/game/Camera.java b/core/src/com/darkrp2d/scenes/game/Camera.java index aae29dc..ad4a246 100644 --- a/core/src/com/darkrp2d/scenes/game/Camera.java +++ b/core/src/com/darkrp2d/scenes/game/Camera.java @@ -5,10 +5,15 @@ */ package com.darkrp2d.scenes.game; +import com.badlogic.gdx.graphics.OrthographicCamera; + /** * * @author Julian */ -public class Camera { - +public class Camera extends OrthographicCamera { + + public Camera(int viewportWidth, int viewportHeight) { + new OrthographicCamera(960,540); + } } diff --git a/core/src/com/darkrp2d/scenes/menu/MenuScreen.java b/core/src/com/darkrp2d/scenes/menu/MenuScreen.java index c7754ba..ce92cca 100644 --- a/core/src/com/darkrp2d/scenes/menu/MenuScreen.java +++ b/core/src/com/darkrp2d/scenes/menu/MenuScreen.java @@ -20,7 +20,7 @@ public class MenuScreen implements Screen{ public MenuScreen(DarkRP2D game) { this.game = game; - layout = new GlyphLayout(game.font, "Hello World"); + layout = new GlyphLayout(game.font, "Menu Opened"); } @Override diff --git a/desktop/src/com/darkrp2d/desktop/DesktopLauncher.java b/desktop/src/com/darkrp2d/desktop/DesktopLauncher.java index 8477155..d39e17b 100755 --- a/desktop/src/com/darkrp2d/desktop/DesktopLauncher.java +++ b/desktop/src/com/darkrp2d/desktop/DesktopLauncher.java @@ -1,6 +1,7 @@ package com.darkrp2d.desktop; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Files; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; @@ -17,8 +18,12 @@ public class DesktopLauncher { //Default conf config.title = "DarkRP2D"; config.useGL30 = false; - config.width = 800; - config.height = 600; + config.width = 960; + config.height = 540; + config.addIcon("logo.png", Files.FileType.Internal); + config.vSyncEnabled = false; // Setting to false disables vertical sync + config.foregroundFPS = 144; // Setting to 0 disables foreground fps throttling + config.backgroundFPS = 0; // Setting to 0 disables background fps throttling loadUserPrefs(new LwjglApplication(new DarkRP2D(), config)); }