Inheritance: Entity
示例#1
0
        public BallControl(Ballz game, Session match, Ball ball)
        {
            Game = game;
            Match = match;
            Ball = ball;

            KeyPressed[InputMessage.MessageType.ControlsAction] = false;
            KeyPressed[InputMessage.MessageType.ControlsUp] = false;
            KeyPressed[InputMessage.MessageType.ControlsDown] = false;
            KeyPressed[InputMessage.MessageType.ControlsLeft] = false;
            KeyPressed[InputMessage.MessageType.ControlsRight] = false;
        }
示例#2
0
 public UserControl(Ballz game, Session match, Ball ball):
     base(game, match, ball)
 {
     AvailableWeapons.Add(new Weapons.Potato(ball, game));
     AvailableWeapons.Add(new Weapons.Grenade(ball, game));
     AvailableWeapons.Add(new Weapons.RopeTool(ball, game));
     AvailableWeapons.Add(new Weapons.Bazooka(ball, game));
     AvailableWeapons.Add(new Weapons.Pistol(ball, game));
     AvailableWeapons.Add(new Weapons.Waterbomb(ball, game));
     AvailableWeapons.Add(new Weapons.Drill(ball, game));
     Weapon = AvailableWeapons[SelectedWeaponIndex];
     Ball.HoldingWeapon = AvailableWeapons[SelectedWeaponIndex].Icon;
 }
示例#3
0
文件: Worms.cs 项目: SpagAachen/Ballz
        protected override Session ImplStartSession(Ballz game, GameSettings settings, bool remoteControlled, int localPlayerId)
        {
            var session = new Session(game, new World(new Terrain(settings.MapTexture)), settings)
                              {
                                  UsePlayerTurns = this.UsePlayerTurns,
                                  Terrain = new Terrain(settings.MapTexture)
                              };

            FindSpawnPoints(settings.MapTexture, session.Terrain.Scale);

            var spawnPoints = SelectSpawnpoints(settings.Teams.Select(t=>t.NumberOfBallz).Sum());

            // Create players and Ballz
            var currBallCreating = 0;
            foreach (var team in settings.Teams)
            {
                var player = new Player
                {
                    Id = team.Id,
                    Name = team.Name,
                    TeamName = team.Country,
                    IsLocal = !remoteControlled || localPlayerId == team.Id
                };

                session.Players.Add(player);

                var ballCount = UsePlayerTurns ? team.NumberOfBallz : 1;
                var ballNames = TeamNames.GetBallNames(team.Country, ballCount);

                for (var i = 0; i < ballCount; ++i)
                {
                    var playerBall = new Ball
                    {
                        Name = ballNames[i],
                        Position = spawnPoints[currBallCreating],
                        Velocity = new Vector2(0, 0),
                        IsAiming = true,
                        Player = player,
                        HoldingWeapon = "Bazooka",
                        IsStatic = false
                    };
                    player.OwnedBalls.Add(playerBall);
                    ++currBallCreating;
                    session.World.AddEntity(playerBall);

                    BallControl controller;

                    if (team.ControlledByAI)
                        controller = new AIControl(game, session, playerBall);
                    else
                        controller = new UserControl(game, session, playerBall);

                    session.SessionLogic.BallControllers[playerBall] = controller;

                }

                player.ActiveBall = player.OwnedBalls.FirstOrDefault();
                session.SessionLogic.ActiveControllers[player] = session.SessionLogic.BallControllers[player.ActiveBall];
            }

            return session;
        }
示例#4
0
 public void AddPlayer(Player player, Ball ball)
 {
     BallControllers[player] = new BallControl(Game, Game.Match, ball);
 }
示例#5
0
		public Waterbomb(Ball ball, Ballz game) : base(ball, game) { }
