Exemple #1
0
        public void Update(List<FloorObject> floorObjectList, List<MiniProgressBar> progBars,Scientist scientist, Assistant assistant, Build build, Graveyard graveyard,FloorObject table, Corpse corpse, NumericalCounter money,
                            Path path, List<Vector2> drawPath,Grid grid, Resurrect resurrect, NumericalCounter humanity, NumericalCounter longevity, NumericalCounter research, Random random)
        {
            MouseState mouseState = Mouse.GetState();

            // Put the cursor where the mouse is constantly

            position.X = mouseState.X;
            position.Y = mouseState.Y;

            mouseOver = false;

            // check if over a progress bar, show values if so

            barMouseover = false;

            foreach (MiniProgressBar bar in progBars)
            {

                // if menu is off, check if over an object, open menu if clicked

                if (menu == false)
                {
                    // objects
                    if (position.X >= bar.position.X && position.X <= (bar.position.X + bar.width)
                            && position.Y >= bar.position.Y && position.Y <= (bar.position.Y + bar.height))
                    {

                        barMouseover = true; // add object mouseover text
                        menuProgBar = bar;

                    }

                }
            }

            // check for clicking on/mouseover build icons

            buildIconMouseover = false;

            foreach (FloorObject curitem in build.buildList)
            {
                if (position.X >= curitem.iconPosition.X && position.X <= curitem.iconPosition.X + 60
                && position.Y >= curitem.iconPosition.Y && position.Y <= curitem.iconPosition.Y + 60)
                {
                    if (curitem.onBuildList == true && build.buildList.IndexOf(curitem) < (build.scrollPos + build.buildScreenLength) && build.buildList.IndexOf(curitem) >= build.scrollPos)
                    {
                        // tooltip + highlighting on
                        buildIconMouseover = true;
                        menuObject = curitem;

                        // build!
                        if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                        {
                            if (click == false)
                            {
                                if (money.value >= curitem.cost)
                                {
                                    remove = curitem;
                                    floorObjectList.Add(curitem);
                                    build.menu = false;
                                }
                            }

                        }

                        click = true;

                    }
                }

            }

            // remove anything that has been built from build list
            if (remove != null)
            {
                build.Remove(remove,money);
                remove = null;
            }
            // check for clicking on objects

                // if menu is off, check if over an object, open menu if clicked & check for clicking on graveyard + tooltip

                if (menu == false && graveMenu == false && corpseMenu == false)
                {
                    foreach (FloorObject floorObject in floorObjectList)
                    {

                        // objects
                        if (position.X >= (floorObject.position.X - floorObject.offset.X) && position.X <= (floorObject.position.X - floorObject.offset.X + ((floorObject.objectTex.Width*floorObject.scale) / floorObject.frames))
                                && position.Y >= floorObject.position.Y - floorObject.offset.Y && position.Y <= (floorObject.position.Y - floorObject.offset.Y + (floorObject.objectTex.Height*floorObject.scale)))
                        {
                            if (floorObject.menuActions.Count > 0)
                            {
                                mouseOver = true; // add object mouseover text
                                menuObject = floorObject;

                                // turn on menu when object is clicked

                                if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                                {
                                    if (click == false)
                                    {

                                        menu = true;

                                    }

                                }

                                click = true;
                            }
                        }

                    }

                    graveMouseOver = false;

                    // graveyard
                    if (position.X >= graveyard.tlcorner.X && position.X <= graveyard.brcorner.X
                            && position.Y >= graveyard.tlcorner.Y && position.Y <= graveyard.brcorner.Y)
                    {

                        graveMouseOver = true; // add object mouseover text

                        // turn on menu when object is clicked

                        if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                        {
                            if (click == false)
                            {
                                graveMenu = true;
                                graveMouseOver = false;
                            }

                        }

                        click = true;
                    }

                    corpseMouseover = false;

                    // corpse
                    if (position.X >= corpse.position.X && position.X <= corpse.position.X + corpse.width
                            && position.Y >= corpse.position.Y && position.Y <= corpse.position.Y + corpse.height && corpse.visible == true)
                    {

                        corpseMouseover = true; // add object mouseover text

                        // turn on menu when object is clicked

                        if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                        {
                            if (click == false)
                            {
                                corpseMenu = true;
                                corpseMouseover = false;
                            }

                        }

                        click = true;
                    }

                }

                // allow clicking on actions, turn off menu when anything else is clicked (if on)

                if (menu == true)
                {

                    if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                    {
                        if (click == false)
                        {
                            if (menu == true)
                            {
                                menu = false;

                                if (menuMouseover == true)
                                {
                                    if (menuHighlightAction.scientist == true)
                                    {
                                        scientist.action = menuHighlightAction;
                                        scientist.floorObject = menuObject;
                                    }

                                    else
                                    {
                                        assistant.action = menuHighlightAction;
                                        assistant.floorObject = menuObject;
                                    }
                                }
                            }

                        }

                        click = true;
                    }

                }

                if (graveMenu == true)
                {

                    if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                    {
                        if (click == false)
                        {

                                graveMenu = false;

                                if (menuMouseover == true)
                                {
                                    if (floorObjectList.Contains(table))
                                    {
                                        assistant.DigUpCorpse(corpse);
                                    }
                                }

                        }

                        click = true;
                    }

                }

                if (corpseMenu == true)
                {

                    if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                    {
                        if (click == false)
                        {

                                corpseMenu = false;

                                if (menuMouseover == true)
                                {
                                        scientist.action = menuHighlightAction;
                                        scientist.corpseWork = true;
                                        //scientist.floorObject = menuObject;
                                }

                        }

                        click = true;
                    }

                }

                // clicking on animate icon

                if (position.X >= resurrect.position.X && position.X < (resurrect.position.X + resurrect.tex.Width) && position.Y >= resurrect.position.Y && position.Y < (resurrect.position.Y + resurrect.tex.Height))
                {
                    if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                    {
                        if (click == false && resurrect.doable == true)
                        {
                            resurrect.Animate(corpse, humanity, longevity, research, random);
                        }

                        click = true;

                    }

                }

              // clicking on build icon

            if (position.X >= build.position.X && position.X < (build.position.X + build.tex.Width) && position.Y >= build.position.Y && position.Y < (build.position.Y + build.tex.Height))
            {
                if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                {
                    if (click == false)
                    {
                        build.menu = true;
                        build.scrollPos = 0;
                    }

                    click = true;

                }

            }

            else
            {
                if ((mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed) && position.Y < build.buildPos.Y)
                {
                    if (click == false)
                    {
                        build.menu = false;
                    }

                    click = true;

                }

            }

            // Scrolling build menu....

            // Right
            if (position.X >= build.rightArrowPos.X - build.arrow.Width && position.X <= build.rightArrowPos.X
                                    && position.Y >= build.rightArrowPos.Y && position.Y <= build.rightArrowPos.Y + build.arrow.Height)
            {
                if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                {
                    if (click == false)
                    {

                        build.ScrollRight();
                    }

                    click = true;

                }

            }

            // Left
            if (position.X >= build.leftArrowPos.X && position.X <= build.leftArrowPos.X + build.arrow.Width
                                    && position.Y >= build.leftArrowPos.Y - build.arrow.Height && position.Y <= build.leftArrowPos.Y)
            {
                if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed)
                {
                    if (click == false)
                    {
                        build.ScrollLeft();
                    }

                    click = true;

                }

            }

            // turn off click flag when no longer clicking

            if (mouseState.LeftButton == ButtonState.Released && mouseState.RightButton == ButtonState.Released)
            {
                click = false;
            }

            text = position.ToString();
        }
