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

@@ -188,7 +188,7 @@ map.spiral.name=spiral
map.tutorial.name=tutorial
tutorial.intro.text=[yellow]Welcome to the tutorial.[] To begin, press 'next'.
tutorial.moveDesktop.text=To move, use the [orange][[WASD][] keys. Hold [orange]shift[] to boost. Hold [orange]CTRL[] while using the [orange]scrollwheel[] to zoom in or out.
tutorial.shoot.text=Use your mouse to aim, hold [orange]left mouse button[] to shoot. Try practicing on the [yellow]target[].
tutorial.shoot.text=Use your mouse to aim, hold [orange]left mouse button[] to shootInternal. Try practicing on the [yellow]target[].
tutorial.moveAndroid.text=To pan the view, drag one finger across the screen. Pinch and drag to zoom in or out.
tutorial.placeSelect.text=Try selecting a [yellow]conveyor[] from the block menu in the bottom right.
tutorial.placeConveyorDesktop.text=Use the [orange][[scrollwheel][] to rotate the conveyor to face [orange]forwards[], then place it in the [yellow]marked location[] using the [orange][[left mouse button][].
@@ -206,10 +206,10 @@ tutorial.deleteBlock.text=You can delete blocks by clicking the [orange]right m
tutorial.deleteBlockAndroid.text=You can delete blocks by [orange]selecting the crosshair[] in the [orange]break mode menu[] in the bottom left and tapping a block. Try deleting this conveyor.
tutorial.placeTurret.text=Now, select and place a [yellow]turret[] at the [yellow]marked location[].
tutorial.placedTurretAmmo.text=This turret will now accept [yellow]ammo[] from the conveyor. You can see how much ammo it has by hovering over it and checking the [green]green bar[].
tutorial.turretExplanation.text=Turrets will automatically shoot at the nearest enemy in range, as long as they have enough ammo.
tutorial.turretExplanation.text=Turrets will automatically shootInternal at the nearest enemy in range, as long as they have enough ammo.
tutorial.waves.text=Every [yellow]60[] seconds, a wave of [coral]enemies[] will spawn in specific locations and attempt to destroy the core.
tutorial.coreDestruction.text=Your objective is to [yellow]defend the core[]. If the core is destroyed, you [coral]lose the game[].
tutorial.pausingDesktop.text=If you ever need to take a break, press the [orange]pause button[] in the top left or [orange]space[] to pause the game. You can still select and place blocks while paused, but cannot move or shoot.
tutorial.pausingDesktop.text=If you ever need to take a break, press the [orange]pause button[] in the top left or [orange]space[] to pause the game. You can still select and place blocks while paused, but cannot move or shootInternal.
tutorial.pausingAndroid.text=If you ever need to take a break, press the [orange]pause button[] in the top left to pause the game. You can still place select and place blocks while paused.
tutorial.purchaseWeapons.text=You can purchase new [yellow]weapons[] for your mech by opening the upgrade menu in the bottom left.
tutorial.switchWeapons.text=Switch weapons by either clicking its icon in the bottom left, or using numbers [orange][[1-9][].
@@ -233,7 +233,7 @@ keybind.move_x.name=move_x
keybind.move_y.name=move_y
keybind.select.name=select
keybind.break.name=break
keybind.shoot.name=shoot
keybind.shootInternal.name=shoot
keybind.zoom_hold.name=zoom_hold
keybind.zoom.name=zoom
keybind.menu.name=menu

View File

@@ -158,7 +158,7 @@ map.spiral.name=Espiral
map.tutorial.name=tutorial
tutorial.intro.text=[yellow]Bienvenido al tutorial.[] Para empezar, presiona siguiente.
tutorial.moveDesktop.text=Para moverte, usa las [orange]teclas [[WASD][]. Mantén presionado [orange]shift[] para acelerar. Mantén presionado [orange]CTRL[] mientras usas la [orange]rueda del ratón[] para acercarte y alejarte.
tutorial.shoot.text=Usa el ratón para apuntar, mantén el [orange]clic izquierdo[] para disparar. Intenta practicar en el [yellow]blanco[].
tutorial.shootInternal.text=Usa el ratón para apuntar, mantén el [orange]clic izquierdo[] para disparar. Intenta practicar en el [yellow]blanco[].
tutorial.moveAndroid.text=Para mover la vista, arrastra un dedo por la pantalla. Usa dos dedos y acércalos o aléjalos para acercar o alejar la vista, respectivamente.
tutorial.placeSelect.text=Intenta seleccionar un [yellow]transportador[] del menú de bloques en la esquina inferior derecha.
tutorial.placeConveyorDesktop.text=Usa la [orange][[rueda del ratón][] para rotar el transportador [orange]hacia el norte[], y luego colócalo en la [yellow]ubicación marcada[] usando el [orange][[clic izquierdo][].
@@ -203,7 +203,7 @@ keybind.move_x.name=mover_x
keybind.move_y.name=mover_y
keybind.select.name=seleccionar
keybind.break.name=quitar
keybind.shoot.name=disparar
keybind.shootInternal.name=disparar
keybind.zoom_hold.name=mant_zoom
keybind.zoom.name=enfoque
keybind.menu.name=menú

View File

@@ -179,7 +179,7 @@ map.spiral.name=Spirale
map.tutorial.name=Tutoriel
tutorial.intro.text=[yellow]Bienvenue dans le tutoriel.[] Pour commencer, appuyez sur "Suivant"
tutorial.moveDesktop.text=Pour déplacer, utilisez les touches [orange][[WASD][] . tenir [orange]MAJ[] active le Booster. tenir [orange]CTRL[] en utilisant la [orange]molette[] pour faire un zoom avant ou arrière.
tutorial.shoot.text=Utilisez votre souris pour viser, maintenez [orange]le bouton gauche de la souris[] pour tirer. essayez de vous entraîner sur la [yellow]cible[].
tutorial.shootInternal.text=Utilisez votre souris pour viser, maintenez [orange]le bouton gauche de la souris[] pour tirer. essayez de vous entraîner sur la [yellow]cible[].
tutorial.moveAndroid.text=Pour déplacer la vue, faites glisser un doigt sur l'écran. Pincez et faites glisser pour effectuer un zoom avant ou arrière.
tutorial.placeSelect.text=Essayez de sélectionner un[yellow]tapis roulant[] du menu de bloc en bas à droite.
tutorial.placeConveyorDesktop.text=Utilisez la [orange][[molette][] faire tourner le tapis roulant pour faire face [orange]avant[], puis placez-le dans l' [yellow]emplacement marqué[] en utilisant le [orange][[bouton gauche de la souris][].
@@ -224,7 +224,7 @@ keybind.move_x.name=déplacement_x
keybind.move_y.name=déplacement_y
keybind.select.name=selectionner
keybind.break.name=casser
keybind.shoot.name=tirer
keybind.shootInternal.name=tirer
keybind.zoom_hold.name=maintenir_pour_zoomer
keybind.zoom.name=zoomer
keybind.menu.name=menu

View File

@@ -160,7 +160,7 @@ map.spiral.name=spiral
map.tutorial.name=tutorial
tutorial.intro.text=[yellow]Bem-vindo ao tutorial.[] Para começar aperte 'próximo'.
tutorial.moveDesktop.text=Para mover, use as teclas [orange][[WASD][]. Segure [orange]shift[] para mover rápido. Segure [orange]CTRL[] enquanto usa a [orange]roda do mouse[] para aumentar ou diminuir o zoom.
tutorial.shoot.text=Use o mouse para mirar, segure [orange]botão esquerdo do mouse[] para atirar. Tente praticar no [yellow]alvo[].
tutorial.shootInternal.text=Use o mouse para mirar, segure [orange]botão esquerdo do mouse[] para atirar. Tente praticar no [yellow]alvo[].
tutorial.moveAndroid.text=Para arrastar a visão, passe um dedo pela tela. Pince com os dedos para aumentar ou diminuir o zoom.
tutorial.placeSelect.text=Tente selecionar uma [yellow]esteira[] do menu de blocos no canto inferior direito.
tutorial.placeConveyorDesktop.text=Use a [orange][[roda do mouse][] para girar a esteira até que aponte [orange]para frente[], então coloque-a no [yellow]local marcado[] usando o [orange][[botão esquerdo do mouse][].
@@ -205,7 +205,7 @@ keybind.move_x.name=move_x
keybind.move_y.name=move_y
keybind.select.name=selecionar
keybind.break.name=quebrar
keybind.shoot.name=atirar
keybind.shootInternal.name=atirar
keybind.zoom_hold.name=segurar_zoom
keybind.zoom.name=zoom
keybind.menu.name=menu

View File

@@ -67,7 +67,7 @@ public class Vars{
//only if smoothCamera
public static boolean snapCamera = true;
//turret and enemy shoot speed inverse multiplier
//turret and enemy shootInternal speed inverse multiplier
public static final float multiplier = android ? 3 : 2;
public static final int tilesize = 8;

View File

@@ -1,16 +1,11 @@
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
import java.util.Arrays;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
@@ -24,6 +19,7 @@ import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.input.DesktopInput;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.io.Saves;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon;
@@ -41,6 +37,10 @@ import io.anuke.ucore.util.Input;
import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.*;
public class Control extends Module{
Tutorial tutorial = new Tutorial();
boolean hiscore = false;
@@ -52,7 +52,7 @@ public class Control extends Module{
public final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
public final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class);
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
Array<EnemySpawn> spawns;
int wave = 1;
@@ -128,7 +128,7 @@ public class Control extends Module{
Core.atlas = new Atlas("sprites.atlas");
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
"corexplode.ogg", "break.ogg", "spawn.ogg", "flame.ogg", "die.ogg",
"respawn.ogg", "purchase.ogg", "flame2.ogg", "bigshot.ogg", "laser.ogg", "lasershot.ogg",
"ping.ogg", "tesla.ogg", "waveend.ogg", "railgun.ogg", "blast.ogg", "bang2.ogg");
@@ -142,7 +142,7 @@ public class Control extends Module{
"move_y", new Axis(Input.S, Input.W),
"select", Input.MOUSE_LEFT,
"break", Input.MOUSE_RIGHT,
"shoot", Input.MOUSE_LEFT,
"shootInternal", Input.MOUSE_LEFT,
"zoom_hold", Input.CONTROL_LEFT,
"zoom", new Axis(Input.SCROLL),
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
@@ -166,7 +166,7 @@ public class Control extends Module{
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
"select", Input.CONTROLLER_R_BUMPER,
"break", Input.CONTROLLER_L_BUMPER,
"shoot", Input.CONTROLLER_R_TRIGGER,
"shootInternal", Input.CONTROLLER_R_TRIGGER,
"zoom_hold", Input.ANY_KEY,
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
"menu", Input.CONTROLLER_X,
@@ -194,6 +194,7 @@ public class Control extends Module{
}
player = new Player();
player.isLocal = true;
spawns = WaveCreator.getSpawns();
@@ -322,6 +323,10 @@ public class Control extends Module{
}
public void runWave(){
if(Net.client() && Net.active()){
return;
}
Sounds.play("spawn");
if(lastUpdated < wave + 1){
@@ -347,6 +352,8 @@ public class Control extends Module{
enemy.tier = spawn.tier(wave, fl);
Effects.effect(Fx.spawn, enemy);
enemy.add(enemyGroup);
Vars.netServer.handleEnemySpawn(enemy);
enemies ++;
}catch (Exception e){

View File

@@ -1,28 +1,31 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.net.Net;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.Disconnect;
import io.anuke.mindustry.net.Packets.EntityDataPacket;
import io.anuke.mindustry.net.Packets.WorldData;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.Module;
import java.util.Arrays;
public class NetClient extends Module {
boolean connecting = false;
boolean gotEntities = false;
float playerSyncTime = 3;
public NetClient(){
Net.handle(Connect.class, packet -> {
connecting = true;
gotEntities = false;
Gdx.app.postRunnable(() -> {
Vars.ui.hideLoading();
Vars.ui.showLoading("$text.connecting.data");
@@ -55,24 +58,98 @@ public class NetClient extends Module {
Net.handle(EntityDataPacket.class, data -> {
Gdx.app.postRunnable(() -> {
Timers.run(10f, () -> {
Timers.run(10f, () -> { //TODO hack
Vars.control.playerGroup.remap(Vars.player, data.playerid);
for (Player player : data.players) {
if (player.id != data.playerid) {
player.add();
}
}
UCore.log("Recieved entities: " + Arrays.toString(data.players) + " player ID: " + data.playerid);
gotEntities = true;
});
});
});
Net.handle(SyncPacket.class, packet -> {
if(!gotEntities) return;
for(int i = 0; i < packet.ids.length; i ++){
int id = packet.ids[i];
if(id != Vars.player.id){
Player player = Vars.control.playerGroup.getByID(id);
player.getInterpolator().type.read(player, packet.data[i]);
}
}
});
Net.handle(ShootPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.playerid);
Weapon weapon = Weapon.values()[packet.weaponid];
weapon.shoot(player, packet.x, packet.y, packet.rotation);
});
Net.handleServer(PlacePacket.class, packet -> {
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
});
Net.handleServer(BreakPacket.class, packet -> {
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
});
Net.handleServer(StateSyncPacket.class, packet -> {
//TODO replace with arraycopy()
for(int i = 0; i < packet.items.length; i ++){
Vars.control.items[i] = packet.items[i];
}
Vars.control.setWaveData(packet.enemies, packet.wave, packet.countdown);
});
}
public void update(){
if(!Net.client()) return;
if(!GameState.is(State.menu) && Net.active()){
sync();
}else if(!connecting){
Net.disconnect();
}
}
public void handleShoot(Weapon weapon, float x, float y, float angle){
ShootPacket packet = new ShootPacket();
packet.weaponid = (byte)weapon.ordinal();
packet.x = x;
packet.y = y;
packet.rotation = angle;
Net.send(packet, SendMode.udp);
}
public void handlePlace(int x, int y, Block block, int rotation){
PlacePacket packet = new PlacePacket();
packet.x = (short)x;
packet.y = (short)y;
packet.rotation = (byte)rotation;
packet.playerid = Vars.player.id;
packet.block = block.id;
Net.send(packet, SendMode.tcp);
}
public void handleBreak(int x, int y){
BreakPacket packet = new BreakPacket();
packet.x = (short)x;
packet.y = (short)y;
Net.send(packet, SendMode.tcp);
}
void sync(){
if(Timers.get("syncPlayer", playerSyncTime)){
PositionPacket packet = new PositionPacket();
packet.data = Vars.player.getInterpolator().type.write(Vars.player);
Net.send(packet, SendMode.tcp); //TODO udp instead?
}
}
}

View File

@@ -1,27 +1,33 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.IntMap;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.EntityDataPacket;
import io.anuke.mindustry.net.Packets.SyncPacket;
import io.anuke.mindustry.net.Packets.WorldData;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.Module;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.Arrays;
public class NetServer extends Module{
IntMap<Player> connections = new IntMap<>();
float serverSyncTime = 4;
float serverSyncTime = 4, itemSyncTime = 20, blockSyncTime = 120;
public NetServer(){
@@ -44,15 +50,70 @@ public class NetServer extends Module{
Player player = new Player();
player.clientid = packet.id;
player.set(Vars.player.x, Vars.player.y);
player.placerot = Vars.player.placerot;
player.add();
connections.put(player.id, player);
connections.put(packet.id, player);
dp.playerid = player.id;
dp.players = Vars.control.playerGroup.all().toArray(Player.class);
UCore.log("Sending entities: " + Arrays.toString(dp.players));
Net.sendTo(packet.id, dp, SendMode.tcp);
});
});
Net.handleServer(PositionPacket.class, pos -> {
Player player = connections.get(Net.getLastConnection());
player.getInterpolator().type.read(player, pos.data);
});
Net.handleServer(ShootPacket.class, packet -> {
Player player = connections.get(Net.getLastConnection());
Weapon weapon = Weapon.values()[packet.weaponid];
weapon.shoot(player, packet.x, packet.y, packet.rotation);
packet.playerid = player.id;
Net.sendExcept(Net.getLastConnection(), packet, SendMode.udp);
});
Net.handleServer(PlacePacket.class, packet -> {
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
packet.playerid = connections.get(Net.getLastConnection()).id;
Recipe recipe = Recipe.getByResult(Block.getByID(packet.block));
if(recipe != null){
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
}
}
Net.sendExcept(Net.getLastConnection(), packet, SendMode.tcp);
});
Net.handleServer(BreakPacket.class, packet -> {
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
packet.playerid = connections.get(Net.getLastConnection()).id;
Net.sendExcept(Net.getLastConnection(), packet, SendMode.tcp);
});
}
//TODO decide whether to use effects
public void sendEffect(Effect effect, Color color, float x, float y, float rotation){
EffectPacket packet = new EffectPacket();
packet.id = effect.id;
packet.color = Color.rgba8888(color);
packet.x = x;
packet.y = y;
packet.rotation = rotation;
Net.send(packet, SendMode.udp);
}
public void handleEnemySpawn(Enemy enemy){
}
public void update(){
@@ -66,12 +127,51 @@ public class NetServer extends Module{
}
void sync(){
if(Timers.get("serverSync", serverSyncTime)){
SyncPacket packet = new SyncPacket();
int amount = Vars.control.playerGroup.amount();
packet.ids = new int[amount];
packet.data = new float[amount][0];
int index = 0;
for(Player player : Vars.control.playerGroup.all()){
float[] out = player.getInterpolator().type.write(player);
packet.data[index] = out;
packet.ids[index] = player.id;
index ++;
}
Net.send(packet, SendMode.udp);
}
if(Timers.get("serverItemSync", itemSyncTime)){
StateSyncPacket packet = new StateSyncPacket();
packet.items = Vars.control.items;
packet.countdown = Vars.control.getWaveCountdown();
packet.enemies = Vars.control.getEnemiesRemaining();
packet.wave = Vars.control.getWave();
Net.send(packet, SendMode.udp);
}
if(Timers.get("serverBlockSync", blockSyncTime)){
BlockSyncPacket packet = new BlockSyncPacket();
}
}
public void sendBlockSync(int client){
BlockSyncPacket packet = new BlockSyncPacket();
ByteArrayOutputStream bs = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream(bs);
packet.stream = new ByteArrayInputStream(bs.toByteArray());
}
}

View File

@@ -1,8 +1,5 @@
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.core.Core.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap.Format;
@@ -12,7 +9,6 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
@@ -25,7 +21,6 @@ import io.anuke.mindustry.world.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.entities.EffectEntity;
@@ -39,6 +34,10 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.core.Core.batch;
import static io.anuke.ucore.core.Core.camera;
public class Renderer extends RendererModule{
private final static int chunksize = 32;
private final static float shieldHitDuration = 18f;
@@ -419,8 +418,11 @@ public class Renderer extends RendererModule{
drawHealth(entity);
}
if(!Vars.android && Vars.showPlayer && !player.isDead())
drawHealth(player);
if(!Vars.android && Vars.showPlayer) {
for(Player player : Vars.control.playerGroup.all()){
if(!player.isDead()) drawHealth(player);
}
}
}
}

View File

@@ -1,22 +1,12 @@
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.scene.actions.Actions.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.ControllerAdapter;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
@@ -28,17 +18,13 @@ import io.anuke.mindustry.ui.fragments.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.Configurable;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*;
import io.anuke.ucore.core.Inputs.DeviceType;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.function.VisibilityProvider;
import io.anuke.ucore.modules.SceneModule;
import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.Skin;
import io.anuke.ucore.scene.builders.build;
import io.anuke.ucore.scene.builders.field;
import io.anuke.ucore.scene.builders.label;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable;
@@ -51,9 +37,11 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Strings;
import javax.tools.Tool;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.scene.actions.Actions.*;
public class UI extends SceneModule{
Table loadingtable, configtable;
MindustrySettingsDialog prefs;
@@ -325,7 +313,7 @@ public class UI extends SceneModule{
placefrag.build();
loadingtable = new table("loadDim"){{
get().setTouchable(Touchable.enabled);
touchable(Touchable.enabled);
get().addImage("white").growX()
.height(3f).pad(4f).growX().get().setColor(Colors.get("accent"));
row();

View File

@@ -1,9 +1,5 @@
package io.anuke.mindustry.entities;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Input.Buttons;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.input.PlaceMode;
@@ -18,19 +14,23 @@ import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class Player extends DestructibleEntity implements Syncable{
private static final float speed = 1.1f;
private static final float dashSpeed = 1.8f;
public transient Weapon weapon;
public transient Weapon weapon = Weapon.blaster;
public Mech mech = Mech.standard;
public float angle;
public transient int clientid;
public transient boolean isLocal = false;
public transient Interpolator<Player> inter = new Interpolator<>(SyncType.player);
public transient float breaktime = 0;
public transient Recipe recipe;
public transient int rotation;
public transient int placerot;
public transient PlaceMode placeMode = android ? PlaceMode.cursor : PlaceMode.hold;
public transient PlaceMode breakMode = android ? PlaceMode.none : PlaceMode.holdDelete;
@@ -41,7 +41,12 @@ public class Player extends DestructibleEntity implements Syncable{
maxhealth = 100;
heal();
}
@Override
public Interpolator getInterpolator() {
return inter;
}
@Override
public void damage(int amount){
if(!Vars.debug && !Vars.android)
@@ -50,14 +55,26 @@ public class Player extends DestructibleEntity implements Syncable{
@Override
public void onDeath(){
remove();
if(isLocal){
remove();
}else{
set(-9999, -9999);
}
Effects.effect(Fx.explosion, this);
Effects.shake(4f, 5f, this);
Effects.sound("die", this);
Vars.control.setRespawnTime(respawnduration);
ui.fadeRespawn(true);
//TODO respawning doesn't work for multiplayer
if(isLocal) {
Vars.control.setRespawnTime(respawnduration);
ui.fadeRespawn(true);
}else{
Timers.run(respawnduration, () -> {
heal();
set(Vars.control.getCore().worldx(), Vars.control.getCore().worldy());
});
}
}
@Override
@@ -74,6 +91,10 @@ public class Player extends DestructibleEntity implements Syncable{
@Override
public void update(){
if(!isLocal){
if(!isDead()) inter.update(this);
return;
}
float speed = Inputs.keyDown("dash") ? Player.dashSpeed : Player.speed;
@@ -95,11 +116,11 @@ public class Player extends DestructibleEntity implements Syncable{
vector.y += ya*speed;
vector.x += xa*speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && recipe == null
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shootInternal") && recipe == null
&& !ui.hasMouse() && !control.getInput().onConfigurable();
if(shooting && Timers.get(this, "reload", weapon.reload)){
weapon.shoot(this);
weapon.shoot(this, x, y, Angles.mouseAngle(x, y));
Sounds.play(weapon.shootsound);
}

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;

View File

@@ -71,7 +71,7 @@ import io.anuke.ucore.entities.Entities;
* Tile type (boolean)- whether the block has a tile entity attached
* Block ID - the block ID (byte)
* (the following only applies to tile entity blocks)
* Block rotation (byte)
* Block placerot (byte)
* Block health (int)
* Amount of items (byte)
* (item list)
@@ -285,7 +285,7 @@ public class SaveIO{
stream.writeInt(tile.block().id); //block ID
if(tile.entity != null){
stream.writeByte(tile.getRotation()); //rotation
stream.writeByte(tile.getRotation()); //placerot
stream.writeInt(tile.entity.health); //health
int amount = 0;
for(int i = 0; i < tile.entity.items.length; i ++){

View File

@@ -1,18 +1,15 @@
package io.anuke.mindustry.net;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.net.Streamable.StreamBegin;
import io.anuke.mindustry.net.Streamable.StreamBuilder;
import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.ucore.function.Consumer;
import java.io.IOException;
//TODO stub
public class Net{
private static boolean server;
@@ -22,6 +19,7 @@ public class Net{
private static ClientProvider clientProvider;
private static ServerProvider serverProvider;
private static int lastConnection = -1;
private static IntMap<StreamBuilder> streams = new IntMap<>();
/**Connect to an address.*/
@@ -65,6 +63,11 @@ public class Net{
serverProvider.sendTo(id, object, mode);
}
/**Send an object to everyone EXCEPT certain client. Server-side only*/
public static void sendExcept(int id, Object object, SendMode mode){
serverProvider.sendExcept(id, object, mode);
}
/**Send a stream to a specific client. Server-side only.*/
public static void sendStream(int id, Streamable stream){
serverProvider.sendStream(id, stream);
@@ -114,13 +117,19 @@ public class Net{
}
/**Call to handle a packet being recieved for the server.*/
public static void handleServerReceived(Object object){
public static void handleServerReceived(Object object, int connection){
if(serverListeners.get(object.getClass()) != null){
lastConnection = connection;
serverListeners.get(object.getClass()).accept(object);
}else{
Gdx.app.error("Mindustry::Net", "Unhandled packet type: '" + object.getClass() + "'!");
}
}
/**Returns the last connection that sent a packet to this server.*/
public static int getLastConnection(){
return lastConnection;
}
/**Whether the net is active, e.g. whether this is a multiplayer game.*/
public static boolean active(){

View File

@@ -1,7 +1,5 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.Player;
/**Class for storing all packets.*/
@@ -27,6 +25,45 @@ public class Packets {
}
public static class SyncPacket{
public int[] ids;
public float[][] data;
}
public static class BlockSyncPacket extends Streamable{
}
public static class StateSyncPacket {
public int[] items;
public float countdown;
public int enemies, wave;
}
public static class PositionPacket{
public float[] data;
}
public static class EffectPacket{
public int id;
public float x, y, rotation;
public int color;
}
public static class ShootPacket{
public byte weaponid;
public float x, y, rotation;
public int playerid;
}
public static class PlacePacket{
public int playerid;
public byte rotation;
public short x, y;
public int block;
}
public static class BreakPacket{
public int playerid;
public short x, y;
}
}

View File

@@ -3,13 +3,10 @@ package io.anuke.mindustry.net;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.Packets.EntityDataPacket;
import io.anuke.mindustry.net.Packets.SyncPacket;
import io.anuke.mindustry.net.Packets.WorldData;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.Streamable.StreamBegin;
import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.mindustry.resource.Mech;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.ucore.entities.Entity;
public class Registrator {
@@ -21,8 +18,18 @@ public class Registrator {
WorldData.class,
SyncPacket.class,
EntityDataPacket.class,
PositionPacket.class,
ShootPacket.class,
PlacePacket.class,
BreakPacket.class,
StateSyncPacket.class,
BlockSyncPacket.class,
Class.class,
byte[].class,
float[].class,
float[][].class,
int[].class,
Entity[].class,
Player[].class,
Array.class,

View File

@@ -1,4 +1,57 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.entities.Player;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Mathf;
public interface Syncable {
public Interpolator<?> getInterpolator();
public abstract class SyncType<T extends Entity>{
public abstract float[] write(T entity);
public abstract void read(T entity, float[] data);
public abstract void update(T entity, Interpolator interpolator);
public static final SyncType<Player> player = new SyncType<Player>() {
@Override
public float[] write(Player entity) {
return new float[]{entity.x, entity.y, entity.angle, entity.health};
}
@Override
public void read(Player entity, float[] data) {
entity.getInterpolator().target.set(data[0], data[1]);
entity.getInterpolator().targetrot = data[2];
entity.health = (int)data[3];
}
@Override
public void update(Player entity, Interpolator interpolator) {
Interpolator i = entity.getInterpolator();
if(i.target.dst(entity.x, entity.y) > 16){
entity.set(i.target.x, i.target.y);
}
entity.x = Mathf.lerpDelta(entity.x, i.target.x, 0.4f);
entity.y = Mathf.lerpDelta(entity.y, i.target.y, 0.4f);
entity.angle = Mathf.lerpAngDelta(entity.angle, i.targetrot, 0.6f);
}
};
}
public static class Interpolator<T extends Entity> {
public SyncType<T> type;
public Vector2 target = new Vector2();
public float targetrot;
public Interpolator(SyncType<T> type){
this.type = type;
}
public void update(T entity){
this.type.update(entity, this);
}
}
}

View File

@@ -1,11 +1,13 @@
package io.anuke.mindustry.resource;
import static io.anuke.mindustry.resource.Section.*;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.blocks.DefenseBlocks;
import io.anuke.mindustry.world.blocks.DistributionBlocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.WeaponBlocks;
import static io.anuke.mindustry.resource.Section.*;
public enum Recipe{
stonewall(defense, DefenseBlocks.stonewall, stack(Item.stone, 2)),
@@ -94,6 +96,15 @@ public enum Recipe{
private static ItemStack stack(Item item, int amount){
return new ItemStack(item, amount);
}
public static Recipe getByResult(Block block){
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
return recipe;
}
}
return null;
}
public static Array<Recipe> getBy(Section section, Array<Recipe> r){
for(Recipe recipe : Recipe.values()){

View File

@@ -3,15 +3,14 @@ package io.anuke.mindustry.resource;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
@@ -22,35 +21,33 @@ public enum Weapon{
}
@Override
public void shoot(Player p){
super.shoot(p);
Effects.effect(Fx.shoot3, p.x + vector.x, p.y+vector.y);
public void shootInternal(Player p, float x, float y, float rotation){
super.shootInternal(p, x, y, rotation);
Effects.effect(Fx.shoot3, x + vector.x, y+vector.y);
}
},
triblaster(13, BulletType.shot, stack(Item.iron, 40)){
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
public void shootInternal(Player p, float x, float y, float rotation){
float space = 12;
bullet(p, p.x, p.y, ang);
bullet(p, p.x, p.y, ang+space);
bullet(p, p.x, p.y, ang-space);
bullet(p, x, y, rotation);
bullet(p, x, y, rotation + space);
bullet(p, x, y, rotation - space);
Effects.effect(Fx.shoot, p.x + vector.x, p.y+vector.y);
Effects.effect(Fx.shoot, x + vector.x, y + vector.y);
}
},
multigun(6, BulletType.multishot, stack(Item.iron, 60), stack(Item.steel, 20)){
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
public void shootInternal(Player p, float x, float y, float rotation){
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
bullet(p, p.x, p.y, ang + Mathf.range(8));
bullet(p, x, y, rotation + Mathf.range(8));
Effects.effect(Fx.shoot2, p.x + vector.x, p.y+vector.y);
Effects.effect(Fx.shoot2, x + vector.x, y + vector.y);
}
},
flamer(5, BulletType.flame, stack(Item.steel, 60), stack(Item.iron, 120)){
@@ -60,12 +57,10 @@ public enum Weapon{
}
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
//????
public void shootInternal(Player p, float x, float y, float rotation){
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
bullet(p, p.x, p.y, ang + Mathf.range(12));
bullet(p, x, y, rotation + Mathf.range(12));
}
},
railgun(40, BulletType.sniper, stack(Item.steel, 60), stack(Item.iron, 60)){
@@ -75,11 +70,9 @@ public enum Weapon{
}
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
bullet(p, p.x, p.y, ang);
Effects.effect(Fx.railshoot, p.x + vector.x, p.y+vector.y);
public void shootInternal(Player p, float x, float y, float rotation){
bullet(p, x, y, rotation);
Effects.effect(Fx.railshoot, x + vector.x, y + vector.y);
}
},
mortar(100, BulletType.shell, stack(Item.titanium, 40), stack(Item.steel, 60)){
@@ -89,11 +82,10 @@ public enum Weapon{
}
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
bullet(p, p.x, p.y, ang);
Effects.effect(Fx.mortarshoot, p.x + vector.x, p.y+vector.y);
Effects.shake(2f, 2f, Vars.player);
public void shootInternal(Player p, float x, float y, float rotation){
bullet(p, x, y, rotation);
Effects.effect(Fx.mortarshoot, x + vector.x, y + vector.y);
Effects.shake(2f, 2f, p);
}
};
public float reload;
@@ -102,7 +94,7 @@ public enum Weapon{
public boolean unlocked;
public ItemStack[] requirements;
public final String description;
Vector2 vector = new Vector2();
public String localized(){
@@ -116,17 +108,21 @@ public enum Weapon{
this.description = Bundles.getNotNull("weapon."+name()+".description");
}
public void shoot(Player p){
bullet(p, p.x, p.y, mouseAngle(p));
void shootInternal(Player p, float x, float y, float rotation){
bullet(p, x, y, rotation);
}
float mouseAngle(Entity owner){
return Angles.mouseAngle(owner.x, owner.y);
public void shoot(Player p, float x, float y, float angle){
shootInternal(p, x, y, angle);
if(Net.active() && p == Vars.player){
Vars.netClient.handleShoot(this, x, y, angle);
}
}
void bullet(Entity owner, float x, float y, float angle){
vector.set(3, 0).rotate(mouseAngle(owner));
new Bullet(type, owner, x+vector.x, y+vector.y, angle).add();
vector.set(3, 0).rotate(angle);
new Bullet(type, owner, x + vector.x, y + vector.y, angle).add();
}
private static ItemStack stack(Item item, int amount){

View File

@@ -10,7 +10,6 @@ import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.*;
import io.anuke.ucore.scene.event.Touchable;
@@ -19,8 +18,6 @@ import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Mathf;
import javax.xml.soap.Text;
public class PlacementFragment implements Fragment{
boolean shown = false;
Table breaktable, next;
@@ -100,9 +97,9 @@ public class PlacementFragment implements Fragment{
}
new imagebutton("icon-arrow", 14*3, ()->{
player.rotation = Mathf.mod(player.rotation + 1, 4);
player.placerot = Mathf.mod(player.placerot + 1, 4);
}).imageColor(color).visible(() -> player.recipe != null).update(image ->{
image.getImage().setRotation(player.rotation*90);
image.getImage().setRotation(player.placerot *90);
image.getImage().setOrigin(Align.center);
});

View File

@@ -33,8 +33,8 @@ public class ToolFragment implements Fragment{
});
tools.addIButton("icon-rotate", isize, () -> {
player.rotation ++;
player.rotation %= 4;
player.placerot++;
player.placerot %= 4;
});
tools.addIButton("icon-check", isize, () -> {

View File

@@ -221,7 +221,7 @@ public class Block{
}
public void draw(Tile tile){
//note: multiblocks do not support rotation
//note: multiblocks do not support placerot
if(!isMultiblock()){
Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(),
tile.worldx(), tile.worldy(), rotate ? tile.getRotation() * 90 : 0);

View File

@@ -17,7 +17,7 @@ public class Tile{
/**Packed block data. Left is floor, right is block.*/
private short blocks;
/**Packed data. Left is rotation, right is extra data, packed into two half-bytes: left is dump, right is extra.*/
/**Packed data. Left is placerot, right is extra data, packed into two half-bytes: left is dump, right is extra.*/
private short data;
/**The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
* This is relative to the block it is linked to; negate coords to find the link.*/
@@ -53,7 +53,7 @@ public class Tile{
return Bits.getLeftByte(blocks);
}
/**Return relative rotation to a coordinate. Returns -1 if the coordinate is not near this tile.*/
/**Return relative placerot to a coordinate. Returns -1 if the coordinate is not near this tile.*/
public int relativeTo(int cx, int cy){
if(x == cx && y == cy - 1) return 1;
if(x == cx && y == cy + 1) return 3;

View File

@@ -172,7 +172,7 @@ public class WeaponBlocks{
shootEffect = Fx.chainshot;
}
//TODO specify turret shoot effect in turret instead of doing it manually
//TODO specify turret shootInternal effect in turret instead of doing it manually
@Override
protected void shoot(Tile tile){
TurretEntity entity = tile.entity();

View File

@@ -1,13 +1,8 @@
package io.anuke.mindustry.world.blocks.types.defense;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
@@ -27,6 +22,10 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class Turret extends Block{
static final int targetInterval = 15;
static boolean drawDebug = false;

View File

@@ -1,28 +1,17 @@
package io.anuke.mindustry.desktop;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.compression.Lzma;
import com.esotericsoftware.kryonet.*;
import com.esotericsoftware.kryonet.util.InputStreamSender;
import com.esotericsoftware.minlog.Log;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.PlatformFunction;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.ClientProvider;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.PlatformFunction;
import io.anuke.mindustry.net.Net.ServerProvider;
import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.Disconnect;
@@ -33,6 +22,15 @@ import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.ucore.UCore;
import io.anuke.ucore.scene.ui.TextField;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
public class DesktopLauncher {
public static void main (String[] arg) {
@@ -158,20 +156,20 @@ public class DesktopLauncher {
Connect c = new Connect();
c.id = connection.getID();
c.addressTCP = connection.getRemoteAddressTCP().toString();
Net.handleServerReceived(c);
Net.handleServerReceived(c, c.id);
}
@Override
public void disconnected (Connection connection) {
Disconnect c = new Disconnect();
c.id = connection.getID();
Net.handleServerReceived(c);
Net.handleServerReceived(c, c.id);
}
@Override
public void received (Connection connection, Object object) {
if(object instanceof FrameworkMessage) return;
Net.handleServerReceived(object);
Net.handleServerReceived(object, connection.getID());
}
});