示例#6
0
        public override bool Update(float elapsedSeconds, World.World worldState)
        {
            base.Update(elapsedSeconds, worldState);

            if (Ball.IsAlive)
            {
                _shootCooldown -= elapsedSeconds;

                if (_shootCooldown <= 0f)
                {
                    if (_currentTarget == null || _currentTarget.Disposed || _currentTarget.Health <= 0)
                    {
                        _currentTarget = (Ball)worldState.Entities
                            .FirstOrDefault(e => e is Ball
                                && ((Ball)e).Player != Ball.Player
                                && ((Ball)e).Health > 0);
                        _currentTarget =
                                worldState.Entities.Aggregate(
                                    (curMin, x) => (x as Ball)?.Player != Ball.Player && (curMin == null || (Ball.Position - x.Position).LengthSquared() < (Ball.Position - curMin.Position).LengthSquared()) ? x : curMin) as Ball;
                    }

                    if (_currentTarget != null)
                    {
                        Ball.IsAiming = false;
                        Ball.IsCharging = false;
                        var curCharge = 0.01f;
                        float o = 0;
                        while (curCharge < 0.5f)
                        {
                            var g = 9.81f; // gravity
                            var v = curCharge * 25f; // velocity
                            var x = _currentTarget.Position.X - Ball.Position.X; // target x
                            var y = _currentTarget.Position.Y - Ball.Position.Y; // target y
                            var s = v * v * v * v - g * (g * (x * x) + 2 * y * (v * v)); //substitution

                            if (s < 0)
                            {
                                curCharge += 0.01f;
                                continue;
                            }
                            o = (float)Math.Atan2(v * v + Math.Sqrt(s), g * x); // launch angle
                            Ball.IsAiming = true;
                            Ball.IsCharging = true;
                            break;
                        }

                        if (!Ball.IsAiming)
                        {
                            Ball.HoldingWeapon = "HandGun";
                            Ball.AimDirection = Vector2.Normalize(_currentTarget.Position - Ball.Position);
                            var muzzle = SpriteGraphicsEffect.CreateMuzzle(
                                Game.Match.GameTime,
                                Ball.Position + 2f * Ball.AimDirection,
                                Ball.AimDirection.RotationFromDirection()
                                );
                            Game.Match.World.GraphicsEvents.Add(muzzle);

                            var rayHit = Game.Match.Physics.Raycast(Ball.Position, Ball.Position + Ball.AimDirection * 1000f);
                            if (rayHit.HasHit)
                            {
                                const float explosionRadius = 0.3f;
                                const float damage = 25f;
                                Game.Match.World.StaticGeometry.SubtractCircle(rayHit.Position.X, rayHit.Position.Y, explosionRadius);
                                Ballz.The().Match.World.GraphicsEvents.Add(SpriteGraphicsEffect.CreateExplosion(Ballz.The().Match.GameTime, rayHit.Position, 0, 0.2f));
                                var theBall = rayHit.Entity as Ball;
                                if (theBall?.Health > 0)
                                    theBall.ChangeHealth(-damage);
                            }
                            _shootCooldown = PauseBetweenShots;
                            return true;
                        }
                        Ball.HoldingWeapon = "Bazooka";

                        Ball.AimDirection = Vector2.UnitX.Rotate(o);

                        if (Ball.ShootCharge > curCharge)
                        {
                            Shot newShot = new Shot
                            {
                                ExplosionRadius = 3.0f,
                                HealthDecreaseFromExplosionImpact = 25,
                                HealthDecreaseFromProjectileHit = 10,
                                ShotType = Shot.ShotType_T.Normal,
                                ExplosionDelay = 0.0f,
                                Recoil = 1.0f,
                                Position = Ball.Position + Ball.AimDirection * (Ball.Radius + 0.101f),
                                Velocity = Ball.AimDirection * curCharge * 25f,
                            };
                            Game.Match.World.AddEntity(newShot);

                            Ball.PhysicsBody.ApplyForce(-10000 * Ball.ShootCharge * newShot.Recoil * Ball.AimDirection);

                            Ball.ShootCharge = 0f;
                            _shootCooldown = PauseBetweenShots;
                            return true;
                        }
                    }
                    else
                    {
                        Ball.IsAiming = false;
                    }
                }
                else
                {
                    Ball.IsCharging = false;
                }
            }

            return false;
        }
示例#7
0
 public Pistol(Ball ball, Ballz game)
     : base(ball, game)
 {
 }
示例#8
0
 public Potato(Ball ball, Ballz game) : base(ball, game) { }
示例#9
0
 public AIControl(Ballz game, Session match, Ball ball)
     : base(game, match, ball)
 {
     pistol = new Pistol(ball, game);
     bazoo = new Bazooka(ball, game);
 }
