Skip to content

Commit

Permalink
Bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
guidota committed Apr 24, 2019
1 parent f0a1aed commit 1373440
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 55 deletions.
4 changes: 2 additions & 2 deletions client/src/game/AOGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class AOGame extends Game {

public static final float GAME_SCREEN_ZOOM = 1.5f;
public static final float GAME_SCREEN_ZOOM = 1.9f;

@Override
public void create() {
Expand All @@ -41,7 +41,7 @@ public void create() {
@Override
public void render() {
GL20 gl = Gdx.gl;
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearColor(0.0f, 0.0f, 0.0f, 1f);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render();
}
Expand Down
119 changes: 82 additions & 37 deletions client/src/game/managers/AOInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import game.screens.GameScreen;
import game.screens.LoginScreen;
import game.ui.GUI;
import game.utils.AOKeys;
import game.utils.AlternativeKeys;
import game.utils.Cursors;
import game.utils.WorldUtils;
Expand All @@ -32,6 +33,7 @@
public class AOInputProcessor extends Stage {

private static final Random r = new Random();
public static boolean alternativeKeys = false;

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
Expand Down Expand Up @@ -73,54 +75,97 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
@Override
public boolean keyUp(int keycode) {
if (!GUI.getDialog().isVisible()) {
switch (keycode) {
case AlternativeKeys.INVENTORY:
toggleInventory();
break;
case AlternativeKeys.SPELLS:
toggleSpells();
break;
case AlternativeKeys.MEDITATE:
toggleMeditate();
break;
case AlternativeKeys.DROP:
dropItem();
break;
case AlternativeKeys.TAKE:
takeItem();
break;
case AlternativeKeys.EQUIP:
equip();
break;
case AlternativeKeys.USE:
use();
break;
case AlternativeKeys.ATTACK_1:
attack();
break;
case AlternativeKeys.ATTACK_2:
attack();
break;
case Input.Keys.O: // testing fxs
int randomFx = r.nextInt(DescriptorHandler.getFxs().size());
Log.info("FX: " + randomFx);
E(GameScreen.getPlayer()).fXAddFx(randomFx);
break;
case Input.Keys.ESCAPE:
// Disconnect & go back to LoginScreen
AOGame game = (AOGame) Gdx.app.getApplicationListener();
// TODO implement
if (alternativeKeys) {
doAlternativeActions(keycode);
} else {
doActions(keycode);
}
}
switch (keycode) {
case AlternativeKeys.TALK:
toggleDialogText();
break;
case Input.Keys.F1:
alternativeKeys = !alternativeKeys;
break;
}

return super.keyUp(keycode);
}


private void doActions(int keycode) {
switch (keycode) {
case AOKeys.INVENTORY:
toggleInventory();
break;
case AOKeys.SPELLS:
toggleSpells();
break;
case AOKeys.MEDITATE:
toggleMeditate();
break;
case AOKeys.DROP:
dropItem();
break;
case AOKeys.TAKE:
takeItem();
break;
case AOKeys.EQUIP:
equip();
break;
case AOKeys.USE:
use();
break;
case AOKeys.ATTACK_1:
attack();
break;
case AOKeys.ATTACK_2:
attack();
break;
case Input.Keys.ESCAPE:
// Disconnect & go back to LoginScreen
AOGame game = (AOGame) Gdx.app.getApplicationListener();
// TODO implement
}
}

private void doAlternativeActions(int keycode) {
switch (keycode) {
case AlternativeKeys.INVENTORY:
toggleInventory();
break;
case AlternativeKeys.SPELLS:
toggleSpells();
break;
case AlternativeKeys.MEDITATE:
toggleMeditate();
break;
case AlternativeKeys.DROP:
dropItem();
break;
case AlternativeKeys.TAKE:
takeItem();
break;
case AlternativeKeys.EQUIP:
equip();
break;
case AlternativeKeys.USE:
use();
break;
case AlternativeKeys.ATTACK_1:
attack();
break;
case AlternativeKeys.ATTACK_2:
attack();
break;
case Input.Keys.ESCAPE:
// Disconnect & go back to LoginScreen
AOGame game = (AOGame) Gdx.app.getApplicationListener();
// TODO implement
}
}

private void use() {
GUI.getInventory().getSelected().ifPresent(slot -> {
GameScreen.getClient().sendToAll(new ItemActionRequest(GUI.getInventory().selectedIndex()));
Expand Down
4 changes: 4 additions & 0 deletions client/src/game/screens/AbstractScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ void createUI() {
getStage().addActor(getMainTable());
}

@Override public void resize(int width, int height) {
getStage().getViewport().update(width, height, true);
}

abstract void createContent();

@Override public void dispose() {
Expand Down
5 changes: 2 additions & 3 deletions client/src/game/screens/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.artemis.*;
import com.artemis.managers.TagManager;
import com.artemis.managers.UuidEntityManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.FPSLogger;
Expand Down Expand Up @@ -32,9 +33,6 @@

public class GameScreen extends ScreenAdapter {

public static final int GAME_SCREEN_WIDTH = 800;
public static final int GAME_SCREEN_HEIGHT = 600;

public static World world;
public static int player = -1;
private static GUI gui = new GUI();
Expand Down Expand Up @@ -86,6 +84,7 @@ public void initWorld() {
.with(WorldConfigurationBuilder.Priority.NORMAL + 3, new NameRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new DialogRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new CharacterStatesRenderingSystem(spriteBatch))
// .with(FONTS_PRIORITY, new LightRenderingSystem(spriteBatch))
// Other
.with(new TagManager())
.with(new UuidEntityManager()); // why?
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/screens/LoginScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class LoginScreen extends AbstractScreen {

private static final String SERVER_IP = "localhost";
private static final String SERVER_IP = "ec2-18-231-116-111.sa-east-1.compute.amazonaws.com";
private static final int SERVER_PORT = 7666;
private ClientSystem clientSystem;
private World world;
Expand Down
3 changes: 3 additions & 0 deletions client/src/game/systems/camera/CameraMovementSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.artemis.Aspect;
import com.artemis.annotations.Wire;
import com.artemis.systems.IteratingSystem;
import com.badlogic.gdx.math.Vector3;
import position.Pos2D;

import static com.artemis.E.E;
Expand All @@ -28,6 +29,8 @@ public CameraMovementSystem() {
@Override
protected void process(int camera) {
final Pos2D pos = E(camera).getPos2D();

// cameraSystem.camera.position.lerp(new Vector3(pos.x, pos.y, 0), 0.6f);
cameraSystem.camera.position.x = (pos.x);
cameraSystem.camera.position.y = (pos.y);
cameraSystem.camera.update();
Expand Down
1 change: 1 addition & 0 deletions client/src/game/systems/map/CaveSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public boolean isBlocked(int x, int y) {

@Override
protected void begin() {
Gdx.gl.glClearColor(0f,0f,0f,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cameraSystem.camera.update();
}
Expand Down
14 changes: 10 additions & 4 deletions client/src/game/systems/physics/PlayerInputSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.artemis.E;
import com.artemis.systems.IteratingSystem;
import com.badlogic.gdx.Gdx;
import game.managers.AOInputProcessor;
import game.utils.AOKeys;
import game.utils.AlternativeKeys;
import physics.AOPhysics;

Expand All @@ -22,10 +24,14 @@ protected void process(int entityId) {
E player = E(entityId);
AOPhysics aoPhysics = player.getAOPhysics();
boolean isWriting = player.isWriting();
move(aoPhysics, AOPhysics.Movement.UP, !isWriting && Gdx.input.isKeyPressed(AlternativeKeys.MOVE_UP));
move(aoPhysics, AOPhysics.Movement.DOWN, !isWriting && Gdx.input.isKeyPressed(AlternativeKeys.MOVE_DOWN));
move(aoPhysics, AOPhysics.Movement.LEFT, !isWriting && Gdx.input.isKeyPressed(AlternativeKeys.MOVE_LEFT));
move(aoPhysics, AOPhysics.Movement.RIGHT, !isWriting && Gdx.input.isKeyPressed(AlternativeKeys.MOVE_RIGHT));
final int moveUp = AOInputProcessor.alternativeKeys ? AlternativeKeys.MOVE_UP : AOKeys.MOVE_UP;
final int moveDown = AOInputProcessor.alternativeKeys ? AlternativeKeys.MOVE_DOWN : AOKeys.MOVE_DOWN;
final int moveLeft = AOInputProcessor.alternativeKeys ? AlternativeKeys.MOVE_LEFT : AOKeys.MOVE_LEFT;
final int moveRight = AOInputProcessor.alternativeKeys ? AlternativeKeys.MOVE_RIGHT : AOKeys.MOVE_RIGHT;
move(aoPhysics, AOPhysics.Movement.UP, !isWriting && Gdx.input.isKeyPressed(moveUp));
move(aoPhysics, AOPhysics.Movement.DOWN, !isWriting && Gdx.input.isKeyPressed(moveDown));
move(aoPhysics, AOPhysics.Movement.LEFT, !isWriting && Gdx.input.isKeyPressed(moveLeft));
move(aoPhysics, AOPhysics.Movement.RIGHT, !isWriting && Gdx.input.isKeyPressed(moveRight));
}

private void move(AOPhysics aoPhysics, AOPhysics.Movement movement, boolean moving) {
Expand Down
74 changes: 74 additions & 0 deletions client/src/game/systems/render/world/LightRenderingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package game.systems.render.world;

import camera.Focused;
import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import entity.character.states.Immobile;
import game.screens.GameScreen;
import game.systems.OrderedEntityProcessingSystem;
import game.systems.camera.CameraSystem;
import game.utils.Fonts;
import game.utils.Resources;
import position.Pos2D;
import position.WorldPos;
import shared.model.map.Tile;
import shared.util.Util;

import java.util.Comparator;

import static com.artemis.E.E;
import static game.utils.Resources.GAME_SHADERS_LIGHT;

@Wire
public class LightRenderingSystem extends OrderedEntityProcessingSystem {

private final SpriteBatch batch;
private final Texture light;
private final int tw;
private final int th;
private CameraSystem cameraSystem;

public LightRenderingSystem(SpriteBatch batch) {
super(Aspect.all(Focused.class));
this.batch = batch;
light = new Texture(Gdx.files.internal(Resources.GAME_SHADERS_PATH + GAME_SHADERS_LIGHT));
tw = light.getWidth();
th = light.getHeight();
}

@Override
protected void begin() {
cameraSystem.camera.update();
batch.setProjectionMatrix(cameraSystem.camera.combined);
batch.begin();
batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_SRC_ALPHA);


}

@Override
protected void end() {
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.end();
}

@Override
protected void process(Entity e) {
final Color color = new Color(batch.getColor());
batch.getColor().a = 0.5f;
// batch.draw(light, cameraSystem.camera.position.x - (tw / 2), cameraSystem.camera.position.y - (th / 2));
batch.setColor(color);
}

@Override
protected Comparator<? super Entity> getComparator() {
return Comparator.comparingInt(entity -> E(entity).getWorldPos().y);
}
}
2 changes: 2 additions & 0 deletions client/src/game/systems/render/world/NameRenderingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.artemis.E;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import entity.character.Character;
Expand Down
12 changes: 6 additions & 6 deletions client/src/game/ui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ private Container<Table> createSpells() {
Container<Table> spellsContainer = new Container<>();
float screenW = getWidth();
float screenH = getHeight();
float width = screenW * 10f / 100f;
float width = screenW * 4f / 100f;
spellView = new SpellView();
spellView.setFillParent(true);
spellsContainer.setWidth(SpellSlot.SIZE);
spellsContainer.setWidth(width);
spellsContainer.setHeight(SpellView.MAX_SPELLS * SpellSlot.SIZE);
spellsContainer.setActor(spellView);
spellsContainer.setTransform(true);
spellsContainer.setScale(0.85f);
spellsContainer.setPosition(getWidth(), (screenH / 2) + 20, Align.right);
final float scaleXY = width / SpellSlot.SIZE;
spellsContainer.setScale(scaleXY);
spellsContainer.setPosition(getWidth() - 5, (screenH / 2), Align.right);
return spellsContainer;
}

Expand All @@ -100,7 +100,7 @@ private Container<Table> createInventory() {
inventory = new Inventory();
final float zoom = width / inventory.getWidth();
inventoryContainer.setScale(zoom);
inventoryContainer.setPosition((getWidth() * 98f / 100f) - width * zoom, 1, Align.bottom);
inventoryContainer.setPosition((getWidth() * 98f / 100f) - width, 1, Align.right | Align.bottom);
inventoryContainer.setActor(inventory);
inventoryContainer.setTransform(true);
return inventoryContainer;
Expand Down
Loading

0 comments on commit 1373440

Please sign in to comment.