public void DrawDebugConsole(Toilet_time_main.Gui_Manager guimanager)
        {
            MouseInformation.text = "Mouse: | " + guimanager.Cursor.x.ToString() + "," + guimanager.Cursor.y.ToString() + " | " + guimanager.LatestInput.MouseButton.Visit <string>(() => { return(""); }, item => { return("" + item.ToString()); }) + " |";
            MouseInformation.Draw(this);

            InputInformation.text = "Input: | " + guimanager.LatestInput.Walk.Visit <string>(() => { return(""); }, item => { return("   " + item.ToString()); }) + guimanager.LatestInput.MoveAction.Visit <string>(() => { return(""); }, item => { return("   " + item.ToString()); }) + guimanager.LatestInput.CharacterActivity.Visit <string>(() => { return(""); }, item => { return("   " + item.ToString()); }) + guimanager.LatestInput.Settings.Visit <string>(() => { return(""); }, item => { return("   " + item.ToString()); }) + "   |";
            InputInformation.Draw(this);

            CooldownInformation.text = "Countdowns: | B: " + ((int)(guimanager.buttoncooldown)).ToString() + " | P: " + ((int)guimanager.pickupcooldown).ToString() + " | C: " + ((int)guimanager.Controls_Cooldown).ToString() + " | E " + ((int)guimanager.End_Of_Level_Cooldown).ToString() + " |";
            CooldownInformation.Draw(this);


            ScreenStats.text = ("Scr: " + guimanager.screen.ToString() + " | Input: " + guimanager.inputmechanism.ToString()) + " | GPonl: " + guimanager.Gamepadonline.ToString() + " | IsLvl: " + guimanager.Current_screen.islevel.ToString();
            ScreenStats.Draw(this);


            LevelStats.text = ("Fallable: " + guimanager.Fallable_Objects.Count().ToString() + " | Inter: " + guimanager.Interacting_Objects.Count().ToString() + " | Stable: " + guimanager.Stable_Objects.Count().ToString() + " | Gui: " + guimanager.Gui_stuff.Count().ToString());
            LevelStats.Draw(this);

            Toilet_time_main.Fallable_Object main = guimanager.GetMain_Character();

            if (main != null)
            {
                MainInformation.text = "MainY: " + main.position.y.ToString() + " | Vel: " + ((int)(main.velocity)).ToString() + " | Baby: " + main.HasBaby.ToString() + " | Next: " + main.nextscreen.ToString();
            }

            MainInformation.Draw(this);


            PerformanceInformation.text = ((int)(1 / guimanager.drawdt)).ToString() + " fps | " + ((int)(1 / guimanager.updatedt)).ToString() + " ups";
            PerformanceInformation.Draw(this);
        }
