changeset 63:199bad12a6be

added a surface level with pumpkins
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Fri, 02 Sep 2011 00:34:08 +0200
parents 87b0fd7142d7
children 5e633ebc8626 b01bdfb36721
files scroungelib/generator.py scroungelib/level.png scroungelib/level.py scroungelib/thing.py
diffstat 4 files changed, 51 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/scroungelib/generator.py	Fri Sep 02 00:08:28 2011 +0200
+++ b/scroungelib/generator.py	Fri Sep 02 00:34:08 2011 +0200
@@ -24,22 +24,30 @@
         [monster.Bat, monster.Skeleton, monster.Zombie, monster.Jack,
          monster.Eye, monster.Jelly, monster.Ghost, monster.Plant],
     ]
+    wall = 'x'
+    floor = '.+:'
+    corridor1 = ',;'
+    corridor2 = '";'
+    door = '+'
+    trash = [thing.Bones, thing.Debris, thing.Rocks,
+            thing.Skull, thing.Bottle, thing.Pot, thing.Shards]
+
 
     def __init__(self, depth):
         self.depth = depth
-        self.map = [['x'] * 30 for i in range(30)]
+        self.map = [[self.wall] * 30 for i in range(30)]
         self.things = {}
         self.monsters = {}
         self.rooms = [[self.make_room(x, y) for x in range(3)]
                       for y in range(3)]
         for line in self.rooms:
             for x1, y1, x2, y2 in line:
-                self.rect(x1, y1, x2, y2, 'X', '.+:')
+                self.rect(x1, y1, x2, y2, 'X', self.floor)
         self.make_connections()
         for line in self.map:
             for i, c in enumerate(line):
                 if c == 'X':
-                    line[i] = 'x'
+                    line[i] = self.wall
         self.make_monsters()
         self.make_trash()
         self.make_stairs()
@@ -51,8 +59,6 @@
         return x1, y1
 
     def make_trash(self):
-        trash = [thing.Plant, thing.Bones, thing.Debris, thing.Rocks,
-                thing.Skull, thing.Bottle, thing.Pot, thing.Shards]
         for i in range(random.randint(2, 5)):
             p = self._random_place()
             if p not in self.things:
@@ -60,7 +66,7 @@
         for i in range(random.randint(5, 25)):
             p = self._random_place()
             if p not in self.things:
-                self.things[p] = random.choice(trash)(*p)
+                self.things[p] = random.choice(self.trash)(*p)
 
     def make_monsters(self):
         for i in range(15):
@@ -138,15 +144,15 @@
             else:
                 m = y1 + 1
             for y in range(y1, m):
-                self.map[y][x1] = random.choice(',;')
+                self.map[y][x1] = random.choice(self.corridor1)
             if x1 < x2:
                 for x in range(x1, x2 + 1):
-                    self.map[m][x] = random.choice(';"')
+                    self.map[m][x] = random.choice(self.corridor2)
             else:
                 for x in range(x2, x1 + 1):
-                    self.map[m][x] = random.choice(';"')
+                    self.map[m][x] = random.choice(self.corridor2)
             for y in range(m, y2):
-                self.map[y][x2] = random.choice(',;')
+                self.map[y][x2] = random.choice(self.corridor1)
         else:
             # horizontal
             v = False
@@ -161,17 +167,17 @@
             else:
                 m = x1 + 1
             for x in range(x1, m):
-                self.map[y1][x] = random.choice(',;')
+                self.map[y1][x] = random.choice(self.corridor1)
             if y1 < y2:
                 for y in range(y1, y2 + 1):
-                    self.map[y][m] = random.choice(';"')
+                    self.map[y][m] = random.choice(self.corridor2)
             else:
                 for y in range(y2, y1 + 1):
-                    self.map[y][m] = random.choice(';"')
+                    self.map[y][m] = random.choice(self.corridor2)
             for x in range(m, x2):
-                self.map[y2][x] = random.choice(',;')
-        self.map[y1][x1] = '+'
-        self.map[y2][x2] = '+'
+                self.map[y2][x] = random.choice(self.corridor1)
+        self.map[y1][x1] = self.door
+        self.map[y2][x2] = self.door
         if random.randint(0, 10) > 7:
             self.things[(x1, y1)] = thing.Door(x1, y1, not v)
         if random.randint(0, 10) > 7:
@@ -188,3 +194,15 @@
         for x in range(x1, x2 + 1):
             self.map[y1][x] = c
             self.map[y2][x] = c
+
+
+class SurfaceLevelGenerator(LevelGenerator):
+    wall = 'z'
+    floor = '*='
+    corridor1 = '"*'
+    corridor2 = ';,'
+    door = '*'
+    depth_monsters = [
+        [monster.Jack, monster.Plant],
+    ]
+    trash = [thing.Plant, thing.Debris, thing.Rocks, thing.Pumpkin, thing.Pumpkins]
Binary file scroungelib/level.png has changed
--- a/scroungelib/level.py	Fri Sep 02 00:08:28 2011 +0200
+++ b/scroungelib/level.py	Fri Sep 02 00:34:08 2011 +0200
@@ -43,6 +43,10 @@
     tx, ty = 3, 4
 
 
+class PlainTile(Tile):
+    tx, ty = 1, 6
+
+
 class DoorTile(Tile):
     tx, ty = 3, 3
 
@@ -103,6 +107,7 @@
         ';': PlantsTile,
         '"': WeedTile,
         '*': GrassTile,
+        '=': PlainTile,
     }
     BLOCKED = 1
     EXPLORED = 2
@@ -110,7 +115,10 @@
     def __init__(self, hero, depth):
         self.hero = hero
         self.depth = depth
-        gen = generator.LevelGenerator(depth)
+        if self.depth > 0:
+            gen = generator.LevelGenerator(depth)
+        else:
+            gen = generator.SurfaceLevelGenerator(depth)
         self.map = gen.map
         self.rooms = gen.rooms
         self.things = {}
--- a/scroungelib/thing.py	Fri Sep 02 00:08:28 2011 +0200
+++ b/scroungelib/thing.py	Fri Sep 02 00:34:08 2011 +0200
@@ -118,6 +118,14 @@
     tx, ty = 2, 2
 
 
+class Pumpkin(Thing):
+    tx, ty = 0, 2
+
+
+class Pumpkins(Thing):
+    tx, ty = 1, 2
+
+
 class Bones(Thing):
     tx, ty = 2, 3