예제 #1
0
        public void MoveMe(double deltatime, double Xspeed, double Yspeed)
        {
            bool sonicMove = true;
            var  thick     = SonicImageControl.Margin;

            //thick.Right += Xspeed * deltatime;
            if (thick.Left == MainWindow.WidthWindow / 2 || thick.Left > WidthWindow / 2)
            {
                sonicMove  = false;
                thick.Left = MainWindow.WidthWindow / 2;
                Map.MoveMap(-Xspeed, 0);
                if (Map.MapImageControl1.Margin.Left >= 0 && IsFlipped)
                {
                    var temp = Map.MapImageControl1.Margin;
                    temp.Left = 0;
                    Map.MapImageControl1.Margin = temp;
                    thick.Left += Xspeed * deltatime;
                    sonicMove   = true;
                }
            }
            if (thick.Left <= 0 && IsFlipped)
            {
                thick.Left = 0;
                MyXSpeed   = 0;
                if (Map.MapImageControl1.Margin.Left < 0)
                {
                    Map.MoveMap(-Xspeed, 0);
                }
                else
                {
                    currentState = CURRENT_STATE.PUSHING;
                }
            }
            if (sonicMove)
            {
                thick.Left += Xspeed * deltatime;// This is m = m/s *s
            }
            Map.MoveMap(0, -Yspeed);
            //thick.Top += Yspeed * deltatime;
            SonicImageControl.Margin = thick;
            //MyXSpeed = 0;
            //MyYSpeed = 0;
            if (!IsIntheAir)
            {
                MyYSpeed = 0;
            }
            if (MyXSpeed > 0)
            {
                MyXSpeed -= FrictionAcceleration;
            }
            else if (MyXSpeed < 0)
            {
                MyXSpeed += FrictionAcceleration;
            }
        }
예제 #2
0
        public Sonic()
        {
            sonicImage        = new BitmapImage(new Uri("pack://application:,,,/Resources/Sonic1.png", UriKind.Absolute));
            sonicRollingImage = new BitmapImage(new Uri("pack://application:,,,/Resources/Sonic_Rolling.bmp", UriKind.Absolute));
            //sonicImage = MainWindow.RemoveBackGroundColor("pack://application:,,,/Resources/Sonic1.png");
            SonicImageControl = new System.Windows.Controls.Image();
            //sonicRollingImage = MainWindow.RemoveBackGroundColor("pack://application:,,,/Resources/Sonic_Rolling.bmp");
            currentState = CURRENT_STATE.WAITING;
            MyWidth      = sonicImage.Width / 6;
            MyHeight     = sonicImage.Height / 5;

            MyRect            = new Rect(0, 0, MyWidth, MyHeight);
            SonicImage.Margin = new Thickness(0, 200, MyWidth, MyHeight);
        }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (State == CURRENT_STATE.Patrol)
        {
            agent.isStopped   = false;
            agent.destination = guardPost.position;
            anim.SetFloat("Move", (float)0.5);
            if (Vector3.Distance(player.position, transform.position) <= detectionRadius)
            {
                State = CURRENT_STATE.Engage;
                if (gameManager.isHiding == true)
                {
                    State = CURRENT_STATE.Patrol;
                }
            }
        }
        if (State == CURRENT_STATE.Engage)
        {
            agent.isStopped   = false;
            agent.destination = player.position;
            anim.SetFloat("Move", (float)0.5);
            if (Vector3.Distance(player.position, transform.position) <= engageDistance)
            {
                anim.SetFloat("Move", 1);

                if (Vector3.Distance(player.position, transform.position) <= attackDistance)
                {
                    anim.SetFloat("Move", 0);
                    anim.SetTrigger("Attack");
                }
            }

            if (Vector3.Distance(player.position, transform.position) >= detectionRadius)
            {
                State = CURRENT_STATE.Patrol;
            }
        }
        if (State == CURRENT_STATE.Dead)
        {
            agent.isStopped = true;
            anim.SetBool("Die", true);
            Destroy(gameObject, 2);
        }
    }