示例#10
0
        /// <summary>
        ///     Draw the game for the specified _time.
        /// </summary>
        /// <param name="time">time since start of game (cf BallzGame draw).</param>
        public override void Draw(GameTime time)
        {
            using (new PerformanceReporter(Game))
            {
                base.Draw(time);
                var worldState = Game.Match.World;
                WaterRenderer.PrepareDrawWater(Game.Match.World);
                //GraphicsDevice.SetRenderTarget(WorldRenderTarget);

                Game.Camera.UseBoundary = true;
                Game.Camera.BottomLeftBoundary = new Vector2(-100f, 0f);
                Game.Camera.TopRightBoundary = new Vector2(100f, 100f);

                if (Game.Match.UsePlayerTurns && Game.Match.ActivePlayer?.ActiveBall != null)
                {
                    CurrentActiveBall = Game.Match.ActivePlayer?.ActiveBall;

                    if (CurrentActiveBall != null && Game.Match.TurnState == TurnState.Running && Game.Match.ActivePlayer?.ActiveBall != CurrentActiveBall && Game.Match.ActivePlayer?.ActiveBall != null)
                    {
                        CurrentActiveBall = Game.Match.ActivePlayer.ActiveBall;
                        Game.Camera.SwitchTarget(CurrentActiveBall.Position, time);
                    }
                    else if (Game.Match.FocussedEntity != null)
                    {
                        Game.Camera.SetTargetPosition((Vector2)Game.Match.FocussedEntity.Position, time);
                    }
                }
                else
                {
                    Game.Camera.SetView(Matrix.CreateOrthographicOffCenter(0, 40, 0, 40 / Game.GraphicsDevice.Viewport.AspectRatio, -20, 20));
                }

                var shakeEffect = worldState.GraphicsEvents.FirstOrDefault(e => e is CameraShakeEffect) as CameraShakeEffect;
                if(shakeEffect != null)
                {
                    var intensity = (1 - shakeEffect.GetProgress(Game.Match.GameTime)) * shakeEffect.Intensity;
                    var offSetX = (float)(random.NextDouble() * 0.02 - 0.01) * intensity;
                    var offSetY = (float)(random.NextDouble() * 0.02 - 0.01) * intensity;
                    var view = Game.Camera.View;
                    view.Translation += new Vector3(offSetX, offSetY, 0);
                    Game.Camera.View = view;
                }

                DrawSky();

                //////////////////////////////////////////////////////////////////////////////////////////////
                // Draw Water
                //////////////////////////////////////////////////////////////////////////////////////////////

                WaterRenderer.DrawWater(worldState);

                //////////////////////////////////////////////////////////////////////////////////
                // Draw the Terrain
                //////////////////////////////////////////////////////////////////////////////////

                BallEffect.View = Game.Camera.View;
                BallEffect.Projection = Game.Camera.Projection;

                var tris = worldState.StaticGeometry.GetTriangles();
                VertexPositionColorTexture[] vpc = new VertexPositionColorTexture[tris.Count * 3];

                int i = 0;

                float TerrainTextureScale = 0.015f;

                var terrainSize = new Vector2(worldState.StaticGeometry.width, worldState.StaticGeometry.height);

                foreach (var t in tris)
                {
                    vpc[i + 0].Color = Color.Maroon;
                    vpc[i + 0].Position = new Vector3(t.A.X, t.A.Y, -1);
                    vpc[i + 0].TextureCoordinate = new Vector2(t.A.X, t.A.Y) / terrainSize;
                    vpc[i + 1].Color = Color.Maroon;
                    vpc[i + 1].Position = new Vector3(t.B.X, t.B.Y, -1);
                    vpc[i + 1].TextureCoordinate = new Vector2(t.B.X, t.B.Y) / terrainSize;
                    vpc[i + 2].Color = Color.Maroon;
                    vpc[i + 2].Position = new Vector3(t.C.X, t.C.Y, -1);
                    vpc[i + 2].TextureCoordinate = new Vector2(t.C.X, t.C.Y) / terrainSize;
                    i += 3;
                }

                Matrix terrainWorld = Matrix.CreateScale(worldState.StaticGeometry.Scale);
                TerrainEffect.CurrentTechnique.Passes[0].Apply();
                
                TerrainEffect.Parameters["ModelViewProjection"].SetValue(terrainWorld * Game.Camera.View * Game.Camera.Projection);
                TerrainEffect.Parameters["TerrainTypesTexture"].SetValue(worldState.StaticGeometry.GetTerrainTypeTexture());
                TerrainEffect.Parameters["EarthTexture"].SetValue(EarthTexture);
                TerrainEffect.Parameters["SandTexture"].SetValue(SandTexture);
                TerrainEffect.Parameters["StoneTexture"].SetValue(StoneTexture);
                TerrainEffect.Parameters["TextureScale"].SetValue(TerrainTextureScale);
                //TerrainEffect.Parameters["TerrainSize"].SetValue(terrainSize);

                GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.TriangleList, vpc, 0, tris.Count);

                ///////////////////////////////////////////////////////////////////////////////////
                // Draw Ballz and shots
                ///////////////////////////////////////////////////////////////////////////////////

                var blending = new BlendState
                {
                    AlphaSourceBlend = Blend.SourceAlpha,
                    AlphaDestinationBlend = Blend.InverseSourceAlpha,
                    ColorSourceBlend = Blend.SourceAlpha,
                    ColorDestinationBlend = Blend.InverseSourceAlpha,
                };

                SpriteBatch.Begin(blendState: blending);
                foreach (var entity in worldState.Entities)
                {
                    if (entity.Disposed)
                        continue;

                    var ball = entity as Ball;
                    if (ball != null)
                        DrawBall(ball);
                    var shot = entity as Shot;
                    if (shot != null)
                        DrawShot(shot);
                }

                foreach(var graphicsEvent in worldState.GraphicsEvents)
                {
                    DrawGraphicsEvent(graphicsEvent);
                }

                SpriteBatch.End();              

                GraphicsDevice.SetRenderTarget(null);
                
                PostProcess();

                DrawStatusOverlay();

                if (Ballz.The().MessageOverlay != null)
                {
                    DrawMessageOverlay(Ballz.The().MessageOverlay);
                }
            }
        }
