Exemplo n.º 1
0
    public void InstantiateProjectile(Schema.ProjectileCreated projectileCreated)
    {
        Debug.Log($"Projectile created at {projectileCreated.Position}");
        GameObject ball = Instantiate(Ball, projectileCreated.Position.ToInternal(), new Quaternion());

        ball.GetComponent <Rigidbody2D>().velocity = projectileCreated.Velocity.ToInternal();
    }
Exemplo n.º 2
0
    public void Game_CreateProjectile()
    {
        Game   game   = new Game();
        Client client = TestObjects.BuildClient();

        game.Players.Add(client);
        Vector2 position = new Vector2(1, 2);
        Vector2 velocity = new Vector2(-1, -1);

        game.Board.CreateProjectile(0, position, velocity, (int)ProjectileType.BouncingBall);
        game.Update(game.LastUpdateTime);
        Assert.IsTrue(game.Players[0].MessageLog.First.Value.Is(Schema.ProjectileCreated.Descriptor));
        Schema.ProjectileCreated createdMessage = game.Players[0].MessageLog.First.Value.Unpack <Schema.ProjectileCreated>();
        Projectile projectile = game.Board.Projectiles[0];

        Assert.AreEqual(position, projectile.Position);
        Assert.AreEqual(velocity, projectile.Velocity);

        Assert.AreEqual(1, game.Board.Projectiles.Count);
        CompareVectors(projectile.Position, createdMessage.Position);
        CompareVectors(projectile.Velocity, createdMessage.Velocity);
        Assert.AreEqual(projectile.Mass, createdMessage.Mass);
        Assert.AreEqual(projectile.Radius, createdMessage.Radius);
        Assert.AreEqual(0, createdMessage.Id);
        game.Board.CreateProjectile(0, new Vector2(1, 1), new Vector2(4, 5), (int)ProjectileType.BouncingBall);
        Assert.AreEqual(1, game.Board.Projectiles.Last().Id);

        game.Update(game.LastUpdateTime.AddSeconds(1));
        Assert.AreEqual(position + velocity, projectile.Position);

        game.Update(game.LastUpdateTime.AddSeconds(1));
        Assert.AreEqual(position + velocity * 2, projectile.Position);
    }
Exemplo n.º 3
0
    private void RequestProjectileCreation(Vector2 inputPosition)
    {
        Vector2 worldPosition = Camera.main.ScreenToWorldPoint(inputPosition);

        Debug.Log($"Requesting projectile be created at {worldPosition}");
        Schema.ProjectileCreated projectileCreated = new Schema.ProjectileCreated
        {
            Position = worldPosition.ToContract(),
            Velocity = Random.insideUnitCircle.ToContract(),
        };

        Managers.Client.SendMessage(Any.Pack(projectileCreated));
    }
Exemplo n.º 4
0
    public void Game_PlayerRequestsProjectile()
    {
        Game game = TestObjects.BuildFullRunningGame();

        Schema.ProjectileCreated projCreated = TestObjects.BuildPlayerCreatesProjectile(new Vector2(5, 6), new Vector2(1, 1), ProjectileType.BouncingBall);
        game.Players[0].ClientSendToServer(Any.Pack(projCreated));
        game.Update(game.LastUpdateTime);
        Schema.ProjectileCreated sentProjCreatedMessage = game.Players[0].MessageLog.First.Next.Value.Unpack <Schema.ProjectileCreated>();
        BouncingBall             dummyBouncingBall      = new BouncingBall(-1, new Vector2(), new Vector2());

        Assert.AreEqual(projCreated.Position, sentProjCreatedMessage.Position);
        Assert.AreEqual(projCreated.Velocity, sentProjCreatedMessage.Velocity);
        Assert.AreEqual(projCreated.Type, sentProjCreatedMessage.Type);
        Assert.AreEqual(dummyBouncingBall.Mass, sentProjCreatedMessage.Mass);
        Assert.AreEqual(dummyBouncingBall.Radius, sentProjCreatedMessage.Radius);
    }
Exemplo n.º 5
0
 private void CreateProjectile(Schema.ProjectileCreated projectileCreated)
 {
     this.Game.Board.CreateProjectile(this.PlayerId, projectileCreated.Position.ToInternal(), projectileCreated.Velocity.ToInternal(), projectileCreated.Type);
 }