コード例 #1
0
ファイル: Lerp.cs プロジェクト: ggilbert108/ProjectR
        public static List<Location> lerp(Location from, Location to)
        {
            double deltaX = to.x - from.x;
            double deltaY = from.y - to.y;
            double error = 0.0;
            double deltaerr = Math.Abs(deltaY/deltaX);

            if (Math.Abs(deltaX) < 0.1)
                return lerpVert(from, to);

            List<Location> lerp = new List<Location>();

            int y = from.y;

            int sx = (from.x < to.x) ? 1 : -1;
            int sy = (from.y < to.y) ? 1 : -1;

            for (int x = from.x; x != to.x; x += sx)
            {
                lerp.Add(new Location(x, y));
                error += deltaerr;
                while (error >= 0.5)
                {
                    y = y + sy;
                    error--;
                    lerp.Add(new Location(x, y));
                }
            }

            return lerp;
        }
コード例 #2
0
ファイル: Location.cs プロジェクト: ggilbert108/ProjectR
        public double distance(Location other)
        {
            int dx = other.x - x;
            int dy = other.y - y;

            return Math.Sqrt(dx*dx + dy*dy);
        }
コード例 #3
0
ファイル: Entity.cs プロジェクト: ggilbert108/ProjectR
        public Entity(DrawTag drawTag, string name)
        {
            _location = new Location(0, 0);
            this.name = name;
            _drawTag = drawTag;

            discovered = false;
            lit = LIT_DIM;
        }
コード例 #4
0
ファイル: EffectBuilder.cs プロジェクト: ggilbert108/ProjectR
 public static Effect buildEffect(EffectDescription description, Location heroLocation)
 {
     switch (description.type)
     {
         case EffectType.Explosion:
             return buildExplosion(description, heroLocation);
     }
     return null;
 }
コード例 #5
0
ファイル: AStarSearch.cs プロジェクト: ggilbert108/ProjectR
        public static Location getFirstStep(Location start, Location end, Level level)
        {
            AStarNode lastStep = aStarSearch(start, end, level);
            while (lastStep.parent != null && lastStep.parent.parent != null)
            {
                lastStep = lastStep.parent;
            }

            return lastStep.location;
        }
コード例 #6
0
ファイル: Effect.cs プロジェクト: ggilbert108/ProjectR
        protected Effect(int interval, DrawTag drawTag, Location coord)
        {
            TimerCallback callback = atInterval;

            timer = new System.Threading.Timer(callback, null, 0, interval);

            this.drawTag = drawTag;
            this.coord = coord;
            finished = false;
        }
コード例 #7
0
ファイル: Lerp.cs プロジェクト: ggilbert108/ProjectR
        private static List<Location> lerpVert(Location from, Location to)
        {
            List<Location> lerp = new List<Location>();
            int dy = (from.y < to.y) ? 1 : -1;

            for (int y = from.y; y != to.y; y += dy)
            {
                lerp.Add(new Location(from.x, y));
            }

            return lerp;
        }
コード例 #8
0
ファイル: EffectBuilder.cs プロジェクト: ggilbert108/ProjectR
        private static Explosion buildExplosion(EffectDescription description, Location heroLocation)
        {
            Location location = description.startLocation;
            location.x -= heroLocation.x;
            location.y -= heroLocation.y;

            location.x *= LevelView.TILE_SIZE;
            location.y *= LevelView.TILE_SIZE;

            Explosion explosion = new Explosion(location);
            return explosion;
        }
コード例 #9
0
ファイル: FOVCalculator.cs プロジェクト: ggilbert108/ProjectR
        private static void scanOctant2(Level level, Location heroLocation, int depth, double startSlope, double endSlope)
        {
            if (depth >= Hero.MAX_SIGHT_DISTANCE)
            {
                return;
            }

            int y = heroLocation.y - depth;
            int x = heroLocation.x + (int)(startSlope * depth);

            while (getSlope(x, y, heroLocation.x, heroLocation.y, false) <= endSlope)
            {
                if (level.blocksSight(new Location(x, y)))
                {
                    if (!level.blocksSight(new Location(x + 1, y)))
                    {
                        double newEndSlope = getSlope(x + 0.5, y + 0.5, heroLocation.x, heroLocation.y, false);
                        scanOctant2(level, heroLocation, depth + 1, startSlope, newEndSlope);
                    }
                }
                else
                {
                    if (level.blocksSight(new Location(x + 1, y)))
                    {
                        startSlope = -getSlope(x + 0.5, y - 0.5, heroLocation.x, heroLocation.y, false);
                    }
                }
                level.setLit(new Location(x, y), 0);
                x--;
            }
            x++;
            if (depth < Hero.MAX_SIGHT_DISTANCE && !level.blocksSight(new Location(x, y)))
            {
                scanOctant2(level, heroLocation, depth + 1, startSlope, endSlope);
            }
        }
