Esempio n. 1
0
 public bool intersect(Room other)
 {
     return (x1 <= other.x2 && x2 >= other.x1 && y1 <= other.y2 && y2 >= other.y1);
 }
Esempio n. 2
0
 void placeThings(Room room)
 {
     placeItems(room);
     placeMonsters(room);
 }
Esempio n. 3
0
        private void placeMonsters(Room room)
        {
            int monsters = TCODRandom.getInstance().getInt(0, Globals.MAX_MON);
            for (var i = 0; i < monsters; i++)
            {
                int mx = TCODRandom.getInstance().getInt(room.x1+1, room.x2-1);
                int my = TCODRandom.getInstance().getInt(room.y1+1, room.y2-1);

                if (TCODRandom.getInstance().getInt(0, 100) < 80)
                {
                    Actor mon = new Actor(mx, my, 't', "thug", TCODColor.darkCyan);
                    mon.destruct = new MonsterDestructible(10, 0, "dead thug", engine);
                    mon.attacker = new Attacker(3);
                    mon.ai = new MonsterAI();
                    engine.actors.Add(mon);
                }
                else
                {
                    Actor mon = new Actor(mx, my, 'g', "gangster", TCODColor.darkCrimson);
                    mon.destruct = new MonsterDestructible(10, 0, "dead gangster", engine);
                    mon.attacker = new Attacker(3);
                    mon.ai = new MonsterAI();
                    engine.actors.Add(mon);
                }
            }
        }
Esempio n. 4
0
        private void placeItems(Room room)
        {
            int numItems = TCODRandom.getInstance().getInt(0, Globals.MAX_ITEMS);
            float random = TCODRandom.getInstance().getFloat(0.0f, 1.0f);

            for (int i = 0; i < numItems; i++)
            {
                random = TCODRandom.getInstance().getFloat(0.0f, 1.0f);
                int x = TCODRandom.getInstance().getInt(room.x1+1, room.x2-1);
                int y = TCODRandom.getInstance().getInt(room.y1+1, room.y2-1);

                if (random < .5)
                {
                    Actor healthpot = new Actor(x, y, '!', "bandage", TCODColor.violet);
                    healthpot.blocks = false;
                    healthpot.pick = new Healer(4);

                    engine.actors.Add(healthpot);
                }
                else if (random >= .5 && random < .6)
                {
                    Actor confuse = new Actor(x, y, '#', "rock", TCODColor.darkBlue);
                    confuse.blocks = false;
                    confuse.pick = new Confuser(10, 10, engine);

                    engine.actors.Add(confuse);
                }
                else if (random >= .6 && random < .9){
                    Actor gun = new Actor(x, y, '#', "ammo", TCODColor.darkYellow);
                    gun.blocks = false;
                    gun.pick = new ammo(engine);

                    engine.actors.Add(gun);
                } else
                {
                    Actor fire = new Actor(x, y, '#', "grenade", TCODColor.darkRed);
                    fire.blocks = false;
                    fire.pick = new grenade(5, 10, engine);

                    engine.actors.Add(fire);
                }
            }
        }
Esempio n. 5
0
        public void genMap()
        {
            int numRooms = 0;
            int newx, newy, prevx, prevy;
            bool failed = false;

            for (var i = 0; i < Globals.ROOMS; i++)
            {
                failed = false;
                int w = TCODRandom.getInstance().getInt(Globals.MIN_SIZE, Globals.MAX_SIZE);
                int h = TCODRandom.getInstance().getInt(Globals.MIN_SIZE, Globals.MAX_SIZE);
                int x = TCODRandom.getInstance().getInt(0, width - w - 1);
                int y = TCODRandom.getInstance().getInt(0, height - h - 1);

                Room newRoom = new Room(x, y, w, h);
                foreach (Room otherroom in rooms)
                {
                    if (newRoom.intersect(otherroom))
                    {
                        failed = true;
                        break;
                    }
                }

                if (!failed)
                {
                    createRoom(newRoom);
                    newx = newRoom.centerx;
                    newy = newRoom.centery;

                    if (numRooms == 0)
                    {
                        engine.player.x = newx;
                        engine.player.y = newy;
                    }
                    else
                    {
                        prevx = rooms[numRooms - 1].centerx;
                        prevy = rooms[numRooms - 1].centery;

                        if (TCODRandom.getInstance().getInt(0, 1) == 1)
                        {
                            hTunnel(prevx, newx, prevy);
                            vTunnel(prevy, newy, newx);
                        }
                        else
                        {
                            vTunnel(prevy, newy, prevx);
                            hTunnel(prevx, newx, newy);
                        }
                    }

                    placeThings(newRoom);
                    rooms.Add(newRoom);
                    numRooms++;
                    lastx = newRoom.centerx;
                    lasty = newRoom.centery;
                }
            }

            entx = engine.player.x+1;
            enty = engine.player.y;
            exx = lastx+1;
            exy = lasty;

            Actor nextLevel = new Actor(exx, exy, '>', "stairs", TCODColor.sea);
            nextLevel.portal = new Portal(this, true, false);
            engine.actors.Add(nextLevel);

            if(gameState.curLevel != 0)
            {
                Actor prevLevel = new Actor(entx, enty, '>', "stairs", TCODColor.sea);
                prevLevel.portal = new Portal(this, false, false);
                engine.actors.Add(prevLevel);
            }
        }
Esempio n. 6
0
 public void createRoom(Room room)
 {
     for (var x = room.x1 + 1; x < room.x2; x++)
     {
         for (var y = room.y1 + 1; y < room.y2; y++)
         {
             tmap.setProperties(x, y, true, true);
             tiles[x + y * width].canWalk = true;
         }
     }
 }