Example #1
0
        private bool HandleNewBalloon(NewBalloonMessage nbm)
        {
            lock(m_screens) {
                if(m_bubbles.ContainsKey(nbm.BalloonID)) {
                    // Balloon already present !
                    return true;
                }
                if(m_screens.Count == 0) {
                    // No screen to display balloon -- sad
                    return true;
                }

                int screen_idx = m_random.Next(m_screens.Count);
                m_bubbles[nbm.BalloonID] = new ServerBalloon(nbm.BalloonID);
                m_screens[screen_idx].EnqueueMessage(nbm, this);
            }
            return true;
        }
Example #2
0
        private bool HandleNewBalloon(NewBalloonMessage nbm)
        {
            if(m_bubbles.ContainsKey(nbm.ObjectID)) {
                // Balloon already present !
                Trace.WriteLine(String.Format("Balloon {0} already present!", nbm.ObjectID));
                return true;
            }
            if(m_screens.Count == 0) {
                // No screen to display balloon -- sad
                return true;
            }

            ServerBalloon balloon = new ServerBalloon(nbm.ObjectID);
            m_bubbles[nbm.ObjectID] = balloon;
            // choose a random screen
            int screen_idx = m_random.Next(m_screens.Count);

            // Notify screen with new ballon message
            balloon.Screen = m_screens[screen_idx];
            balloon.Screen.Connection.SendMessage(nbm);

            return true;
        }
Example #3
0
        private bool HandleScreenDisconnected(DisconnectedMessage msg)
        {
            Screen s = msg.Sender as Screen;
            if(s == null)
            {
                return true;
            }
            Trace.WriteLine(String.Format("Screen disconnected: {0}", s.ID));

            // Gets screen's balloons
            var balloons = BallonsOnScreen(s.ID);
            // Gets left and right screens
            Screen left = GetPreviousScreen(s);
            Screen right = GetNextScreen(s);
            if(left == s || right == s) {
                // if next or previous screen are equal to current screen
                // it means that this was the last screen left
                m_bubbles.Clear();
                m_planes.Clear();
            } else {
                foreach(ServerBalloon balloon in balloons)
                {
                    // Choose randomly between left or right screen
                    int random = m_random.Next(2);
                    Screen newScreen = null;
                    NewBalloonMessage nbm = null;
                    if(random == 0) {
                        newScreen = left;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Right,
                                                    0.1f, Configuration.BalloonVelocityLeft);
                    } else {
                        newScreen = right;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Left,
                                                    0.1f, Configuration.BalloonVelocityRight);
                    }
                    balloon.Screen = newScreen;
                    if(newScreen != null)
                    {
                        newScreen.Connection.SendMessage(nbm);
                    }
                }

                // Remove any plane present in the screen
                foreach (ServerPlane plane in m_planes.Values)
                {
                    // Use enqueue so that the map isn't changed during iteration
                    EnqueueMessage(new PopObjectMessage(plane.ID));
                }
            }
            m_screens.Remove(s);
            return true;
        }
        private void HandleNewBalloon(NewBalloonMessage nbm)
        {
            // ask the server to send the balloon's content
            if (!balloonCache.ContainsKey(nbm.BalloonID))
            {
                balloonCache.Add(nbm.BalloonID, new Balloon(nbm.BalloonID));
                m_conn.SendMessage(new GetBalloonContentMessage(nbm.BalloonID));
            }

            // ask the server to send up-to-date state
            // TODO: only do this if the details have been changed
            m_conn.SendMessage(new GetBalloonStateMessage(nbm.BalloonID));
        }
        public void OnNewBalloon(NewBalloonMessage m)
        {
            // Choose where to place the balloon
            Vector2 position = new Vector2();
            switch (m.Direction)
            {
                case Direction.Left:
                    position.X = ClientBalloon.BalloonWidth * -1;
                    break;
                case Direction.Right:
                    position.X = ClientBalloon.BalloonWidth + screenDimensions.X;
                    break;

                case Direction.Any:
                default:
                    position.X = rng.Next((int)screenDimensions.X);
                    break;
            }

            position.Y = m.Y * screenDimensions.Y;

            // Setup the balloon's body
            Vector2 velocity = new Vector2(m.Velocity.X, m.Velocity.Y);
            WorldEntity balloonEntity = physicsManager.CreateBalloon(position, velocity);

            Balloon balloon = NetworkManager.GetBalloonDetails(m.BalloonID);
            ClientBalloon b = new ClientBalloon(balloon);
            b.Texture = balloonTextures[balloon.Type][balloon.OverlayType];
            b.BalloonContentCache = contentBox.GetBalloonContent(b.ID);

            // Render the balloon's caption if we already have it
            if (!String.IsNullOrWhiteSpace(b.Label))
            {
                contentBox.GenerateCaption(b);
            }

            balloons.Add(b.ID, b);
            balloonEntities[b] = balloonEntity;
        }