Exemple #2
0
        public void Update(GameTime gametime, GraphicsDevice graphicsDevice, Cursor cursor, NumericalCounter research,NumericalCounter money, NumericalCounter madness, List<MiniProgressBar> proglist, ReachableArea reachable)
        {
            // get most recent reachable areas
            path.Update(reachable);

            // update position from grid position

            position = grid.CartesianCoords(gridPosition);

            // determine later from position and direction of movement

            if (walking == true)
            {
                layer = 0.2f + (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.2f + (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....

            if (action != null && walking == false && doing == false)
            {
                // to corpse
                if (corpseWork == true)
                {
                    if (gridPosition != corpsePosition)
                    {
                        walking = true;
                        drawPath = path.PathList(gridPosition, corpsePosition, grid);
                        pathStep = 1;
                        walkingTarget = drawPath[pathStep];
                    }

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

                // to machine
                else if (gridPosition !=  floorObject.opPos)
                {
                    walking = true;
                    drawPath = path.PathList(gridPosition, floorObject.opPos, grid);
                    pathStep = 1;
                    walkingTarget = drawPath[pathStep];
                }

                // arrived at destination, start doing
                else
                {
                    doing = true;
                    currentFrame = 0;
                    gridPosition = drawPath[pathStep - 1];
                    position = grid.CartesianCoords(gridPosition);
                }
            }

            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)
                {
                    anim = 4;

                    if (action != null)
                    {
                        // if not staying, run anim once, start 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[-1];
                                action = null;

                            }
                        }

                        // if staying to work machine...
                        else
                        {
                            // if starting, create progress bar and start anim
                            if (animStart == true)
                            {
                                animStart = false;

                                if (corpseWork == true)
                                {
                                    proglist.Add(new MiniProgressBar(graphicsDevice, position + new Vector2(0, -100), action, null));
                                    progBar = proglist[proglist.Count -1];
                                }

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

                            // run anim until machine work is finished
                            else
                            {
                                if (currentFrame++ == numberOfFrames - 1)
                                {
                                    currentFrame = 0;

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

                                        if (corpseWork == true)
                                        {
                                            corpseWork = false;
                                        }
                                    }
                                }

                            }
                        }

                    }

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

                        if (currentFrame++ == numberOfFrames - 1)
                        {
                            doing = false;
                            animating = false;

                        }

                    }
                }

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

                // set anim and frame
                rect.X = currentFrame * width;
                rect.Y = height * anim;
            }
        }
Exemple #3
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;
            }
        }