public ClassDefinition(int myType, string name, ClassNode classNode, StaticEntity staticEntity)
 {
     Name         = name;
     MyType       = myType;
     ClassNode    = classNode;
     StaticEntity = staticEntity;
 }
예제 #2
0
        private bool targetIsInRange()
        {
            if (target.getEntityType() == Entity.EntityType.Unit)
            {
                Unit tUnit = (Unit)target;

                double dis = Math.Sqrt(Math.Pow((tUnit.x - unit.x), 2) + Math.Pow(tUnit.y - unit.y, 2));
                return(dis <= unit.stats.attackRange);
            }
            else
            {
                StaticEntity se     = (StaticEntity)(target);
                float        xC     = se.orginCell.Xcoord;
                float        yC     = se.orginCell.Ycoord;
                short        width  = se.width;
                short        height = se.height;

                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        if (EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j) <= unit.stats.attackRange)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /*
         * public functions
         */

        /// <summary>
        /// Inserts a StaticEntity to the Map, if possible
        /// </summary>
        /// <param name="e">The StaticEntity to add</param>
        /// <param name="x">The X-coordinate of the intended origin Cell</param>
        /// <param name="y">The Y-coordinate of the intended origin Cell</param>
        /// <returns>True if insertion was successful, false if not</returns>
        public bool insert(StaticEntity e, int x, int y)
        {
            // check to see if we can actually insert the entity here; if not, return false
            if (x < 0 || x + e.width > this.width)
            {
                return(false);
            }
            if (y < 0 || y + e.height > this.height)
            {
                return(false);
            }
            for (int j = 0; j < this.height; j++)
            {
                for (int i = 0; i < this.width; i++)
                {
                    if (!cells[i, j].isValid)
                    {
                        return(false);
                    }
                }
            }

            // set the appropriate Cell StaticEntity pointers to the given StaticEntity
            for (int j = 0; j < e.height; j++)
            {
                for (int i = 0; i < e.width; i++)
                {
                    cells[i, j].entity = e;
                }
            }

            // set the given StaticEntity's origin Cell to the given (x, y) coordinate and return true
            e.setOrginCell(cells[x, y]);
            return(true);
        }
        /// <summary>
        /// Check if there is room for the StaticEntity
        /// </summary>
        /// <param name="b">Building to be built</param>
        /// <param name="c">Cell to be origin cell</param>
        /// <returns>True if there is enough space, false if else</returns>
        public bool checkSpace(StaticEntity e, Cell c)
        {
            int x = c.Xcoord;
            int y = c.Ycoord;

            if (x < 0 || x + e.width > map.width)
            {
                return(false);
            }
            if (y < 0 || y + e.height > map.height)
            {
                return(false);
            }
            for (int i = x; i < x + e.width; i++)
            {
                for (int j = y; j < y + e.height; j++)
                {
                    if (!map.getCell(i, j).isValid)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #5
0
        public MainMenuScreen(OnScreenChanged screenChanged) : base(screenChanged)
        {
            UserInterfaceLoader uiLoader   = UserInterfaceLoader.GetInstance();
            TileLoader          tileLoader = TileLoader.GetInstance();

            tileBrick1Sprite = tileLoader.Get("brick1");
            titleSprite      = uiLoader.Get("title");
            newGameSprite    = uiLoader.Get("newGame");
            loadGameSprite   = uiLoader.Get("loadGame");
            sandboxSprite    = uiLoader.Get("sandbox");
            adventureSprite  = uiLoader.Get("adventure");

            title           = new StaticEntity("Title Card", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.TILE_SIZE * 2), titleSprite);
            newGameButton   = new StaticEntity("New Game Button", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.TILE_SIZE * 11 / 2), newGameSprite);
            loadGameButton  = new StaticEntity("Load Game Button", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.TILE_SIZE * 8), loadGameSprite);
            sandboxButton   = new StaticEntity("Sandbox Button", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.TILE_SIZE * 21 / 2), sandboxSprite);
            adventureButton = new StaticEntity("Achievements Button", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.TILE_SIZE * 13), adventureSprite);

            for (int i = 0; i < GameConstants.TILES_WIDE; i++)
            {
                for (int j = 0; j < GameConstants.TILES_HIGH + 1; j++) //The +1 allows us to cover the action bar
                {
                    Vector2    tileLocation = new Vector2(i * GameConstants.TILE_SIZE + GameConstants.TILE_SIZE / 2, j * GameConstants.TILE_SIZE + GameConstants.TILE_SIZE / 2);
                    GridEntity newTile      = new GridEntity("Tile", i, j, 0, tileLocation, GameConstants.TILE_SIZE, tileBrick1Sprite);
                    menuBackground.Add(newTile);
                }
            }
        }
        /// <summary>
        /// Inserts a StaticEntity to the Map and the appropriate List, if possible.
        /// </summary>
        /// <param name="e">The StaticEntity to insert</param>
        /// <param name="x">The X-coordinate of the intended origin Cell</param>
        /// <param name="y">The Y-coordinate of the intended origin Cell</param>
        /// <returns>True if insertion was successful, false otherwise</returns>
        public bool insert(StaticEntity e, int x, int y)
        {
            bool worked = map.insert(e, x, y);

            if (worked)
            {
                Console.WriteLine("Gameworld inserted StaticEntity");
                switch (e.getEntityType())
                {
                case Entity.EntityType.Object:
                    objects.Add((ObjectEntity)e);
                    break;

                case Entity.EntityType.Resource:
                    resources.Add((ResourceEntity)e);
                    break;

                case Entity.EntityType.Building:
                    Console.WriteLine("Inserted Building");
                    this.buildings.Add((Building)e);
                    break;
                }
            }
            return(worked);
        }