コード例 #10
0
ファイル: LevelView.cs プロジェクト: ggilbert108/ProjectR
        private void drawEntity(SpriteBatch spriteBatch, Texture2D atlas, Entity entity, Location screenLocation)
        {
            if (!entity.discovered) return;

            Rectangle source = imagePositions[entity.drawTag];
            Rectangle dest = new Rectangle(screenLocation.x * TILE_SIZE, screenLocation.y * TILE_SIZE, TILE_SIZE, TILE_SIZE);

            spriteBatch.Draw(atlas, dest, source, Color.White);

            int alpha = entity.lit;
            Color color = new Color(0, 0, 0, alpha);

            spriteBatch.Draw(Game1.alphaOverlay, dest, color);

            if (entity is Actor)
            {
                drawHealthBar(spriteBatch, (Actor)entity, dest);
            }
        }
コード例 #11
0
        public static void generateDungeon(Level level, int width, int height)
        {
            Rect dungeonRect = new Rect(0, 0, width, height);
            level.bounds = dungeonRect;

            carveRoom(level, dungeonRect, true, TileType.Dungeon_Wall);

            Location center = new Location(width / 2, height / 2);
            Rect innerRoom = createRect(center, Direction.West, Feature.Room);
            carveRoom(level, innerRoom, false, TileType.Dungeon_Floor);

            for (int i = 0; i < 100; i++)
            {
                Location doorLoc = findDoor(level, dungeonRect);

                //randomly choose a feature to add to the dungeon
                Feature[] features = {Feature.Corridor, Feature.Room};
                Feature feature = Util.chooseRandomElement(features);

                tryAddFeature(level, doorLoc, feature);
            }
            addEntranceAndExit(level, dungeonRect);
            addChests(level, dungeonRect);
            addMonsters(level, dungeonRect);
            initLighting(level, dungeonRect);
        }
コード例 #12
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void addActor(Actor actor, Location location)
 {
     actor.location = location;
     _actors.Add( actor);
 }
コード例 #13
0
 public EffectDescription(EffectType type, Location startLocation)
 {
     this.type = type;
     this.startLocation = startLocation;
 }
コード例 #14
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void setLit(Location location, int lit)
 {
     List<Entity> entities = getEntities(location);
     foreach (Entity entity in entities)
     {
         entity.lit = lit;
     }
 }
コード例 #15
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
        private int getLit(Location location)
        {
            Tile tile = getTile(location);
            if (tile == null) return -1;

            return tile.lit;
        }
コード例 #16
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public Entity getWalkable(Location location)
 {
     return _walkables.ContainsKey(location) ? _walkables[location] : null;
 }
コード例 #17
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void addWalkable(Entity entity, Location location)
 {
     entity.location = location;
     if (_walkables.ContainsKey(location))
     {
         _walkables.Remove(location);
     }
     _walkables.Add(location, entity);
 }
コード例 #18
0
ファイル: LevelView.cs プロジェクト: ggilbert108/ProjectR
        public void draw(SpriteBatch spriteBatch, Texture2D atlas, int screenWidth, int screenHeight)
        {
            int screenVertTiles = screenHeight/TILE_SIZE;
            int screenHorizTiles = screenWidth/TILE_SIZE;

            Location heroLocation = _level.getHeroLocation();

            int x1 = heroLocation.x - (screenHorizTiles / 2);
            int x2 = heroLocation.x + (screenHorizTiles / 2);
            int y1 = heroLocation.y - (screenVertTiles / 2);
            int y2 = heroLocation.y + (screenVertTiles / 2);

            bool redraw = _level.hero.visibleRect.Equals(new Rect(0, 0, 0, 0));

            _level.hero.visibleRect = new Rect(x1, y1, x2, y2);
            _level.hero.visibleRect.expand();

            for (int x = x1; x <= x2; x++)
            {
                for (int y = y1; y <= y2; y++)
                {
                    Location location = new Location(x, y);

                    Location offset = new Location(x - x1, y - y1);

                    List<Entity> entities = _level.getEntities(location);
                    foreach (Entity entity in entities)
                    {
                        drawEntity(spriteBatch, atlas, entity, offset);
                    }
                }
            }

            if (redraw)
            {
                _level.updatePlayerVision();
                draw(spriteBatch, atlas, screenWidth, screenHeight);
            }
        }
