Ejemplo n.º 1
0
 public BotPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player, StickFigure target)
     : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
 {
     this.player = player;
     this.hasTarget = false;
     attention_radius = 100;
     //this.ListStickFigures = list;
     this.target = target;
 }
Ejemplo n.º 2
0
 public BotPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player, StickFigure[] dudes)
     : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
 {
     this.player = player;
     this.target = null;
     attention_radius = 100;
     this.ListStickFigures = dudes;
     attention_countdown_max = 5f;
     attention_countdown = attention_countdown_max;
     attention_countdown_delta = 0.0075f;
 }
Ejemplo n.º 3
0
 public BotPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player, StickFigure[] dudes)
     : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
 {
     this.player = player;
     this.target = null;
     //attention_radius = 100;
     this.ListStickFigures = dudes;
     random = new Random();
     //if (nav == null) nav = new Pathfinding.NavAgent(this, mesh);
     move_countdown = 0.05f + 0.15f * (float)random.NextDouble(); // initial delay 0.05-0.25s
     melee_countdown = 0.1f + 0.5f * (float)random.NextDouble(); // initial delay 0.1-0.4s
     shoot_countdown = 0.2f + 0.5f * (float)random.NextDouble(); // initial delay 0.2-0.7s
 }
Ejemplo n.º 4
0
        public AiPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player, StickFigure[] dudes)
            : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
        {
            destinations = new List<Vector2>();
            this.player = player;
            this.target = null;
            this.ListStickFigures = dudes;
            random = new Random();
            if (nav == null) nav = new NavAgent(this);

            SetAttackTimeRange(100, 300); // milliseconds
            SetMissileTimeRange(250, 750);
            SetBombTimeRange(2000, 4000);
        }
Ejemplo n.º 5
0
        public SingleMap()
        {
            world = new World(new Vector2(0, 9.8f)); // That'd be cool to have gravity as a map property, so you could play 0G levels

            object[] map = Map.LoadCastle(world);
            background = (Texture2D)map[0];
            walls = (List<Wall>)map[1];
            spawnPoints = (Vector2[])map[2];
            Vector3[] ammoPoints = (Vector3[])map[3];
            ammo = new TrapAmmo[ammoPoints.Length];
            for (int i = 0; i < ammoPoints.Length; i++)
                ammo[i] = new TrapAmmo(world, new Vector2(ammoPoints[i].X, ammoPoints[i].Y) * MainGame.PIXEL_TO_METER, (int)ammoPoints[i].Z);

            testFigure1 = new LocalPlayer(world, spawnPoints[0] * MainGame.PIXEL_TO_METER, Category.Cat1, 1.5f, 1.0f, 1.0f, true, Color.Red, PlayerIndex.One);
        }
Ejemplo n.º 6
0
        public SingleMap(Color[] colors, string mapString, float gravity, int lives, float limbStrength, bool suddenDeath, bool traps, bool longRange, bool bots)
        {
            world = new World(new Vector2(0, gravity));
            this.limbStrength = limbStrength;
            this.suddenDeath = suddenDeath;

            MapData data = Map.LoadMap(world, mapString);
            background = data.background;
            walls = data.walls;
            spawnPoints = data.spawnPoints;
            Vector3[] ammoPoints = data.ammoPoints;
            ammo = new TrapAmmo[ammoPoints.Length];
            if (traps)
                for (int i = 0; i < ammoPoints.Length; i++)
                    ammo[i] = new TrapAmmo(world, new Vector2(ammoPoints[i].X, ammoPoints[i].Y) * MainGame.PIXEL_TO_METER, (int)ammoPoints[i].Z);
            music = data.music;
            MediaPlayer.Play(music);
            foreground = data.foreground;

            StickFigure.AllowTraps = traps;
            StickFigure.AllowLongRange = longRange;

            player = new StickFigure[bots ? 4 : colors.Length];
            this.info = new PlayerValues[bots ? 4 : colors.Length];
            enemies = new List<StickFigure>();
            toRemove = new Dictionary<StickFigure, int>();
            temp = new List<StickFigure>();
            winStick = null;

            for (int i = 0; i < colors.Length; i++)
                if (colors[i] != null)
                {
                    player[i] = new LocalPlayer(world, spawnPoints[i] * MainGame.PIXEL_TO_METER, Category.Cat1, 1.5f, limbStrength, suddenDeath ? 0.001f : 1f, false, colors[i], Players[i]);
                    player[i].LockControl = true;
                }

            for (int i = 0; i < info.Length; i++)
                info[i] = new PlayerValues(lives);

            maxEnemies = player.Length;
            kills = 0;
            millis = 0;
            startPause = 180;
            gameOver = false;
            enterPressed = true;
        }