예제 #7
0
        /// <summary>
        /// template method
        /// </summary>
        /// <param name="driveContainer"></param>
        /// <param name="mobile"></param>
        internal virtual void DriveMobile(StaticEntity driveContainer, MobileEntity mobile)
        {
            var dctx = this.Observe(driveContainer, mobile);

            switch (driveContainer.EntityType)
            {
            //use way  as container for lane changing
            case EntityType.Lane:

                this.WayDriver.DriveMobile(mobile, dctx);

                break;

            case EntityType.XNode:

                this.XNodeDriver.DriveMobile(mobile, dctx);

                break;

            default:
                ThrowHelper.ThrowArgumentException("不正确的参数");
                break;
            }

            mobile.iAcceleration = Math.Max(dctx.Params.iAcceleration, 1);
            mobile.iSpeed        = dctx.Params.iSpeed;
        }
예제 #8
0
        private void updateUnitOrientation()
        {
            float x, y;

            if (target.entityType == Entity.EntityType.Unit)
            {
                Unit tempUnit = (Unit)target;
                x = tempUnit.x;
                y = tempUnit.y;
            }
            else
            {
                StaticEntity tempSE = (StaticEntity)target;
                // NOTE: This should be changed to the cell that is closest to the unit.
                x = tempSE.orginCell.Xcoord;
                y = tempSE.orginCell.Ycoord;
            }

            if (x == unit.x)
            {
                if (y > unit.y)
                {
                    unit.orientation = Unit.Orientation.S;
                }
                else
                {
                    unit.orientation = Unit.Orientation.N;
                }
            }
            else if (y == unit.y)
            {
                if (x > unit.x)
                {
                    unit.orientation = Unit.Orientation.E;
                }
                else
                {
                    unit.orientation = Unit.Orientation.W;
                }
            }
            else if (y < unit.y && x < unit.x)
            {
                unit.orientation = Unit.Orientation.NW;
            }
            else if (y < unit.y && x > unit.x)
            {
                unit.orientation = Unit.Orientation.NE;
            }
            else if (y > unit.y && x < unit.x)
            {
                unit.orientation = Unit.Orientation.SW;
            }
            else if (y > unit.y && x > unit.x)
            {
                unit.orientation = Unit.Orientation.SE;
            }
        }
예제 #9
0
        public GameOverScreen(OnScreenChanged screenChanged) : base(screenChanged)
        {
            FontLoader          fontLoader = FontLoader.GetInstance();
            UserInterfaceLoader uiLoader   = UserInterfaceLoader.GetInstance();

            font20           = fontLoader.Get("font");
            playButtonSprite = uiLoader.Get("continue");
            gameOverButton   = new StaticEntity("BackToMainMenu", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.WINDOW_HEIGHT / 2), playButtonSprite);
        }
