예제 #1
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     RightTimer.Stop();
     LeftTimer.Stop();
     JumpTimer.Stop();
     PhysicTimer.Stop();
 }
예제 #2
0
        private void JumpTimer_Tick(object sender, EventArgs e)
        {
            if (CheckBirdCollisionWithPipes() && !dead)
            {
                GameOver();
            }

            if (miliseconds == 50)
            {
                FlappyBirdSprite.Image = frame1;
            }

            if (CheckBirdCollisionWithCoin() && !gotCoin)
            {
                gotCoin = true;
                this.Controls.Remove(coin);
                Score++;
                Score_Label.Text = "Score: " + Score.ToString();
                // I should also play a sound, but we will implement it later.
            }

            if (miliseconds < 100)
            {
                miliseconds += JumpTimer.Interval;
                Point p = FlappyBirdSprite.Location;
                p.Y += jumpSpeed;
                FlappyBirdSprite.Location = p;
            }
            else
            {
                JumpTimer.Stop();
                JumpAnimationWaitTimer.Start();
                FlappyBirdSprite.Image = frame2;
            }
        }
예제 #3
0
        /// <summary> Updates the creature </summary>
        public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (!IsActive)
            {
                return;
            }

            CheckNeighborhood(chunks, (float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateAnimation(gameTime, chunks, camera);
            Status.Update(this, gameTime, chunks, camera);
            JumpTimer.Update(gameTime);
            HandleBuffs(gameTime);

            if (Stats.LaysEggs)
            {
                if (EggTimer == null)
                {
                    EggTimer = new Timer(1200.0f, false);
                }
                EggTimer.Update(gameTime);

                if (EggTimer.HasTriggered)
                {
                    LayEgg();
                    EggTimer = new Timer(1200.0f + MathFunctions.Rand(-30.0f, 30.0f), false);
                }
            }
        }
예제 #4
0
        public override void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            CheckNeighborhood(chunks, (float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateAnimation(gameTime, chunks, camera);
            Status.Update(this, gameTime, chunks, camera);
            JumpTimer.Update(gameTime);
            HandleBuffs(gameTime);

            base.Update(gameTime, chunks, camera);
        }
예제 #5
0
        /// <summary> Updates the creature </summary>
        public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (FirstUpdate)
            {
                FirstUpdate = false;
                Faction.Minions.Add(AI);
                Physics.AllowPhysicsSleep = false;
            }

            if (!Active)
            {
                return;
            }
            DrawLifeTimer.Update(gameTime);

            if (!DrawLifeTimer.HasTriggered)
            {
                float val   = Hp / MaxHealth;
                Color color = val < 0.75f ? (val < 0.5f ? Color.Red : Color.Orange) : Color.LightGreen;
                Drawer2D.DrawLoadBar(Manager.World.Camera, AI.Position - Vector3.Up * 0.5f, color, Color.Black, 32, 2, Hp / MaxHealth);
            }

            CheckNeighborhood(chunks, (float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateAnimation(gameTime, chunks, camera);
            Status.Update(this, gameTime, chunks, camera);
            JumpTimer.Update(gameTime);
            HandleBuffs(gameTime);

            if (Stats.LaysEggs)
            {
                if (EggTimer == null)
                {
                    EggTimer = new Timer(1200f + MathFunctions.Rand(-30, 30), false);
                }
                EggTimer.Update(gameTime);

                if (EggTimer.HasTriggered)
                {
                    LayEgg();
                    EggTimer = new Timer(1200f + MathFunctions.Rand(-30, 30), false);
                }
            }

            if (IsPregnant && World.Time.CurrentDate > CurrentPregnancy.EndDate)
            {
                var baby = EntityFactory.CreateEntity <GameComponent>(BabyType, Physics.Position);
                baby.GetRoot().GetComponent <CreatureAI>().PositionConstraint = AI.PositionConstraint;
                CurrentPregnancy = null;
            }

            if (MathFunctions.RandEvent(0.0001f))
            {
                NoiseMaker.MakeNoise("Chirp", AI.Position, true, 0.25f);
            }
        }
예제 #6
0
        private void FlappyBirdForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ' && !dead)
            {
                SoundPlayer player = new SoundPlayer(path_jump_sound);
                player.Play();

                miliseconds = 0;
                GravityTimer.Stop();
                JumpTimer.Start();
            }
        }
예제 #7
0
        /// <summary> Updates the creature </summary>
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            base.Update(gameTime, chunks, camera);

            if (FirstUpdate)
            {
                FirstUpdate = false;
                Faction.Minions.Add(AI);
                Physics.AllowPhysicsSleep = false;

                addToSpeciesCount();
            }

            if (_selectionCircle != null &&
                Faction == World.PlayerFaction && World.Master.SelectedMinions.Contains(AI))
            {
                _selectionCircle.IsVisible = true;
            }
            else if (_selectionCircle != null)
            {
                _selectionCircle.IsVisible = false;
            }

            if (AI == null)
            {
                Console.Out.WriteLine("Error: creature {0} {1} has no AI. Deleting it.", Name, GlobalID);
                GetRoot().Delete();
                return;
            }


            if (!Active)
            {
                return;
            }

            UpdateCloak();
            UpdateHealthBar(gameTime);
            CheckNeighborhood(chunks, (float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateAnimation(gameTime, chunks, camera);
            Status.Update(this, gameTime, chunks, camera);
            JumpTimer.Update(gameTime);
            HandleBuffs(gameTime);
            UpdateMigration(gameTime);
            UpdateEggs(gameTime);
            UpdatePregnancy();
            MakeNoises();
        }
예제 #8
0
        public virtual void Update()
        {
            ManageMovement();

            if (IsAffectedByGravityPush)
            {
                float multiplier = 1;
                if (GravityPushPushDurationTimer != null)
                {
                    multiplier = GravityPushPushDurationTimer.Progress;
                    GravityPushPushDurationTimer.Update();
                }

                // Horizontal
                Rectangle futurePositionX = new Rectangle(CollisionBox.X + VelocityX * multiplier, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height);
                ManageHorizontalMovement(futurePositionX);

                // Vertical
                Rectangle futurePositionY = new Rectangle(CollisionBox.X, CollisionBox.Y + VelocityY, CollisionBox.Width, CollisionBox.Height);
                SetCollisionBoxY(futurePositionY.Y);

                // Rotate clockwise in the air
                // Make one full rotation for the duration of the timer
                InclineAngle = 2 * (float)Math.PI * multiplier;

                // Return the state of the unit back to normal after the push is over
                if (GravityPushPushDurationTimer != null && GravityPushPushDurationTimer.Progress == 0)
                {
                    ResetVelocities();
                    IsUnableToMove          = false;
                    IsAffectedByGravityPush = false;
                    IsIdle = true;
                    GravityPushPushDurationTimer = null;
                    InclineAngle = 0;
                }
            }

            // Update timers
            RunTimer.Update();
            JumpTimer.Update();

            LastState = new Midori(this);
        }
예제 #9
0
        protected void ManageInput()
        {
            if (!IsUnableToMove)
            {
                IsIdle = true;
            }

            // Interaction
            if (Engine.InputManager.IsKeyDown(Key.F) && !IsUnableToMove)
            {
                if (!IsInteracting)
                {
                    IsMovingLeft  = false;
                    IsMovingRight = false;
                    IsIdle        = true;
                    IsInteracting = true;
                    Interact();
                    return;
                }
                else if (GameContext.Scene.CurrentInteration.Finished)
                {
                    IsInteracting  = false;
                    InteractTarget = null;
                    return;
                }
            }

            if (IsInteracting)
            {
                return;
            }

            // Movement
            if (Engine.InputManager.IsKeyHeld(Key.A) && !IsUnableToMove)
            {
                if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoNormal();
                    Sprite.Reset();
                }
                IsMovingLeft  = true;
                IsMovingRight = false;
                IsIdle        = false;
                IsFacingRight = false;
            }
            else
            {
                IsMovingLeft = false;
                if (!IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoInReverse();
                    RunTimer.End();
                }
            }

            if (Engine.InputManager.IsKeyHeld(Key.D) && !IsUnableToMove)
            {
                if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoNormal();
                    Sprite.Reset();
                }
                IsMovingRight = true;
                IsMovingLeft  = false;
                IsIdle        = false;
                IsFacingRight = true;
            }
            else
            {
                IsMovingRight = false;
                if (!IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoInReverse();
                    RunTimer.End();
                }
            }

            // Jumping
            if (Engine.InputManager.IsKeyHeld(Key.Space) && IsGrounded && !IsUnableToMove)
            {
                IsGrounded = false;
                IsJumping  = true;
                JumpTimer.GoInReverse();
                VelocityY = _jumpVelocity;
            }

            // Gravity Push
            if (Engine.InputManager.IsKeyHeld(Key.G) && IsGrounded && !IsUnableToMove)
            {
                IsIdle              = false;
                IsMovingLeft        = false;
                IsMovingRight       = false;
                IsUnableToMove      = true;
                IsGravityPushActive = true;

                Sprite.Reset();
            }

            // Magic Flow
            if (Engine.InputManager.IsKeyHeld(Key.H) && !IsUnableToMove && !IsMagicFlowActive)
            {
                // Set CurrentMagicFlow
                CurrentMagicFlow = CollisionUtils.RectangleIntesectsWithMagicFlow(CollisionBox.ToRectangle());
                if (CurrentMagicFlow == null)
                {
                    return;
                }

                if (CurrentMagicFlow.TraverseFirstToLast)
                {
                    // If traversing from first to last => start from Point A of the first segment
                    CurrentMagicFlowSegmentIndex = 0;
                    SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.X - (CollisionBox.Width / 2));
                    SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.Y - (CollisionBox.Height / 2));
                }
                else
                {
                    // If traversing from last to first => start from Point B of the last segment
                    CurrentMagicFlowSegmentIndex = CurrentMagicFlow.Segments.Count - 1;
                    SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.X - (CollisionBox.Width / 2));
                    SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.Y - (CollisionBox.Height / 2));
                }

                // TODO: Reset timers
                IsIdle            = false;
                IsMovingLeft      = false;
                IsMovingRight     = false;
                IsJumping         = false; // Reset jump timer
                IsFalling         = false;
                IsUnableToMove    = true;  // ?
                IsMagicFlowActive = true;

                Sprite.Reset();
            }

            // Debug
            // Teleport to X
            if (Engine.InputManager.IsKeyHeld(Key.LeftControl))
            {
                IsGrounded = true;
                IsFalling  = false;
                IsJumping  = false;
                JumpTimer.End();
                SetCollisionBoxY(500);
                SetCollisionBoxX(700);
            }
            else if (Engine.InputManager.IsKeyHeld(Key.RightControl))
            {
                IsGrounded = true;
                IsFalling  = false;
                IsJumping  = false;
                JumpTimer.End();
                SetCollisionBoxY(5100);
                SetCollisionBoxX(550);
            }

            if (Engine.InputManager.IsKeyDown(Key.Q))
            {
                CodeSwitch = !CodeSwitch;
                Console.WriteLine(CodeSwitch);
            }
        }