Пример #2
0
        public override void Update(float dt, Gui_Manager guimanager)
        {
            base.Update(dt, guimanager);
            // makes spider walk
            if (left)
            {
                new_x_add -= speed * dt;
            }
            else
            {
                new_x_add += speed * dt;
            }

            x_addition      = (int)(new_x_add);
            this.steps_out += x_addition;

            new_x_add = new_x_add - x_addition;
            Fallable_Object main = guimanager.GetMain_Character();

            if (main != null)
            {
                if (left == false && !guimanager.Check_Collision(this, this.position.x + x_addition + 2, this.position.y, this.size.x, this.size.y))
                {
                    this.left = true;
                }
                else if (left == true && (!guimanager.Check_Collision(this, this.position.x - x_addition - 2, this.position.y, this.size.x, this.size.y)))
                {
                    this.left = false;
                }
                else
                {
                    if (!((this.position.x + x_addition + 2 < main.position.x + main.size.x && this.position.x + x_addition - 2 + this.size.x > main.position.x && this.position.y + this.size.y > main.position.y && this.position.y < main.position.y + main.size.y)))
                    {
                        this.position.x += x_addition;
                    }
                    else
                    {
                        guimanager.Main_Dead();
                    }
                }
            }

            if (this.position.y > 600)
            {
                Console.WriteLine("respawning");
                this.position.y = startposition.y;
                this.position.x = this.startposition.x - guimanager.movementchange;
            }
        }
        // Update
        // CheckIfTouching
        public List <iObject> CheckIfMainTouching() // returns a list of iteracting objects touching the main character
        {
            List <iObject>  returnlist = new List <iObject>();
            Fallable_Object main       = GetMain_Character();

            if (main != null)
            {
                Interacting_Objects.Reset();

                while (Interacting_Objects.GetNext().Visit(() => false, unusedvalue => true))
                {
                    // checking gravity: falling and other
                    if (Interacting_Objects.GetCurrent().Visit <bool>(

                            () => { return(false); }

                            ,


                            item =>
                    {
                        if (main.position.x < item.position.x + item.size.x && main.position.x + main.size.x > item.position.x)
                        {
                            if (main.position.y + main.size.y > item.position.y && main.position.y < item.position.y + item.size.y)
                            {
                                return(true);
                            }
                        }

                        return(false);
                    }

                            )
                        )
                    {
                        returnlist.Add(Interacting_Objects.GetCurrent().Visit <iObject>(() => { throw new Exception("interaction error"); }, item => { return(item); }));
                    }
                }
            }

            return(returnlist);
        }
        // small walk check
        public bool CheckIfMove(float dt, WalkDirectionInput way, int walkspeed) // returns a bool if the maincharacter can walk in a certain direction
        {
            Fallable_Object main       = GetMain_Character();
            bool            moveable   = false;
            int             multiplyer = 1;

            if (main != null)
            {
                if (way == WalkDirectionInput.Right)
                {
                    multiplyer = 1;
                }
                if (way == WalkDirectionInput.Left)
                {
                    multiplyer = -1;
                }

                moveable = Check_Collision(main, main.position.x + walkspeed * multiplyer, main.position.y, main.size.x, main.size.y);
            }
            return(moveable);
        }
Пример #5
0
        public override void Update(float dt, Gui_Manager guimanager)
        {
            if (cooldown > 0)
            {
                cooldown = cooldown - (1 * dt);
            }
            else
            {
                cooldown = 0;
            }
            // adds new spike
            if (cooldown <= 0)
            {
                Spike spike_to_add = new Spike(position.x, position.y);
                spike_to_add.velocity = -3;
                droppingobjects.Add(spike_to_add);
                cooldown = interval;
            }
            // gives dropping objects their functionality
            droppingobjects.Reset();
            while (droppingobjects.GetNext().Visit <bool>(() => false, _ => true))
            {
                Spike droppingobject = droppingobjects.GetCurrent().Visit <Spike>(() => throw new Exception("spike error"), item => item);
                droppingobject.position.x = this.position.x;

                droppingobject.Update(dt, guimanager);

                Fallable_Object main = guimanager.GetMain_Character();
                if (main != null)
                {
                    if (main.position.x < droppingobject.position.x + droppingobject.size.x && main.position.x + main.size.x > droppingobject.position.x)
                    {
                        if (main.position.y + main.size.y > droppingobject.position.y && main.position.y < droppingobject.position.y + droppingobject.size.y)
                        {
                            guimanager.Main_Dead(); // main dead on touch
                        }
                    }
                }

                if (droppingobject.position.y > 2000) // remove when falling below 2000 pixels
                {
                    // removing from list
                    List <Spike> COPYdroppingobjects = droppingobjects;

                    List <Spike> Newdroppingobjects = new List <Spike>();
                    {
                        COPYdroppingobjects.Reset();
                        while (COPYdroppingobjects.GetNext().Visit <bool>(() => false, _ => true))
                        {
                            Spike dropob = COPYdroppingobjects.GetCurrent().Visit <Spike>(() => throw new Exception("copyfail"), item => item);

                            if (dropob.position.y != droppingobject.position.y)
                            {
                                Newdroppingobjects.Add(dropob);
                            }
                        }
                    }

                    droppingobjects = Newdroppingobjects;
                }
            }
        }