예제 #10
0
        private StaticSpriteObject GetStaticSpriteObjectForEntity(StaticEntity entity)
        {
            var poolable = _staticSpriteObjectPool.GetObjectFromPool();
            var poolObj  = (StaticSpriteObject)poolable;

            poolObj.transform.parent           = _levelContainer.transform;
            poolObj.transform.localEulerAngles = Vector3.zero;
            poolObj.transform.localScale       = Vector3.one;
            return(poolObj);
        }
예제 #11
0
        /// <summary>
        /// This function will perform the Attack Action.
        /// </summary>
        /// <returns>true if the action is completed, false if it is not.</returns>
        public override bool work()
        {
            // target is dead, return true.
            if (target.getState().getPrimaryState() == State.PrimaryState.Dead)
            {
                return(true);
            }

            // unit cannot attack, return true.
            if (!unit.stats.canAttack)
            {
                return(true);
            }

            // Target is in range attack target.
            if (targetIsInRange())
            {
                // Create a SimpleAttackAction if it is needed.
                if (this.attackAction == null)
                {
                    attackAction = new SimpleAttackAction(unit, target);
                }

                // Call the SimpleAttackAction
                attackAction.work();

                // Set the MoveAction to null.
                moveAction = null;
            }
            // Target is not in range, move to it.
            else
            {
                // Create a MoveAction if it is needed.
                if (moveAction == null)
                {
                    if (target.getEntityType() == Entity.EntityType.Unit)
                    {
                        Unit temp = (Unit)target;
                        moveAction = new MoveAction(temp.x, temp.y, gw, unit);
                    }
                    else
                    {
                        StaticEntity temp = (StaticEntity)target;
                        moveAction = new MoveAction(temp.orginCell.Xcoord, temp.orginCell.Ycoord, gw, unit);
                    }
                }
                // Set the SimpleAttackAction to null.
                attackAction = null;

                // Call the MoveAction.
                moveAction.work();
            }

            return(false);
        }
        private bool lineIntersectsCircle(StaticEntity obj)
        {
            bool intersects = false;

            if (obj.center.Distance(ahead) <= ((obj.size.Length() / 2) + (movingEntity.radius / 2)) || obj.center.Distance(ahead2) <= ((obj.size.Length() / 2) + (movingEntity.radius / 2)))
            {
                intersects = true;
            }


            return(intersects);
        }
예제 #13
0
        //--------------------------20160131--------------------------------------
        public static MobileEntity MakeMobile(EdgeRoute route, StaticEntity container)
        {
            SmallCar mobile = new SmallCar(container);

            mobile.Color = MobileSimulator.GetRandomColor();
            //mobile.Color = Color.Red;

            mobile.Route = route;

            mobile.Container = container;

            return(mobile);
        }
예제 #14
0
    public override void Act(StateController controller)
    {
        StaticEntity entity = controller.entity as StaticEntity;

        if (entity.remainingTurnsBeforReproduction == 0)
        {
            entity.IncreasePopulation();
            entity.remainingTurnsBeforReproduction = entity.staticEntitySO.nbTurnsBeforeReproduction;
        }
        else
        {
            entity.remainingTurnsBeforReproduction--;
        }
    }
