Example #1
0
 public void DrawLineOfSight()
 {
     if (Game.lOS)
     {
         LineOfSight.Draw();
     }
 }
Example #2
0
 public void UpdateLineOfSight()
 {
     if (Game.lOS)
     {
         LineOfSight.Update();
     }
 }
Example #3
0
        public SmoothCamera(Scene parent, Vector2 position, float rotation, float zoom, Vector2 offset, params CollisionLayer[] ignoredLineOfSight) : base(TextureName.None, position, 1, rotation, parent, false)
        {
            this.offset = new Vector2(Game.screenWidth / 2 + offset.x, GetScreenHeight() / 2 + offset.y);
            camera      = new Camera2D {
                target = position, offset = position + new Vector2(GetScreenWidth() / 2 + offset.x, GetScreenHeight() / 2 + offset.y), zoom = zoom, rotation = rotation
            };

            //lineofsight ignores some collisions
            LineOfSight.SetIgnored(ignoredLineOfSight);

            //a vignette is rendered as a child object of the camera. please note I added this before I added UI to the scene, that's why it is not a UI object
            GameObject vignette = new GameObject(TextureName.Vignette);

            AddChild(vignette);
            vignette.GetSprite().SetLayer(SpriteLayer.Foreground);
            vignette.LocalScale = new Vector2(Game.screenWidth, Game.screenHeight) / (1120);
            LineOfSight.SetMaxDist(new Vector2(Game.screenWidth / 2, Game.screenHeight / 2).Magnitude() + smoothMultiplier * 15);
            parent.SetCamera(this);
            LineOfSight.Initiate(parent);
        }
