public BlueProjectile(World world, Vector2 position, Texture2D texture, Vector2 size, Vector2 cursPosition, CompositeCharacter player, CheckCollision collisionChecker)
     : base(world, position, texture, size, cursPosition, player, collisionChecker)
 {
     color = Color.Blue;
     speed = 200;
     damage = 100;
     delay = 5000;
 }
 public YellowProjectile(World world, Vector2 position, Texture2D texture, Vector2 size, Vector2 cursPosition, CompositeCharacter player, CheckCollision collisionChecker)
     : base(world, position, texture, size, cursPosition, player, collisionChecker)
 {
     color = Color.Yellow;
     speed = 500;
     damage = 20;
     manaCost = 20;
     delay = 500;
 }
Example #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public HUD(Game game, CompositeCharacter player, ContentManager content, SpriteBatch spriteBatch)
     : base(game)
 {
     this.game = game;
     this.player = player;
     this.spriteBatch = spriteBatch;
     health = content.Load<Texture2D>("HealthBar");
     mana = content.Load<Texture2D>("HealthBar");
     box = content.Load<Texture2D>("Box");
     crosshair = content.Load<Texture2D>("CrossHair");
     projectileIconYellow = content.Load<Texture2D>("projectile_fire_yellow");
     projectileIconBlue = content.Load<Texture2D>("projectile_fire_blue");
     projectileIconRed = content.Load<Texture2D>("projectile_fire_red");
     HUDfont = content.Load<SpriteFont>("gamefont");
     timerFont = content.Load<SpriteFont>("gamefont");
     timer = new RespawnTimer();
     gameTimer = new GameTimer();
 }