예제 #15
0
        public static bool InterpretFromFileName(string filePath)
        {
            string src;

            try
            {
                src = File.ReadAllText(filePath);
            }
            catch (Exception)
            {
                //Reprotar error de preprocesador
                return(false);
            }
            var grammar   = new PyUsacGrammar();
            var langData  = new LanguageData(grammar);
            var parser    = new Irony.Parsing.Parser(langData);//Para evitar conflicto con el namespace Parser
            var parseTree = parser.Parse(src);
            var root      = parseTree.Root;

            bool hasErrors = false;

            foreach (var error in parseTree.ParserMessages)
            {
                if (error.Level == Irony.ErrorLevel.Error)
                {
                    hasErrors = true;
                }
                ErrorHelper.ErrorFactory.CreateParsingError(error, filePath);
            }
            if (hasErrors)
            {
                return(false);
            }
            //var dotCode = GetDot(root);//Descomentar en debug mode! :)

            var astBuilder = new PyAstBuilder(new AstContext(langData), filePath);

            astBuilder.BuildAst(parseTree);
            var programNode = (ProgramNode)parseTree.Root.AstNode;
            //GetDot(programNode);//Descomentar en debug mode! :)

            var entity = new StaticEntity(programNode);

            entity.InitVisitor(true);
            entity.InvokeMain();
            TypeConstants.ClearTypeHashtable();

            return(true);
        }
        private StaticEntity findMostThreatening()
        {
            StaticEntity mostThreatening = null;

            foreach (StaticEntity s in objects)
            {
                bool collision = lineIntersectsCircle(s);

                if (collision && (mostThreatening == null || pos.Distance(s.Pos) < pos.Distance(mostThreatening.Pos)))
                {
                    mostThreatening = s;
                }
            }
            return(mostThreatening);
        }
        public void Test_StaticEntity_Equality()
        {
            StaticEntity ent1 = new StaticEntity(EntityTypes.Wall, 0, 0, 0);
            StaticEntity ent2 = new StaticEntity(EntityTypes.Wall, 0, 0, 0);
            StaticEntity ent3 = new StaticEntity(EntityTypes.FinishFlag, 0, 0, 0);
            StaticEntity ent4 = new StaticEntity(EntityTypes.Wall, 0, 1, 0);
            StaticEntity ent5 = new StaticEntity(EntityTypes.Wall, 0, 0, 1);
            StaticEntity ent6 = new StaticEntity(EntityTypes.Wall, 1, 0, 0);

            Assert.AreEqual(ent1, ent2);
            Assert.AreNotEqual(ent1, ent3);
            Assert.AreNotEqual(ent1, ent4);
            Assert.AreNotEqual(ent1, ent5);
            Assert.AreNotEqual(ent1, ent6);
        }
예제 #18
0
        /// <summary>
        /// Removes a StaticEntity from the Map
        /// </summary>
        /// <param name="e">The StaticEntity to remove</param>
        public void remove(StaticEntity e)
        {
            int x = e.orginCell.Xcoord;
            int y = e.orginCell.Ycoord;
            int h = e.height;
            int w = e.width;

            for (int j = y; j < y + h; j++)
            {
                for (int i = x; i < x + w; i++)
                {
                    cells[i, j].entity = null;
                }
            }
        }
예제 #19
0
        private static string _root = "E:\\TCPJW_Developer\\Code\\TCPJW.OA\\ImageServer";// SysStatic.GetNoStaticNode("imageServer").Text;

        /// <summary>
        /// 省
        /// </summary>
        /// <returns></returns>
        public static List <StaticEntity> GetProDataSource()
        {
            tcpjw3.oa.Models.tcpjwEntities db   = new tcpjw3.oa.Models.tcpjwEntities();
            List <StaticEntity>            list = new List <StaticEntity>();
            var query = (from sysParent in db.SysStatic
                         join sysChild in db.SysStatic on sysParent.ID equals sysChild.PID
                         where sysParent.Value.Equals("administrative_regions")
                         select sysChild).Distinct();

            foreach (var item in query)
            {
                StaticEntity entity = new StaticEntity();
                entity.Text  = item.Text;
                entity.Value = item.Value;
                list.Add(entity);
            }
            return(list);
        }
        /// <summary>
        /// Removes a StaticEntity from the Map and the appropriate List.
        /// </summary>
        /// <param name="e">The StaticEntity to remove</param>
        public void remove(StaticEntity e)
        {
            map.remove(e);
            switch (e.getEntityType())
            {
            case Entity.EntityType.Object:
                objects.Remove((ObjectEntity)e);
                break;

            case Entity.EntityType.Resource:
                resources.Remove((ResourceEntity)e);
                break;

            case Entity.EntityType.Building:
                buildings.Remove((Building)e);
                break;
            }
        }
