Ejemplo n.º 1
0
        public NPAvatar(Scene scene, string label, Vector3 pos, Vector3 orientAxis,float radians, string meshFile)
                        : base(scene, label, pos, orientAxis, radians, meshFile) {  
            first.Name =  "npFirst";
            follow.Name = "npFollow";
            above.Name =  "npAbove";
            stepSize = 40;
            random = new Random();
            move = true;
            cellsVisited = new Boolean[512,512];
            for (int row = 0; row < scene.Range; row++) {
                for(int col = 0; col < scene.Range; col++) {
                    cellsVisited[row, col] = false;
                }
            }
            Vector3 oldTranslation = Orientation.Translation;
            Orientation *= Matrix.CreateTranslation(-1 * Orientation.Translation);
            Orientation *= Matrix.CreateRotationY(90 * MathHelper.Pi / 180);
            Orientation *= Matrix.CreateTranslation(oldTranslation);
            targetTreasures = null;
            bearing = null;
            targetTreasures = new Queue<Model3D>();
            inverse_tressure_path = new Stack<Queue<OrderedPair>>();
            scene.PAUSE = false;
            currentTreasure = null;
            previousTreasure = null;
            destinationExploring = null;
            currentWayPoint = 1;
            direction = true;
            wayPointsToExplore = new OrderedPair [] {
                                                        new OrderedPair(504,0,504),
                                                        new OrderedPair(352,0,496),
                                                        new OrderedPair(16,0,496),
                                                        new OrderedPair(16,0,16),
                                                        new OrderedPair(32,0,16),
                                                        new OrderedPair(32,0,488),
                                                        new OrderedPair(48,0,488),
                                                        new OrderedPair(48,0,16),
                                                        new OrderedPair(64,0,16),
                                                        new OrderedPair(64,0,488),
                                                        new OrderedPair(80,0,488),
                                                        new OrderedPair(80,0,16),
                                                        new OrderedPair(96,0,16),
                                                        new OrderedPair(96,0,488),
                                                        new OrderedPair(112,0,488),
                                                        new OrderedPair(112,0,16),

                                                        new OrderedPair(128,0,16),
                                                        new OrderedPair(128,0,488),

                                                        new OrderedPair(144,0,488),
                                                        new OrderedPair(144,0,16),

                                                        new OrderedPair(160,0,16),
                                                        new OrderedPair(160,0,488),

                                                        new OrderedPair(176,0,488),
                                                        new OrderedPair(176,0,16),

                                                        new OrderedPair(192,0,16),
                                                        new OrderedPair(192,0,488),

                                                        new OrderedPair(208,0,488),
                                                        new OrderedPair(208,0,16),

                                                        new OrderedPair(224,0,16),
                                                        new OrderedPair(225,0,488),
                                                    };

            /*  STATE VARIABLES */
            previousMovementMethod = MovementMethod.NONE;
            currentMovementMethod = MovementMethod.NONE;
            path_builder = PathBuildMethod.NONE;
            wayPointReached = false;
            treasuresChanged = false;
            returnedToOrigin = true;
        }
