Пример #1
0
        public void SetCharacter(Character c, int carSprite, CharacterDirection carSpriteDir, int view = 0, int loop = 0, int frame = 0)
        {
            this.DetachCharacter();
            int carl = 0;
            int carw = 0;

            if (carSpriteDir == eDirectionDown || carSpriteDir == eDirectionUp)
            {
                carl = Game.SpriteHeight[carSprite];
                carw = Game.SpriteWidth[carSprite];
            }
            else if (carSpriteDir == eDirectionLeft || carSpriteDir == eDirectionRight)
            {
                carl = Game.SpriteWidth[carSprite];
                carw = Game.SpriteHeight[carSprite];
            }
            else
            {
                AbortGame("Source car sprite direction cannot be diagonal, please provide sprite having one of the following directions: left, right, up or down.");
                return;
            }
            this.c               = c;
            this.carSprite       = carSprite;
            this.carSpriteAngle  = RotatedView.AngleForLoop(carSpriteDir);
            this.viewFrame       = Game.GetViewFrame(view, loop, frame);
            this.bodyLength      = IntToFloat(carl);
            this.bodyWidth       = IntToFloat(carw);
            this.collPointOff[0] = VectorF.create(carl / 2, -carw / 2);
            this.collPointOff[1] = VectorF.create(carl / 2, carw / 2);
            this.collPointOff[2] = VectorF.create(-carl / 2, carw / 2);
            this.collPointOff[3] = VectorF.create(-carl / 2, -carw / 2);
            this.SyncCharacter();
        }
Пример #2
0
        // Methods
        public void ResetBase(VectorF pos, VectorF dir)
        {
            if (pos == null)
            {
                this.position = VectorF.create(Room.Width / 2, Room.Height / 2);
            }
            else
            {
                this.position = pos.clone();
            }
            if (dir == null)
            {
                this.direction = VectorF.create(0, 1);
            }
            else
            {
                this.direction = dir.clone();
                this.direction.normalize();
            }
            int i = 0;

            for (i = 0; i < NUM_COLLISION_POINTS; i += 1)
            {
                this.collPoint[i] = new VectorF();
            }
            this.velocity        = VectorF.zero();
            this.angularVelocity = 0.0f;
        }
Пример #3
0
        public void UpdateDebugAIRegions(DrawingSurface ds)
        {
            ds.DrawingColor = Game.GetColorFromRGB(255, 255, 255);
            int i = 0;

            for (i = 0; i < MAX_RACING_CARS; i += 1)
            {
                int veh = RobotsRB[i].vehicleIndex;
                if (veh < 0)
                {
                    continue;
                }
                VectorF pos = Cars[veh].position;
                if (pos == null)
                {
                    continue;
                }
                VectorF dir = VectorF.create(50, 0);
                dir.rotate(RobotsRB[i].targetAngle);
                dir.add(pos);
                int x1 = FloatToInt(pos.x, eRoundNearest) - GetViewportX();
                int y1 = FloatToInt(pos.y, eRoundNearest) - GetViewportY();
                int x2 = FloatToInt(dir.x, eRoundNearest) - GetViewportX();
                int y2 = FloatToInt(dir.y, eRoundNearest) - GetViewportY();
                ds.DrawLine(x1, y1, x2, y2);
            }
        }
Пример #4
0
        public int TryHitNode(int x, int y, float threshold)
        {
            if (PathNodeCount == 0)
            {
                return(-1);
            }
            VectorF hit         = VectorF.create(x, y);
            float   minDist     = 9999.0f;
            int     nearestNode = -1;
            int     i           = 0;

            for (i = 0; i < MAX_PATH_NODES; i += 1)
            {
                if (Paths[i].pt == null)
                {
                    continue;
                }
                float dist = VectorF.distance(hit, Paths[i].pt);
                if (dist <= threshold && dist < minDist)
                {
                    minDist     = dist;
                    nearestNode = i;
                }
            }
            return(nearestNode);
        }
Пример #5
0
 public void reset(VectorF pos, VectorF dir)
 {
     this.engine   = 0.0f;
     this.steering = 0.0f;
     this.brakes   = 0.0f;
     this.friction = 0.0f;
     if (pos == null)
     {
         this.position = VectorF.create(Room.Width / 2, Room.Height / 2);
     }
     else
     {
         this.position = pos.clone();
     }
     if (dir == null)
     {
         this.direction = VectorF.create(0, 1);
     }
     else
     {
         this.direction = dir.clone();
         this.direction.normalize();
     }
     this.directionAngle     = this.direction.angle();
     this.thrust             = new VectorF();
     this.brakeForce         = new VectorF();
     this.driveVelocityValue = 0.0f;
     this.driveVelocity      = new VectorF();
     this.impactVelocity     = new VectorF();
     this.velocity           = new VectorF();
     this.thrustForceValue   = 0.0f;
     this.brakeForceValue    = 0.0f;
     this.syncCharacter();
 }