예제 #21
0
        public LoadGameScreen(OnScreenChanged screenChanged) : base(screenChanged)
        {
            UserInterfaceLoader uiLoader   = UserInterfaceLoader.GetInstance();
            FontLoader          fontLoader = FontLoader.GetInstance();

            var TileSize = GameConstants.TILE_SIZE;

            fileSelected = -1;
            Texture2D blankButtonSprite   = uiLoader.Get("select");
            Texture2D confirmButtonSprite = uiLoader.Get("confirm");
            Texture2D backButtonSprite    = uiLoader.Get("back");

            backButton = new StaticEntity("Back Button", new Vector2(TileSize * 2, GameConstants.WINDOW_HEIGHT - TileSize), backButtonSprite);

            fileButtons      = new List <StaticEntity>();
            levelData        = new List <String>();
            weapon1ItemBoxes = new List <ItemBox>();
            weapon2ItemBoxes = new List <ItemBox>();
            shield1ItemBoxes = new List <ItemBox>();
            charm1ItemBoxes  = new List <ItemBox>();
            for (int i = 0; i < GameConstants.NUMBER_OF_SAVES; i++)
            {
                fileButtons.Add(new StaticEntity("Button " + i.ToString(), new Vector2(TileSize * 2, TileSize * 3 + i * TileSize * 2), blankButtonSprite));
                levelData.Add("");
                weapon1ItemBoxes.Add(new ItemBox("Weapon1 File " + i.ToString(), new Vector2(TileSize * 7, TileSize * 3 + i * TileSize * 2)));
                weapon2ItemBoxes.Add(new ItemBox("Weapon2 File " + i.ToString(), new Vector2(TileSize * 8, TileSize * 3 + i * TileSize * 2)));
                shield1ItemBoxes.Add(new ItemBox("Shield1 File " + i.ToString(), new Vector2(TileSize * 9, TileSize * 3 + i * TileSize * 2)));
                charm1ItemBoxes.Add(new ItemBox("Charm1 File " + i.ToString(), new Vector2(TileSize * 10, TileSize * 3 + i * TileSize * 2)));
            }
            confirmButton = new StaticEntity("Confirm Button", new Vector2(TileSize * 5, GameConstants.WINDOW_HEIGHT - TileSize), confirmButtonSprite);

            font   = fontLoader.Get("font");
            font20 = fontLoader.Get("font20");

            actionBarBackground = uiLoader.Get("blankBackground");
            background          = new StaticEntity("Background", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.WINDOW_HEIGHT / 2), actionBarBackground);

            for (int i = 0; i < GameConstants.NUMBER_OF_SAVES; i++)
            {
                CheckGameData(i, levelData, weapon1ItemBoxes, weapon2ItemBoxes, shield1ItemBoxes, charm1ItemBoxes);
            }
        }
        public override Vector2D Calculate()
        {
            pos    = movingEntity.Pos;
            ahead  = movingEntity.Pos + Vector2D.Vec2DNormalize(movingEntity.Velocity) * MAX_SEE_AHEAD;
            ahead2 = movingEntity.Pos + Vector2D.Vec2DNormalize(movingEntity.Velocity) * MAX_SEE_AHEAD * 0.5;

            StaticEntity mostThreatening = findMostThreatening();
            Vector2D     avoidance       = new Vector2D();

            if (mostThreatening != null)
            {
                avoidance.X = ahead.X - mostThreatening.center.X;
                avoidance.Y = ahead.Y - mostThreatening.center.Y;

                avoidance = avoidance.Normalize();
                avoidance.ScaleBy(MAX_AVOID_FORCE);
            }

            return(avoidance);
        }
예제 #23
0
        /// <summary>
        /// Constructs a new room.
        /// </summary>
        /// <param name="camera">The camera to be used to draw the room.</param>
        /// <param name="Content">The content manager to load models from.</param>
        /// <param name="physics">The physics environment to which the room belogns.</param>
        public Room(Camera camera, ContentManager Content, PhysicsEngine.Environment physics)
        {
            wallModel = Content.Load <Model>("Models\\Wall");
            wallGraphicsTransforms = CommonFunctions.SetupEffectDefaults(wallModel, camera);

            ConvexSegment wallSegment
                = PhysicsEngine.CommonFunctions.LoadConvexHull(new System.IO.StreamReader(@"..\..\..\Content/Hulls/Wall.hull"));

            wallHull = new ConvexHull[] { new ConvexHull(wallSegment, Matrix.Identity) };

            // Create wall entities
            leftWall   = CreateWallEntity(-Vector3.UnitX, -MathHelper.PiOver2 * Vector3.UnitZ);
            rightWall  = CreateWallEntity(Vector3.UnitX, +MathHelper.PiOver2 * Vector3.UnitZ);
            bottomWall = CreateWallEntity(-Vector3.UnitY, 0.0f * Vector3.UnitX);
            topWall    = CreateWallEntity(Vector3.UnitY, MathHelper.Pi * Vector3.UnitX);
            backWall   = CreateWallEntity(-Vector3.UnitZ, +MathHelper.PiOver2 * Vector3.UnitX);
            frontWall  = CreateWallEntity(Vector3.UnitZ, -MathHelper.PiOver2 * Vector3.UnitX);

            physics.Add(new Entity[] { leftWall, rightWall, bottomWall, topWall, backWall, frontWall });
        }