Ejemplo n.º 2
0
        public void STATE_MACHINE_FUNCTION_TO_DETERMINE_MOVEMENT_METHOD_THIS_IS_KEY() {
            if(currentWayPoint == wayPointsToExplore.Length && wayPointReached) {
                direction = false;
                currentWayPoint=wayPointsToExplore.Length-2;
            }
            if(currentWayPoint == -1 && WayPointReached) {
                direction = true;
                currentWayPoint = 1;
            }
            //if (treasureCount() == 0){
            //    treasuresChanged = false;
            //}

            /*
             *  WHEN THE GAME STARTS FIRST STATE IS TO BUILD EXPLORER PATH
             *  THIS IS ALSO THE STATE WHERE YOU RETURN WHEN YOU HIT A WAY
             *  POINT IN THE EXPLORER PATH
             */
            if  ( 
                    treasureCount() == 0 &&
                    path_builder == PathBuildMethod.NONE &&
                    previousMovementMethod == MovementMethod.NONE &&
                    currentMovementMethod == MovementMethod.NONE && 
                    !(WayPointReached || treasuresChanged) &&
                    returnedToOrigin
                ) {
                
                status = "FIRST STATE";
                path_builder = PathBuildMethod.EXPLORER_PATH;
                previousMovementMethod = MovementMethod.BUILD_PATH;
                currentMovementMethod = MovementMethod.BUILD_PATH;
                //printStateVariables(1);
            } 
            
            /*
             *  STATES THAT DEAL IF YOU GO INTO EXPLORER PATH FIRST
             */
            else if (
		                treasureCount() == 0 &&
                        path_builder == PathBuildMethod.EXPLORER_PATH &&
                        previousMovementMethod == MovementMethod.BUILD_PATH &&
                        currentMovementMethod == MovementMethod.BUILD_PATH &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "SWITCHING TO EXPLORER";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.EXPLORER;
                //printStateVariables(2);
            } else if(  treasureCount() == 0 &&
                        path_builder == PathBuildMethod.NONE && 
                        previousMovementMethod == MovementMethod.BUILD_PATH && 
                        currentMovementMethod == MovementMethod.EXPLORER &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                     ) {
                status = "FIRST STEP EVER -- GOING TO EXPLORE";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.EXPLORER;
                //printStateVariables(3);                     
            } else if(  treasureCount() == 0 &&
                        path_builder == PathBuildMethod.NONE && 
                        previousMovementMethod == MovementMethod.EXPLORER && 
                        currentMovementMethod == MovementMethod.EXPLORER &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                     ) {
                status = "EXPLORING";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.EXPLORER;
                //printStateVariables(3);                     
            } else if(  treasureCount() == 0 && 
                        path_builder == PathBuildMethod.NONE && 
                        previousMovementMethod == MovementMethod.EXPLORER && 
                        currentMovementMethod == MovementMethod.EXPLORER && 
                        wayPointReached &&
                        !treasuresChanged &&
                        returnedToOrigin
                     ) {
                status = "RENEW EXPLORER PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = MovementMethod.NONE;
                currentMovementMethod = MovementMethod.NONE;
                wayPointReached = false;
                //printStateVariables(4);
            }

            /*
            *  STATES THAT DEAL WITH IF YOU HAVE TREASURES SITED
            */
            else if(    treasureCount() != 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.EXPLORER &&
                        currentMovementMethod == MovementMethod.EXPLORER &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "FOUND TREASURE BUILDING PATH";
                path_builder = PathBuildMethod.A_STAR_PATH;
                previousMovementMethod = MovementMethod.BUILD_PATH;
                currentMovementMethod = MovementMethod.BUILD_PATH;
                //printStateVariables(5);
            } else if(  treasureCount() != 0 && 
                        path_builder == PathBuildMethod.A_STAR_PATH &&
                        previousMovementMethod == MovementMethod.BUILD_PATH &&
                        currentMovementMethod == MovementMethod.BUILD_PATH &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "SWITCHING TO TREASURE PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.TRESSURE;
                //printStateVariables(6);
            } else if(  treasureCount() != 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.BUILD_PATH &&
                        currentMovementMethod == MovementMethod.TRESSURE &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "FIRST STEP TOWARDS -- TREASURE";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.TRESSURE;
                //printStateVariables(7);
            } else if(  treasureCount() != 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.TRESSURE &&
                        currentMovementMethod == MovementMethod.TRESSURE &&
                        !(wayPointReached || treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "GETTING TREASURE";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.TRESSURE;
                //printStateVariables(8);
            } else if(  treasureCount() != 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.TRESSURE &&
                        currentMovementMethod == MovementMethod.TRESSURE &&
                        !(wayPointReached || !treasuresChanged) &&
                        returnedToOrigin
                    ) {
                status = "ANOTHER TREASURE FOUND -- SETTING PATH";
                path_builder = PathBuildMethod.A_STAR_PATH;
                previousMovementMethod = MovementMethod.BUILD_PATH;
                currentMovementMethod = MovementMethod.BUILD_PATH;
                //printStateVariables(9);
            }

           /*
            *  STATES THAT DEAL WITH IF YOU HAVE TREASURES OBTAINED
            *  ALL SITED TREASURE AND NEED TO RETURN TO EXPLORER PATH
            */
            else if(    treasureCount() == 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.TRESSURE &&
                        currentMovementMethod == MovementMethod.TRESSURE &&
                        !(wayPointReached || !treasuresChanged) &&
                        returnedToOrigin//RETURNED TO ORIGING SET AFTER THIS
                    ) {
                status = "SETTING UP RETURN PATH";
                path_builder = PathBuildMethod.SET_RETURN_TO_EXPLORER_PATH;
                previousMovementMethod = MovementMethod.BUILD_PATH;
                currentMovementMethod = MovementMethod.BUILD_PATH;
                //printStateVariables(10);
            } else if(  treasureCount() == 0 && 
                        path_builder == PathBuildMethod.SET_RETURN_TO_EXPLORER_PATH &&
                        previousMovementMethod == MovementMethod.BUILD_PATH &&
                        currentMovementMethod == MovementMethod.BUILD_PATH && 
                        !wayPointReached &&
                        treasuresChanged &&
                        !returnedToOrigin
                    ) {
                status = "FIRST STEP BACK TO RETURN PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.RETURN_TO_EXPLORER_PATH;
                //printStateVariables(11);
            }else if(  treasureCount() == 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.BUILD_PATH &&
                        currentMovementMethod == MovementMethod.RETURN_TO_EXPLORER_PATH &&
                        !wayPointReached &&
                        treasuresChanged &&
                        !returnedToOrigin
                    ) {
                status = "ON RETURN PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.RETURN_TO_EXPLORER_PATH;
                //printStateVariables(12);
            }else if(  treasureCount() == 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.RETURN_TO_EXPLORER_PATH &&
                        currentMovementMethod == MovementMethod.RETURN_TO_EXPLORER_PATH &&
                        !wayPointReached &&
                        treasuresChanged &&
                        !returnedToOrigin
                    ) {
                status = "ON RETURN PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = currentMovementMethod;
                currentMovementMethod = MovementMethod.RETURN_TO_EXPLORER_PATH;
                //printStateVariables(13);
            }else if(  treasureCount() == 0 && 
                        path_builder == PathBuildMethod.NONE &&
                        previousMovementMethod == MovementMethod.RETURN_TO_EXPLORER_PATH &&
                        currentMovementMethod == MovementMethod.RETURN_TO_EXPLORER_PATH &&
                        !wayPointReached &&
                        treasuresChanged &&
                        returnedToOrigin
                    ) {
                status = "BACK AT WHERE I LEFT OFF IN EXPLORER PATH";
                path_builder = PathBuildMethod.NONE;
                previousMovementMethod = MovementMethod.EXPLORER;
                currentMovementMethod = MovementMethod.EXPLORER;
                treasuresChanged = false;
                foreach(OrderedPair O in queue) {
                    scene.WayPoints[(int)O.Z, (int)O.X].changeCubeColor(Color.Green);
                }
                //printStateVariables(14);
            }

            /*  
             *  THIS IS JUST IN THE "CASE" THAT I MISSED A TRANSITION
             *  IN MY STATE MACHINE
             */
            else {
                scene.PAUSE = true;
                printStateVariables(-1);
            }

        }