Example #1
0
 public void AddNotification(string text, Hospital team = null, float time = 1.0f)
 {
     notification = new Notification(text, time);
     if (wordsDict.ContainsKey(text))
     {
         SoundManager.Play2DSound(wordsDict[text]);
     }
 }
Example #2
0
        public override void OnEnter()
        {
            dorfs = new List<Person>();
               players = new List<Player>();
               aiPlayers = new List<Player>();
               hospitals = new List<Hospital>() ;
            Bloom = new BloomPostprocess.BloomComponent(Game);

            Bloom.Initialize();
            Bloom.Settings = BloomPostprocess.BloomSettings.PresetSettings[5];
            IsInitialized = true;

            MapHeight = 40;
            MapWidth = 40;
            Player.defib = new Player.defibCallbackType(defib);
            online = false; // DO NOT CHANGE, offline mode is now detected when server connection is refused
            SoundManager.Content = Game.Content;
            Camera = new OrbitCamera(Game.GraphicsDevice, 0, 0, 0.001f, new Vector3(0, 15, 0), new Vector3(-10, 10, 0), (float)Math.PI * 0.25f, Game.GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000.0f);
            ComponentManager = new ComponentManager();
            ComponentManager.RootComponent = new LocatableComponent(ComponentManager, "root", null, Matrix.Identity, Vector3.Zero, Vector3.Zero);

            notification = null;
            particles = new ParticleManager(ComponentManager);

            EmitterData testData = new EmitterData();
            testData.AngularDamping = 1.0f;
            List<Point> frm = new List<Point>();
            frm.Add(new Point(0, 0));
            frm.Add(new Point(1, 0));
            frm.Add(new Point(0, 1));
            frm.Add(new Point(1, 1));
            testData.Animation = new Animation(Game.GraphicsDevice, Game.Content.Load<Texture2D>("electricity"),
                "electricity", 32, 32, frm, true, Color.White, 20f, 1.0f, 1.0f, false);
            testData.ConstantAccel = new Vector3(0, -1, 0);
            testData.LinearDamping = 0.9f;
            testData.AngularDamping = 0.9f;
            testData.EmissionFrequency = 1.0f;
            testData.EmissionRadius = 1.0f;
            testData.EmissionSpeed = 20.0f;
            testData.GrowthSpeed = -0.9f;
            testData.MaxAngle = 3.14159f;
            testData.MinAngle = 0.0f;
            testData.MaxParticles = 1000;
            testData.MaxScale = 1.0f;
            testData.MinScale = 0.1f;
            testData.MinAngular = -5.0f;
            testData.MaxAngular = 5.0f;
            testData.ParticleDecay = 0.1f;
            testData.ParticlesPerFrame = 0;
            testData.ReleaseOnce = true;
            testData.Texture = Game.Content.Load<Texture2D>("electricity");
            particles.RegisterEffect("shock", testData);

            ChargeCooldown = 1.0f;
            CurrentChargeCooldown = 1.0f;

            InputManager inputManager = new InputManager();
            InputManager.KeyPressedCallback += pressKey;
            InputManager.KeyReleasedCallback += releaseKey;

            sounds = new SoundManager();

            wordsDict = new Dictionary<string, string>();
            wordsDict.Add("MONSTER SAVE", "monstersave");
            wordsDict.Add("DOUBLE SAVE", "doublesave");
            wordsDict.Add("TRIPLE SAVE", "triplesave");

            drawer2D = new Drawer2D(Game.Content, Game.GraphicsDevice);

            client = new Client(online);
            string name = client.Connect();
            if (name == "error")
            {
                Console.Out.WriteLine("connection refused");
                name = "0";
                online = false;
            }

            Hospital hospital1 = new Hospital(new Vector3(-10, 0, -10), new Vector3(4, 2, 3), ComponentManager, Game.Content, Game.GraphicsDevice, "hospital", Color.Red, new Point(2, 0));
            Hospital hospital2 = new Hospital(new Vector3(12, 0, 12), new Vector3(4, 2, 3), ComponentManager, Game.Content, Game.GraphicsDevice, "hospital", Color.Blue, new Point(1, 0));
            hospitals.Add(hospital1);
            hospitals.Add(hospital2);

            Random r = new Random(1);
            for (int i = 0; i < 20; i++) // fnord
            {
                NPC npc;
                switch ((int)(detRand(r) * 3))
                {
                    case (0):
                        npc = new Smoker(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager,
                                        Game.Content, Game.GraphicsDevice);
                        break;
                    case (1):
                        npc = new Fatter(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager,
                                        Game.Content, Game.GraphicsDevice);
                        break;
                    case (2):
                        npc = new Older(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager,
                                        Game.Content, Game.GraphicsDevice);
                        break;
                    default:
                        /* graphics don't exist yet, never reached */
                        npc = new Worker(new Vector3(detRand(r) * 9, 5, detRand(r) * 10 - 0), ComponentManager,
                                        Game.Content, Game.GraphicsDevice);
                        break;
                }
                npc.velocityController.MaxSpeed = 1;
                npc.SetTag((i + 1000).ToString());
                int al = (int)(detRand(r) * 2);
                npc.Team = hospitals[al];
                npc.Velocity = new Vector3(0f, -0.5f, 0f);
                npc.HasMoved = true;
                dorfs.Add(npc);
            }

            player = new Player(name, new Vector3(hospital1.Component.LocalTransform.Translation.X + 5,
                hospital1.Component.LocalTransform.Translation.Y,
                hospital1.Component.LocalTransform.Translation.Z),
                                ComponentManager, Game.Content, Game.GraphicsDevice, "surgeonwalk");
            player.Velocity = new Vector3(0f, -0.5f, 0f);
            player.HasMoved = true;
            dorfs.Add(player);
            players.Add(player);

            if (!online)
            {
                aiPlayers.Add(new Player("1", new Vector3(hospital2.Component.LocalTransform.Translation.X - 5,
                    hospital2.Component.LocalTransform.Translation.Y,
                    hospital2.Component.LocalTransform.Translation.Z), ComponentManager, Game.Content, Game.GraphicsDevice, "surgeonwalk"));

                players.Add(aiPlayers.ElementAt(0));
                dorfs.Add(aiPlayers.ElementAt(0));

                aiPlayers.ElementAt(0).team = hospital2;

                VelocityController velocityController4 = new VelocityController(aiPlayers.ElementAt(0));
                velocityController4.IsTracking = true;
            }

            VelocityController velocityController3 = new VelocityController(player);
            velocityController3.IsTracking = true;

            Vector3 boundingBoxPos = new Vector3(0, -2, 0);
            Vector3 boundingBoxExtents = new Vector3(MapWidth, 4, MapHeight);
            Vector3 boundingBoxMin = boundingBoxPos - boundingBoxExtents * 0.5f;
            Vector3 boundingBoxMax = boundingBoxPos + boundingBoxExtents * 0.5f;

            ground = (LocatableComponent)EntityFactory.GenerateBlankBox(new BoundingBox(boundingBoxMin, boundingBoxMax), ComponentManager, Game.Content, Game.GraphicsDevice, "newground", Point.Zero, Point.Zero, 128, 128);

            if (Convert.ToInt32(name) % 2 == 0)
                player.team = hospital1;
            else
                player.team = hospital2;

            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);
            Shader = Game.Content.Load<Effect>("Hargraves");

            SunMap = Game.Content.Load<Texture2D>("sungradient");
            AmbientMap = Game.Content.Load<Texture2D>("ambientgradient");
            TorchMap = Game.Content.Load<Texture2D>("torchgradient");

            if (online)
            {
                AddNotification("Mash Space to Begin");
            }
            base.OnEnter();
        }