Example #4
0
        public override void Update()
        {
            accelerationCap = accelerationCapNorm;             //accelerationcap is added to when player is running

            //new game plus is activated when the player eats every chicken in the game
            //when activated, the player can shoot infinite eggs, has a really high mass, is bigger, shakes the ground as it walks, and is a bit slower (also is bigger)
            //it also flings 'confetti' everywhere when it walks.
            //the programming for this is a bit dumb because at first if you shot out an egg newgameplus was disabled again, so everything had to revert back.
            //this is no longer what i want of course since i like the idea of shooting infinite chickens out when you win
            //but i didn't fix everything again because im lazy AND I needed to do professional studies work
            if (newGamePlus)
            {
                velocityCap = velocityCapSlow;
                frameSpeed  = frameSpeedNorm - frameSpeedSlowDown;
                scale       = new Vector2(1.05f, 1.05f);
                int f = spriteManager.GetCurrentFrame();
                iMass            = 0.000001f;
                Eye.laserPower   = 200000000;               //laser power is set to this constant
                Eye.cookStrength = 50;
                chickenEatAmount = 200;
                //shake the camera and shoot rainbow feathers out when the feet hit the ground
                if ((f >= 1 && f <= 3) || (f >= 12 && f <= 14))
                {
                    camera.SetShakeAmount(4);
                    new Feather(position + new Vector2(Game.globalRand.Next(-20, 20), 110), (float)Game.globalRand.NextDouble() * Num.pi * 2 - Num.pi, (float)Game.globalRand.NextDouble() * 0.2f + 0.1f, -3f * new Vector2(velocity.x, (float)Game.globalRand.NextDouble() * 50 - 25), (float)Game.globalRand.NextDouble() - 0.5f, Game.GetCurrentScene(), SpriteLayer.Foreground, true);
                }
                else
                {
                    camera.SetShakeAmount(0);                     //this actually breaks the laser's camera shake but whatever, member I'm adding all these comments after the fact
                }
            }
            else
            {
                //set all values to their defaults (every frame).
                //should have made it that eye contained its own default laserpower and cookstrength consts
                Eye.cookStrength = 5;
                iMass            = defaultIMass;
                Eye.laserPower   = 20000000;
                velocityCap      = velocityCapNorm;
                frameSpeed       = frameSpeedNorm;
                scale            = Vector2.one;
            }

            //input direction is reset every frame. using WASD changes it.
            inputDirection = Vector2.zero;

            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                inputDirection -= Vector2.up;
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                inputDirection += Vector2.up;
            }
            if (IsKeyDown(KeyboardKey.KEY_A))             //A and S also change a bunch of variables to do with flipping the character
            {
                inputDirection -= Vector2.right;
                spriteManager.FlipX(false);
                headSprite.FlipX(false);
                fix.GetSprite().FlipX(false);
                eye1.FlipX(false);
                chicken.GetSprite().FlipX(false);
                chicken.LocalPosition    = new Vector2(eatingOffset.x, eatingOffset.y);
                headHolder.LocalPosition = new Vector2(headOffset.x, LocalPosition.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                inputDirection += Vector2.right;
                spriteManager.FlipX(true);
                headSprite.FlipX(true);
                fix.GetSprite().FlipX(true);
                eye1.FlipX(true);
                chicken.GetSprite().FlipX(true);
                chicken.LocalPosition    = new Vector2(-eatingOffset.x, eatingOffset.y);
                headHolder.LocalPosition = new Vector2(-headOffset.x, LocalPosition.y);
            }

            //shift is used for running. when running the velocitycap, acceleration cap and frame speed are made bigger.
            if (IsKeyPressed(KeyboardKey.KEY_LEFT_SHIFT))
            {
                running = true;
            }
            if (IsKeyReleased(KeyboardKey.KEY_LEFT_SHIFT))
            {
                running = false;
            }
            if (running)
            {
                frameSpeed      -= frameSpeedAddition;
                velocityCap     += velocityFasterAmount;
                accelerationCap += accelerationFasterAmount;
            }
            spriteManager.SetSpeed(frameSpeed);

            //now for lasering
            //lasering can only happen when not biting
            if (!biting && IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
            {
                cooling  = false;
                charging = true;
            }
            if (charging)
            {
                buildUp += Game.deltaTime * chargeSpeed;

                while (buildUp >= 1)
                {
                    if (eyeColor.r >= 255)
                    {
                        eyeColor.r = 255;
                        charging   = false;
                        buildUp    = 0;
                        eye1.SetLaser(true);
                        camera.SetShakeAmount(5);
                        break;
                    }
                    eyeColor.r++;
                    buildUp--;
                    eye1.SetTint(eyeColor);
                    camera.SetShakeAmount(eyeColor.r * 0.005f);
                }
            }
            if (cooling)
            {
                buildUp += Game.deltaTime * chargeSpeed * 2;

                while (buildUp >= 1)
                {
                    if (eyeColor.r == 0)
                    {
                        cooling = false;
                        buildUp = 0;
                        break;
                    }

                    eyeColor.r--;
                    buildUp--;
                    eye1.SetTint(eyeColor);
                    camera.SetShakeAmount(eyeColor.r * 0.005f);
                }
            }
            if (IsMouseButtonReleased(MouseButton.MOUSE_LEFT_BUTTON))
            {
                cooling  = true;
                charging = false;
                eye1.SetLaser(false);
                buildUp = 0;
            }

            //biting can only happen when leftclick isn't held (cannot be charging or lasering)
            if (!charging && IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON) && eyeColor.r != 255)
            {
                //when first clicked the headsprites limits values are set so that the jaw opens
                headSprite.SetLimits(0, 5);
                headSprite.SetBackwards(false);
                headSprite.PlayFrom((headSprite.GetCurrentFrame() + 1) % 5);
                biting             = true;
                endingBite         = false;
                broadcastingHunger = true;
                camera.SetShakeAmount(0);
            }
            if (biting)             //biting is basically true at any point that the mousth is not at frame 0 (shut)
            {
                int fr = headSprite.GetCurrentFrame();
                UpdateTiedChickens();                 //update tied chickens if mouth is becoming agape

                //if a chicken is dead, the camera shakes based on how open the mouth is
                //frame five is when the mouth is completely open
                if (chickensBeingSucked)
                {
                    if (fr > 5)
                    {
                        camera.SetShakeAmount(0.5f * (5 - fr % 5));
                    }
                    else
                    {
                        camera.SetShakeAmount(0.3f * (fr));
                    }
                }

                //if rightclick has been released, the frames either start reversing toward 0 or continue toward frame 10
                if (endingBite)
                {
                    if (fr <= 0)                     //if it reverses towards zero, when it reaches zero disable everything to do with biting. the bite has been canceled
                    {
                        headSprite.Pause();
                        headSprite.SetBackwards(false);
                        biting              = false;
                        endingBite          = false;
                        chickensBeingSucked = false;
                        broadcastingHunger  = false;
                        camera.SetShakeAmount(0);
                    }

                    if (fr >= 10)                     //if it continues towards 10, the 'chomp' is being played. reset everything and if the chickens eaten during this bite is more than 0, make a not of it.
                    {
                        headSprite.Pause();
                        headSprite.SetFrame(0);
                        endingBite          = false;
                        biting              = false;
                        chickensBeingSucked = false;
                        broadcastingHunger  = false;
                        camera.SetShakeAmount(0);
                        chickensEatenTotal += chickenEatAmount;
                        h.hungerPercent     = (float)chickensEatenTotal / chickenTotalInScene;

                        //if every chicken has been eaten, newGamePlus is enabled and infinite chickens can now be shot out
                        if (newGamePlus || chickensEatenTotal >= chickenTotalInScene)
                        {
                            newGamePlus      = true;
                            chickenEatAmount = 300;
                        }
                        else                         //else the chicken eat amount is reset at the end of the bite
                        {
                            chickenEatAmount = 0;
                        }

                        //the chicken gameobject is visible (due to a chicken class being completely eaten), disable the chicken
                        chicken.SetDrawn(false);
                    }
                    else if (fr > 6)
                    {
                        //at the end of the bite make a crunch-like camera shake
                        camera.SetShakeAmount(4);
                    }
                }
                else if (fr == 5)                 //if the mouth becomes fully agape stay it their until the right mouse button has been released
                {
                    headSprite.Pause();

                    //at this point eggs can be shot using the left mouse button as long as the player has eaten a chicken.
                    if (chickensEatenTotal > 0 && IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                    {
                        //the chicken is shot towards the mouse and a bunch of feathers are shot in the general direction as well
                        Vector2 direction = (camera.GetMouseWorldPosition() - chicken.GlobalPosition).Normalised() * 500;
                        new PhysicsChicken(chicken.GlobalPosition, direction, 0.1f, 3);
                        Vector2 rot = direction.Rotated(-Num.pi / 8);
                        for (int i = 0; i < 15; i++)
                        {
                            new Feather(position, (float)Game.globalRand.NextDouble() * Num.pi * 2 - Num.pi, (float)Game.globalRand.NextDouble() * 0.2f + 0.1f, (float)(Game.globalRand.NextDouble() * 0.5f + 1) * rot.Rotated((float)Game.globalRand.NextDouble() * 0.1f - 0.05f), (float)Game.globalRand.NextDouble() - 0.5f, Game.GetCurrentScene(), SpriteLayer.Foreground);
                            rot.Rotate(Num.pi * 0.01675f);
                        }
                        if (!newGamePlus)                         //if the game is in newGamePlus this does not effect the hunger level.
                        {
                            chickensEatenTotal--;
                            h.hungerPercent = (float)(chickensEatenTotal) / chickenTotalInScene;
                            h.chickenCount  = chickenTotalInScene - chickensEatenTotal;
                        }
                    }
                }
            }
            if (IsMouseButtonReleased(MouseButton.MOUSE_RIGHT_BUTTON) && !endingBite)
            {
                if (headSprite.GetCurrentFrame() >= 5)
                {
                    //initiate close animation
                    headSprite.SetLimits(5, 10);
                    headSprite.Play();
                    CancelTiedChickens();                     //if their are chickens left after holding right click, cancel the vacuum effect
                }
                else
                {
                    //if the mouth hadn't fully opened yet, just reverse the animation to close the mouth softly
                    headSprite.SetBackwards(true);
                }
                endingBite = true;
            }

            //if input has been given but the character is still standing, animate the character and disable standing.
            if (standing && (inputDirection.x != 0 || inputDirection.y != 0))
            {
                standing = false;
                spriteManager.PlayFrom(1);
            }

            //if their is no input yet the character is moving, make it stand still
            if ((inputDirection.x == 0 && inputDirection.y == 0) && !standing)
            {
                spriteManager.Pause();
                spriteManager.SetFrame(0);
                standing = true;
            }

            //eyes are offset by the eye offset and the head offset
            //head is only offset by the eye offset
            float offset = eyeOffset[spriteManager.GetCurrentFrame()];

            eye1.SetOffsetY(offset + headEyeOffset[headSprite.GetCurrentFrame()]);
            headHolder.LocalPosition = new Vector2(headHolder.LocalPosition.x, offset + headOffset.y);

            // it basically gives a velocity that points from the current velocity to the aimed velocity (which has the direction of input direction and the magnitude of velocity cap)
            //the velocity can only change by a vector with a max value of acceleration cap. If the distance between the aimed velocity and the current velocity is less than accelerationCap, the current velocity becomes the aimed velocity
            //just as in the chicken class, the implementation of this is not very clean and could be easily remade to be better

            Vector2 cache = inputDirection.Normalised() * velocityCap - velocity;

            if (cache.MagnitudeSquared() > accelerationCap * Game.deltaTime * accelerationCap * Game.deltaTime)
            {
                inputVelocity = cache.Normalised() * (accelerationCap * Game.deltaTime);
            }
            else
            {
                inputVelocity = cache;
            }
            inputVelocity = velocityCap > accelerationCap * Game.deltaTime ? inputVelocity : cache + velocity;
            AddVelocity(inputVelocity);

            base.Update();

            //lineofsight is a static class. the origin is set to the player + an offset
            LineOfSight.SetOrigin(LocalPosition + lOSOffset);

            if (!newGamePlus)             //if newgameplus this value is not ever updated
            {
                h.chickenCount = chickenTotalInScene - chickensEatenTotal;
            }
        }