Ejemplo n.º 7
0
        public SingleMap()
        {
            world = new World(new Vector2(0, 9.8f)); // That'd be cool to have gravity as a map property, so you could play 0G levels

            testFigure = new LocalPlayer(world, new Vector2(480 * MainGame.PIXEL_TO_METER, 480 * MainGame.PIXEL_TO_METER), Category.Cat1, Color.Red);
            dummyFigure = new StickFigure(world, new Vector2(150 * MainGame.PIXEL_TO_METER, 900 * MainGame.PIXEL_TO_METER), Category.Cat2, Color.Green);
            weapon = new TestWeapon(world, new Vector2(640 * MainGame.PIXEL_TO_METER, 480 * MainGame.PIXEL_TO_METER));
            walls = new List<Wall>();
            walls.Add(new Wall(world, 480 * MainGame.PIXEL_TO_METER, 700 * MainGame.PIXEL_TO_METER, 960 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 16 * MainGame.PIXEL_TO_METER, 540 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 1080 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 960 * MainGame.PIXEL_TO_METER, 1040 * MainGame.PIXEL_TO_METER, 1920 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1500 * MainGame.PIXEL_TO_METER, 960 * MainGame.PIXEL_TO_METER, 870 * MainGame.PIXEL_TO_METER, 120 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1450 * MainGame.PIXEL_TO_METER, 865 * MainGame.PIXEL_TO_METER, 248 * MainGame.PIXEL_TO_METER, 98 * MainGame.PIXEL_TO_METER, -(float)Math.PI / 6));
            walls.Add(new Wall(world, 1735 * MainGame.PIXEL_TO_METER, 840 * MainGame.PIXEL_TO_METER, 402 * MainGame.PIXEL_TO_METER, 176 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1904 * MainGame.PIXEL_TO_METER, 540 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 1080 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1859 * MainGame.PIXEL_TO_METER, 717 * MainGame.PIXEL_TO_METER, 109 * MainGame.PIXEL_TO_METER, 123 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1600 * MainGame.PIXEL_TO_METER, 570 * MainGame.PIXEL_TO_METER, 122 * MainGame.PIXEL_TO_METER, 104 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1320 * MainGame.PIXEL_TO_METER, 487 * MainGame.PIXEL_TO_METER, 113 * MainGame.PIXEL_TO_METER, 107 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 180 * MainGame.PIXEL_TO_METER, 300 * MainGame.PIXEL_TO_METER, 41 * MainGame.PIXEL_TO_METER, 370 * MainGame.PIXEL_TO_METER, 0.0f));

            bulletList = new List<Bullet>();
        }
        public void Update(World w)
        {
            if (state != State.SelectingPlayer && state != State.Ready)
                state = GetState();

            if (state == State.Keyboard)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    if (!joinPressed)
                    {
                        joinPressed = true;
                        usesKeyboard = true;
                        state = State.SelectingPlayer;
                    }
                }
                else
                    joinPressed = false;
            }
            else if (state == State.Controller)
            {
                if (GamePad.GetState(index).IsButtonDown(Buttons.A))
                {
                    if (!joinPressed)
                    {
                        joinPressed = true;
                        state = State.SelectingPlayer;
                    }
                }
                else
                    joinPressed = false;
            }
            else if (state == State.SelectingPlayer)
            {
                if (player == null)
                {
                    player = new StickFigure(w, (position + Vector2.UnitY * 200 + Vector2.UnitX * 250) * MainGame.PIXEL_TO_METER, Category.None, 3f, 1f, 1f, false, LocalPlayer.Colors[selectedColor]);
                    player.Invulnerability = 0;
                    player.Stand();
                }
                else
                {
                    player.Color = LocalPlayer.Colors[selectedColor];
                    player.Update();
                }

                bool pressingLeft, pressingRight, pressingBack;
                if (usesKeyboard)
                {
                    pressingLeft = Keyboard.GetState().IsKeyDown(Keys.Left);
                    pressingRight = Keyboard.GetState().IsKeyDown(Keys.Right);
                    pressingBack = Keyboard.GetState().IsKeyDown(Keys.Back) || Keyboard.GetState().IsKeyDown(Keys.Escape);
                }
                else
                {
                    pressingLeft = GamePad.GetState(index).IsButtonDown(Buttons.DPadLeft) || GamePad.GetState(index).IsButtonDown(Buttons.LeftThumbstickLeft);
                    pressingRight = GamePad.GetState(index).IsButtonDown(Buttons.DPadRight) || GamePad.GetState(index).IsButtonDown(Buttons.LeftThumbstickRight);
                    pressingBack = GamePad.GetState(index).IsButtonDown(Buttons.Back) || GamePad.GetState(index).IsButtonDown(Buttons.B);
                }

                if (pressingLeft)
                {
                    if (!leftPressed)
                    {
                        selectedColor = selectedColor == 0 ? LocalPlayer.Colors.Length - 1 : selectedColor - 1;
                        leftPressed = true;
                    }
                }
                else
                    leftPressed = false;

                if (pressingRight)
                {
                    if (!rightPressed)
                    {
                        selectedColor = selectedColor == LocalPlayer.Colors.Length - 1 ? 0 : selectedColor + 1;
                        rightPressed = true;
                    }
                }
                else
                    rightPressed = false;

                if (pressingBack)
                {
                    if (!backPressed)
                    {
                        backPressed = true;
                        usesKeyboard = false;
                        if (usesKeyboard)
                            state = State.Keyboard;
                        else
                            state = State.Controller;
                    }
                }
                else
                    backPressed = false;

                if ((!usesKeyboard && GamePad.GetState(index).IsButtonDown(Buttons.A)) || (usesKeyboard && Keyboard.GetState().IsKeyDown(Keys.Enter)))
                {
                    if (!joinPressed)
                    {
                        joinPressed = true;
                        state = State.Ready;
                    }
                }
                else
                    joinPressed = false;
            }
            else if (state == State.Ready)
            {
                bool pressingBack;
                if (usesKeyboard)
                    pressingBack = Keyboard.GetState().IsKeyDown(Keys.Escape) || Keyboard.GetState().IsKeyDown(Keys.Back);
                else
                    pressingBack = GamePad.GetState(index).IsButtonDown(Buttons.Back) || GamePad.GetState(index).IsButtonDown(Buttons.B);

                if (pressingBack)
                {
                    if (!backPressed)
                    {
                        state = State.SelectingPlayer;
                        backPressed = true;
                    }
                }
                else
                    backPressed = false;
            }
        }