예제 #4
0
        public void Tick(double Deltatime, Dictionary <string, bool> KeysDown)
        {
            if (SonicImage.Margin.Top != HeightWindow / 3)
            {
                var temp = SonicImage.Margin;
                temp.Top          = HeightWindow / 3;
                SonicImage.Margin = temp;
            }
            MyXAcceleration = 0;
            MyYAcceleration = 0;
            Tickteller++;
            //teller++;
            switch (currentState)
            {
            case CURRENT_STATE.AFK:
                if (teller < 3 && teller > 0)
                {
                    goto default;
                }
                teller = 1;
                break;

            case CURRENT_STATE.WAITING:
                //if (teller < 5) { goto default; }
                teller = 0;
                break;

            case CURRENT_STATE.WALKING:
                if (teller < 4)
                {
                    goto default;
                }
                teller = 0;
                break;

            case CURRENT_STATE.RUNNING:
                if (teller < 3)
                {
                    goto default;
                }
                teller = 0;
                break;

            case CURRENT_STATE.PUSHING:
                if (teller < 3)
                {
                    goto default;
                }
                teller = 0;
                break;

            case CURRENT_STATE.BREAKING:
                if (!IsFlipped && SonicImageControl.Margin.Left < MyBreakingXPos + 50)
                {
                    //MyXSpeed = 10;
                    //MoveMe(1, MyXSpeed, MyYSpeed);
                }
                else if (IsFlipped && SonicImageControl.Margin.Left > MyBreakingXPos - 50)
                {
                    //MyXSpeed = -10;
                    //MoveMe(1, MyXSpeed, MyYSpeed);
                }
                else if (SonicImageControl.Margin.Left <= MyBreakingXPos - 50 || SonicImageControl.Margin.Left >= MyBreakingXPos + 50)
                {
                    currentState = CURRENT_STATE.WAITING;
                }
                if (teller < 1)
                {
                    goto default;
                }
                teller = 0;
                break;

            case CURRENT_STATE.LOOKDOWN:
                teller = 5;
                break;

            case CURRENT_STATE.BALANCING:
                if (teller < 3)
                {
                    goto default;
                }
                teller = 2;
                break;

            case CURRENT_STATE.LOOKUP:
                teller = 4;
                break;

            default:
                teller++;
                break;
            }

            if (KeysDown.ContainsValue(true))
            {
                if (KeysDown["D"])
                {
                    if (KeysDown["Q"])
                    {
                        if (currentState == CURRENT_STATE.RUNNING || (currentState == CURRENT_STATE.ROLLING && !IsIntheAir))
                        {
                            currentState   = CURRENT_STATE.BREAKING;
                            MyBreakingXPos = SonicImageControl.Margin.Left;
                        }
                        else if (currentState == CURRENT_STATE.WALKING)
                        {
                            currentState = CURRENT_STATE.WAITING;
                        }
                    }
                    else
                    {
                        MyXAcceleration += 1.5;
                        //MyXSpeed = 10;
                        IsFlipped = false;
                        //MoveMe(1, MyXSpeed, MyYSpeed);
                        currentState = CURRENT_STATE.WALKING;
                    }
                }
                if (KeysDown["Z"])
                {
                    if (currentState == CURRENT_STATE.WAITING || currentState == CURRENT_STATE.AFK || currentState == CURRENT_STATE.LOOKUP)
                    {
                        currentState = CURRENT_STATE.LOOKUP;
                    }
                }
                if (KeysDown["Q"])
                {
                    if (KeysDown["D"])
                    {
                        if (currentState == CURRENT_STATE.RUNNING)
                        {
                            currentState = CURRENT_STATE.BREAKING;
                        }
                        else if (currentState == CURRENT_STATE.WALKING)
                        {
                            currentState = CURRENT_STATE.WAITING;
                        }
                    }
                    else
                    {
                        if (currentState != CURRENT_STATE.PUSHING)
                        {
                            MyXAcceleration += -1.5;
                            //MyXSpeed = -10;
                            IsFlipped = true;
                            //MoveMe(1, MyXSpeed, MyYSpeed);
                            currentState = CURRENT_STATE.WALKING;
                        }
                    }
                }
                if (KeysDown["S"])
                {
                    if (currentState == CURRENT_STATE.WAITING || currentState == CURRENT_STATE.AFK || currentState == CURRENT_STATE.LOOKDOWN)
                    {
                        currentState = CURRENT_STATE.LOOKDOWN;
                    }
                }
                if (KeysDown["Space"])
                {
                    if (!IsIntheAir)
                    {
                        currentState = CURRENT_STATE.ROLLING;
                    }
                }
            }
            else
            {
                currentState = CURRENT_STATE.WAITING;
            }

            if (MyXSpeed != 0)
            {
                currentState = CURRENT_STATE.WALKING;
            }

            MyRect.Y = (int)currentState * MyHeight;
            if ((int)currentState < 0)
            {
                MyRect.Y = 0;
            }
            MyRect.X = teller * MyWidth;
            if (currentState == CURRENT_STATE.BALANCING)
            {
                MyRect.Y = 4 * MyHeight;
                if (teller < 2)
                {
                    MyRect.X = 2 * MyWidth;
                }
            }

            if (Tickteller >= 30 && (currentState == CURRENT_STATE.WAITING || currentState == CURRENT_STATE.AFK))
            {
                //currentState = CURRENT_STATE.AFK;
                //Animate_Right();
                //dikte.Left = teller * SONICWIDHT;
                //dikte.Top = (int)currentState * (MyHeight * -1);
                if (currentState == CURRENT_STATE.AFK)
                {
                    MyRect.Y = 0;
                    //dikte.Top = 0;
                }
            }

            /*
             *  Gravity norm = 9.811 m/s^2
             *  In Sonic.cpp m_Velocity += m_Acceleration * deltatime
             *  m_Pos.x += m_Velocity * deltatime
             */
            if (IsIntheAir)
            {
                MyYSpeed += GravityAcceleration;
            }
            MyXSpeed += MyXAcceleration;
            MyYSpeed += MyYAcceleration;
            MainWindow.DebugText(new Dictionary <string, string> {
                { "My Xspeed", MyXSpeed.ToString() }, { "My Yspeed", MyYSpeed.ToString() }, { "My X acc", MyXAcceleration.ToString() }, { "My Y acc", MyYAcceleration.ToString() }, { "In air", IsIntheAir.ToString() }
            });
            MoveMe(Deltatime, MyXSpeed, MyYSpeed);
            ClipImage(SonicImageControl, MyRect, IsFlipped);
            //ClipImage(SonicImageControl, new Rect(0,0,sonicImage.Width,sonicImage.Height), IsFlipped);
        }