Пример #1
0
 public static List<List<Vector3>> findWater(LevelInfo levelInfo)
 {
     height = levelInfo.getHeight();
     width = levelInfo.getHeight();
     map = levelInfo.TextureMap;
     List<List<Vector3>> waterPoints = new List<List<Vector3>>();
     waterMap = new bool[width, height];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             if (!waterMap[x, y] && isEdge(x, y))
             {
                 waterMap[x, y] = true;
                 List<Vector3> edgePoints = depthFirstSearch(new Vector3(x, y, 0), new Vector3(x + 1, y, 0));
                 if (edgePoints.Count > 0)
                 {
                     edgePoints.Reverse();
                     waterPoints.Add(edgePoints);
                 }
             }
         }
     }
     return waterPoints;
 }
Пример #2
0
        public MovableEntity(GameState gameState, LevelInfo aLevelInfo, Model3D aModel, Path aPath, int uid, float spd, float rad, int maxh, int maxw, float waterSuckAmt, int waterRadius)
        {
            levelInfo = aLevelInfo;
            this.model = aModel;
            path = aPath;
            uniqueID = uid;
            speed = spd;
            radius = rad;
            maxHealth = maxh;
            health = maxh;
            maxWater = maxw;
            water = 0;
            this.waterSuckAmt = waterSuckAmt;
            this.waterRadius = waterRadius;

            position = path.getPosition();
            prevPosition = path.getPosition();
            hasMoved = true;
            waiting = 0;
            heading = new Vector3((float)Math.Cos(uid), (float)Math.Sin(uid), 0);
            normal = levelInfo.getNormal(position.X, position.Y);
            orientation = Matrix.Identity;
            setOrientation();

            selected = false;
            infoBar = new InfoBox(gameState);
            pathTool = new LineTool(gameState.getGraphics());
            ringTool = new LineTool(gameState.getGraphics());
            ringTool.setColor(new Vector3(1.0f, 0.0f, 0.0f));

            rebuildRing();
        }
Пример #3
0
 public Water(List<Vector3> points, LevelInfo levelInfo, Sun aSun, GraphicsDevice graphics)
 {
     initialize(points, levelInfo);
     vd = new VertexDeclaration(graphics, VertexPositionColor.VertexElements);
     effect = new BasicEffect(graphics, null);
     sun = aSun;
 }
Пример #4
0
 public Guard(GameState gameState, LevelInfo levelInfo, ModelLoader modelLoader, Path path, int uid, ProjectileManager proj)
     : base(gameState, levelInfo, modelLoader.getModel3D(modelType.Tank), path, uid, SPEED, RADIUS, FULL_HEALTH, WATER_CAPACITY, 0, 0)
 {
     attackRadiusTool = new LineTool(gameState.getGraphics());
     attackRadiusTool.setColor(Color.Green.ToVector3());
     attackTarget = null;
     projectiles = proj;
 }
Пример #5
0
        public Camera(GameState gameState, LevelInfo levelInfo, bool isRestricted)
        {
            this.gameState = gameState;
            this.levelInfo = levelInfo;
            this.isRestricted = isRestricted;

            initialize();
        }
Пример #6
0
        public Terrain(GraphicsDevice device, ContentManager content, LevelInfo levelInfo, Camera camera)
        {
            this.device = device;
            this.content = content;
            this.levelInfo = levelInfo;

            this.camera = camera;

            initialise();
        }
Пример #7
0
        public NetLevelState(IStateManager manager, DroughtGame game, Level aLevel, bool isHost)
            : base(manager, game)
        {
            soundManager = game.getSoundManager();
            networkManager = game.getNetworkManager();
            hosting = isHost;

            input = DeviceInput.getInput();

            sun = new Sun(new Vector3(0, -200, 200));

            levelInfo = new LevelInfo();
            levelInfo.initialise(aLevel);

            List<List<Vector3>> waterList = Water.findWater(levelInfo);
            waters = new Water[waterList.Count];

            for (int i = 0; i < waters.Length; i++)
                waters[i] = new Water(waterList[i], levelInfo, sun, getGraphics());

            aStar = new AStar(levelInfo);

            rain = new PlaneParticleEmitter(512, 256, new Vector3(256, 128, 200), new Vector3(0, 0, 0), new Vector3(3f, 0, -19f), Color.LightBlue.ToVector4(), 100000, 9);

            camera = new Camera(this, levelInfo, false);

            terrain = new Terrain(getGraphics(), getContentManager(), levelInfo, camera);

            soundManager.setListener(camera);

            modelLoader = new ModelLoader(getContentManager(), getGraphics());

            skybox = new Skybox(camera, sun, modelLoader.getModel3D(modelType.Skybox));

            lineTool = new LineTool(getGraphics());

            loadContent();

            initializeEntities();

            foreach (MovableEntity entity in localEntities)
                soundManager.playSound(SoundHandle.Truck, entity);
        }