Пример #6
0
        public override void Update(float dt, Gui_Manager guimanager)
        {
            if (cooldown > 0)
            {
                cooldown = cooldown - (1 * dt);
            }
            else
            {
                cooldown = 0;
            }

            // spawns new object when
            if (cooldown <= 0)
            {
                Toilet_Paper To_add = new Toilet_Paper(position.x, position.y);
                To_add.velocity = -3;
                droppingobjects.Add(To_add);
                cooldown = interval;
            }

            droppingobjects.Reset();
            while (droppingobjects.GetNext().Visit <bool>(() => false, _ => true))
            {
                Toilet_Paper droppingobject = droppingobjects.GetCurrent().Visit <Toilet_Paper>(() => throw new Exception("toiletpaper error"), item => item);
                droppingobject.position.x = this.position.x;

                droppingobject.Update(dt, guimanager);

                // making main die when touching droppingobject
                Fallable_Object main = guimanager.GetMain_Character();
                if (main != null)
                {
                    if (main.position.x < droppingobject.position.x + droppingobject.size.x && main.position.x + main.size.x > droppingobject.position.x)
                    {
                        if (main.position.y + main.size.y > droppingobject.position.y && main.position.y < droppingobject.position.y + droppingobject.size.y)
                        {
                            //touches main
                            guimanager.Main_Dead();
                        }
                    }
                    // removing objects form list when below 2000 pixels
                    if (droppingobject.position.y > 2000)
                    {
                        List <Toilet_Paper> COPYdroppingobjects = droppingobjects;

                        List <Toilet_Paper> Newdroppingobjects = new List <Toilet_Paper>();
                        {
                            COPYdroppingobjects.Reset();
                            while (COPYdroppingobjects.GetNext().Visit <bool>(() => false, _ => true))
                            {
                                Toilet_Paper dropob = COPYdroppingobjects.GetCurrent().Visit <Toilet_Paper>(() => throw new Exception("copyfail"), item => item);

                                if (dropob.position.y != droppingobject.position.y)
                                {
                                    Newdroppingobjects.Add(dropob);
                                }
                            }
                        }

                        droppingobjects = Newdroppingobjects;
                    }
                }
            }
        }
        //


        public void Update(float dt) // global update function of the application
        {
            updatedt = dt;
            bool controllsenabled = true; // able to walk?

            //manages cooldowns
            if (pickupcooldown > 0)
            {
                pickupcooldown -= dt;
            }
            if (buttoncooldown > 0)
            {
                buttoncooldown -= dt;
            }
            if (Controls_Cooldown > 0)
            {
                Controls_Cooldown -= dt;
            }
            if (End_Of_Level_Cooldown > 0)
            {
                End_Of_Level_Cooldown -= dt;
            }

            if (Controls_Cooldown > 0)
            {
                controllsenabled = false;
            }
            ;

            input = inputadapter.GetInput(inputmechanism); //gets input from inputadapter from current input mechanism

            LatestInput = input;
            // Check if gamepad is enabled


            bool newgamepadonline = input.GamePadOnline; // manages the gamepadonline option: reloads screen when becomes active when in option menu

            if (Gamepadonline != newgamepadonline && screen == 2)
            {
                Gamepadonline = newgamepadonline;
                Reload_screen();
            }
            Gamepadonline = input.GamePadOnline;

            //kill on fall


            Fallable_Object main = GetMain_Character(); // checks if main falls down the screen -> Main_dead();

            if (main != null)
            {
                if (main.position.y + main.size.y > lowestyvalue)
                {
                    Main_Dead();
                }
            }
            // checks if baby falls down the screen -> calls Miain_dead();
            Interacting_Objects.Reset();
            while (Interacting_Objects.GetNext().Visit(() => false, _ => true))
            {
                if (Interacting_Objects.GetCurrent().Visit(() => false, item => { return(item.IsBaby); }))
                {
                    iObject baby = Interacting_Objects.GetCurrent().Visit <iObject>(() => throw new Exception("failed getting interaction"), act => { return(act); });
                    if (baby.position.y + baby.size.y > lowestyvalue)
                    {
                        Main_Dead();
                    }
                }
            }

            bool walk      = false;
            bool CanMove   = false;
            int  walkspeed = 0;

            localwalkspeed += CharacterSpeed * dt; //calculates walkspeed: float -> int: don't lose data!!
            for (int i = (int)(localwalkspeed); i > 0; i--)
            {
                localwalkspeed = localwalkspeed - 1.0f;
                walkspeed++;
            }

            // cursor
            this.Cursor = input.cursor; // reloads cursor position form input

            if (paused == false)        // if game not paused then update the rest
            {
                // walk
                // manages walk on walk input
                WalkDirectionInput walkdirection = WalkDirectionInput.Right;

                if (input.Walk.Visit(() => false, _ => true))
                {
                    walk          = true;
                    walkdirection = input.Walk.Visit <WalkDirectionInput>(() => { throw new Exception("walkdirection failed"); }, item => { return(item); });

                    CanMove = CheckIfMove(dt, walkdirection, walkspeed); // Checks if allowed to move character
                    if (CanMove == false && walkspeed > 1)
                    {
                        for (int i = walkspeed; i > 0 && CanMove == false; i--)
                        {
                            CanMove = CheckIfMove(dt, walkdirection, i); // Checks if allowed to move character
                            if (CanMove == true)
                            {
                                walkspeed = i;
                            }
                        }
                    }
                }


                // handles jump input: if possible :)
                if (controllsenabled == true)
                {
                    if (input.MoveAction.Visit(() => false, _ => true))
                    {
                        if (input.MoveAction.Visit <CharacterMovementAction>(() => { throw new Exception("Charactermovement failed"); }, item => { return(item); }) == CharacterMovementAction.Jump)
                        {
                            if (main != null)
                            {
                                if (main.IsMainCharacter == true)
                                {
                                    main.Jump(this);
                                }
                            }
                        }
                    }
                }

                //handles movement if left/right
                if (controllsenabled == true && walk == true && CanMove == true)
                {
                    if (walkdirection == WalkDirectionInput.Left)
                    {
                        movementchange -= walkspeed;
                    }
                    else if (walkdirection == WalkDirectionInput.Right)
                    {
                        movementchange += walkspeed;
                    }
                }

                // updates stableobjects + make them move if character has to move
                Stable_Objects.Reset();
                while (Stable_Objects.GetNext().Visit(() => false, _ => true))
                {
                    Stable_Objects.GetCurrent().Visit(() => { }, item => { item.Update(dt, this); });

                    if (controllsenabled == true)
                    {
                        if (controllsenabled == true && walk == true && CanMove == true)
                        {
                            Stable_Objects.GetCurrent().Visit(() => { }, item => { item.Move(dt, this, walkdirection, walkspeed); });
                        }
                    }
                }
                // updates fallable objects + make them move if character has to move
                Fallable_Objects.Reset();
                while (Fallable_Objects.GetNext().Visit(() => false, _ => true))
                {
                    Fallable_Objects.GetCurrent().Visit(() => { }, item => { item.Update(dt, this); });

                    if (controllsenabled == true)
                    {
                        if (controllsenabled == true && walk == true && CanMove == true)
                        {
                            Fallable_Objects.GetCurrent().Visit(() => { }, item => { item.Move(dt, this, walkdirection, walkspeed); });
                        }
                    }
                }


                // updates interaction objects + make them move if character has to move
                Interacting_Objects.Reset();
                while (Interacting_Objects.GetNext().Visit(() => false, unusedvalue => true))
                {
                    Interacting_Objects.GetCurrent().Visit(() => { }, item => { item.Update(dt, this); });

                    if (controllsenabled == true)
                    {
                        if (walk == true && CanMove == true)
                        {
                            Interacting_Objects.GetCurrent().Visit(() => { }, item => { item.Move(dt, this, walkdirection, walkspeed); });
                        }
                    }
                }

                // Checking interaction with main character by interacting objects

                List <iObject> interacton = CheckIfMainTouching();

                // checking for baby: picking up when autopickup is on

                if (autopickup == false)
                {
                    if (input.CharacterActivity.Visit(() => false, _ => true))
                    {
                        CharacterActivity activityinput = input.CharacterActivity.Visit <CharacterActivity>(() => throw new Exception("failed getting interaction"), act => { return(act); });
                        if (controllsenabled == true)
                        {
                            if (activityinput == CharacterActivity.Action && pickupcooldown <= 0)
                            {
                                pickupcooldown = 0.5f;
                                if (main != null)
                                {
                                    if (main.HasBaby == false)
                                    {
                                        interacton.Reset();
                                        while (interacton.GetNext().Visit(() => false, unusedvalue => true))
                                        {
                                            if (interacton.GetCurrent().Visit(() => false, item => { return(item.IsBaby); }))
                                            {
                                                // on babypickup...
                                                iObject baby = interacton.GetCurrent().Visit <iObject>(() => throw new Exception("failed getting interaction"), act => { return(act); });
                                                main.HasBaby = true;
                                                baby.Visible = false;
                                                sound_handler.PlayBackground(ChooseBackGroundMusic.game_noncry);
                                                sound_handler.PlaySoundEffect(ChooseSoundEffect.baby_laugh);
                                            }
                                        }
                                    }


                                    else
                                    {
                                        // on babydrop...
                                        Interacting_Objects.Reset();
                                        while (Interacting_Objects.GetNext().Visit(() => false, unusedvalue => true))
                                        {
                                            if (Interacting_Objects.GetCurrent().Visit(() => false, item => { return(item.IsBaby); }))
                                            {
                                                iObject baby = Interacting_Objects.GetCurrent().Visit <iObject>(() => throw new Exception("failed getting interaction"), act => { return(act); });
                                                main.HasBaby  = false;
                                                baby.position = new Position(main.position.x, main.position.y + 20);
                                                baby.Visible  = true;
                                                sound_handler.PlayBackground(ChooseBackGroundMusic.game_cry);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // checking if touching items


                interacton.Reset();
                while (interacton.GetNext().Visit(() => false, unusedvalue => true))
                {
                    // killing main character when touching object is deadly
                    iObject TouchingObject = interacton.GetCurrent().Visit <iObject>(() => throw new Exception("failed getting interaction"), act => { return(act); });

                    if (TouchingObject.IsDeadly)
                    {
                        Main_Dead();
                    }

                    // picking baby up when autopickup is on
                    if (TouchingObject.IsBaby)
                    {
                        if (autopickup == true)
                        {
                            if (main.HasBaby == false)
                            {
                                main.HasBaby           = true;
                                TouchingObject.Visible = false;
                                sound_handler.PlayBackground(ChooseBackGroundMusic.game_noncry);
                                sound_handler.PlaySoundEffect(ChooseSoundEffect.baby_laugh);
                            }
                        }
                    }

                    // when the main character reaches the end
                    if (TouchingObject.IsEnd)
                    {
                        //then the main character is carying the baby...
                        if (main.HasBaby)
                        {
                            //on levelend
                            main.HasBaby               = false;
                            TouchingObject.HasBaby     = true;
                            this.End_Of_Level_Cooldown = 3;
                            this.Controls_Cooldown     = 3;
                            this.End_Of_Level          = true;
                            sound_handler.PlaySoundEffect(ChooseSoundEffect.game_end);
                        }
                    }
                }
            }
            // update our gui_stuff: buttons and labels
            Gui_stuff.Reset();
            while (Gui_stuff.GetNext().Visit(() => false, unusedvalue => true))
            {
                Gui_stuff.GetCurrent().Visit(() => { }, item => { item.Update(dt, this); });
            }

            // when end animation is over: load next level
            if (End_Of_Level_Cooldown <= 0 && End_Of_Level == true)
            {
                End_Of_Level_Cooldown = 0;
                End_Of_Level          = false;
                Controls_Cooldown     = 0;
                Create_screen(main.nextscreen);
            }
        }