예제 #24
0
        /// <summary>
        /// 城市
        /// </summary>
        /// <returns></returns>
        public static List <StaticEntity> GetCityDataSource(string parentValue)
        {
            tcpjw3.oa.Models.tcpjwEntities db   = new tcpjw3.oa.Models.tcpjwEntities();
            List <StaticEntity>            list = new List <StaticEntity>();

            if (string.IsNullOrEmpty(parentValue))
            {
                return(list);
            }
            var query = (from sysParent in db.SysStatic
                         join sysChild in db.SysStatic on sysParent.ID equals sysChild.PID
                         where sysParent.Value.Equals(parentValue)
                         select sysChild).Distinct();

            foreach (var item in query)
            {
                StaticEntity entity = new StaticEntity();
                entity.Text  = item.Text;
                entity.Value = item.Value;
                list.Add(entity);
            }
            return(list);
        }
예제 #25
0
        /// <summary>
        /// Inserts a StaticEntity to the Map and the appropriate List, if possible.
        /// </summary>
        /// <param name="e">The StaticEntity to insert</param>
        /// <param name="x">The X-coordinate of the intended origin Cell</param>
        /// <param name="y">The Y-coordinate of the intended origin Cell</param>
        /// <returns>True if insertion was successful, false otherwise</returns>
        public bool insert(StaticEntity e, int x, int y)
        {
            bool worked = map.insert(e, x, y);

            if (worked)
            {
                switch (e.getEntityType())
                {
                case Entity.EntityType.Object:
                    objects.Add((ObjectEntity)e);
                    break;

                case Entity.EntityType.Resource:
                    resources.Add((ResourceEntity)e);
                    break;

                case Entity.EntityType.Building:
                    buildings.Add((Building)e);
                    break;
                }
            }
            return(worked);
        }
        /// <summary>
        /// This method will find the cell closest to 'unit' that 'entity' is currently occupying.
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static Cell findClosestCell(Unit unit, StaticEntity se, GameWorld gw)
        {
            Cell  cell = null;
            float dis  = 10000;

            short xC     = se.orginCell.Xcoord;
            short yC     = se.orginCell.Ycoord;
            short width  = se.width;
            short height = se.height;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j) <= dis)
                    {
                        cell = gw.map.getCell(xC + i, yC + j);
                        dis  = EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j);
                    }
                }
            }

            return(cell);
        }
예제 #27
0
        public bool LoadWorldEntities()
        {
            // load and map the world entities
            worldEntityMap.Add("DirectionalLight0", new DirectionalLight("DirectionalLight0", new Vector3(-0.5f, -1.0f, -0.3f)));
            worldEntityMap.Add("TestLevel", new StaticEntity("TestLevel", "test_level.mesh"));

            StaticEntity cage = new StaticEntity("PipeCage", "pipe_cage_001.mesh", 2);

            cage.CastShadows   = true;
            cage.CollisionMode = CollisionMode.BoundingBox;
            worldEntityMap.Add("PipeCage", cage);

            DynamicEntity cone = new DynamicEntity("TrafficCone", "traffic_cone_001.mesh");

            cone.CollisionMode = CollisionMode.ConvexHull;
            worldEntityMap.Add("TrafficCone", cone);

            DynamicEntity pot = new DynamicEntity("FlowerPot", "pot_001.mesh");

            pot.CollisionMode  = CollisionMode.ConvexHull;
            pot.CollisionSound = @"Media\sounds\brickhit.wav";
            worldEntityMap.Add("FlowerPot", pot);
            return(true);
        }