示例#11
0
        public void DrawBall(Ball ball)
        {
            if (ball.AttachedRope != null)
                DrawRope(ball.AttachedRope);

            BallEffect.DiffuseColor = Vector3.One;
            if(ball.Player.TeamName != null)
                BallEffect.Texture = TeamTextures[ball.Player.TeamName];

            Matrix world = Matrix.CreateRotationY((float)(2 * Math.PI * ball.ViewRotation * 50f / 360f)) * Matrix.CreateTranslation(new Vector3(ball.Position, 0));
            BallEffect.World = world;
            GraveEffect.World = world * Matrix.CreateScale(0.3f);

            if (ball.Health > 0)
            {
                BallModel.Draw(world, Game.Camera.View, Game.Camera.Projection);

                var aimTarget = ball.Position + ball.AimDirection * 2;
                var aimTargetScreen = WorldToScreen(aimTarget);
                var aimRotation = ball.AimDirection.RotationFromDirection();

                var effects =  SpriteEffects.None;

                if (!string.IsNullOrEmpty(ball.HoldingWeapon))
                {
                    var weaponRotation = aimRotation;
                    if (ball.AimDirection.X < 0)
                    {
                        effects = SpriteEffects.FlipHorizontally;
                        weaponRotation += (float)Math.PI;
                    }

                    var weaponPosScreen = WorldToScreen(ball.Position - new Vector2(0, 0.33f));
                    var weaponTexture = Game.Content.Load<Texture2D>("Textures/" + ball.HoldingWeapon);
                    var weaponTextureScale = 256f / weaponTexture.Width * (float)Game.Window.ClientBounds.Width / 1920f; //assume the weapon texture was designed for full HD 1080p resolution

                    // Draw weapon
                    SpriteBatch.Draw(weaponTexture, position: weaponPosScreen, color: Color.White, rotation: weaponRotation, scale: new Vector2(weaponTextureScale, weaponTextureScale), origin: new Vector2(weaponTexture.Width / 2f, weaponTexture.Height / 2f), effects: effects);

                }

                if (ball.IsAiming && (!Game.Match.UsePlayerTurns || ball == Game.Match.ActivePlayer?.ActiveBall))
                {
                    int width = (int)(ball.ShootCharge * 100);
                    var aimIndicator = ball.Position + ball.AimDirection * 2.1f;
                    var aimIndicatorScreen = WorldToScreen(aimIndicator);
                    var aimIndicatorSize = new Vector2(width, 20);

                    if (ball.ShootCharge > 0)
                    {
                        var chargeColor = GetChargeColor(ball.ShootCharge);

                        // Draw charge indicator
                        SpriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: new Vector2(100, 20), color: new Color(Color.Black, (int)(64*ball.ShootCharge)), rotation: aimRotation, origin: new Vector2(0, 0.5f));
                        SpriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: aimIndicatorSize, color: new Color(chargeColor), rotation: aimRotation, origin: new Vector2(0, 0.5f));
                    }
                    // Draw crosshair
                    SpriteBatch.Draw(CrosshairTexture, position: aimTargetScreen, color: Color.White, rotation: aimRotation, origin: new Vector2(16, 16));
                }
            }
            else // Player is dead
            {
                GraveModel.Draw(world, Game.Camera.View, Game.Camera.Projection);
            }
            
            var screenPos = WorldToScreen(ball.Position + new Vector2(0, 2.5f));

            DrawText(ball.Health.ToString("0"), screenPos, 0.5f, Color.White, 1, true, true);
            screenPos += new Vector2(0, 25) * resolutionFactor;
            DrawText(ball.Name, screenPos, 0.5f, Color.LawnGreen, 1, true, true);
            screenPos += new Vector2(0, 25) * resolutionFactor;
            DrawText(ball.Player.Name, screenPos, 0.33f, Color.LawnGreen, 1, true, true);

            if (Game.Match.UsePlayerTurns && Game.Match.TurnState == TurnState.Running && Game.Match.ActivePlayer == ball.Player && ball.Player.ActiveBall == ball)
            {
                // Show turn-indicator for a couple of seconds only
                if (Game.Match.TurnTime < 4)
                {
                    screenPos -= new Vector2(0, resolutionFactor *(30 + (float)(15 * Math.Sin(5 * ElapsedTime.TotalSeconds))));
                    SpriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/RedArrow"), screenPos, color: Color.White, origin: new Vector2(29, 38));
                }
            }
        }