Пример #8
0
 public Tanker(GameState gameState, LevelInfo levelInfo, ModelLoader modelLoader, Path path, int uid)
     : base(gameState, levelInfo, modelLoader.getModel3D(modelType.Truck), path, uid, SPEED, RADIUS, FULL_HEALTH, WATER_CAPACITY, WATER_SUCK_AMOUNT, WATER_RADIUS)
 {
 }
Пример #9
0
 /**
  * Constructs and initialises AStar to search for paths in the
  * current level info.
  *
  * @param level The level information to search.
  */
 public AStar(LevelInfo level)
 {
     initialise(level);
 }
Пример #10
0
        /**
         * Initialises AStar to search for paths in a level.
         * This method must be called whenever levelInfo changes
         * to keep AStar up to date with the latest level.
         *
         * @param level The level information to search.
         */
        public void initialise(LevelInfo level)
        {
            this.level = level;
            width = level.getWidth() / SCALE;
            height = level.getHeight() / SCALE;
            scaledHeightMap = new float[width, height];
            traversable = new bool[width, height];

            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                {
                    scaledHeightMap[x, y] = level.getHeight(x * SCALE, y * SCALE);

                    //if a water texture then a node is not traversable
                    traversable[x, y] = level.getTextureValue(x * SCALE, y * SCALE).X > 0 ? false : true;
                }

            //set the border of the map to be non-traversable
            for (int x = 0; x < width; x++)
            {
                traversable[x, 0] = false;
                traversable[x, height - 1] = false;
            }

            for (int y = 0; y < height; y++)
            {
                traversable[0, y] = false;
                traversable[width - 1, y] = false;
            }

            /*
            StringBuilder sb = new StringBuilder();
            for (int x = 0; x < width; x++)
            {
                sb.Append("\n");
                for (int y = 0; y < height; y++)
                    sb.Append(level.getHeight(x, y) + " ");
            }
            Console.WriteLine(sb);
             */
        }
Пример #11
0
        public LevelState(IStateManager manager, DroughtGame game, Level aLevel)
            : base(manager, game)
        {
            /* TEMP */
            explosionParticles = new ExplosionParticleSystem(getContentManager(), getGraphics());
            explosionSmokeParticles = new ExplosionSmokeParticleSystem(getContentManager(), getGraphics());
            projectileTrailParticles = new ProjectileTrailParticleSystem(getContentManager(), getGraphics());
            smokePlumeParticles = new SmokePlumeParticleSystem(getContentManager(), getGraphics());
            fireParticles = new FireParticleSystem(getContentManager(), getGraphics());
            projectileManager = new ProjectileManager(explosionParticles, explosionSmokeParticles, projectileTrailParticles);

            soundManager = game.getSoundManager();

            input = DeviceInput.getInput();

            sun = new Sun(new Vector3(0, -200, 200));

            levelInfo = new LevelInfo();
            levelInfo.initialise(aLevel);

            TextureMap textureMap = new TextureMap(aLevel);
            //List<List<Vector3>> waterList = Water.findWater(levelInfo);
            List<List<Vector3>> waterListPleh = textureMap.findWater();
            //waters = new Water[waterList.Count];
            waters = new Water[waterListPleh.Count];

            Water[,] waterLocationTable = new Water[levelInfo.getWidth(), levelInfo.getHeight()];
            for (int i = 0; i < waters.Length; i++)
            {
                //waters[i] = new Water(waterList[i], levelInfo, getGraphics());
                waters[i] = new Water(waterListPleh[i], levelInfo, sun, getGraphics());

                for (int j = 0; j < waterListPleh[i].Count; j++)
                {
                    Vector3 p = waterListPleh[i][j];
                    waterLocationTable[(int)p.X, (int)p.Y] = waters[i];
                }
            }
            levelInfo.setWaterPools(waterLocationTable);

            camera = new Camera(this, levelInfo, false);

            rain = new PlaneParticleEmitter(512, 256, new Vector3(256, 128, 200), new Vector3(0, 0, 0), new Vector3(3f, 0, -19f), Color.LightBlue.ToVector4(), 10000, 9);

            terrain = new Terrain(getGraphics(), getContentManager(), levelInfo, camera);

            modelLoader = new ModelLoader(getContentManager(), getGraphics());

            skybox = new Skybox(camera, sun, modelLoader.getModel3D(modelType.Skybox));

            lineTool = new LineTool(getGraphics());

            aStar = new AStar(levelInfo);

            soundManager.setListener(camera);

            loadContent();

            initializeEntities();

            foreach (MovableEntity entity in entities)
                soundManager.playSound(SoundHandle.Truck, entity);
        }
