コード例 #1
0
        public void UpdateEntities(GameTime gt)
        {
            while (creating.Count > 0)
            {
                entities.Insert(0, creating.Dequeue());
            }
            while (removing.Count > 0)
            {
                entities.Remove(removing.Dequeue());
            }

            foreach (Entity ent in entities)
            {
                if (!ent.Destroyed)
                {
                    //if(world.WorldCamera.isOnCamera(ent.Center))
                    ent.Update(gt);

                    if (ent is IInteractable)
                    {
                        IInteractable ii = (IInteractable)ent;

                        if (world.CollisionManager.checkPerfect(world.Player, ent))
                        {
                            world.Player.interact(new Action.InteractEntityActionArgs(world.Player, ii));
                        }
                    }

                    if (ent is MoveableEntity)
                    {
                        MoveableEntity mov = (MoveableEntity)ent;

                        foreach (Entity ent2 in entities)
                        {
                            if (ent is IInteractable && ent2 is IInteractable)
                            {
                                IInteractable inter1 = (IInteractable)ent,
                                        inter2       = (IInteractable)ent2;

                                if (ent != ent2)
                                {
                                    if (world.CollisionManager.checkPerfect(ent, ent2))
                                    {
                                        inter1.interact(new Action.InteractEntityActionArgs(mov, inter2));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public int checkHorizontalMove(Entity.MoveableEntity entity, TileMap tileMap)
        {
            Rectangle rect = entity.CollisionArea;

            rect.Offset(0, 0);

            int   endy = 0;
            float xVel = entity.Velocity.X, yVel = entity.Velocity.Y;

            //if (xVel > 0)
            //{
            int maxy = 0;

            int left   = (int)rect.Left / Tile.STANDARD_GTILE_WIDTH,
                right  = (int)rect.Right / Tile.STANDARD_GTILE_WIDTH,
                top    = (int)rect.Top / Tile.STANDARD_GTILE_WIDTH,
                bottom = (int)rect.Bottom / Tile.STANDARD_GTILE_WIDTH;

            for (int y = top; y <= bottom; y++)
            {
                for (int x = left; x <= right; x++)
                {
                    if (!entity.World.Level.getTile(x, y).isEmpty)
                    {
                        if (Mask.IntersectsWithTile(entity, entity.World, x, y, out maxy))
                        {
                            //if (y == top)
                            //    endy += maxy;
                            //if (y == bottom)
                            endy += maxy;
                        }
                    }
                }
            }

            return(endy);
        }
コード例 #3
0
        public int checkVerticalMove(Entity.MoveableEntity entity, TileMap tileMap)
        {
            Rectangle rect = entity.CollisionArea;
            int       startx, endx,
                      starty, endy;
            int   result = 0;
            float yVel   = entity.Velocity.Y;

            startx = rect.Left / Tile.STANDARD_GTILE_WIDTH;
            endx   = rect.Right / Tile.STANDARD_GTILE_WIDTH;
            starty = rect.Top / Tile.STANDARD_GTILE_HEIGHT;
            endy   = rect.Bottom / Tile.STANDARD_GTILE_HEIGHT;

            bool ad = false, sb = false;

            for (int x = startx; x <= endx; x++)
            {
                if (!entity.World.Level.getTile(x, starty).isEmpty)
                {
                    int buffer = 0;

                    if (entity.World.Level.getTile(x, starty).HasEvents)
                    {
                        if (((Event.EventTile)entity.World.Level.getTile(x, starty)).OneWayModifier)
                        {
                            if (yVel < 0)
                            {
                                continue;
                            }
                        }
                    }

                    if (Mask.IntersectsWithTile(entity, entity.World, x, starty, out buffer) && !ad)
                    {
                        result += buffer;
                        ad      = true;
                    }
                }

                if (!entity.World.Level.getTile(x, endy).isEmpty)
                {
                    int buffer = 0;

                    if (entity.World.Level.getTile(x, endy).HasEvents)
                    {
                        if (((Event.EventTile)entity.World.Level.getTile(x, endy)).OneWayModifier)
                        {
                            if (yVel < 0)
                            {
                                continue;
                            }
                        }
                    }

                    if (Mask.IntersectsWithTile(entity, entity.World, x, endy, out buffer) && !sb)
                    {
                        result += buffer;
                        sb      = true;
                    }
                }
            }

            return(result);
        }
コード例 #4
0
        public int checkVerticalMove(Entity.MoveableEntity entity, TileMap tileMap, bool test)
        {
            Rectangle rect = entity.CollisionArea;
            Location  current;
            int       endy = 0;
            float     yVel = entity.Velocity.Y;

            if (yVel < 0)
            {
                int maxy = 0;

                current = new Location(entity.World, rect.Right, rect.Top);
                if (!current.getTile().isEmpty)
                {
                    if (current.getTile().HasEvents)
                    {
                        if (((Event.EventTile)current.getTile()).OneWayModifier)
                        {
                            goto escape1;
                        }
                    }

                    if (Mask.IntersectsWithTile(entity, current, out maxy))
                    {
                        endy += maxy;
                        return(endy);
                    }

                    escape1 :;
                }

                current = new Location(entity.World, rect.Left, rect.Top);
                if (!current.getTile().isEmpty)
                {
                    if (current.getTile().HasEvents)
                    {
                        if (((Event.EventTile)current.getTile()).OneWayModifier)
                        {
                            goto escape1;
                        }
                    }

                    if (Mask.IntersectsWithTile(entity, current, out maxy))
                    {
                        endy += maxy;
                        return(endy);
                    }

                    escape1 :;
                }
            }
            else if (yVel > 0)
            {
                int maxy = 0;

                current = new Location(entity.World, rect.Right, rect.Bottom);
                if (!current.getTile().isEmpty)
                {
                    if (Mask.IntersectsWithTile(entity, current, out maxy))
                    {
                        endy -= maxy;
                        return(endy);
                    }
                }

                current = new Location(entity.World, rect.Left, rect.Bottom);
                if (!current.getTile().isEmpty)
                {
                    if (Mask.IntersectsWithTile(entity, current, out maxy))
                    {
                        endy -= maxy;
                        return(endy);
                    }
                }
            }

            return(endy);
        }