예제 #10
0
        protected void ManageMovement()
        {
            if (IsUnableToMove)
            {
                return;
            }

            Room  currentRoom = GameContext.Scene.LoadedRoom;
            float newVelocity = VelocityX * RunTimer.Progress;

            if (IsMovingLeft)
            {
                // Make sure movement is within the room borders
                if (CollisionBox.X > 0 + newVelocity)
                {
                    Rectangle futurePosition = new Rectangle(CollisionBox.X - newVelocity, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height);
                    ManageHorizontalMovement(futurePosition);
                }
                else
                {
                    SetCollisionBoxX(0);
                    IsMovingLeft = false;
                    IsIdle       = true;
                }
            }

            if (IsMovingRight)
            {
                // Make sure movement is within the room borders
                if (CollisionBox.X + CollisionBox.Width < currentRoom.Size.X - newVelocity)
                {
                    Rectangle futurePosition = new Rectangle(CollisionBox.X + newVelocity, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height);
                    ManageHorizontalMovement(futurePosition);
                }
                else
                {
                    SetCollisionBoxX(currentRoom.Size.X - CollisionBox.Width);
                    IsMovingRight = false;
                    IsIdle        = true;
                }
            }

            if (IsJumping)
            {
                if (JumpTimer.Finished && !IsFalling)
                {
                    IsFalling = true;
                    JumpTimer.GoNormal();
                }

                if (IsFalling)
                {
                    VelocityY = StartingVelocityY;
                }

                Rectangle             futurePosition      = new Rectangle(CollisionBox.X, CollisionBox.Y - (JumpTimer.Progress * VelocityY), CollisionBox.Width, CollisionBox.Height);
                Collision.LineSegment intersectedPlatform = CollisionUtils.IntersectsWithPlatforms(futurePosition);
                if (intersectedPlatform == null)
                {
                    SetCollisionBoxY(CollisionBox.Y - JumpTimer.Progress * VelocityY);
                }
                else
                {
                    IsJumping  = false;
                    IsFalling  = false;
                    IsGrounded = true;
                    JumpTimer.End();
                    //Y = 580;
                }
            }
            else
            {
                VelocityY = StartingVelocityY;
                ApplyGravity();
            }
        }