Пример #1
0
        public void newBullet()
        {
            BulletObject objBullet = new BulletObject();

            objBullet.Init(Position, bullet, angle);
            bullets.Add(objBullet);
        }
Пример #2
0
        private BulletObject initBullet(string[] ann)
        {
            BulletObject blt = new BulletObject();

            blt.Init(new Vector2(Convert.ToInt32(Convert.ToInt32(ann[3]) * rapportoLarghezzaClientServer), Convert.ToInt32(Convert.ToInt32(ann[4]) * rapportoAltezzaClientServer)), Content.Load <Texture2D>("bulletMin"), (float)Convert.ToDouble(ann[5]));
            blt.Id = Convert.ToInt32(ann[1]);
            bullets.Add(blt);

            /*var time = new myTimer(blt, 10);
             * time.Elapsed += myTimerTick;
             * time.Start();
             */
            return(blt);
        }
Пример #3
0
        private BulletObject initBullet(GameObject app, string[] ann, int id)
        {
            BulletObject blt = new BulletObject();

            blt.Init(new Vector2(app.Position.X, app.Position.Y), Content.Load <Texture2D>("bulletMin"), (float)Convert.ToDouble(ann[1]));
            blt.Id     = id;
            blt.IdTank = app.Id;
            bullets.Add(blt);

            /*var time = new myTimer(blt, 30000);
             * time.Elapsed += myTimerServerTick;
             * time.Start();*/

            return(blt);
        }
Пример #4
0
        private int BulletsCollision(BulletObject blt, out int life)
        {
            life = -1;
            foreach (GameObject g in players.Where(x => x.Id != blt.IdTank))
            {
                //gestione collisioni
                if (blt.TankColliding(g))
                {
                    life = g.Health - 50;

                    return(g.Id);
                }
            }

            if (blt.Position.X <= 0 || blt.Position.X + blt.BoundingBox.Width >= larghezzaSchermoServer + costante ||
                blt.Position.Y <= 0 || blt.Position.Y + blt.BoundingBox.Height >= altezzaSchermoServer + costante)
            {
                return(-1);
            }

            return(-2);
        }
Пример #5
0
 public myTimer(BulletObject blt, int interval)
 {
     base.Interval = interval;
     this.Blt      = blt;
     this.lifeTime = 0;
 }
Пример #6
0
 public void removeBullet(BulletObject bullet)
 {
     bullets.Remove(bullet);
 }
