Featured image of post Revolver – Game Prototype

Revolver – Game Prototype

Turn based, bullet ricochet combat.

After having worked in a completely deterministic game framework on Stardust Battle. A lot of my Unity projects started to embrace those ideas. This project in particular was well suited for determinism, as, to accurately predict the future, you have to be certain that all objects will react in exactly the same way every time you run the simulation.

Predicting the Future

The idea of predicting the future is really fascinating. In code the algorithm goes something like this:

  1. Clone the model of the world.
  2. Shoot a bullet in the direction of the player towards the mouse.
  3. Tick the world 100 times.
  4. Destroy the clone, and go back to the original world.
  5. Show an overlay of what we saw in the future.

Source Code

public class World
{
	public int tickNum = 0;
	public int turnNum = 0;
	public GameState gameState = GameState.EnemyTurn;
	public Player player = new Player();
	public List<Bandit> bandits = new List<Bandit>();
	public List<Bullet> bullets = new List<Bullet>();
	public int nextBanditSpawnTick = 0;
	public int bulletHitsScore = 0;
	public List<Position> gizmos = new List<Position>();
	public Position wind = new Position(0.01f, 0.01f);
}

// The original model.
World model = new World();

void DrawPrediction()
{
    World clone = LogicService.CloneWorldWithoutBullets(model);

    LogicService.ShootBullet(clone, input.GetShootDir());

    for (int i = 0; i < 16; i++)
        LogicService.Tick(clone);

    // Draw the what you see.
}

Video

Last updated on Jan 31, 2021 21:38 UTC
Built with Hugo
Theme Stack designed by Jimmy