Пример #12
0
        public void initialize(List<Vector3> points, LevelInfo levelInfo)
        {
            Vector3 averageCenter = new Vector3(0, 0, 0);
            float totalDist = 0;
            Vector3 boxCenter = new Vector3(0, 0, 0);
            float xMin = float.MaxValue; int xMinPos = -1; float xMax = float.MinValue; int xMaxPos = -1;
            float yMin = float.MaxValue; int yMinPos = -1; float yMax = float.MinValue; int yMaxPos = -1;
            float zMin = float.MaxValue;
            for (int i = 0; i < points.Count; i++)
            {
                points[i] = new Vector3(points[i].X, points[i].Y, levelInfo.getHeight(points[i].X, points[i].Y) - 0.01f);
                if (points[i].X < xMin) { xMin = points[i].X; xMinPos = i; }
                if (points[i].X > xMax) { xMax = points[i].X; xMaxPos = i; }
                if (points[i].Y < yMin) { yMin = points[i].Y; yMinPos = i; }
                if (points[i].Y > yMax) { yMax = points[i].Y; yMaxPos = i; }
                if (points[i].Z < zMin && notEdgePoint(points[i], levelInfo)) { zMin = points[i].Z; }
                averageCenter += points[i];
                totalDist += Vector3.Distance(points[i], points[(i+1)%points.Count]);
            }
            float zMinInside = zMin;
            for (float i = xMin; i <= xMax; i++)
                for (float j = yMin; j <= yMax; j++)
                    if (levelInfo.getHeight(i, j) < zMinInside) zMinInside = levelInfo.getHeight(i, j);

            zMinInside -= 0.02f;
            initialWaterLevel = zMin;
            bottomWaterLevel = zMinInside;
            float waterHeight = zMin - zMinInside;

            totalWater = approximateArea(totalDist, waterHeight) / 333.0f;
            currentWater = totalWater;

            averageCenter /= points.Count;
            boxCenter.X = (points[xMinPos].X + points[xMaxPos].X) / 2;
            boxCenter.Y = (points[yMinPos].Y + points[yMaxPos].Y) / 2;
            boxCenter.Z = averageCenter.Z;

            List<Vector3> extremePoints = new List<Vector3>();
            List<Vector3> restPoints = new List<Vector3>();
            for (int i=0; i<points.Count; i++)
            {
                if (i == xMinPos || i == xMaxPos || i == yMinPos || i == yMaxPos) {
                    extremePoints.Add(points[i]);
                }
                else restPoints.Add(points[i]);
            }

            //very broken!
            //List<Vector3> finalPoints = minimumConvexArea(restPoints, extremePoints, boxCenter);
            //working
            List<Vector3> finalPoints = facePointArea(points, averageCenter);

            vertices = new VertexPositionColor[finalPoints.Count + 2];
            vertices[0].Position = averageCenter;
            vertices[0].Position.Z = zMin;
            for (int i = 0; i < finalPoints.Count; i++)
            {
                //vertices[i+1].Position = new Vector3(finalPoints[i].X, finalPoints[i].Y, averageCenter.Z);
                vertices[i + 1].Position = new Vector3(finalPoints[i].X, finalPoints[i].Y, zMin);
            }
            vertices[vertices.Length - 1] = vertices[1];
        }
Пример #13
0
 private bool notEdgePoint(Vector3 p, LevelInfo levelInfo)
 {
     return (p.X > 0 && p.X < levelInfo.getWidth()-1 && p.Y > 0 && p.Y < levelInfo.getHeight()-1);
 }