Example #6
0
        private bool HandleScreenDisconnected(DisconnectedMessage msg)
        {
            Screen s = msg.Sender as Screen;
            if(s == null)
            {
                return true;
            }
            Trace.WriteLine(String.Format("Screen disconnected: {0}", s.ID));

            // Gets screen's balloons
            var balloons = s.Balloons;
            // Gets left and right screens
            Screen left = GetPreviousScreen(s);
            Screen right = GetNextScreen(s);
            if(left == s || right == s) {
                // if next or previous screen are equal to current screen
                // it means that this was the last screen left
                m_bubbles.Clear();
            } else {
                foreach(ServerBalloon balloon in balloons.Values)
                {
                    // Choose randomly between left or right screen
                    int random = m_random.Next(1);
                    Screen newScreen = null;
                    NewBalloonMessage nbm = null;
                    if(random == 0) {
                        newScreen = left;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Right,
                                                    0.1f, Configuration.VelocityLeft);
                    } else {
                        newScreen = right;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Left,
                                                    0.1f, Configuration.VelocityRight);
                    }
                    balloon.Screen = newScreen;
                    if(newScreen != null)
                    {
                        newScreen.Balloons.Add(nbm.BalloonID, balloon);
                        newScreen.Connection.SendMessage(nbm);
                    }
                }
            }
            m_screens.Remove(s);
            return true;
        }
Example #7
0
        private bool HandleNewBalloon(NewBalloonMessage nbm)
        {
            if(m_bubbles.ContainsKey(nbm.BalloonID)) {
                // Balloon already present !
                Trace.WriteLine(String.Format("Balloon {0} already present!", nbm.BalloonID));
                return true;
            }
            if(m_screens.Count == 0) {
                // No screen to display balloon -- sad
                return true;
            }

            ServerBalloon balloon = new ServerBalloon(nbm.BalloonID);
            m_bubbles[nbm.BalloonID] = balloon;
            if(m_screens.Count > 0 )
            {
                // choose a random screen
                int screen_idx = m_random.Next(m_screens.Count);
                Screen screen = null;
                if((0 <= screen_idx) || (screen_idx < m_screens.Count))
                {
                    screen = m_screens[screen_idx];
                }
                if(screen == null)
                {
                    Trace.WriteLine(String.Format(
                        "Warning: random screen ID out of bounds: {0} ({1} screens)",
                        screen_idx, m_screens.Count));
                    return true;
                }
                balloon.Screen = screen;
                screen.Balloons.Add(nbm.BalloonID, balloon);
                screen.Connection.SendMessage(nbm);
            }
            else
            {
                balloon.Screen = null;
            }

            return true;
        }
Example #8
0
        public void OnNewBalloon(NewBalloonMessage m)
        {
            // Choose where to place the balloon
            Vector2 position = new Vector2();
            switch (m.Direction)
            {
                case Direction.Left:
                    position.X = balloonTexture.Width * -1;
                    break;
                case Direction.Right:
                    position.X = balloonTexture.Width + screenDimensions.X;
                    break;

                case Direction.Any:
                default:
                    position.X = new Random().Next((int)screenDimensions.X);
                    break;
            }

            position.Y = m.Y * screenDimensions.Y;

            // Setup the balloon's body.
            Body balloonBody = BodyFactory.CreateCircle(_world, 128f / (2f * MeterInPixels), 1f, PixelToWorld(position));
            balloonBody.BodyType = BodyType.Dynamic;
            balloonBody.Restitution = 0.3f;
            balloonBody.Friction = 0.5f;
            balloonBody.LinearDamping = 1.0f;

            Vector2 velocity = new Vector2(m.Velocity.X, m.Velocity.Y);
            balloonBody.ApplyLinearImpulse(velocity * balloonBody.Mass);

            ClientBalloon b = new ClientBalloon(m.BalloonID, balloonBody);
            balloons.Add(b.ID, b);
        }