Example #3
0
        public Person(string _tag, Vector3 position,
            ComponentManager componentManager,
            ContentManager content,
            GraphicsDevice graphics,
            string spritesheet)
            : base(componentManager, "person", componentManager.RootComponent, Matrix.CreateTranslation(position),  new Vector3(0.5f, 1.0f, 0.5f),
            new Vector3(0.0f, -0.3f, 0.0f),  1.0f, 1.0f, 0.999f, 0.999f)
        {
            OrientWithVelocity = true;
            Texture2D sprites = content.Load<Texture2D>(spritesheet);
            tag = _tag;
            Tags.Add(tag);
            string name = "person";
            OrientWithVelocity = true;
            this.team = null;
            Score = 0.0f;
            AnimationState = new Dictionary<string,string>();
            IsSleeping = false;

            List<Point> offsets = new List<Point>();
            offsets.Add(new Point(0, 0));

            Point offset = offsets[RandomHelper.random.Next(0, offsets.Count)];

            List<Point> rightFrames = new List<Point>();
            rightFrames.Add(new Point(1 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(2 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(3 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(4 + offset.X, 0 + offset.Y));

            Animation walkRight = new Animation(graphics, sprites, name + "_walk_right", 32, 32, rightFrames, true, Color.White, 10.0f, 0.8f, 1, true);

            List<Point> leftFrames = new List<Point>();
            leftFrames.Add(new Point(1 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(2 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(3 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(4 + offset.X, 0 + offset.Y));

            Animation walkLeft = new Animation(graphics, sprites, name + "_walk_left", 32, 32, leftFrames, true, Color.White, 10.0f, 0.8f, 1, false);

            List<Point> rightFramesIdle = new List<Point>();
            rightFramesIdle.Add(new Point(0 + offset.X, 0 + offset.Y));

            Animation idleRight = new Animation(graphics, sprites, name + "_idle_right", 32, 32, rightFramesIdle, true, Color.White, 2.0f, 0.8f, 1, true);

            List<Point> leftFramesIdle = new List<Point>();
            leftFramesIdle.Add(new Point(0 + offset.X, 0 + offset.Y));

            Animation idleLeft = new Animation(graphics, sprites, name + "_idle_left", 32, 32, leftFramesIdle, true, Color.White, 2.0f, 0.8f, 1, false);

            walkLeft.Play();
            walkRight.Play();
            idleLeft.Play();
            idleRight.Play();

            Matrix spriteMatrix = Matrix.Identity;
            image = new OrientableBillboardSpriteComponent(componentManager, "idlesprite", this, spriteMatrix, sprites);
            OrientedAnimation idle = new OrientedAnimation(idleLeft, idleRight);
            image.AddOrientedAnimation(idle);
            AnimationState["idle"] = idle.Name;
            OrientedAnimation walk = new OrientedAnimation(walkLeft, walkRight);
            image.AddOrientedAnimation(walk);
            AnimationState["walk"] = walk.Name;

            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);
            //shadowTransform.Translation = new Vector3(0.0f, -0.31f, 0.0f);
            shadow = new ShadowComponent(componentManager, "shadow", this, shadowTransform, content.Load<Texture2D>("shadowcircle"));
            shadow.OrientsToCamera = false;
            List<Point> shP = new List<Point>();
            shP.Add(new Point(0, 0));
            Animation shadowAnimation = new Animation(graphics, content.Load<Texture2D>("shadowcircle"), "sh", 32, 32, shP, false, Color.White, 1, 0.7f, 0.7f, false);
            shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            shadow.SetCurrentAnimation("sh");

            Matrix teamTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);
            //shadowTransform.Translation = new Vector3(0.0f, -0.31f, 0.0f);
            ShadowComponent team = new ShadowComponent(componentManager, "team", this, shadowTransform, content.Load<Texture2D>("circle"));
            team.OrientsToCamera = false;
            List<Point> circleP = new List<Point>();
            circleP.Add(new Point(0, 0));
            Animation circleAnimation = new Animation(graphics, content.Load<Texture2D>("circle"), "teamcircle", 32, 32, shP, false, Color.Red, 1, 0.9f, 0.9f, false);
            team.AddAnimation(circleAnimation);
            circleAnimation.Play();
            team.SetCurrentAnimation("teamcircle");
            teamCircle = team;

            Tags.Add("Walker");

            velocityController = new VelocityController(this);
            velocityController.IsTracking = true;
        }