Changed weapon to an upgrade
This commit is contained in:
@@ -140,7 +140,7 @@ public class Control extends Module{
|
|||||||
"move_y", new Axis(Input.S, Input.W),
|
"move_y", new Axis(Input.S, Input.W),
|
||||||
"select", Input.MOUSE_LEFT,
|
"select", Input.MOUSE_LEFT,
|
||||||
"break", Input.MOUSE_RIGHT,
|
"break", Input.MOUSE_RIGHT,
|
||||||
"shootInternal", Input.MOUSE_LEFT,
|
"shoot", Input.MOUSE_LEFT,
|
||||||
"zoom_hold", Input.CONTROL_LEFT,
|
"zoom_hold", Input.CONTROL_LEFT,
|
||||||
"zoom", new Axis(Input.SCROLL),
|
"zoom", new Axis(Input.SCROLL),
|
||||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
"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),
|
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||||
"select", Input.CONTROLLER_R_BUMPER,
|
"select", Input.CONTROLLER_R_BUMPER,
|
||||||
"break", Input.CONTROLLER_L_BUMPER,
|
"break", Input.CONTROLLER_L_BUMPER,
|
||||||
"shootInternal", Input.CONTROLLER_R_TRIGGER,
|
"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||||
"zoom_hold", Input.ANY_KEY,
|
"zoom_hold", Input.ANY_KEY,
|
||||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||||
"menu", Input.CONTROLLER_X,
|
"menu", Input.CONTROLLER_X,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class Player extends DestructibleEntity implements Syncable{
|
|||||||
private static final float dashSpeed = 1.8f;
|
private static final float dashSpeed = 1.8f;
|
||||||
|
|
||||||
public String name = "name";
|
public String name = "name";
|
||||||
public transient Weapon weapon = Weapon.blaster;
|
public Weapon weapon = Weapon.blaster;
|
||||||
public Mech mech = Mech.standard;
|
public Mech mech = Mech.standard;
|
||||||
public float angle;
|
public float angle;
|
||||||
public boolean isAndroid;
|
public boolean isAndroid;
|
||||||
@@ -124,12 +124,11 @@ public class Player extends DestructibleEntity implements Syncable{
|
|||||||
vector.y += ya*speed;
|
vector.y += ya*speed;
|
||||||
vector.x += xa*speed;
|
vector.x += xa*speed;
|
||||||
|
|
||||||
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shootInternal") && control.getInput().recipe == null
|
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.getInput().recipe == null
|
||||||
&& !ui.hasMouse() && !control.getInput().onConfigurable();
|
&& !ui.hasMouse() && !control.getInput().onConfigurable();
|
||||||
|
|
||||||
if(shooting && Timers.get(this, "reload", weapon.reload)){
|
if(shooting){
|
||||||
weapon.shoot(this, x, y, Angles.mouseAngle(x, y));
|
weapon.update(player);
|
||||||
Sounds.play(weapon.shootsound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyDown("dash") && Timers.get(this, "dashfx", 3) && vector.len() > 0){
|
if(Inputs.keyDown("dash") && Timers.get(this, "dashfx", 3) && vector.len() > 0){
|
||||||
|
|||||||
23
core/src/io/anuke/mindustry/resource/Upgrade.java
Normal file
23
core/src/io/anuke/mindustry/resource/Upgrade.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package io.anuke.mindustry.resource;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
|
public abstract class Upgrade {
|
||||||
|
private static Array<Upgrade> upgrades = new Array<>();
|
||||||
|
private static byte lastid;
|
||||||
|
|
||||||
|
public final byte id;
|
||||||
|
|
||||||
|
public Upgrade(){
|
||||||
|
this.id = lastid ++;
|
||||||
|
upgrades.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Upgrade getByID(byte id){
|
||||||
|
return upgrades.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<Upgrade> getAllUpgrades() {
|
||||||
|
return upgrades;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package io.anuke.mindustry.resource;
|
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.Vars;
|
||||||
import io.anuke.mindustry.entities.Bullet;
|
import io.anuke.mindustry.entities.Bullet;
|
||||||
import io.anuke.mindustry.entities.BulletType;
|
import io.anuke.mindustry.entities.BulletType;
|
||||||
@@ -10,109 +7,86 @@ import io.anuke.mindustry.entities.Player;
|
|||||||
import io.anuke.mindustry.graphics.Fx;
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Effects.Effect;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.entities.Entity;
|
import io.anuke.ucore.entities.Entity;
|
||||||
|
import io.anuke.ucore.util.Angles;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
public enum Weapon{
|
public class Weapon extends Upgrade{
|
||||||
blaster(15, BulletType.shot){
|
public static final Weapon
|
||||||
|
|
||||||
|
blaster = new Weapon("blaster", 15, BulletType.shot){
|
||||||
{
|
{
|
||||||
unlocked = true;
|
effect = Fx.shoot3;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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)){
|
triblaster = new Weapon("blaster", 13, BulletType.shot){
|
||||||
|
{
|
||||||
@Override
|
shots = 3;
|
||||||
public void shootInternal(Player p, float x, float y, float rotation){
|
effect = Fx.shoot;
|
||||||
float space = 12;
|
|
||||||
|
|
||||||
bullet(p, x, y, rotation);
|
|
||||||
bullet(p, x, y, rotation + space);
|
|
||||||
bullet(p, x, y, rotation - space);
|
|
||||||
|
|
||||||
Effects.effect(Fx.shoot, x + vector.x, y + vector.y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
multigun(6, BulletType.multishot, stack(Item.iron, 60), stack(Item.steel, 20)){
|
multigun = new Weapon("blaster", 6, BulletType.multishot){
|
||||||
@Override
|
{
|
||||||
public void shootInternal(Player p, float x, float y, float rotation){
|
effect = Fx.shoot2;
|
||||||
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
|
inaccuracy = 8f;
|
||||||
|
|
||||||
bullet(p, x, y, rotation + Mathf.range(8));
|
|
||||||
|
|
||||||
Effects.effect(Fx.shoot2, x + vector.x, y + vector.y);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
flamer(5, BulletType.flame, stack(Item.steel, 60), stack(Item.iron, 120)){
|
flamer = new Weapon("blaster", 5, BulletType.flame){
|
||||||
|
|
||||||
{
|
{
|
||||||
shootsound = "flame2";
|
shootsound = "flame2";
|
||||||
}
|
inaccuracy = 12f;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shootInternal(Player p, float x, float y, float rotation){
|
|
||||||
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
|
|
||||||
|
|
||||||
bullet(p, x, y, rotation + Mathf.range(12));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
railgun(40, BulletType.sniper, stack(Item.steel, 60), stack(Item.iron, 60)){
|
railgun = new Weapon("blaster", 40, BulletType.sniper){
|
||||||
|
|
||||||
{
|
{
|
||||||
shootsound = "railgun";
|
shootsound = "railgun";
|
||||||
}
|
effect = Fx.railshoot;
|
||||||
|
|
||||||
@Override
|
|
||||||
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)){
|
mortar = new Weapon("blaster", 100, BulletType.shell){
|
||||||
|
|
||||||
{
|
{
|
||||||
shootsound = "bigshot";
|
shootsound = "bigshot";
|
||||||
}
|
effect = Fx.mortarshoot;
|
||||||
|
shake = 2f;
|
||||||
@Override
|
|
||||||
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;
|
float reload;
|
||||||
public BulletType type;
|
BulletType type;
|
||||||
public String shootsound = "shoot";
|
String shootsound = "shoot";
|
||||||
public boolean unlocked;
|
int shots = 1;
|
||||||
public ItemStack[] requirements;
|
float inaccuracy = 0f;
|
||||||
|
float shake = 0f;
|
||||||
|
Effect effect;
|
||||||
|
|
||||||
public final String description;
|
public final String description;
|
||||||
|
public final String name;
|
||||||
|
|
||||||
Vector2 vector = new Vector2();
|
private Weapon(String name, float reload, BulletType type){
|
||||||
|
|
||||||
public String localized(){
|
|
||||||
return Bundles.get("weapon."+name() + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Weapon(float reload, BulletType type, ItemStack... requirements){
|
|
||||||
this.reload = reload;
|
this.reload = reload;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.requirements = requirements;
|
this.name = name;
|
||||||
this.description = Bundles.getNotNull("weapon."+name()+".description");
|
this.description = Bundles.getNotNull("weapon."+name+".description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(Player p){
|
||||||
|
if(Timers.get(p, "reload", reload)){
|
||||||
|
shoot(p, p.x, p.y, Angles.mouseAngle(p.x, p.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void shootInternal(Player p, float x, float y, float rotation){
|
void shootInternal(Player p, float x, float y, float rotation){
|
||||||
bullet(p, x, y, rotation);
|
Angles.shotgun(shots, 12f, rotation, f -> bullet(p, x, y, f + Mathf.range(inaccuracy)));
|
||||||
|
Angles.translation(rotation, 3f);
|
||||||
|
if(effect != null) Effects.effect(effect, x + Angles.x(), y + Angles.y());
|
||||||
|
Effects.shake(shake, shake, x, y);
|
||||||
|
Effects.sound(shootsound, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shoot(Player p, float x, float y, float angle){
|
void shoot(Player p, float x, float y, float angle){
|
||||||
shootInternal(p, x, y, angle);
|
shootInternal(p, x, y, angle);
|
||||||
|
|
||||||
if(Net.active() && p == Vars.player){
|
if(Net.active() && p == Vars.player){
|
||||||
@@ -121,8 +95,12 @@ public enum Weapon{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bullet(Entity owner, float x, float y, float angle){
|
void bullet(Entity owner, float x, float y, float angle){
|
||||||
vector.set(3, 0).rotate(angle);
|
Angles.translation(angle, 3f);
|
||||||
new Bullet(type, owner, x + vector.x, y + vector.y, angle).add();
|
new Bullet(type, owner, x + Angles.x(), y + Angles.y(), angle).add();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String localized(){
|
||||||
|
return Bundles.get("weapon."+name + ".name");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack stack(Item item, int amount){
|
private static ItemStack stack(Item item, int amount){
|
||||||
|
|||||||
Reference in New Issue
Block a user