Example #1
0
        public void Update(Game1 game)
        {
            int input = GetInput();

            if (OneDirectionTimer > 0) {
                if (OneDirectionMask == 0)
                    OneDirectionMask = input;
                input &= OneDirectionMask;
            }

            if (ConfuseTimer > 0)
                input = ((input & 1) << 1) | ((input & 2) >> 1);

            UpdatePowerUps(game);

            float rot = RotationSpeed;
            if (SlowTurnTimer > 0) rot /= 3;

            if ((input & 0x2) != 0) // turn left
                Angle -= rot;
            if ((input & 0x1) != 0) // turn right
                Angle += rot;

            Vector2 speed = new Vector2(0, 0);
            speed.X = (float)(Math.Cos(Angle) * CurrentSpeed);
            speed.Y = (float)(Math.Sin(Angle) * CurrentSpeed);

            Position += speed;

            if (WallhackTimer > 0)
            {
                Vector2 deltaPos = new Vector2(0, 0);
                if (Position.X > Game1.ScreenWidth)
                    deltaPos.X = -Game1.ScreenWidth;
                if (Position.X < 0)
                    deltaPos.X = +Game1.ScreenWidth;
                if (Position.Y > Game1.ScreenHeight)
                    deltaPos.Y = -Game1.ScreenHeight;
                if (Position.Y < 0)
                    deltaPos.Y = +Game1.ScreenHeight;

                if (deltaPos != Vector2.Zero)
                {
                    LayWall(game, true);
                    Position += deltaPos;
                    LastPos += deltaPos;
                    OlderPos += deltaPos;
                }
            }

            foreach (Wall wall in game.Walls)
            {
                if ((WallhackTimer > 0) && (wall.Owner == null))
                    continue;

                if ((game.Ticks - wall.LayTime < 30 && wall.IsOwner(this)) || (WallhackTimer > 0))
                    continue;

                Vector2 e, f, g;
                float l, skait, var;
                f = wall.p2 - wall.p1;
                e = Position - wall.p1;
                g = OlderPos - Position;

                skait = f.X * e.Y - e.X * f.Y;
                var = g.X * f.Y - f.X * g.Y;

                if (Math.Abs(var) > 0.001)
                {
                    l = skait / var;
                    float l1 = (e.X * g.Y - g.X * e.Y) / -var;

                    if (l1 >= 0 && l1 <= 1 && l >= 0 && l <= 1 && game.WinningTeam == null)
                    {
                        Position = wall.p1 + e + g * l;
                        game.Walls.Add(new Wall(LastPos, Position, Color, game.Ticks, this));
                        this.Dead = true;
                        Team.UpdateAliveStatus();
                        game.AddScore(Team);
                        Team.TestIfEnded(game);
                        return;
                    }
                }
            }

            if (LayWallDelay < 0)
            {
                LastPos = OlderPos = Position;
            }

            LayWallDelay++;
            GapTimer--;
            if (LayWallDelay > 6)
            {
                LayWall(game, false);
                OlderPos = LastPos;
                LastPos = Position;
                LayWallDelay = 0;
            }
            else if (GapTimer < 0)
            {
                GapTimer = game.rnd.Next(800) + 80;
                LayWall(game, true);
                OlderPos = LastPos = Position;
                LayWallDelay = -8;
            }

            if (PartyTimer > 0)
                for (int i = 0; i < 30 / game.Players.Count; i++)
                    DropParticle(game, Position);
        }