コード例 #1
0
        public void Update()
        {
            if (gameObject.Tag.Contains("Firewave"))
            {
                foreach (GameObject go in GameWorld.gameObjects)
                {
                    if (go.Tag == "Player" || go.Tag == "Dummy")
                    {
                        if (intersects((go.GetComponent("Collider") as Collider).CircleCollisionBox, (gameObject.GetComponent("Collider") as Collider).CollisionBox))
                        {
                            FirewavePush(go, go.Id);
                        }
                    }
                }
            }

            if (gameObject.Id == GameWorld.Instance.player.Id)
            {
                foreach (GameObject other in GameWorld.gameObjects)
                {
                    if (other.Tag == "Deflect" && other.Id != gameObject.Id)
                    {
                        GameObject temp = new GameObject();

                        foreach (GameObject go in GameWorld.gameObjects)
                        {
                            if (go.Tag == "Enemy" && go.Id == other.Id)
                            {
                                temp = go;
                            }
                            if (temp.Tag == "Enemy")
                            {
                                Circle playerCircle = new Circle();
                                playerCircle.Center = new Vector2(temp.transform.position.X + 16, temp.transform.position.Y + 16);
                                playerCircle.Radius = (temp.GetComponent("Collider") as Collider).CircleCollisionBox.Radius * 2F;
                                if (playerCircle.Intersects((gameObject.GetComponent("Collider") as Collider).CircleCollisionBox))
                                {
                                    Deflect.SetVector(temp, gameObject);
                                    temp = new GameObject();
                                }
                            }
                        }
                    }
                }

                KeyboardState keyState = Keyboard.GetState();

                if (gameObject.Tag.Contains("Boomerang"))
                {
                    if (Vector2.Distance(originalPos, gameObject.transform.position) > 100)
                    {
                        boomerangReturn = true;
                    }
                    else
                    {
                        (gameObject.GetComponent("Physics") as Physics).Acceleration += testVector / 10 * projectileSpeed;
                    }

                    if (boomerangReturn)
                    {
                        boomerangTimer += GameWorld.Instance.deltaTime;
                        Vector2 playerPos  = GameWorld.Instance.player.transform.position;
                        Vector2 boomReturn = (gameObject.GetComponent("Physics") as Physics).GetVector((new Vector2(playerPos.X + 16, playerPos.Y + 16)), new Vector2(gameObject.transform.position.X + 16, gameObject.transform.position.Y + 16));
                        boomReturn.Normalize();
                        (gameObject.GetComponent("Physics") as Physics).Acceleration += boomReturn / 10 * projectileSpeed;
                    }

                    if (boomerangTimer >= 5)
                    {
                        if (gameObject.Tag == "Boomerang")
                        {
                            //GameWorld.objectsToRemove.Add(gameObject);
                        }
                    }
                }

                if (gameObject.Tag == "DeathMeteor")
                {
                    (gameObject.GetComponent("Physics") as Physics).Acceleration += meteorVector / 10;
                    abilityTimer += 0.001f;
                }

                if (gameObject.Tag == "GravityWell")
                {
                    (gameObject.GetComponent("Physics") as Physics).Acceleration += (TestVector / 4) * projectileSpeed;
                    foreach (GameObject go in GameWorld.gameObjects)
                    {
                        Vector2 pull = (gameObject.GetComponent("Physics") as Physics).GetVector(gameObject.transform.position, go.transform.position);
                        pull.Normalize();

                        if (go.Tag == "Dummy" || go.Tag == "Enemy")
                        {
                            if (Vector2.Distance(gameObject.transform.position, go.transform.position) < 300)
                            {
                                (go.GetComponent("Physics") as Physics).Acceleration += pull / 10;
                                if (GameWorld.Instance.client != null && go.Tag == "Enemy")
                                {
                                    GameWorld.Instance.client.SendEnemyAcceleration(go.Id, pull / 10);
                                }
                            }
                        }
                    }
                }

                if (gameObject.Tag == "DeathMine")
                {
                    mineTimer += GameWorld.Instance.deltaTime;
                    if (mineTimer > mineActivationTime)
                    {
                        deathMineActivated = true;
                        (gameObject.GetComponent("SpriteRenderer") as SpriteRenderer).Color = Color.Red;
                        Color color = Color.Red;
                        if (GameWorld.Instance.client != null)
                        {
                            GameWorld.Instance.client.SendColor(gameObject.Id, gameObject.Tag, color.R, color.G, color.B, color.A);
                        }
                    }
                }

                if ((gameObject.Tag.Contains("Fireball") || gameObject.Tag.Contains("Drain") || gameObject.Tag.Contains("Chain") || gameObject.Tag.Contains("Nova")) && !gameObject.Tag.Contains("Firewave"))
                {
                    if (gameObject.Tag.Contains("Drain") || gameObject.Tag.Contains("Chain"))
                    {
                        (gameObject.GetComponent("Physics") as Physics).Acceleration += (testVector / 2.5F) * projectileSpeed;
                    }
                    else
                    {
                        (gameObject.GetComponent("Physics") as Physics).Acceleration += (testVector / 2) * projectileSpeed;
                    }
                    if (distanceTravelled > travelDistance)
                    {
                        if (gameObject.Tag.Contains("Chain") && !chainActivated)
                        {
                            //GameWorld.objectsToRemove.Add(gameObject);
                        }
                        else if (gameObject.Tag != "Chain")
                        {
                            //GameWorld.objectsToRemove.Add(gameObject);
                        }
                    }
                }

                if (gameObject.Tag.Contains("Firewave"))
                {
                    (gameObject.GetComponent("Physics") as Physics).Acceleration += (testVector / 15);
                }

                if (chainActivated)
                {
                    if (chainTarget != null)
                    {
                        chainTimer += GameWorld.Instance.deltaTime;
                        gameObject.transform.position = chainTarget.transform.position;
                        Vector2 pull = (gameObject.GetComponent("Physics") as Physics).GetVector(GameWorld.Instance.player.transform.position, chainTarget.transform.position);
                        pull.Normalize();
                        (GameWorld.Instance.player.GetComponent("Physics") as Physics).Acceleration -= pull / 10;
                        if (chainTarget.Tag == "Enemy")
                        {
                            if (GameWorld.Instance.client != null)
                            {
                                GameWorld.Instance.client.Chain(chainTarget.Id, pull / 10);
                            }
                        }
                        if (keyState.IsKeyDown(Keys.T) || chainTimer > 2 || Vector2.Distance(new Vector2(chainTarget.transform.position.X + 16, chainTarget.transform.position.Y + 16), new Vector2(GameWorld.Instance.player.transform.position.X + 16, GameWorld.Instance.player.transform.position.Y + 16)) < 35)
                        {
                            chainActivated = false;

                            GameWorld.objectsToRemove.Add(gameObject);

                            if (GameWorld.Instance.client != null && gameObject.Id == GameWorld.Instance.player.Id)
                            {
                                GameWorld.Instance.client.SendRemoval(gameObject.Tag, gameObject.Id);
                                if (chainTarget.Tag == "Enemy")
                                {
                                    GameWorld.Instance.client.ChainRemove(chainTarget.Id);
                                }
                            }
                        }
                    }
                }

                if (gameObject.Tag == "HomingMissile")
                {
                    if (homingTimer > 0.5F)
                    {
                        //if (!GameWorld.gameObjects.Exists(x => x.Tag == "Enemy") && !GameWorld.gameObjects.Exists(x => x.Tag == "Dummy"))
                        //{
                        //    GameWorld.objectsToRemove.Add(gameObject);
                        //    if (GameWorld.Instance.client != null)
                        //    {
                        //        GameWorld.Instance.client.SendRemoval(gameObject.Tag, gameObject.Id);
                        //    }
                        //}
                        foreach (GameObject go in GameWorld.gameObjects)
                        {
                            if (Vector2.Distance(gameObject.transform.position, go.transform.position) < 300 && (go.Tag == "Dummy" || go.Tag == "Enemy"))
                            {
                                distance   = Vector2.Distance(gameObject.transform.position, go.transform.position);
                                bestTarget = go.transform.position;
                                foreach (GameObject item in GameWorld.gameObjects)
                                {
                                    if (Vector2.Distance(gameObject.transform.position, item.transform.position) < distance && (item.Tag == "Dummy" || item.Tag == "Enemy"))
                                    {
                                        distance   = Vector2.Distance(gameObject.transform.position, item.transform.position);
                                        bestTarget = item.transform.position;
                                    }
                                }
                                if (bestTarget != null)
                                {
                                }
                                Vector2 test = (gameObject.GetComponent("Physics") as Physics).GetVector(bestTarget, gameObject.transform.position);
                                test.Normalize();
                                (gameObject.GetComponent("Physics") as Physics).Acceleration += (test / 5) * projectileSpeed;
                                break;
                                //if (go.Tag == "Enemy")
                                //{
                                //    (gameObject.GetComponent("Physics") as Physics).Acceleration += (test / 10) * projectileSpeed;
                                //    break;
                                //}
                                //else
                                //{
                                //    (gameObject.GetComponent("Physics") as Physics).Acceleration += (test / 10) * projectileSpeed;
                                //    break;
                                //}
                            }
                            if (Vector2.Distance(gameObject.transform.position, go.transform.position) > 300 && (go.Tag == "Dummy" || go.Tag == "Enemy"))
                            {
                                //Vector2 test = (gameObject.GetComponent("Physics") as Physics).GetVector(target, gameObject.transform.position);
                                //test.Normalize();
                                (gameObject.GetComponent("Physics") as Physics).Acceleration += (testVector / 10) * projectileSpeed;
                            }
                        }
                    }
                    else
                    {
                        homingTimer += GameWorld.Instance.deltaTime;
                        Vector2 test = (gameObject.GetComponent("Physics") as Physics).GetVector(target, gameObject.transform.position);
                        test.Normalize();
                        (gameObject.GetComponent("Physics") as Physics).Acceleration += (test / 10) * projectileSpeed;
                    }
                }
                Vector2 oldPos = gameObject.transform.position;
                gameObject.transform.position += (gameObject.GetComponent("Physics") as Physics).Velocity;
                distanceTravelled             += Vector2.Distance(oldPos, gameObject.transform.position);
                CheckDistance();
                if (GameWorld.Instance.client != null)
                {
                    if (!gameObject.Tag.Contains("Enemy"))
                    {
                        GameWorld.Instance.client.SendProjectile(gameObject.Tag + ",Update", gameObject.transform.position, (gameObject.GetComponent("Physics") as Physics).Velocity);
                    }
                }

                if (abilityTimer > 2)
                {
                    if (gameObject.Tag == "DeathMeteor" || gameObject.Tag.Contains("Nova"))
                    {
                        //GameWorld.objectsToRemove.Add(gameObject);
                    }
                }
            }
        }