Example #4
0
        public Projectile(World world, Vector2 position, Texture2D texture, Vector2 size, Vector2 cursPosition, CompositeCharacter player, CheckCollision collisionChecker)
            : base(world, position, texture, size, 0f)
        {
            this.body.CollisionCategories = Category.Cat24;
            this.collisionChecker = collisionChecker;
            this.cursPosition = cursPosition;
            movements = cursPosition - position;
            if (movements != Vector2.Zero)
            {
                movements.Normalize();
            }

            float angle = (float)Math.Atan2( movements.Y, movements.X );
            movements = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));

            //ignore collision with the player shooting
            body.IgnoreCollisionWith(player.body);
            body.IgnoreCollisionWith(player.wheel);
            body.IgnoreGravity = true;
            body.IsBullet = true;
            body.LinearVelocity = movements + player.body.LinearVelocity;
            if(collisionChecker != null)
                body.OnCollision += new OnCollisionEventHandler(OnProjectileCollision);
        }
        private void ProcessData(byte[] data)
        {
            readStream.SetLength(0);
            readStream.Position = 0;//reset data

            readStream.Write(data, 0, data.Length);//read data
            readStream.Position = 0;
            Protocol p;
            while (readStream.Position != data.Length)
            {
                try
                {
                    p = (Protocol)reader.ReadByte();
                    /*if (GameScreen.isExiting)
                    {
                        System.Diagnostics.Debug.WriteLine
                    }*/
                    if (p == Protocol.Initialize)
                    {
                        id = reader.ReadByte();
                        //if (id == 0)
                        //    terrain.CreateRandomTerrain(new Vector2(0, 0));
                    }
                    else if (p == Protocol.Connected)
                    {
                        lock (client.GetStream())
                        {
                            terrainMaster = true;
                            foreach (byte otherID in playerMap.Keys)
                            {
                                if (otherID < this.id)
                                {
                                    terrainMaster = false;
                                    break;
                                }
                            }
                            //pindex++;
                            System.Diagnostics.Debug.WriteLine(pindex);
                            byte id = reader.ReadByte();
                            string ip = reader.ReadString();
                            ScreenManager.CharacterColor = Color.White;

                            CompositeCharacter newPlayer = new CompositeCharacter(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f),
                                    Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);
                            newPlayer.body.IgnoreGravity = true;
                            newPlayer.wheel.IgnoreGravity = true;
                            newPlayer.body.CollidesWith = Category.Cat24;
                            newPlayer.wheel.CollidesWith = Category.Cat24;
                            playerMap.Add(id, newPlayer);

                            writeStream.Position = 0;
                            writer.Write((byte)Protocol.AddCharacter);
                            writer.Write((byte)playerMap.Count);
                            SendData(GetDataFromMemoryStream(writeStream));
                            try
                            {
                                if (terrainMaster)
                                {
                                    writeStream.Position = 0;
                                    writer.Write((byte)Protocol.CreateTerrain);
                                    writer.Write(terrain.seed1);
                                    writer.Write(terrain.seed2);
                                    writer.Write(terrain.seed3);
                                    SendData(GetDataFromMemoryStream(writeStream));
                                }
                            }
                            catch (Exception e)
                            {

                            }
                        }
                    }

                    else if (p == Protocol.Disconnected)
                    {
                        //pindex--;
                        //System.Diagnostics.Debug.WriteLine(pindex);
                        byte id = reader.ReadByte();
                        string ip = reader.ReadString();
                        playerMap[id].Dispose();
                        playerMap.Remove(id);
                    }
                    else if (p == Protocol.Movement)
                    {
                        float px = reader.ReadSingle();
                        float py = reader.ReadSingle();
                        bool dead = reader.ReadBoolean();
                        Character.CharDirection dir = (Character.CharDirection)reader.ReadByte();
                        Character.CharState state = (Character.CharState)reader.ReadByte();
                        byte id = reader.ReadByte();
                        string ip = reader.ReadString();

                        playerMap[id].Dead = dead;
                        playerMap[id].Direction = dir;
                        playerMap[id].State = state;
                        playerMap[id].Position = new Vector2(px, py);
                    }
                    else if (p == Protocol.AddCharacter)
                    {
                        byte numPlayers = reader.ReadByte();
                        byte id = reader.ReadByte();
                        string ip = reader.ReadString();
                        CompositeCharacter newPlayer;
                        if (numPlayers != playerMap.Count)
                        {
                            newPlayer = new CompositeCharacter(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f),
                                Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);
                            newPlayer.body.IgnoreGravity = true;
                            newPlayer.wheel.IgnoreGravity = true;
                            newPlayer.body.CollidesWith = Category.Cat24;
                            newPlayer.wheel.CollidesWith = Category.Cat24;
                            playerMap.Add(id, newPlayer);
                        }
                    }
                    else if (p == Protocol.CreateTerrain)
                    {
                        if (!terrain.Created)
                        {
                            double s1 = reader.ReadDouble();
                            double s2 = reader.ReadDouble();
                            double s3 = reader.ReadDouble();
                            byte id = reader.ReadByte();
                            string ip = reader.ReadString();
                            terrain.CreateTerrain(new Vector2(0, 0), s1, s2, s3);
                        }
                    }
                    else if (p == Protocol.FireProjectile)
                    {
                        byte color = reader.ReadByte();
                        byte pId = reader.ReadByte();
                        float cx = reader.ReadSingle();
                        float cy = reader.ReadSingle();
                        float px = reader.ReadSingle();
                        float py = reader.ReadSingle();
                        byte id = reader.ReadByte();
                        string ip = reader.ReadString();
                        Projectile projectile;

                        switch (color)
                        {
                            case 0:
                                projectile = new YellowProjectile(world, new Vector2(px, py), projectileTexYellow,
                                    new Vector2(10f, 10f), new Vector2(cx, cy), playerMap[id]);
                                break;
                            case 1:
                                projectile = new RedProjectile(world, new Vector2(px, py), projectileTexRed,
                                    new Vector2(10f, 10f), new Vector2(cx, cy), playerMap[id]);
                                break;
                            case 2:
                                projectile = new BlueProjectile(world, new Vector2(px, py), projectileTexBlue,
                                    new Vector2(10f, 10f), new Vector2(cx, cy), playerMap[id]);
                                break;
                            default:
                                projectile = new Projectile(world, new Vector2(px, py), projectileTexYellow,
                                    new Vector2(10f, 10f), new Vector2(cx, cy), playerMap[id], null);
                                break;
                        }
                        projectile.id = ((id+1) * 100) + pId;
                        projectile.body.CollidesWith = Category.None;
                        projectiles.Add(projectile);
                    }

                    else if (p == Protocol.ModifyTerrain)
                    {
                        byte pId = reader.ReadByte();
                        float px = reader.ReadSingle();
                        float py = reader.ReadSingle();

                        byte id = reader.ReadByte();
                        string ip = reader.ReadString();

                        for (int i = 0; i < projectiles.Count; i++ )
                        {
                            if (projectiles[i].id == ((id + 1) * 100) + pId)
                            {
                                CheckCollision(projectiles[i]);
                                projectiles.RemoveAt(i);
                            }
                        }

                    }

                    oldP = p;
                }
                catch (Exception e)
                {

                }
            }
        }
 private void LaunchPlayer(CompositeCharacter player, Vector2 origin, float radius, int damage)
 {
     if (player.Position.X > origin.X - radius && player.Position.Y > origin.Y - radius && player.Position.X < origin.X + radius && player.Position.Y < origin.Y + radius)
     {
         Vector2 force = player.Position - origin;
         force = Vector2.Normalize(force) * 10;
         player.body.ApplyLinearImpulse(force);
         //Damage the player being hit
         player.Health -= (int)(Math.Abs(force.X) * damage + Math.Abs(force.Y) * damage);
     }
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            //read write stream to the server
            readStream = new MemoryStream();
            writeStream = new MemoryStream();

            reader = new BinaryReader(readStream);
            writer = new BinaryWriter(writeStream);
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            //DebugView Stuff
            Settings.EnableDiagnostics = true;
            DebugView = new DebugViewXNA(world);
            DebugView.LoadContent(ScreenManager.GraphicsDevice, Content);

            terrain.LoadContent(ScreenManager.GraphicsDevice);

            //Create camera using current viewport. Track a body without rotation.
            camera = new Camera2D(ScreenManager.GraphicsDevice);

            gameFont = Content.Load<SpriteFont>("gamefont");

            // Back ground stuff --------------------------------
            List<Texture2D> list = new List<Texture2D>();
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Sky"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("trees"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Grass"));
            skyLayer = new GameBackground(list, camera.Position)
            {
                Height = ScreenManager.GraphicsDevice.Viewport.Height,
                Width = ScreenManager.GraphicsDevice.Viewport.Width,
                SpeedX = 0.3f
            };
            //---------------------------------------------------

            Texture2D terrainTex = Content.Load<Texture2D>("ground");

            font = Content.Load<SpriteFont>("font");

            //Create player
            player = new CompositeCharacter(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f),
                Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);

            //Create HUD
            playerHUD = new HUD(ScreenManager.Game, player, ScreenManager.Game.Content, ScreenManager.SpriteBatch);
            ScreenManager.Game.Components.Add(playerHUD);

            client = new TcpClient();
            client.NoDelay = true;
            IPAddress ipadd = System.Net.IPAddress.Parse("169.254.169.231");
            client.Connect(ipadd, PORT);
            readBuffer = new byte[BUFFER_SIZE];
            client.GetStream().BeginRead(readBuffer, 0, BUFFER_SIZE, StreamReceived, null);

            Thread.Sleep(2000);

            if (id == 0)
            {
                terrain.CreateRandomTerrain(new Vector2(0, 0));
            }
            // Set camera to track player
            camera.TrackingBody = player.body;

            //Create walls
            leftWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(-100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));
            rightWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));

            ground = new StaticPhysicsObject(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 4.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f + 100), Content.Load<Texture2D>("platformTex"), new Vector2(2000f, 20f));
            // Load projectile and explosion textures
            projectileTexRed = Content.Load<Texture2D>("projectile_fire_red");
            projectileTexBlue = Content.Load<Texture2D>("projectile_fire_blue");
            projectileTexYellow = Content.Load<Texture2D>("projectile_fire_yellow");
            explosionTex = Content.Load<Texture2D>("explosion");

            // ----------------------------------------------------------

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            //DebugView Stuff
            Settings.EnableDiagnostics = true;
            DebugView = new DebugViewXNA(world);
            DebugView.LoadContent(ScreenManager.GraphicsDevice, Content);

            terrain.LoadContent(ScreenManager.GraphicsDevice);

            //Create camera using current viewport. Track a body without rotation.
            camera = new Camera2D(ScreenManager.GraphicsDevice);

            gameFont = Content.Load<SpriteFont>("gamefont");

            // Back ground stuff --------------------------------
            List<Texture2D> list = new List<Texture2D>();
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Sky"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("trees"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Grass"));
            skyLayer = new GameBackground(list, camera.Position)
            {
                Height = ScreenManager.GraphicsDevice.Viewport.Height,
                Width = ScreenManager.GraphicsDevice.Viewport.Width,
                SpeedX = 0.3f
            };
            //---------------------------------------------------

            Texture2D terrainTex = Content.Load<Texture2D>("ground");
            terrain.CreateRandomTerrain(new Vector2(0, 0));

            font = Content.Load<SpriteFont>("font");

            player = new CompositeCharacter(world, new Vector2(0, 0), Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);

            //Create HUD
            playerHUD = new HUD(ScreenManager.Game, player, ScreenManager.Game.Content, ScreenManager.SpriteBatch);
            ScreenManager.Game.Components.Add(playerHUD);

            // Set camera to track player
            camera.TrackingBody = player.body;

            //Create walls
            leftWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(-100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));
            rightWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));

            // Load projectile and explosion textures
            projectileTexRed = Content.Load<Texture2D>("projectile_fire_red");
            projectileTexBlue = Content.Load<Texture2D>("projectile_fire_blue");
            projectileTexYellow = Content.Load<Texture2D>("projectile_fire_yellow");
            explosionTex = Content.Load<Texture2D>("explosion");
            enemyTex = Content.Load<Texture2D>("enemy_new");

            // ----------------------------------------------------------

            // Sleep for the loading screen
            Thread.Sleep(500);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
 public BlueProjectile(World world, Vector2 position, Texture2D texture, Vector2 size, Vector2 cursPosition, CompositeCharacter player)
     : this(world, position, texture, size, cursPosition, player, null)
 {
 }
 public Input(CompositeCharacter character)
 {
     player = character;
 }
 public void IgnoreCollisionWith(CompositeCharacter player)
 {
     body.IgnoreCollisionWith(player.body);
     wheel.IgnoreCollisionWith(player.body);
     body.IgnoreCollisionWith(player.wheel);
     wheel.IgnoreCollisionWith(player.wheel);
 }