public static bool FindPoint(LogicTileMap tileMap, LogicVector2 pos1, LogicVector2 pos2, LogicVector2 pos3, LogicVector2 pos4)
        {
            pos1.Set(pos2.m_x, pos2.m_y);
            pos1.Substract(pos3);

            int length = pos1.GetLength();

            pos1.m_x = (pos1.m_x << 7) / length;
            pos1.m_y = (pos1.m_y << 7) / length;

            pos4.Set(pos3.m_x, pos3.m_y);

            int radius = LogicMath.Clamp(length / 128, 10, 25);

            for (int i = 0; i < radius; i++)
            {
                if (tileMap.IsPassablePathFinder(pos4.m_x >> 8, pos4.m_y >> 8))
                {
                    pos4.m_x = (int)((pos4.m_x & 0xFFFFFF00) | 128);
                    pos4.m_y = (int)((pos4.m_y & 0xFFFFFF00) | 128);

                    return(true);
                }

                pos4.Add(pos1);
            }

            return(false);
        }
示例#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 SetPosition(int x, int y)
        {
            if (this.m_parent != null)
            {
                if (!this.m_parent.IsFlying() &&
                    !this.m_parent.IsUnderground() &&
                    this.m_parent.GetJump() <= 0 &&
                    !this.m_ignorePush)
                {
                    this.ValidatePos();

                    if (this.m_position.m_x >> 8 == x >> 8)
                    {
                        if ((this.m_position.m_y ^ (uint)y) < 256)
                        {
                            goto set;
                        }
                    }

                    LogicTileMap tileMap = this.m_parent.GetParent().GetLevel().GetTileMap();

                    int pathFinderX = x >> 8;
                    int pathFinderY = y >> 8;

                    if (!tileMap.IsPassablePathFinder(pathFinderX, pathFinderY))
                    {
                        LogicTile tile = tileMap.GetTile(pathFinderX / 2, pathFinderY / 2);

                        if (LogicDataTables.GetGlobals().JumpWhenHitJumpable())
                        {
                            bool allowJump = false;

                            for (int i = 0; i < tile.GetGameObjectCount(); i++)
                            {
                                LogicGameObject gameObject = tile.GetGameObject(i);

                                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                {
                                    LogicBuilding building = (LogicBuilding)gameObject;

                                    if (building.GetHitWallDelay() > 0)
                                    {
                                        allowJump = true;
                                    }
                                }
                            }

                            if (allowJump)
                            {
                                this.m_position.m_x = x;
                                this.m_position.m_y = y;

                                this.m_parent.EnableJump(128);

                                return;
                            }
                        }

                        if (LogicDataTables.GetGlobals().SlideAlongObstacles())
                        {
                            throw new NotImplementedException(); // TODO: Implement this.
                        }
                        else
                        {
                            x = LogicMath.Clamp(x, (int)(this.m_position.m_x & 0xFFFFFF00), this.m_position.m_x | 0xFF);
                            y = LogicMath.Clamp(y, (int)(this.m_position.m_y & 0xFFFFFF00), this.m_position.m_y | 0xFF);
                        }

                        this.m_position.m_x = x;
                        this.m_position.m_y = y;

                        this.ValidatePos();
                        return;
                    }
                }
            }

set:

            this.m_position.m_x = x;
            this.m_position.m_y = y;
        }