예제 #28
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < transforms.Count; i++)
        {
            //get the new closest point
            int   currentClosestPoint = closestPoints[i];
            int   leastDistPoint      = currentClosestPoint;
            float leastSqrDist        = Vector3.SqrMagnitude(points[currentClosestPoint] -
                                                             transforms[i].position);
            foreach (int possibleNewClosest in map[currentClosestPoint])
            {
                float newSqrDist = Vector3.SqrMagnitude(points[possibleNewClosest] - transforms[i].position);
                if (newSqrDist < leastSqrDist)
                {
                    leastDistPoint = possibleNewClosest;
                    leastSqrDist   = newSqrDist;
                }
            }
            closestPoints[i] = leastDistPoint;
            List <StaticEntity[]> closestEntitiesOfType = new List <StaticEntity[]>();
            foreach (List <StaticEntity>[] entities in staticEntities)
            {
                StaticEntity[]      closestEntities = new StaticEntity[numObjectsCache];
                List <StaticEntity> staticEnts      = new List <StaticEntity>();
                if (entities[closestPoints[i]] != null)
                {
                    staticEnts.AddRange(entities[closestPoints[i]]);
                }

                foreach (int a in map[closestPoints[i]])
                {
                    if (entities[a] != null)
                    {
                        staticEnts.AddRange(entities[a]);
                    }
                }
                staticEnts.Sort((p2, p1) => - Vector3.SqrMagnitude(p1.position - transforms[i].position).CompareTo(Vector3.SqrMagnitude(p2.position - transforms[i].position)));
                for (int i1 = 0; i1 < staticEnts.Count; i1++)
                {
                    if (i1 >= numObjectsCache)
                    {
                        break;
                    }
                    closestEntities[i1] = staticEnts[i1];
                }
                closestEntitiesOfType.Add(closestEntities);
            }

            for (int i1 = 0; i1 < closestEntitiesOfType.Count; i1++)
            {
                for (int a = 0; a < numObjectsCache; a++)
                {
                    if (closestEntitiesOfType[i1][a] != null)
                    {
                        emptyColliders[i1][i][a].transform.position   = closestEntitiesOfType[i1][a].position;
                        emptyColliders[i1][i][a].transform.rotation   = closestEntitiesOfType[i1][a].rotation;
                        emptyColliders[i1][i][a].transform.localScale = closestEntitiesOfType[i1][a].scale;
                    }
                }
            }
        }
    }
 /// <summary>
 /// Inserts a StaticEntity to the Map and the appropriate List, if possible.
 /// </summary>
 /// <param name="e">The StaticEntity to insert</param>
 /// <param name="c">The intended origin Cell</param>
 /// <returns>True if insertion was successful, false otherwise</returns>
 public bool insert(StaticEntity e, Cell c)
 {
     return(insert(e, c.Xcoord, c.Ycoord));
 }
