示例#1
0
        // === load things... ==============
        protected override void LoadContent()
        {
            //========== GRAPHICS ==============================================

            // set viewport to size of screen, dependant on fullscreen/windowed
            if (graphics.IsFullScreen == true)
            {
                GraphicsDevice.Viewport = new Viewport(0, 0, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width,
                                                GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
            }
            else
            {
                GraphicsDevice.Viewport = new Viewport(0, 0, Screen.PrimaryScreen.WorkingArea.Width - borderSpace,
                                                                Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace);
            }

            // find maximum size of render field with 16:9 aspect ratio when full screen

            width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            height = (int)(width / aspectRatio);

            if (height > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)
            {
                height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                width = (int)(height * aspectRatio);
            }

            xScale = (float)((double)width / (double)targetWidth);
            yScale = (float)((double)height / (double)targetHeight);

            xOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - width) / 2.0);
            yOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - height) / 2.0);

            // find maximum size of render field with 16:9 aspect ratio when windowed

            wheight = Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace;
            wwidth = (int)(wheight * aspectRatio);

            if (wwidth > Screen.PrimaryScreen.WorkingArea.Width - borderSpace)
            {
                wwidth = Screen.PrimaryScreen.WorkingArea.Width - borderSpace;
                wheight = (int)(wwidth / aspectRatio);
            }

            wxScale = (float)((double)wwidth / (double)targetWidth);
            wyScale = (float)((double)wheight / (double)targetHeight);

            wxOffset = (int)((Screen.PrimaryScreen.WorkingArea.Width - borderSpace - wwidth) / 2.0);
            wyOffset = (int)((Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace - wheight) / 2.0);

            // set viewport to this maximum render size, dependent on fullscreen/windowed
            if (graphics.IsFullScreen == true)
            {
                GraphicsDevice.Viewport = new Viewport(xOffset, yOffset, width, height);
            }

            if (graphics.IsFullScreen == false)
            {
                GraphicsDevice.Viewport = new Viewport(wxOffset, wyOffset, wwidth, wheight);

                var form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
                form.Location = new System.Drawing.Point(0, 0);
            }

            // spritebatch

            spriteBatch = new SpriteBatch(GraphicsDevice);

            // ========= GAME OBJECTS ================================================

            // fonts

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

            // grid

            grid = new Grid(3600, 1750, 450, 20, 20, new Vector2(-850, 1070), true);
            reachable = new ReachableArea(grid, floorObjectList);

            // counters
            research = new NumericalCounter("Research", new Vector2(25, 15), 0, 100, 0, 0, counterFont, Color.Green, Color.Green, Content.Load<Texture2D>("counter_box"));
            madness = new NumericalCounter("Madness", new Vector2(25, 85), 0, 0, 0, 0, counterFont, Color.Red, Color.Green, Content.Load<Texture2D>("counter_box"));
            money = new NumericalCounter("Money", new Vector2(25, 155), 0, 500, 0, 60, counterFont, Color.Orange, Color.Yellow, Content.Load<Texture2D>("counter_box"), true);
            papers = new NumericalCounter("Papers Published", new Vector2(10, 300), 0, 0, 0, 0, cursorFont, Color.Black, Color.Black);
            lifeForce = new NumericalCounter("Life Force", new Vector2(10, 320), 100, 100, 0, 0, cursorFont, Color.Black, Color.Black);
            longevity = new NumericalCounter("Longevity", new Vector2(10, 340), 100, 30, 0, 0, cursorFont, Color.Black, Color.Black);
            humanity = new NumericalCounter("Humanity", new Vector2(10, 360), 100, 30, 0, 0, cursorFont, Color.Black, Color.Black);

            counters = new List<NumericalCounter>{research,madness,money,papers,lifeForce,longevity,humanity};

            build = new Build(new Vector2(5, 900), Content.Load<Texture2D>("build_icon_standard"), Content.Load<Texture2D>("build_icon_highlight"), Content.Load<Texture2D>("build_icon_pressed"), Content.Load<Texture2D>("invarrow"), Content.Load<Texture2D>("highinvarrow"), GraphicsDevice);

            //=====================================================

            // load menu actions from XML
            System.IO.Stream stream = TitleContainer.OpenStream("XMLActions.xml");

            XDocument doc = XDocument.Load(stream);

            menuActions = (from action in doc.Descendants("menuAction")
                           select new MenuAction(
                                                           action.Element("name").Value,
                                                           Convert.ToBoolean(action.Element("scientist").Value),
                                                           Convert.ToBoolean(action.Element("assistant").Value),
                                                           Convert.ToInt32(action.Element("time").Value),
                                                           (float)Convert.ToDouble(action.Element("reasearchUp").Value),
                                                           (float)Convert.ToDouble(action.Element("madnessUp").Value),
                                                           (float)Convert.ToDouble(action.Element("moneyChange").Value),
                                                           (float)Convert.ToDouble(action.Element("lifeForceUp").Value),
                                                           (float)Convert.ToDouble(action.Element("longevityUp").Value),
                                                           (float)Convert.ToDouble(action.Element("humanityUp").Value),
                                                           Convert.ToBoolean(action.Element("remain").Value),
                                                           Convert.ToBoolean(action.Element("turnOn").Value),
                                                           Convert.ToBoolean(action.Element("turnOff").Value),
                                                           new List<NumericalCounter> { research },
                                                           (float)Convert.ToDouble(action.Element("reasearchUpMultiplier").Value),
                                                           (float)Convert.ToDouble(action.Element("madnessUpMultiplier").Value),
                                                           (float)Convert.ToDouble(action.Element("moneyChangeMultiplier").Value),
                                                           (float)Convert.ToDouble(action.Element("lifeForceUpMultiplier").Value),
                                                           (float)Convert.ToDouble(action.Element("longevityUpMultiplier").Value),
                                                           (float)Convert.ToDouble(action.Element("humanityUpMultiplier").Value)
                                                           )).ToList();

            // dependant actions

            studyLiveCorpse = menuActions[6];
            writePaper = menuActions[9];

            // independent actions
            studyCorpse = menuActions[2];
            dissectCorpse = menuActions[3];
            clearCorpse = menuActions[4];
            talk = menuActions[7];

            // load in multiplying counters

            List<Tuple<string, string, string, string>> multipliers = new List<Tuple<string, string, string, string>>();

            multipliers = (from floorObject in doc.Descendants("menuAction")
                           select new Tuple<string, string, string, string>(
                            floorObject.Element("name").Value,
                            floorObject.Element("multiplyingCounter").Value,
                            floorObject.Element("multiplyingCounter2").Value,
                            floorObject.Element("multiplyingCounter3").Value)
                               ).ToList();

            foreach (MenuAction action in menuActions)
            {
                foreach (Tuple<string, string, string, string> tuple in multipliers)
                {
                    if (tuple.Item1 == action.name)
                    {
                        foreach (NumericalCounter counter in counters)
                        {
                            foreach (string name in new List<string> { tuple.Item2, tuple.Item3, tuple.Item4 })
                            {
                                if (counter.name == name)
                                {
                                    action.dependent.Add(counter);
                                }
                            }
                        }
                    }
                }
            }

            // load floor objects from XML
            System.IO.Stream stream2 = TitleContainer.OpenStream("XMLFloorObjects.xml");

            XDocument doc2 = XDocument.Load(stream2);

            build.buildList = (from floorObject in doc2.Descendants("FloorObject") select new FloorObject(Content.Load<Texture2D>(
                                    Convert.ToString(floorObject.Element("texture").Value)),
                                    Content.Load<Texture2D>(Convert.ToString(floorObject.Element("icon").Value)),
                                    Convert.ToInt32(floorObject.Element("frameNumber").Value),
                                    Convert.ToInt32(floorObject.Element("animNumber").Value),
                                    new Vector2(Convert.ToInt32(floorObject.Element("gridPositionX").Value),Convert.ToInt32(floorObject.Element("gridPositionY").Value)), grid,
                                    floorObject.Element("name").Value,
                                    Convert.ToInt32(floorObject.Element("cost").Value),
                                    new List<MenuAction>{}, GraphicsDevice,
                                    new Vector2(Convert.ToInt32(floorObject.Element("footprintX").Value),Convert.ToInt32(floorObject.Element("footprintY").Value)),
                                    Convert.ToBoolean(floorObject.Element("prebuilt").Value))
                                    ).ToList();

            // load in menu actions

            List<Tuple<string,string,string,string>> actions = new List<Tuple<string,string,string,string>>();

            actions = (from floorObject in doc2.Descendants("FloorObject")
                           select new Tuple<string,string,string,string>(
                            floorObject.Element("name").Value,
                            floorObject.Element("menuAction").Value,
                            floorObject.Element("menuAction2").Value,
                            floorObject.Element("menuAction3").Value)
                               ).ToList();

            foreach (FloorObject machine in build.buildList)
            {
                foreach (Tuple<string,string,string,string> tuple in actions)
                {
                    if (tuple.Item1 == machine.name)
                    {
                        foreach (MenuAction action in menuActions)
                        {
                            foreach (string name in new List<string>{tuple.Item2,tuple.Item3,tuple.Item4})
                            {
                                if (action.name == name)
                                {
                                    machine.menuActions.Add(action);
                                }
                            }
                        }
                    }
                }
            }

            // build any prebuilt objects

            foreach (FloorObject machine in build.buildList)
            {
                if (machine.prebuilt == true)
                {
                    build.BuildThis(floorObjectList, machine, reachable);
                }
            }

            build.removeUpdate(money);

            // objects

            table = build.buildList[0];
            lightningAbsorber = build.buildList[1];

            resurrect = new Resurrect(new Vector2(1750, 900), Content.Load<Texture2D>("raise_icon_standard"), Content.Load<Texture2D>("raise_icon_highlight"), Content.Load<Texture2D>("raise_icon_pressed"), GraphicsDevice, table);

            //===================================================

            // background stuff

            room = new NonInteractive(Vector2.Zero, 0.6f, Content.Load<Texture2D>("room"));
            door = new NonInteractive(new Vector2(380, 200), 0.59f, Content.Load<Texture2D>("door"),2);
            graveyard = new Graveyard(new Vector2(1140,200), 0.8f, new Vector2(10,760),Content.Load<Texture2D>("back"), Content.Load<Texture2D>("dig_icon_standard"), Content.Load<Texture2D>("dig_icon_highlight"), Content.Load<Texture2D>("dig_icon_pressed"), GraphicsDevice, 0.5f);
            digger = new NonInteractive(new Vector2(1200, 300), 0.79f, Content.Load<Texture2D>("digger"), 1, 10);
            Switch = new NonInteractive(new Vector2(860,400), 0.58f, Content.Load<Texture2D>("switch"), 2, 1);

            // cursor

            cursor = new Cursor(Content.Load<Texture2D>("cursor"),GraphicsDevice);

            // characters

            Simon = new Scientist(Content.Load<Texture2D>("tmpprof"), new Vector2(10,1),grid,reachable,table);
            Jeremy = new Assistant(Content.Load<Texture2D>("tmpass"), new Vector2(8, 1), grid,reachable,table);

            // the corpse!

            corpse = new Corpse(new Vector2(725, 540),Content.Load<Texture2D>("corpse"), new List<MenuAction> { studyCorpse, dissectCorpse }, new List<MenuAction> { talk,studyLiveCorpse }, new List<MenuAction> { clearCorpse },GraphicsDevice);

            // update reachable area to account for these

            reachable.Update(floorObjectList);

            // test items...

            blob = new positionTextBlob(Content.Load<Texture2D>("gball"), new Vector2(1, 1));

            knob = new Knob(new Vector2(300, 300), 0.2f, Content.Load<Texture2D>("knob"));

            // test saving...
        }