Ejemplo n.º 9
0
        public GameScreen Update(GameTime gameTime)
        {
            for (int i = 0; i < player.Length; i++)
            {
                if (player[i] != null && info[i].HasLives())
                {
                    player[i].Update();
                    if (player[i].IsDead || player[i].Position.Y * MainGame.METER_TO_PIXEL > 1080)
                    {
                        if (info[i].RespawnTimer < 0)
                            info[i].Kill();

                        if (info[i].ShouldRespawn())
                        {
                            player[i].Destroy();
                            if (info[i].HasLives())
                                player[i] = player[i].Respawn();
                            else
                                player[i] = null;
                            info[i].RespawnTimer--;
                        }
                        else
                            info[i].RespawnTimer--;
                    }
                }
            }

            // Update ammo
            foreach (TrapAmmo t in ammo)
                if (t != null)
                    t.Update();

            // Endgame
            if (!gameOver)
            {
                gameOver = true;
                winners.Clear();
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].Lives > 0)
                    {
                        winners.Add(i);
                        if (winners.Count >= 2)
                        {
                            gameOver = false;
                            winners.Clear();
                            break;
                        }
                    }
                }

                if (timed && !gameOver)
                {
                    millisLeft -= gameTime.ElapsedGameTime.Milliseconds;
                    if (millisLeft <= 0)
                    {
                        gameOver = true;
                        winners.Add(0);
                        for (int i = 1, max = info[0].Lives; i < info.Length; i++)
                        {
                            if (info[i].Lives > max)
                            {
                                winners.Clear();
                                winners.Add(i);
                                max = info[i].Lives;
                            }
                            else if (info[i].Lives == max)
                                winners.Add(i);
                        }
                    }
                }
            }
            else
            {
                if (winStick == null)
                {
                    winStick = new StickFigure(world, new Vector2(600, 500) * MainGame.PIXEL_TO_METER, Category.None, 3f, 1, 1, false, player[winners[0]].Color);
                    winStick.Stand();
                }
                winStick.Update();
                winStick.ApplyForce(world.Gravity * -1);

                if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start)))
                    return GoBack();
            }

            world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);
            return this;
        }
