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

@@ -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){