Exemple #1
0
        private void CreateRock()
        {
            if (PurviewMgr.IsMainHost)
            {
                Vector2 newPos = new Vector2();
                while (true)
                {
                    newPos = RandomHelper.GetRandomVector2(-100, 100);

                    int posType = RandomHelper.GetRandomInt(0, 2);

                    if (posType == 0)
                    {
                        if (newPos.X < 0)
                            newPos.X -= mapRect.X + AddObjSpace;
                        else
                            newPos.X += mapRect.Width + mapRect.X + AddObjSpace;

                        if (newPos.Y < 0)
                            newPos.Y -= mapRect.Y + AddObjSpace;
                        else
                            newPos.Y += mapRect.Y + mapRect.Height + AddObjSpace;
                    }
                    else if (posType == 1)
                    {
                        newPos.X *= mapRect.Width / 200;
                        newPos.X += mapRect.Width / 2 + mapRect.X;

                        if (newPos.Y < 0)
                            newPos.Y -= mapRect.Y + AddObjSpace;
                        else
                            newPos.Y += mapRect.Y + mapRect.Height + AddObjSpace;
                    }
                    else if (posType == 2)
                    {
                        newPos.Y *= mapRect.Height / 200;
                        newPos.Y += mapRect.Y + mapRect.Height / 2;

                        if (newPos.X < 0)
                            newPos.X -= mapRect.X + AddObjSpace;
                        else
                            newPos.X += mapRect.Width + mapRect.X + AddObjSpace;

                    }
                    if (CanAddObjAtPos(newPos))
                        break;

                }
                float speed = RandomHelper.GetRandomFloat(SpaceWarConfig.RockMinSpeed, SpaceWarConfig.RockMaxSpeed);
                Vector2 way = Vector2.Normalize(MapCenterPos - newPos);
                Vector2 delta = RandomHelper.GetRandomVector2(-0.7f, 0.7f);
                Vector2 Vel = Vector2.Normalize(way + delta) * speed;

                float aziVel = RandomHelper.GetRandomFloat(0, SpaceWarConfig.RockMaxAziSpeed);
                float scale = RandomHelper.GetRandomFloat(0.4f, 1.4f);
                int kind = RandomHelper.GetRandomInt(0, ((int)RockTexNo.Max) - 1);

                Rock newRock = new Rock("Rock" + rockCount, newPos, Vel, aziVel, scale, kind);

                newRock.OnCollided += new OnCollidedEventHandler(Rock_OnCollided);
                sceneMgr.AddGameObj("rock", newRock);

                rocks.Add(newRock);
                SyncCasheWriter.SubmitCreateObjMg("rock", typeof(Rock), "Rock" + rockCount, newPos, Vel, aziVel, scale, kind);

                rockCount++;

            }
        }
Exemple #2
0
        private void CreateRock()
        {
            if (PurviewMgr.IsMainHost)
            {
                Vector2 newPos = new Vector2();
                while (true)
                {
                    newPos = RandomHelper.GetRandomVector2(-100, 100);

                    int posType = RandomHelper.GetRandomInt(0, 2);

                    if (posType == 0)
                    {
                        if (newPos.X < 0)
                        {
                            newPos.X -= mapRect.X + AddObjSpace;
                        }
                        else
                        {
                            newPos.X += mapRect.Width + mapRect.X + AddObjSpace;
                        }

                        if (newPos.Y < 0)
                        {
                            newPos.Y -= mapRect.Y + AddObjSpace;
                        }
                        else
                        {
                            newPos.Y += mapRect.Y + mapRect.Height + AddObjSpace;
                        }
                    }
                    else if (posType == 1)
                    {
                        newPos.X *= mapRect.Width / 200;
                        newPos.X += mapRect.Width / 2 + mapRect.X;

                        if (newPos.Y < 0)
                        {
                            newPos.Y -= mapRect.Y + AddObjSpace;
                        }
                        else
                        {
                            newPos.Y += mapRect.Y + mapRect.Height + AddObjSpace;
                        }
                    }
                    else if (posType == 2)
                    {
                        newPos.Y *= mapRect.Height / 200;
                        newPos.Y += mapRect.Y + mapRect.Height / 2;

                        if (newPos.X < 0)
                        {
                            newPos.X -= mapRect.X + AddObjSpace;
                        }
                        else
                        {
                            newPos.X += mapRect.Width + mapRect.X + AddObjSpace;
                        }
                    }
                    if (CanAddObjAtPos(newPos))
                    {
                        break;
                    }
                }
                float   speed = RandomHelper.GetRandomFloat(SpaceWarConfig.RockMinSpeed, SpaceWarConfig.RockMaxSpeed);
                Vector2 way   = Vector2.Normalize(MapCenterPos - newPos);
                Vector2 delta = RandomHelper.GetRandomVector2(-0.7f, 0.7f);
                Vector2 Vel   = Vector2.Normalize(way + delta) * speed;

                float aziVel = RandomHelper.GetRandomFloat(0, SpaceWarConfig.RockMaxAziSpeed);
                float scale  = RandomHelper.GetRandomFloat(0.4f, 1.4f);
                int   kind   = RandomHelper.GetRandomInt(0, ((int)RockTexNo.Max) - 1);

                Rock newRock = new Rock("Rock" + rockCount, newPos, Vel, aziVel, scale, kind);

                newRock.OnCollided += new OnCollidedEventHandler(Rock_OnCollided);
                sceneMgr.AddGameObj("rock", newRock);

                rocks.Add(newRock);
                SyncCasheWriter.SubmitCreateObjMg("rock", typeof(Rock), "Rock" + rockCount, newPos, Vel, aziVel, scale, kind);

                rockCount++;
            }
        }