Ejemplo n.º 10
0
 private void ResetTarget()
 {
     float closestDist = 999f, dist;
     foreach (StickFigure s in ListStickFigures)
     {
         if (s != this && !s.IsDead && (s.CollisionCategory != this.collisionCat) && !IsRaycast(s.Position))
         {
             if ((this.target != null) && (s is BotPlayer) && (float)random.NextDouble() < 0.25f)
             {
                 continue; // sometimes prefer humans
             }
             dist = (s.Position - this.Position).Length();
             if (((float)random.NextDouble() < 0.6f) && (dist < closestDist))
             {
                 closestDist = dist; // sometimes not pick the closest guy
                 this.target = s;
             }
         }
     }
 }
Ejemplo n.º 11
0
        public override void Update()
        {
            if (!IsDead)
            {
                bool stand = true;
                // get target

                if (this.target == null)// || (this.target is BotPlayer))
                {
                    float closestDist = 999f, dist;
                    Random r = new Random();
                    // May pick nearest stick figure, or nearest player-controlled stick figure.
                    // Makes the game more challenging.
                    if (r.Next(10) > 4)
                    {
                        foreach (StickFigure s in ListStickFigures)
                        {
                            if (s != this && !s.IsDead && (s.CollisionCategory != this.collisionCat))
                            {
                                dist = (s.Position - this.Position).Length() + (float)r.NextDouble() * 1.5f;
                                if (dist < closestDist)
                                {
                                    closestDist = dist;
                                    this.target = s;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (StickFigure s in ListStickFigures)
                        {
                            if (!(s is BotPlayer) && !s.IsDead && (s.CollisionCategory != this.collisionCat))
                            {
                                dist = (s.Position - this.Position).Length() + (float)r.NextDouble() * 1.5f;
                                if (dist < closestDist)
                                {
                                    closestDist = dist;
                                    this.target = s;
                                }
                                // check collisioncat
                                /*  if ((s.Position - this.Position).Length() <= attention_radius)
                                  {
                                      this.hasTarget = true;
                                      this.target = s;
                                      break;
                                  }*/
                            }
                        }
                    }

                }
                else if (this.target.IsDead)
                {
                    this.target = null;
                }
                else
                {
                    if (target.Position.X > this.Position.X)
                    {
                        WalkRight();
                        stand = false;
                    }
                    else if (target.Position.X <= this.Position.X)
                    {
                        WalkLeft();
                        stand = false;
                    }
                    if (target.Position.Y < this.Position.Y - 4)
                    {
                        Jump();
                        stand = false;
                    }

                    if ((target.Position - this.Position).Length() < 1) // ADJUST AS NEEDED
                    {
                        if (target.Position.X > this.Position.X)
                        {
                            Punch(0);
                        }
                        else
                        {
                            Punch(MathHelper.Pi);
                        }
                    }
                    else if (((target.Position - this.Position).Length() < 2.5) && // ADJUST AS NEEDED
                        (target.Position.Y > this.Position.Y))
                    {
                        if (target.Position.X > this.Position.X)
                        {
                            Kick(0);
                        }
                        else
                        {
                            Kick(MathHelper.Pi);
                        }
                    }
                }

                if (stand)
                    Stand();

                // After doing stuff, determine whether should check for better target
                if (attention_countdown <= 0)
                {
                    this.target = null;
                    attention_countdown = attention_countdown_max;
                }
                else
                {
                    attention_countdown -= attention_countdown_delta; // how to normalize this to actual game time?
                }
            }
            base.Update();
        }
Ejemplo n.º 12
0
 private void GetNewTarget()
 {
     float mindist = float.MaxValue;
     float dist;
     this.target = ListStickFigures[0];
     foreach (StickFigure s in ListStickFigures)
     {
         if (s != this && !s.IsDead && (s.CollisionCategory != this.collisionCat))
         {
             dist = 1; // estimate path distance
             if (dist < mindist)
             {
                 mindist = dist;
                 this.target = s;
             }
         }
     }
 }
Ejemplo n.º 13
0
        public GameScreen Update(GameTime gameTime)
        {
            startPause--;
            if (startPause == 0)
            {
                foreach (StickFigure s in player)
                    if (s != null)
                        s.LockControl = false;
            }

            for (int i = 0; i < player.Length; i++)
            {
                if (player[i] != null && info[i].HasLives())
                {
                    player[i].Update();
                    if (player[i].IsDead)
                    {
                        if (info[i].RespawnTimer < 0)
                            info[i].Kill();

                        if (info[i].ShouldRespawn())
                        {
                            player[i].Destroy();
                            if (info[i].HasLives())
                                player[i] = player[i].Respawn();
                            else
                                player[i] = null;
                            info[i].RespawnTimer--;
                        }
                        else
                            info[i].RespawnTimer--;
                    }
                }
            }

            foreach (StickFigure s in enemies)
            {
                s.Update();
                if (s.IsDead && !toRemove.ContainsKey(s))
                {
                    if (!gameOver)
                        kills++;
                    toRemove.Add(s, 255);
                }
            }
            temp.Clear();
            foreach (StickFigure s in from StickFigure s in toRemove.Keys select s)
                if (!temp.Contains(s))
                    temp.Add(s);
            foreach (StickFigure s in temp)
            {
                toRemove[s]--;
                if (toRemove[s] <= 0)
                {
                    enemies.Remove(s);
                    toRemove.Remove(s);
                    s.Destroy();
                }
            }

            if (enemies.Count - toRemove.Count < (int)maxEnemies && startPause < 0)
            {
                enemies.Add(new BotPlayer(world, new Vector2(new Random().Next(1000) + 460, 0) * MainGame.PIXEL_TO_METER, Category.Cat2, 1.5f, this.limbStrength, suddenDeath ? 0.001f : 0.4f, true, Color.White, PlayerIndex.Four, player));
                enemies[enemies.Count - 1].Invulnerability = 0;
            }

            // Update ammo
            foreach (TrapAmmo t in ammo)
                if (t != null)
                    t.Update();

            // Endgame
            if (!gameOver)
            {
                if (maxEnemies < 4)
                    maxEnemies += 0.0002f;
                if (startPause < 0)
                    millis += gameTime.ElapsedGameTime.Milliseconds;
                gameOver = GameIsOver();

                if (Keyboard.GetState().IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                    enterPressed = true;
            }
            else
            {
                if (winStick == null)
                {
                    winStick = new StickFigure(world, new Vector2(960, 440) * MainGame.PIXEL_TO_METER, Category.None, 3f, 1, 1, true, Color.White);
                    winStick.Invulnerability = 0;
                    winStick.Stand();
                }

                if (winStick != null)
                {
                    winStick.Update();
                    winStick.ApplyForce(world.Gravity * -1);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                {
                    if (!enterPressed)
                        return GoBack();
                }
                else
                    enterPressed = false;
            }

            world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);
            return this;
        }