示例#12
0
 public ChargedProjectileWeapon(Ball ball, Ballz game)
     : base(ball, game)
 {
 }
示例#13
0
 public WeaponControl(Ball ball, Ballz game)
 {
     Ball = ball;
     Game = game;
 }
示例#14
0
        public void DrawBall(Ball ball)
        {
            BallEffect.DiffuseColor = Vector3.One;

            Vector2 nV = ball.Direction;
            Matrix world = Matrix.CreateRotationY((float)(2 * Math.PI * 50 * nV.X / 360.0)) * Matrix.CreateTranslation(new Vector3(ball.Position, 0));
            BallEffect.World = world;
            GraveEffect.World = world * Matrix.CreateScale(0.3f);

            if (ball.Health > 0)
            {
                BallModel.Draw(world, Game.Camera.View, Game.Camera.Projection);

                var aimTarget = ball.Position + ball.AimDirection * 2;
                var aimTargetScreen = WorldToScreen(aimTarget);
                var aimRotation = ball.AimDirection.RotationFromDirection();

                var effects =  SpriteEffects.None;

                if (!String.IsNullOrEmpty(ball.HoldingWeapon))
                {
                    var weaponRotation = aimRotation;
                    if (ball.AimDirection.X < 0)
                    {
                        effects = SpriteEffects.FlipHorizontally;
                        weaponRotation += (float)Math.PI;
                    }

                    var weaponPosScreen = WorldToScreen(ball.Position - new Vector2(0, 0.33f));
                    var weaponTexture = Game.Content.Load<Texture2D>("Textures/" + ball.HoldingWeapon);

                    // Draw weapon
                    spriteBatch.Draw(weaponTexture, position: weaponPosScreen, color: Color.White, rotation: weaponRotation, origin: new Vector2(32, 32), effects: effects);
                }

                if (ball.IsAiming)
                {
                    int width = (int)(ball.ShootCharge * 100);
                    var aimIndicator = ball.Position + ball.AimDirection * 2.1f;
                    var aimIndicatorScreen = WorldToScreen(aimIndicator);
                    var aimIndicatorSize = new Vector2(width, 20);

                    if (ball.ShootCharge > 0)
                    {
                        var chargeColor = GetChargeColor(ball.ShootCharge);

                        // Draw charge indicator
                        spriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: new Vector2(100, 20), color: new Color(Color.Black, (int)(64*ball.ShootCharge)), rotation: aimRotation, origin: new Vector2(0, 0.5f));
                        spriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: aimIndicatorSize, color: new Color(chargeColor), rotation: aimRotation, origin: new Vector2(0, 0.5f));
                    }
                    // Draw crosshair
                    spriteBatch.Draw(CrosshairTexture, position: aimTargetScreen, color: Color.White, rotation: aimRotation, origin: new Vector2(16, 16));
                }
            }
            else // Player is dead
            {
                GraveModel.Draw(world, Game.Camera.View, Game.Camera.Projection);
            }
            
            var screenPos = WorldToScreen(ball.Position + new Vector2(0, 2f));

            DrawText(ball.Player.Name, screenPos, 0.5f, Color.LawnGreen, 1, true, true);
            screenPos += new Vector2(0, 20);
            DrawText(ball.Health.ToString("0"), screenPos, 0.5f, Color.White, 1, true, true);
        }