Пример #6
0
        public VectorF PositionCarOnGrid(int car, int gridpos)
        {
            VectorF pos = StartingGrid[gridpos].clone();

            pos.x += 4.0f + Cars[car].bodyLength / 2.0f;
            pos.y += 1.0f;
            Cars[car].Reset(pos, VectorF.create(-1, 0));
            return(null);
        }
Пример #7
0
 public override void room_Load()
 {
     StartingGrid[0] = VectorF.create(1140, 326 + 12);
     StartingGrid[1] = VectorF.create(1172, 273 + 12);
     StartingGrid[2] = VectorF.create(1204, 326 + 12);
     StartingGrid[3] = VectorF.create(1236, 273 + 12);
     StartingGrid[4] = VectorF.create(1268, 326 + 12);
     StartingGrid[5] = VectorF.create(1300, 273 + 12);
     FadeOut(0);
     StopAllAudio();
     SetupAIRace();
     aWelcome_to_the_Show.Play();
 }
Пример #8
0
        public int PutNewNode(int x, int y)
        {
            if (FreePathSlot < 0)
            {
                return(0);
            }
            int newnode = FreePathSlot;

            Paths[newnode].Reset();
            Paths[newnode].pt = VectorF.create(x, y);
            OnNewNode(newnode, LastPathNode, FirstPathNode);
            PathNodeCount += 1;
            FindFirstFreeNode();
            return(newnode);
        }
Пример #9
0
        public int PutNewNode(int x, int y)
        {
            if (FreeCheckptSlot < 0)
            {
                return(0);
            }
            int newnode = FreeCheckptSlot;

            Checkpoints[newnode].Reset();
            Checkpoints[newnode].pt = VectorF.create(x, y);
            OnNewNode(newnode, LastCheckpt, FirstCheckpt);
            Checkpoints[newnode].order = CheckptCount;
            CheckptCount += 1;
            FindFirstFreeCheckpoint();
            return(newnode);
        }
Пример #10
0
        public void LoadAIPaths()
        {
            File f = File.Open("$APPDATADIR$/Data/aipaths.dat", eFileRead);

            if (f == null)
            {
                f = File.Open("$INSTALLDIR$/Data/aipaths.dat", eFileRead);
                if (f == null)
                {
                    return;
                }
            }
            int n = 0;

            for (n = 0; n < MAX_PATH_NODES; n += 1)
            {
                Paths[n].Reset();
            }
            PathNodeCount = 0;
            FirstPathNode = f.ReadInt();
            LastPathNode  = f.ReadInt();
            n             = FirstPathNode;
            int loads = 0;

            do
            {
                loads += 1;
                if (loads % 50 == 0)
                {
                    Wait(1);
                }
                int x = f.ReadInt();
                int y = f.ReadInt();
                Paths[n].pt        = VectorF.create(x, y);
                Paths[n].radius    = IntToFloat(f.ReadInt());
                Paths[n].threshold = IntToFloat(f.ReadInt());
                Paths[n].speed     = IntToFloat(f.ReadInt());
                Paths[n].prev      = f.ReadInt();
                Paths[n].next      = f.ReadInt();
                PathNodeCount     += 1;
                n = Paths[n].next;
            }while (n != FirstPathNode);

            FindFirstFreeNode();
        }
Пример #11
0
        public void LoadRaceCheckpoints()
        {
            File f = File.Open("$APPDATADIR$/Data/checkpoints.dat", eFileRead);

            if (f == null)
            {
                f = File.Open("$INSTALLDIR$/Data/checkpoints.dat", eFileRead);
                if (f == null)
                {
                    return;
                }
            }
            int n = 0;

            for (n = 0; n < MAX_CHECKPOINTS; n += 1)
            {
                Checkpoints[n].Reset();
            }
            CheckptCount = 0;
            FirstCheckpt = f.ReadInt();
            LastCheckpt  = f.ReadInt();
            n            = FirstCheckpt;
            int loads = 0;

            do
            {
                loads += 1;
                if (loads % 50 == 0)
                {
                    Wait(1);
                }
                int x = f.ReadInt();
                int y = f.ReadInt();
                Checkpoints[n].pt    = VectorF.create(x, y);
                Checkpoints[n].order = CheckptCount;
                Checkpoints[n].prev  = f.ReadInt();
                Checkpoints[n].next  = f.ReadInt();
                CheckptCount        += 1;
                n = Checkpoints[n].next;
            }while (n != FirstCheckpt);

            f.Close();
            FindFirstFreeCheckpoint();
        }