예제 #30
0
        /// <summary>
        /// Will insert associated static entities from a landscape entity.
        /// Ex :
        /// For the landscape entity "Tree", multiple static entities can be found "around" it : apple, stick, banana, ...
        /// </summary>
        /// <param name="dataCursor"></param>
        /// <param name="chunk"></param>
        /// <param name="chunkRnd"></param>
        /// <param name="entityFactory"></param>
        /// <param name="landscapeEntities"></param>
        private void InsertMicrolandscapeStaticEntities(ByteChunkCursor dataCursor, GeneratedChunk chunk, FastRandom chunkRnd, EntityFactory entityFactory, List <LandscapeEntity> landscapeEntities)
        {
            if (landscapeEntities == null)
            {
                return;
            }

            Vector2I chunkWorldPosition = new Vector2I(chunk.Position.X * AbstractChunk.ChunkSize.X, chunk.Position.Z * AbstractChunk.ChunkSize.Z);

            //The entities are sorted by their origine chunk hashcode value
            foreach (LandscapeEntity entity in landscapeEntities)
            {
                bool isLandscapeEntityRootInsideChunk = (entity.RootLocation.X >= 0 && entity.RootLocation.X < AbstractChunk.ChunkSize.X && entity.RootLocation.Z >= 0 && entity.RootLocation.Z < AbstractChunk.ChunkSize.Z);

                //Get LandscapeEntity
                var landscapeEntity = _worldParameters.Configuration.LandscapeEntitiesDico[entity.LandscapeEntityId];

                foreach (var staticEntity in landscapeEntity.StaticItems)
                {
                    //Get number of object
                    var nbr = chunkRnd.Next(staticEntity.Quantity.Min, staticEntity.Quantity.Max);
                    if (isLandscapeEntityRootInsideChunk)
                    {
                        //This entity location is inside the correct chunk.

                        //Its a tree !
                        if (landscapeEntity is TreeBluePrint)
                        {
                            //Create tree soul and attach this entity to the chunk
                            var soul = entityFactory.CreateEntity <TreeSoul>();
                            soul.Position    = new Vector3D(chunkWorldPosition.X + entity.RootLocation.X + 0.5, entity.RootLocation.Y, chunkWorldPosition.Y + entity.RootLocation.Z + 0.5);
                            soul.TreeRndSeed = entity.GenerationSeed;
                            soul.TreeTypeId  = entity.LandscapeEntityId;
                            chunk.Entities.Add(soul);
                        }
                    }
                    else
                    {
                        //If Root out of chunk, devide the qt of object to spawn by 2
                        nbr = (int)(nbr / 2.0);
                    }

                    //Foreach object to create
                    while (nbr > 0)
                    {
                        //find location of the static entity
                        double x = chunkRnd.NextDouble(-staticEntity.SpawningRange, staticEntity.SpawningRange) + entity.RootLocation.X;
                        double z = chunkRnd.NextDouble(-staticEntity.SpawningRange, staticEntity.SpawningRange) + entity.RootLocation.Z;

                        //If out of current chunk, don't create it
                        if (x < 0 || x >= AbstractChunk.ChunkSize.X || z < 0 || z >= AbstractChunk.ChunkSize.Z)
                        {
                            break;
                        }

                        bool groundSpawing;
                        if (staticEntity.SpawningType == SpawningType.Both)
                        {
                            groundSpawing = chunkRnd.NextFloat() > 0.5;
                        }
                        else
                        {
                            groundSpawing = staticEntity.SpawningType == SpawningType.Ground;
                        }

                        StaticEntity landscapeStaticEntity = null;
                        //Find Y spawning position
                        if (groundSpawing)
                        {
                            dataCursor.SetInternalPosition(MathHelper.Floor(x), entity.RootLocation.Y, MathHelper.Floor(z));
                            //Loop until I hit the ground, with a maximum of Y - 15 blocks
                            for (int y = entity.RootLocation.Y; y > entity.RootLocation.Y - 15 && y > 0; y--)
                            {
                                if (dataCursor.Read() != WorldConfiguration.CubeId.Air)
                                {
                                    //Add Static item here on the ground !
                                    landscapeStaticEntity          = (StaticEntity)entityFactory.CreateFromBluePrint(staticEntity.ItemblueprintId);
                                    landscapeStaticEntity.Position = new Vector3D(x + chunkWorldPosition.X, dataCursor.InternalPosition.Y + 1, z + chunkWorldPosition.Y);
                                    break;
                                }
                                dataCursor.Move(CursorRelativeMovement.Down);
                            }
                        }
                        else
                        {
                            dataCursor.SetInternalPosition(MathHelper.Floor(x), entity.RootLocation.Y + 1, MathHelper.Floor(z));
                            //Loop until I hit the ground, with a maximum of Y + 15 blocks
                            for (int y = entity.RootLocation.Y + 1; y <= entity.RootLocation.Y + 15 && y < AbstractChunk.ChunkSize.Y; y++)
                            {
                                if (dataCursor.Read() != WorldConfiguration.CubeId.Air)
                                {
                                    //Add Static item here on the ground !
                                    landscapeStaticEntity          = (StaticEntity)entityFactory.CreateFromBluePrint(staticEntity.ItemblueprintId);
                                    landscapeStaticEntity.Position = new Vector3D(x + chunkWorldPosition.X, dataCursor.InternalPosition.Y - 0.25, z + chunkWorldPosition.Y);
                                    break;
                                }
                                dataCursor.Move(CursorRelativeMovement.Up);
                            }
                        }

                        if (landscapeStaticEntity != null)
                        {
                            chunk.Entities.Add(landscapeStaticEntity);
                        }

                        nbr--;
                    }
                }
            }
        }