PvP game over condition
This commit is contained in:
@@ -153,8 +153,8 @@ public class Control extends Module{
|
||||
|
||||
threads.runGraphics(() -> {
|
||||
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
|
||||
ui.restart.show();
|
||||
state.set(State.menu);
|
||||
//the restart dialog can show info for any number of scenarios
|
||||
ui.restart.show(event);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.Teams;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
@@ -81,7 +82,23 @@ public class Logic extends Module{
|
||||
private void checkGameOver(){
|
||||
if(!state.mode.isPvp && state.teams.get(defaultTeam).cores.size == 0 && !state.gameOver){
|
||||
state.gameOver = true;
|
||||
Events.fire(new GameOverEvent());
|
||||
Events.fire(new GameOverEvent(waveTeam));
|
||||
}else if(state.mode.isPvp){
|
||||
Team alive = null;
|
||||
|
||||
for(Team team : Team.all){
|
||||
if(state.teams.get(team).cores.size > 0){
|
||||
if(alive != null){
|
||||
return;
|
||||
}
|
||||
alive = team;
|
||||
}
|
||||
}
|
||||
|
||||
if(alive != null && !state.gameOver){
|
||||
state.gameOver = true;
|
||||
Events.fire(new GameOverEvent(alive));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,11 @@ public class EventType{
|
||||
}
|
||||
|
||||
public static class GameOverEvent implements Event{
|
||||
public final Team winner;
|
||||
|
||||
public GameOverEvent(Team winner){
|
||||
this.winner = winner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public enum Team{
|
||||
none(Color.DARK_GRAY),
|
||||
@@ -18,4 +19,8 @@ public enum Team{
|
||||
this.color = color;
|
||||
intColor = Color.rgba8888(color);
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
return Bundles.get("team." + name() + ".name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.EventType.GameOverEvent;
|
||||
import io.anuke.mindustry.maps.Sector;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class RestartDialog extends FloatingDialog{
|
||||
private GameOverEvent event;
|
||||
|
||||
public RestartDialog(){
|
||||
super("$text.gameover");
|
||||
@@ -14,13 +16,25 @@ public class RestartDialog extends FloatingDialog{
|
||||
shown(this::rebuild);
|
||||
}
|
||||
|
||||
public void show(GameOverEvent event){
|
||||
this.event = event;
|
||||
show();
|
||||
}
|
||||
|
||||
void rebuild(){
|
||||
buttons().clear();
|
||||
content().clear();
|
||||
|
||||
buttons().margin(10);
|
||||
|
||||
if(world.getSector() == null){
|
||||
if(state.mode.isPvp){
|
||||
content().add(Bundles.format("text.gameover.pvp", event.winner.localized())).pad(6);
|
||||
buttons().addButton("$text.menu", () -> {
|
||||
hide();
|
||||
state.set(State.menu);
|
||||
logic.reset();
|
||||
}).size(130f, 60f);
|
||||
}else if(world.getSector() == null){
|
||||
if(control.isHighScore()){
|
||||
content().add("$text.highscore").pad(6);
|
||||
content().row();
|
||||
|
||||
Reference in New Issue
Block a user