コード例 #19
0
        private static void tryAddFeature(Level level, Location doorLoc, Feature feature)
        {
            Direction[] directions = { Direction.North, Direction.South, Direction.West, Direction.East };

            foreach (Direction direction in directions)
            {
                Rect rect = createRect(doorLoc, direction, feature);
                rect.expand();
                if (rectIsClear(level, rect))
                {
                    rect.compress();
                    if (feature == Feature.Room)
                    {
                        carveRoom(level, rect, false, TileType.Dungeon_Floor);
                    }
                    else if (feature == Feature.Corridor)
                    {
                        carveCorridor(level, rect, false, TileType.Dungeon_Floor);
                    }
                    level.addTile(new Tile(false, TileType.Dungeon_Floor), doorLoc);
                    level.addWalkable(new Door(), doorLoc);
                    break;
                }
            }
        }
コード例 #20
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void addItem(Item item, Location location)
 {
     item.location = location;
     _items.Add(item.location, item);
 }
コード例 #21
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public Actor getActor(Location location)
 {
     foreach (Actor actor in _actors)
     {
         if (actor.location.Equals(location))
             return actor;
     }
     return null;
 }
コード例 #22
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
        public bool blocksSight(Location location)
        {
            Tile tile = getTile(location);
            Entity walkable = getWalkable(location);

            if (tile != null && tile.blocksMovement)
                return true;
            if (walkable != null)
            {
                if (walkable is Door && ((Door) walkable).closed)
                    return true;
                if (walkable is Chest)
                    return true;
            }

            return false;
        }
コード例 #23
0
ファイル: Explosion.cs プロジェクト: ggilbert108/ProjectR
 public Explosion(Location coord)
     : base(50, DrawTag.Explosion_1, coord)
 {
     _curSprite = 0;
 }
コード例 #24
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void removeItem(Location location)
 {
     if (_items.ContainsKey(location))
     {
         _items.Remove(location);
     }
 }
コード例 #25
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
        public List<Entity> getEntities(Location location)
        {
            //TODO add the other entites from the other layers to the list
            Entity[] entities =
            {
                getTile(location),
                getWalkable(location),
                getItem(location),
                getActor(location)
            };

            List<Entity> result = new List<Entity>();
            foreach (Entity entity in entities)
            {
                if (entity != null)
                {
                    result.Add(entity);
                }
            }

            return result;
        }
コード例 #26
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public void addTile(Tile tile, Location location)
 {
     tile.location = location;
     if (_tiles.ContainsKey(location))
     {
         _tiles.Remove(location);
     }
     _tiles.Add(tile.location, tile);
 }
コード例 #27
0
ファイル: AStarSearch.cs プロジェクト: ggilbert108/ProjectR
 public AStarNode(Location location)
 {
     this.location = location;
     g = 1000;
 }
コード例 #28
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public Item getItem(Location location)
 {
     return _items.ContainsKey(location) ? _items[location] : null;
 }
コード例 #29
0
ファイル: AStarSearch.cs プロジェクト: ggilbert108/ProjectR
        private static AStarNode aStarSearch(Location start, Location end, Level level)
        {
            HashSet<AStarNode> open = new HashSet<AStarNode>();
            HashSet<AStarNode> closed = new HashSet<AStarNode>();

            AStarNode startNode = new AStarNode(start);
            startNode.g = 0;
            startNode.h = start.distance(end);
            open.Add(startNode);

            while (open.Count > 0)
            {
                AStarNode q = new AStarNode(new Location(0, 0));
                double min = 10000;
                foreach (AStarNode node in open)
                {
                    if (node.f() < min)
                    {
                        min = node.f();
                        q = node;
                    }
                }

                open.Remove(q);
                Direction[] directions = {Direction.North, Direction.South, Direction.East, Direction.West};

                for (int i = 0; i < 4; i++)
                {
                    Location adj = q.location.getAdjLocation(directions[i]);
                    if (level.getTile(adj).blocksMovement)
                        continue;

                    AStarNode node = new AStarNode(adj);
                    if (closed.Contains(node))
                        continue;
                    node.setParent(q);

                    if (adj.Equals(end))
                        return node;

                    node.g = q.g + 1;
                    node.h = adj.distance(end);

                    bool add = true;
                    foreach (AStarNode openNode in open)
                    {
                        if (openNode.location.Equals(node.location) && openNode.f() < node.f())
                            add = false;
                    }
                    foreach (AStarNode closedNode in closed)
                    {
                        if (closedNode.location.Equals(node.location) && closedNode.f() < node.f())
                            add = false;
                    }
                    if (add)
                    {
                        open.Add(node);
                    }
                }
                closed.Add(q);
            }
            return startNode;
        }
コード例 #30
0
ファイル: Level.cs プロジェクト: ggilbert108/ProjectR
 public Tile getTile(Location location)
 {
     return _tiles.ContainsKey(location) ? _tiles[location] : null;
 }