示例#2
0
        public void Update(GameTime gametime, GraphicsDevice graphicsDevice, Grid grid, Cursor cursor, NumericalCounter research, NumericalCounter money, 
                                        NumericalCounter madness, List<MiniProgressBar> proglist, Corpse corpse,NonInteractive door,NonInteractive digger, Resurrect resurrect, NonInteractive Switch,
                                        NumericalCounter humanity, NumericalCounter longevity,NumericalCounter lifeForce, Random random, ReachableArea reachable)
        {
            path.Update(reachable);

            if (outside == false)
            {
                position = grid.CartesianCoords(gridPosition);

                if (walking == true)
                {
                    layer = 0.21f + (0.2f / (float)grid.rows) * walkingTarget.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(walkingTarget.X - (float)grid.columns / 2.0f);
                }

                else
                {
                    layer = 0.21f + (0.2f / (float)grid.rows) * gridPosition.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(gridPosition.X - (float)grid.columns / 2.0f);
                }
            }

            offset = new Vector2((width * scale) / 2.0f, height * scale); // factor of 2 here and in the draw command are just for this test anim, so it's a decent size...

            // walking....

            // to use a machine
            if (action != null && walking == false && doing == false)
            {

                // to corpse
                if (corpseWork == true)
                {
                    if (gridPosition != tableLocation)
                    {
                        walking = true;
                        drawPath = path.PathList(gridPosition, tableLocation, grid);
                        pathStep = 1;
                        walkingTarget = drawPath[pathStep];
                    }

                    else
                    {
                        doing = true;
                        currentFrame = 0;
                        gridPosition = drawPath[pathStep - 1];
                        position = grid.CartesianCoords(gridPosition);
                    }
                }

                else if (gridPosition != floorObject.opPos)
                {
                    walking = true;

                    drawPath = path.PathList(gridPosition, floorObject.opPos, grid);

                    pathStep = 1;

                    walkingTarget = drawPath[pathStep];
                }

                else
                {
                    doing = true;
                    currentFrame = 0;
                    gridPosition = drawPath[pathStep - 1];
                    position = grid.CartesianCoords(gridPosition);
                }

            }

            else if (gridPosition != defaultGridPosition && walking == false && doing == false)
            {
                walking = true;
                drawPath = path.PathList(gridPosition, defaultGridPosition, grid);
                pathStep = 1;
                walkingTarget = drawPath[pathStep];
            }

            // if he's walking, make him walk!

            if (walking == true)
            {

                direction = (grid.CartesianCoords(walkingTarget) - grid.CartesianCoords(gridPosition));

                targetDistance = direction.Length();
                direction.Normalize();

                walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.2f;
                distanceGone = walkingOffset.Length();

                if (distanceGone < targetDistance)
                {
                    Vector2 move = walkingOffset;
                    position += move;
                }

                else
                {
                    pathStep += 1;

                    if (pathStep < drawPath.Count)
                    {
                        gridPosition = drawPath[pathStep - 1];
                        walkingTarget = drawPath[pathStep];
                        position = grid.CartesianCoords(gridPosition);
                    }

                    else
                    {
                        walking = false;
                        doing = true;
                        currentFrame = 0;
                        gridPosition = drawPath[pathStep - 1];
                        position = grid.CartesianCoords(gridPosition);
                    }

                    walkingOffset = Vector2.Zero;
                    targetDistance = 0;
                    distanceGone = 0;

                }
            }

            // update animation frame

            timer += gametime.ElapsedGameTime.Milliseconds;

            if (timer >= msecsTweenFrames)
            {
                timer = 0;

                if (walking == true)
                {
                    if (Math.Abs(direction.X) >= Math.Abs(direction.Y))
                    {
                        if (direction.X >= 0)
                        {
                            anim = 1;
                        }

                        else
                        {
                            anim = 0;
                        }
                    }

                    if (Math.Abs(direction.Y) >= Math.Abs(direction.X))
                    {
                        if (direction.Y >= 0)
                        {
                            anim = 2;
                        }

                        else
                        {
                            anim = 3;
                        }
                    }

                    if (currentFrame++ == numberOfFrames - 1)
                    {
                        currentFrame = 0;
                    }
                }

                // start up menu action if doing is done, animate doing
                if (doing == true)
                {
                    // coming through door (either way)
                    if (digging == true)
                    {
                        anim = 4;

                        if (door.animNum == 0)
                        {
                            door.SetAnim(1);
                            door.layer -= 0.3f;
                        }

                        if (currentFrame++ == 2)
                        {

                            digging = false;

                            if (dug == true)
                            {
                                CarryCorpse();
                                doing = false;
                                dug = false;
                                outside = false;
                            }

                            else
                            {
                                outside = true;
                                layer = 0.61f;
                                position += new Vector2(0, -20);
                            }

                            currentFrame = 0;
                            door.SetAnim(0);
                            door.layer += 0.3f;
                        }

                        else if (dug == true)
                        {
                            layer = 0.595f;
                            anim = 5;
                        }
                    }

                    // animate digging outside
                    else if (outside == true)
                    {
                        outTimer += gametime.ElapsedGameTime.Milliseconds;

                        if (outTimer >= 150 && dug == false)
                        {
                            digger.anim = true;
                            dug = true;
                            outTimer = 0;
                        }

                        if (dug == true && digger.anim == false && outTimer >= 350)
                        {
                            digging = true;
                            outTimer = 0;

                        }
                    }

                    // animate putting corpse on table
                    else if (corpseCarrying == true)
                    {

                        doing = false;
                        corpseCarrying = false;
                        corpse.flies.Restart(0);
                        corpse.visible = true;
                    }

                    // animate animation!
                    else if (animating == true)
                    {
                        anim = 4;

                        if (currentFrame++ == numberOfFrames - 1)
                        {
                            doing = false;
                            animating = false;
                            Switch.SetAnim(1);
                            resurrect.Alive(corpse, humanity, longevity,lifeForce, research,madness, random, this);
                        }
                    }

                    // if not in the usual spot...
                    else if (gridPosition != defaultGridPosition)
                    {
                        anim = 4;

                        if (action != null)
                        {
                            // if not staying to run machine, run doing anim once, create mini progress bar
                            if (action.remain == false)
                            {
                                if (currentFrame++ == numberOfFrames - 1)
                                {
                                    doing = false;
                                    proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject));
                                    progBar = proglist[proglist.Count - 1];
                                    action = null;

                                }
                            }

                            // if staying to run machine...
                            else
                            {
                                // create a progess bar if starting
                                if (animStart == true)
                                {
                                    animStart = false;

                                    if (corpseWork == true)
                                    {
                                        proglist.Add(new MiniProgressBar(graphicsDevice, corpse.position + new Vector2(-5, -105), action, floorObject));
                                        progBar = proglist[proglist.Count - 1];
                                        corpseWork = false;
                                    }

                                    else
                                    {
                                        proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject));
                                        progBar = proglist[proglist.Count - 1];
                                    }
                                }

                                // run animation until finished
                                else
                                {
                                    if (currentFrame++ == numberOfFrames - 1)
                                    {
                                        currentFrame = 0;

                                        if (action.done == true)
                                        {
                                            doing = false;
                                            action.done = false;
                                            action = null;
                                            animStart = true;

                                        }
                                    }

                                }
                            }
                        }
                    }

                    // if not doing anything, stop...
                    else
                    {
                        walking = false;
                        doing = false;
                        currentFrame = 0;
                    }

                }

                // if not walking, do standing anim
                if (walking == false && doing == false)
                {
                    anim = 2;
                    currentFrame = 0;
                }

                // set frame and anim
                rect.X = currentFrame * width;
                rect.Y = height * anim;
            }
        }