コード例 #1
0
        public void CheckWall(LogicVector2 position)
        {
            if (this.m_parent != null)
            {
                LogicGameObject gameObject = this.m_parent.GetParent();
                LogicTile       tile       = gameObject.GetLevel().GetTileMap().GetTile(position.m_x >> 9, position.m_y >> 9);

                if (tile != null)
                {
                    for (int i = 0; i < tile.GetGameObjectCount(); i++)
                    {
                        LogicGameObject go = tile.GetGameObject(i);

                        if (go.IsWall() &&
                            go.IsAlive())
                        {
                            this.m_wall = go;

                            if (((LogicBuilding)go).GetHitWallDelay() <= 0)
                            {
                                ++this.m_wallCount;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void PushTrap(LogicVector2 position, int time, int id, bool ignorePrevPush, bool verifyPushPosition)
        {
            if (this.m_pushTime <= 0 || ignorePrevPush)
            {
                if (this.m_parent != null && this.m_parent.GetJump() <= 0 && !this.m_parent.GetParent().IsHero())
                {
                    LogicGameObject parent = this.m_parent.GetParent();

                    if (!parent.IsHero())
                    {
                        if (id != 0 && !ignorePrevPush)
                        {
                            int idx = -1;

                            for (int k = 0; k < 3; k++)
                            {
                                if (this.m_preventsPushId[k] == id)
                                {
                                    return;
                                }

                                if (this.m_preventsPushTime[k] == 0)
                                {
                                    idx = k;
                                }
                            }

                            if (idx == -1)
                            {
                                return;
                            }

                            this.m_preventsPushId[idx]   = id;
                            this.m_preventsPushTime[idx] = 1500;
                        }

                        this.m_pushTime     = time;
                        this.m_pushInitTime = time;
                        this.m_pushBackStartPosition.m_x = this.m_position.m_x;
                        this.m_pushBackStartPosition.m_y = this.m_position.m_y;
                        this.m_pushBackEndPosition.m_x   = this.m_position.m_x + position.m_x;
                        this.m_pushBackEndPosition.m_y   = this.m_position.m_y + position.m_y;

                        if (verifyPushPosition)
                        {
                            int pushBackEndPositionX = this.m_pushBackEndPosition.m_x;
                            int pushBackEndPositionY = this.m_pushBackEndPosition.m_y;

                            if (LogicMath.Max(LogicMath.Abs(position.m_x), LogicMath.Abs(position.m_y)) != 0)
                            {
                                LogicTileMap tileMap = parent.GetLevel().GetTileMap();

                                if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8))
                                {
                                    LogicVector2 pos = new LogicVector2();
                                    LogicRandom  rnd = new LogicRandom(pushBackEndPositionX + pushBackEndPositionY);

                                    tileMap.GetNearestPassablePosition(pushBackEndPositionX + rnd.Rand(512) - 256,
                                                                       pushBackEndPositionY + rnd.Rand(512) - 256, pos, 2048);

                                    pushBackEndPositionX = pos.m_x;
                                    pushBackEndPositionY = pos.m_y;
                                }

                                if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8))
                                {
                                    Debugger.Warning("PushTrap->ended on inmovable");
                                }
                            }

                            this.m_pushBackEndPosition.m_x = pushBackEndPositionX;
                            this.m_pushBackEndPosition.m_y = pushBackEndPositionY;
                        }

                        this.m_ignorePush = verifyPushPosition;

                        int angle = position.GetAngle();
                        this.m_direction = angle + (angle <= 180 ? 180 : -180);
                    }
                }
            }
        }
コード例 #3
0
        public void CreatePatrolArea(LogicGameObject patrolPost, LogicLevel level, bool unk, int idx)
        {
            LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(8);

            if (this.m_patrolPost == null)
            {
                this.m_patrolPost = patrolPost;
            }

            int startX = 0;
            int startY = 0;
            int endX   = 0;
            int endY   = 0;
            int midX   = 0;
            int midY   = 0;

            int width  = 0;
            int height = 0;

            int radius = 0;

            if (patrolPost != null)
            {
                startX = patrolPost.GetX() - 128;
                startY = patrolPost.GetY() - 128;
                endX   = patrolPost.GetX() + (patrolPost.GetWidthInTiles() << 9) + 128;
                endY   = patrolPost.GetY() + (patrolPost.GetHeightInTiles() << 9) + 128;
                midX   = patrolPost.GetMidX();
                midY   = patrolPost.GetMidY();
                width  = patrolPost.GetWidthInTiles() << 8;
                height = patrolPost.GetHeightInTiles() << 8;
                radius = 1536;
            }

            if (radius * radius >= (uint)(width * width + height * height))
            {
                LogicVector2 tmp1 = new LogicVector2();
                LogicVector2 tmp2 = new LogicVector2();
                LogicVector2 tmp3 = new LogicVector2();
                LogicVector2 tmp4 = new LogicVector2();

                tmp2.Set(midX, midY);

                int rnd = patrolPost.GetLevel().GetLogicTime().GetTick() + idx;

                midX = midX + 127 * rnd % 1024 - 512;
                midY = midY + 271 * rnd % 1024 - 512;

                for (int i = 0, j = 45; i < 4; i++, j += 90)
                {
                    tmp1.Set(midX + LogicMath.Cos(j, radius), midY + LogicMath.Sin(j, radius));
                    LogicHeroBaseComponent.FindPoint(patrolPost.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4);
                    wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y));
                }

                tmp1.Destruct();
                tmp2.Destruct();
                tmp3.Destruct();
                tmp4.Destruct();
            }
            else
            {
                wayPoints.Add(new LogicVector2(endX, endY));
                wayPoints.Add(new LogicVector2(startX, endY));
                wayPoints.Add(new LogicVector2(startX, startY));
                wayPoints.Add(new LogicVector2(endX, startY));
            }

            this.ClearPatrolArea();

            this.m_wayPoints         = wayPoints;
            this.m_patrolAreaCounter = 0;

            if (this.m_wayPoints.Size() > 1)
            {
                int closestLength = 0x7FFFFFFF;

                for (int i = 1, size = this.m_wayPoints.Size(); i < size; i++)
                {
                    LogicVector2 wayPoint = this.m_wayPoints[i];

                    int length = (wayPoint.m_x - (this.m_position.m_x >> 16)) * (wayPoint.m_x - (this.m_position.m_x >> 16)) +
                                 (wayPoint.m_y - (this.m_position.m_y >> 16)) * (wayPoint.m_y - (this.m_position.m_y >> 16));

                    if (length < closestLength)
                    {
                        this.m_patrolAreaCounter = i;
                        closestLength            = length;
                    }
                }
            }

            this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true);
        }