Пример #7
0
        private void Analisi(Pacchetto pkt)
        {
            GameObject   app;
            BulletObject blt;
            string       pos;

            var ann = new String[1];

            ann[0] = pkt.Msg;

            if (pkt.Msg.Contains(';'))
            {
                ann = pkt.Msg.Split(';');
            }

            switch (ann[0])
            {
            case "l":
                if (serverStatus)
                {
                    Send(new Pacchetto("srv;" + myAddress, pkt.Address));
                }

                break;

            case "srv":     //messaggi dal server
                switch (ann[1])
                {
                case "acc":         //gaming true o comunque sono in partita
                    initMyPlayer(Convert.ToInt32(ann[2]));
                    break;

                case "ref":
                    //rimango nel menu, gli spazi sono pieni oppure sono gia all'interno
                    break;

                case "str":
                    //gaming = true;
                    break;

                default:
                    lTimer.Stop();
                    serverAddress = pkt.Address;
                    //operazione che eseguo solo adesso in testing
                    if (serverTick != 0)
                    {
                        Send(new Pacchetto("r;" + username, serverAddress));
                    }

                    serverTick = 0;
                    break;
                }
                break;

            case "r":
                if (serverStatus)
                {
                    if (players.Count < postiMax && (players.FirstOrDefault(x => x.Username == ann[1] && x.Address == pkt.Address)) == null)     //ann[1] username
                    {
                        app = new GameObject();
                        players.Add(app);
                        app.InitEnemy(new Vector2(100, 400), Content.Load <Texture2D>("tankEnemy"), Content.Load <Texture2D>("bulletMin"), ann[1], pkt.Address, players.IndexOf(app));
                        Send(new Pacchetto("srv;acc;" + app.Id, pkt.Address));
                        Send(new Pacchetto(app.Id + ";pos;" + app.ToString(), pkt.Address));
                        SendPlayersInformation(app);
                        SendPlayerInformation(app);
                    }
                    else
                    {
                        Send(new Pacchetto("srv;ref", pkt.Address));
                    }
                }

                break;

            case "ang":
                if (serverStatus)
                {
                    app = players.FirstOrDefault(x => x.Address == pkt.Address);
                    if (app != null)
                    {
                        app.angle = (float)Convert.ToDouble(ann[1]);
                        foreach (GameObject tnk in players)
                        {
                            Send(new Pacchetto(app.Id + ";pos;" + app.ToString(), tnk.Address));
                        }
                    }
                }

                break;

            case "for":
                if (serverStatus)
                {
                    app = players.FirstOrDefault(x => x.Address == pkt.Address);
                    if (app != null)
                    {
                        app.angle = (float)Convert.ToDouble(ann[1]);
                        pos       = app.moveForward();
                        if (VerifyMovement(pos))
                        {
                            //e a tutti quelli all'interno della lobby
                            foreach (GameObject tnk in players)
                            {
                                Send(new Pacchetto(app.Id + ";pos;" + app.ToString(), tnk.Address));
                            }
                        }
                    }
                }
                break;

            case "bck":
                if (serverStatus)
                {
                    app = players.FirstOrDefault(x => x.Address == pkt.Address);
                    if (app != null)
                    {
                        app.angle = (float)Convert.ToDouble(ann[1]);
                        pos       = app.moveBack();
                        if (VerifyMovement(pos))
                        {
                            foreach (GameObject tnk in players)
                            {
                                Send(new Pacchetto(app.Id + ";pos;" + pos, tnk.Address));
                            }
                        }
                    }
                }

                break;

            case "dct":
                if (serverStatus)
                {
                    app = players.FirstOrDefault(x => x.Address == pkt.Address);
                    if (app != null)
                    {
                        players.Remove(app);

                        foreach (GameObject tnk in players.Where(x => x.Id != myId))
                        {
                            Send(new Pacchetto(app.Id + ";dct", tnk.Address));
                        }
                    }
                }

                break;

            case "fire":
                if (serverStatus)
                {
                    app = players.FirstOrDefault(x => x.Address == pkt.Address);
                    if (app != null)
                    {
                        int id = bullets.Count == 0 ? 0 : bullets[bullets.Count - 1].id + 1;

                        blt = new BulletObject();
                        blt.Init(new Vector2(app.Position.X, app.Position.Y), Content.Load <Texture2D>("bulletMin"), (float)Convert.ToDouble(ann[1]));
                        blt.id = id;
                        bullets.Add(blt);
                        time          = new myTimer(blt, 50);
                        time.Elapsed += myTimerTick;
                        time.Start();

                        foreach (GameObject tnk in players.Where(x => x.Id != myId))
                        {
                            Send(new Pacchetto("blt;" + blt.id + ";crt;" + blt.ToString(), tnk.Address));
                        }
                    }
                }

                break;

            case "user":
                app = new GameObject();
                players.Add(app);
                app.InitEnemy(new Vector2(100, 400), Content.Load <Texture2D>("tankEnemy"), Content.Load <Texture2D>("bulletMin"), ann[2], pkt.Address, Convert.ToInt32(ann[1]));
                break;

            case "blt":
                blt = bullets.FirstOrDefault(x => x.id == Convert.ToInt32(ann[1]));

                if (blt != null)
                {
                    if (ann[2] == "wtr")
                    {
                        bullets.Remove(blt);
                    }
                    else
                    {
                        if (ann[2] == "pos")
                        {
                            blt.Position = new Vector2(Convert.ToInt32(ann[3]), Convert.ToInt32(ann[4]));
                            blt.angle    = (float)Convert.ToDouble(ann[5]);
                        }
                    }
                }
                else
                {
                    if (ann[2] == "crt")
                    {
                        blt = new BulletObject();
                        blt.Init(new Vector2(Convert.ToInt32(ann[3]), Convert.ToInt32(ann[4])), Content.Load <Texture2D>("bulletMin"), (float)Convert.ToDouble(ann[5]));
                        blt.id = Convert.ToInt32(ann[1]);
                        bullets.Add(blt);
                    }
                }

                break;

            default:
                //metto qua i controlli per i vari giocatori, controllo se esiste in primis, lato client
                app = players.FirstOrDefault(x => x.Id == Convert.ToInt32(ann[0]));
                if (players.Contains(app))
                {
                    if (ann[1] == "pos")
                    {
                        app.Position = new Vector2(Convert.ToInt32(ann[2]), Convert.ToInt32(ann[3]));
                        app.angle    = (float)Convert.ToDouble(ann[4]);
                    }
                    else
                    {
                        if (ann[1] == "dct")
                        {
                            players.Remove(app);
                        }
                        else
                        {
                            if (ann[1] == "win")
                            {
                                //vittoria del giocatore ID
                            }
                        }
                    }
                }

                break;
            }
        }