Basic multiplayer placing/breaking/movement (broken)

This commit is contained in:
Anuken
2017-12-31 14:23:13 -05:00
parent eecd0f6d02
commit 36e357819b
29 changed files with 508 additions and 197 deletions

View File

@@ -127,9 +127,9 @@ public class AndroidInput extends InputHandler{
player.x += xa * 4f;
player.y += ya * 4f;
player.rotation += Inputs.getAxis("rotate_alt");
player.rotation += Inputs.getAxis("rotate");
player.rotation = Mathf.mod(player.rotation, 4);
player.placerot += Inputs.getAxis("rotate_alt");
player.placerot += Inputs.getAxis("rotate");
player.placerot = Mathf.mod(player.placerot, 4);
if(enableHold && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.scl(50))
&& !ui.hasMouse()){
@@ -171,7 +171,7 @@ public class AndroidInput extends InputHandler{
validPlace(x, y, player.recipe.result) && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
placeBlock(x, y, player.recipe.result, player.rotation, true, sound);
placeBlock(x, y, player.recipe.result, player.placerot, true, sound);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);

View File

@@ -3,8 +3,6 @@ package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.core.GameState;
@@ -12,14 +10,10 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.Configurable;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Inputs.DeviceType;
import io.anuke.ucore.core.KeyBinds;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf;
public class DesktopInput extends InputHandler{
@@ -66,18 +60,18 @@ public class DesktopInput extends InputHandler{
}
if(!rotated) {
player.rotation += Inputs.getAxis("rotate_alt");
player.placerot += Inputs.getAxis("rotate_alt");
rotated = true;
}
if(!Inputs.getAxisActive("rotate_alt")) rotated = false;
if(!rotatedAlt) {
player.rotation += Inputs.getAxis("rotate");
player.placerot += Inputs.getAxis("rotate");
rotatedAlt = true;
}
if(!Inputs.getAxisActive("rotate")) rotatedAlt = false;
player.rotation = Mathf.mod(player.rotation, 4);
player.placerot = Mathf.mod(player.placerot, 4);
if(Inputs.keyDown("break")){
player.breakMode = PlaceMode.areaDelete;

View File

@@ -1,15 +1,13 @@
package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.world.Block;
@@ -27,6 +25,8 @@ import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public abstract class InputHandler extends InputAdapter{
public abstract void update();
public abstract float getCursorX();
@@ -54,7 +54,7 @@ public abstract class InputHandler extends InputAdapter{
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
placeBlock(x, y, player.recipe.result, player.rotation, true, sound);
placeBlock(x, y, player.recipe.result, player.placerot, true, sound);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
@@ -116,7 +116,7 @@ public abstract class InputHandler extends InputAdapter{
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
|| (rotation != -1 && rotation != Vars.player.placerot)){
return false;
}
}else if(Vars.control.getTutorial().active()){
@@ -160,7 +160,7 @@ public abstract class InputHandler extends InputAdapter{
Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
|| (rotation != -1 && rotation != Vars.player.placerot)){
return false;
}
}else{
@@ -172,18 +172,27 @@ public abstract class InputHandler extends InputAdapter{
}
public void placeBlock(int x, int y, Block result, int rotation, boolean effects, boolean sound){
placeBlockInternal(x, y, result, rotation, effects, sound);
if(Net.active()){
Vars.netClient.handlePlace(x, y, result, rotation);
}
}
public void placeBlockInternal(int x, int y, Block result, int rotation, boolean effects, boolean sound){
Tile tile = world.tile(x, y);
//just in case
if(tile == null)
return;
tile.setBlock(result, rotation);
if(result.isMultiblock()){
int offsetx = -(result.width-1)/2;
int offsety = -(result.height-1)/2;
for(int dx = 0; dx < result.width; dx ++){
for(int dy = 0; dy < result.height; dy ++){
int worldx = dx + offsetx + x;
@@ -193,47 +202,55 @@ public abstract class InputHandler extends InputAdapter{
if(toplace != null)
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
}
}
}else{
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
}
if(effects && sound) Sounds.play("place");
result.placed(tile);
}
public void breakBlock(int x, int y, boolean sound){
breakBlockInternal(x, y, sound);
if(Net.active()){
Vars.netClient.handleBreak(x, y);
}
}
public void breakBlockInternal(int x, int y, boolean sound){
Tile tile = world.tile(x, y);
if(tile == null) return;
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = null;
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
result = recipe;
break;
}
}
if(result != null){
for(ItemStack stack : result.requirements){
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
}
}
if(tile.block().drops != null){
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
}
//Effects.shake(3f, 1f, player);
if(sound) Sounds.play("break");
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());

View File

@@ -20,8 +20,6 @@ import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import javax.tools.Tool;
public enum PlaceMode{
cursor{
{
@@ -45,12 +43,12 @@ public enum PlaceMode{
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, player.rotation, valid);
player.recipe.result.drawPlace(tilex, tiley, player.placerot, valid);
Draw.thickness(2f);
if(player.recipe.result.rotate){
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(player.rotation * 90);
Tmp.v1.set(7, 0).rotate(player.placerot * 90);
Draw.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
}
@@ -319,7 +317,7 @@ public enum PlaceMode{
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
player.rotation = this.rotation;
player.placerot = this.rotation;
boolean first = true;
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
@@ -358,7 +356,7 @@ public enum PlaceMode{
else if(endy < tiley)
rotation = 3;
else
rotation = player.rotation;
rotation = player.placerot;
if(endx < tilex){
int t = endx;