Пример #12
0
        public int TryInsertNode(int refNode, int x, int y)
        {
            if (FreePathSlot < 0)
            {
                return(0);
            }
            int nodep = Paths[refNode].prev;
            int noden = Paths[refNode].next;

            if (nodep < 0 && noden < 0)
            {
                return(PutNewNode(x, y));
            }
            int nodeopp = 0;

            if (nodep < 0)
            {
                nodeopp = noden;
            }
            else if (noden < 0)
            {
                nodeopp = nodep;
            }
            else
            {
                VectorF hit     = VectorF.create(x, y);
                VectorF hitDir  = VectorF.subtract(hit, Paths[refNode].pt);
                VectorF nextDir = VectorF.subtract(Paths[noden].pt, Paths[refNode].pt);
                VectorF prevDir = VectorF.subtract(Paths[nodep].pt, Paths[refNode].pt);
                if (Maths.AbsF(VectorF.angleBetween(hitDir, nextDir)) <= Maths.AbsF(VectorF.angleBetween(hitDir, prevDir)))
                {
                    nodeopp = noden;
                }
                else
                {
                    nodeopp = nodep;
                }
            }
            VectorF newpt = Paths[refNode].pt.clone();

            newpt.add(Paths[nodeopp].pt);
            newpt.scale(0.5f);
            int insertPrev = 0;
            int insertNext = 0;

            if (nodeopp == noden)
            {
                insertPrev = refNode;
                insertNext = noden;
            }
            else
            {
                insertPrev = nodep;
                insertNext = refNode;
            }
            int newnode = FreePathSlot;

            Paths[newnode].Reset();
            Paths[newnode].pt = newpt;
            OnNewNode(newnode, insertPrev, insertNext);
            PathNodeCount += 1;
            FindFirstFreeNode();
            return(newnode);
        }
Пример #13
0
        public int TryInsertNode(int refNode, int x, int y)
        {
            if (FreeCheckptSlot < 0)
            {
                return(0);
            }
            int nodep = Checkpoints[refNode].prev;
            int noden = Checkpoints[refNode].next;

            if (nodep < 0 && noden < 0)
            {
                return(PutNewNode(x, y));
            }
            int nodeopp = 0;

            if (nodep < 0)
            {
                nodeopp = noden;
            }
            else if (noden < 0)
            {
                nodeopp = nodep;
            }
            else
            {
                VectorF hit     = VectorF.create(x, y);
                VectorF hitDir  = VectorF.subtract(hit, Checkpoints[refNode].pt);
                VectorF nextDir = VectorF.subtract(Checkpoints[noden].pt, Checkpoints[refNode].pt);
                VectorF prevDir = VectorF.subtract(Checkpoints[nodep].pt, Checkpoints[refNode].pt);
                if (Maths.AbsF(VectorF.angleBetween(hitDir, nextDir)) <= Maths.AbsF(VectorF.angleBetween(hitDir, prevDir)))
                {
                    nodeopp = noden;
                }
                else
                {
                    nodeopp = nodep;
                }
            }
            VectorF newpt = Checkpoints[refNode].pt.clone();

            newpt.add(Checkpoints[nodeopp].pt);
            newpt.scale(0.5f);
            int insertPrev = 0;
            int insertNext = 0;

            if (nodeopp == noden)
            {
                insertPrev = refNode;
                insertNext = noden;
            }
            else
            {
                insertPrev = nodep;
                insertNext = refNode;
            }
            int newnode = FreeCheckptSlot;

            Checkpoints[newnode].Reset();
            Checkpoints[newnode].pt = newpt;
            OnNewNode(newnode, insertPrev, insertNext);
            CheckptCount += 1;
            int fixnode = insertNext;

            while (fixnode != FirstCheckpt)
            {
                Checkpoints[fixnode].order += 1;
                fixnode = Checkpoints[fixnode].next;
            }
            FindFirstFreeCheckpoint();
            return(newnode);
        }