mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-16 14:21:43 -08:00
Changed weapon to an upgrade
This commit is contained in:
parent
5480a92cbb
commit
cccf4a7e38
4 changed files with 83 additions and 83 deletions
|
|
@ -140,7 +140,7 @@ public class Control extends Module{
|
|||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"shootInternal", Input.MOUSE_LEFT,
|
||||
"shoot", 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,
|
||||
"shootInternal", Input.CONTROLLER_R_TRIGGER,
|
||||
"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class Player extends DestructibleEntity implements Syncable{
|
|||
private static final float dashSpeed = 1.8f;
|
||||
|
||||
public String name = "name";
|
||||
public transient Weapon weapon = Weapon.blaster;
|
||||
public Weapon weapon = Weapon.blaster;
|
||||
public Mech mech = Mech.standard;
|
||||
public float angle;
|
||||
public boolean isAndroid;
|
||||
|
|
@ -124,12 +124,11 @@ public class Player extends DestructibleEntity implements Syncable{
|
|||
vector.y += ya*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();
|
||||
|
||||
if(shooting && Timers.get(this, "reload", weapon.reload)){
|
||||
weapon.shoot(this, x, y, Angles.mouseAngle(x, y));
|
||||
Sounds.play(weapon.shootsound);
|
||||
if(shooting){
|
||||
weapon.update(player);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
|
@ -10,109 +7,86 @@ 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.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public enum Weapon{
|
||||
blaster(15, BulletType.shot){
|
||||
public class Weapon extends Upgrade{
|
||||
public static final Weapon
|
||||
|
||||
blaster = new Weapon("blaster", 15, BulletType.shot){
|
||||
{
|
||||
unlocked = true;
|
||||
}
|
||||
|
||||
@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);
|
||||
effect = Fx.shoot3;
|
||||
}
|
||||
},
|
||||
triblaster(13, BulletType.shot, stack(Item.iron, 40)){
|
||||
|
||||
@Override
|
||||
public void shootInternal(Player p, float x, float y, float rotation){
|
||||
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);
|
||||
|
||||
triblaster = new Weapon("blaster", 13, BulletType.shot){
|
||||
{
|
||||
shots = 3;
|
||||
effect = Fx.shoot;
|
||||
}
|
||||
},
|
||||
multigun(6, BulletType.multishot, stack(Item.iron, 60), stack(Item.steel, 20)){
|
||||
@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(8));
|
||||
|
||||
Effects.effect(Fx.shoot2, x + vector.x, y + vector.y);
|
||||
multigun = new Weapon("blaster", 6, BulletType.multishot){
|
||||
{
|
||||
effect = Fx.shoot2;
|
||||
inaccuracy = 8f;
|
||||
}
|
||||
},
|
||||
flamer(5, BulletType.flame, stack(Item.steel, 60), stack(Item.iron, 120)){
|
||||
|
||||
flamer = new Weapon("blaster", 5, BulletType.flame){
|
||||
{
|
||||
shootsound = "flame2";
|
||||
}
|
||||
|
||||
@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));
|
||||
inaccuracy = 12f;
|
||||
}
|
||||
},
|
||||
railgun(40, BulletType.sniper, stack(Item.steel, 60), stack(Item.iron, 60)){
|
||||
|
||||
railgun = new Weapon("blaster", 40, BulletType.sniper){
|
||||
{
|
||||
shootsound = "railgun";
|
||||
}
|
||||
|
||||
@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);
|
||||
effect = Fx.railshoot;
|
||||
}
|
||||
},
|
||||
mortar(100, BulletType.shell, stack(Item.titanium, 40), stack(Item.steel, 60)){
|
||||
|
||||
mortar = new Weapon("blaster", 100, BulletType.shell){
|
||||
{
|
||||
shootsound = "bigshot";
|
||||
}
|
||||
|
||||
@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);
|
||||
effect = Fx.mortarshoot;
|
||||
shake = 2f;
|
||||
}
|
||||
};
|
||||
public float reload;
|
||||
public BulletType type;
|
||||
public String shootsound = "shoot";
|
||||
public boolean unlocked;
|
||||
public ItemStack[] requirements;
|
||||
float reload;
|
||||
BulletType type;
|
||||
String shootsound = "shoot";
|
||||
int shots = 1;
|
||||
float inaccuracy = 0f;
|
||||
float shake = 0f;
|
||||
Effect effect;
|
||||
|
||||
public final String description;
|
||||
|
||||
Vector2 vector = new Vector2();
|
||||
|
||||
public String localized(){
|
||||
return Bundles.get("weapon."+name() + ".name");
|
||||
}
|
||||
public final String name;
|
||||
|
||||
private Weapon(float reload, BulletType type, ItemStack... requirements){
|
||||
private Weapon(String name, float reload, BulletType type){
|
||||
this.reload = reload;
|
||||
this.type = type;
|
||||
this.requirements = requirements;
|
||||
this.description = Bundles.getNotNull("weapon."+name()+".description");
|
||||
this.name = name;
|
||||
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){
|
||||
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);
|
||||
|
||||
if(Net.active() && p == Vars.player){
|
||||
|
|
@ -121,8 +95,12 @@ public enum Weapon{
|
|||
}
|
||||
|
||||
void bullet(Entity owner, float x, float y, float angle){
|
||||
vector.set(3, 0).rotate(angle);
|
||||
new Bullet(type, owner, x + vector.x, y + vector.y, angle).add();
|
||||
Angles.translation(angle, 3f);
|
||||
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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue