changeset 33:deb53da4ef98

extra loops in the maps
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Tue, 23 Aug 2011 18:31:39 +0200
parents 8cffbc75c591
children 2d976c526ad4
files generator.py level.py main.py
diffstat 3 files changed, 45 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/generator.py	Tue Aug 23 17:33:06 2011 +0200
+++ b/generator.py	Tue Aug 23 18:31:39 2011 +0200
@@ -7,7 +7,25 @@
 
 
 class LevelGenerator(object):
-    def __init__(self):
+    depth_monsters = [
+        [monster.Bat],
+        [monster.Bat, monster.Skeleton],
+        [monster.Bat, monster.Skeleton, monster.Zombie],
+        [monster.Skeleton, monster.Zombie],
+        [monster.Skeleton, monster.Zombie, monster.Jelly],
+        [monster.Skeleton, monster.Zombie, monster.Jelly, monster.Ghost],
+        [monster.Jelly, monster.Zombie, monster.Ghost],
+        [monster.Jelly, monster.Ghost, monster.Jack],
+        [monster.Ghost, monster.Jack],
+        [monster.Ghost, monster.Jack, monster.Eye],
+        [monster.Jack, monster.Eye],
+        [monster.Bat, monster.Jack, monster.Eye],
+        [monster.Bat, monster.Skeleton, monster.Zombie, monster.Jack,
+         monster.Eye, monster.Jelly, monster.Ghost],
+    ]
+
+    def __init__(self, depth):
+        self.depth = depth
         self.map = [['x'] * 30 for i in range(30)]
         self.things = {}
         self.monsters = {}
@@ -43,9 +61,7 @@
             p = self._random_place()
             if (p not in self.monsters and
                 not isinstance(self.things.get(p), thing.Entrance)):
-                monsters = [monster.Skeleton, monster.Zombie, monster.Jack,
-                            monster.Bat, monster.Ghost, monster.Eye,
-                            monster.Jelly]
+                monsters = self.depth_monsters[self.depth]
                 self.monsters[p] = random.choice(monsters)(*p)
 
     def make_stairs(self):
@@ -60,11 +76,12 @@
         self.map[y1][x1] = '>'
 
     def make_connections(self):
+        dirs = [(0, 1), (0, -1), (1, 0), (-1, 0)]
+        connections = []
         connected = [(random.randint(0, 2), random.randint(0, 2))]
         while len(connected) < 9:
             x1, y1 = random.choice(connected)
             try:
-                dirs = [(0, 1), (0, -1), (1, 0), (-1, 0)]
                 dx, dy = random.choice([(dx, dy) for (dx, dy)
                     in dirs if 0 <= x1 + dx <= 2 and 0 <= y1 + dy <= 2 and
                         (x1 + dx, y1 + dy) not in connected])
@@ -75,7 +92,23 @@
             x2, y2 = x1 + dx, y1 + dy
             r2 = self.rooms[y2][x2]
             self.connect_rooms(r1, r2)
+            connections.append((x1, y1, x2, y2))
             connected.append((x2, y2))
+        for loop in range(3):
+            x1 = random.randint(0, 2)
+            y1 = random.randint(0, 2)
+            possible = [(dx, dy) for (dx, dy)
+                in dirs if 0 <= x1 + dx <= 2 and 0 <= y1 + dy <= 2 and
+                not ((x1, y1, x1 + dx, y1 + dy) in connections or
+                     (x1 + dx, y1 + dy, x1, y1) in connections)]
+            if not possible:
+                continue
+            dx, dy = random.choice(possible)
+            x2, y2 = x1 + dx, y1 + dy
+            r1 = self.rooms[y1][x1]
+            r2 = self.rooms[y2][x2]
+            self.connect_rooms(r1, r2)
+            connections.append((x1, y1, x2, y2))
 
     def make_room(self, x1, y1):
         w = random.randint(3, 8)
--- a/level.py	Tue Aug 23 17:33:06 2011 +0200
+++ b/level.py	Tue Aug 23 18:31:39 2011 +0200
@@ -2,7 +2,6 @@
 # -*- coding: utf-8 -*-
 
 import display
-import hero
 import thing
 import generator
 import pygame
@@ -98,9 +97,10 @@
     }
     BLOCKED = 1
 
-    def __init__(self, hero):
+    def __init__(self, hero, depth):
         self.hero = hero
-        gen = generator.LevelGenerator()
+        self.depth = depth
+        gen = generator.LevelGenerator(depth)
         self.map = gen.map
         self.things = {}
         for t in gen.things.itervalues():
--- a/main.py	Tue Aug 23 17:33:06 2011 +0200
+++ b/main.py	Tue Aug 23 18:31:39 2011 +0200
@@ -10,13 +10,15 @@
 
 class Game(object):
     def __init__(self):
-        self.display = display.Display((320, 256))
+        self.depth = 0
+        self.display = display.Display((320, 200))
         self.hero = hero.Hero()
         self.start_level()
 
     def start_level(self):
         self.display.empty()
-        self.level = level.Level(self.hero)
+        self.level = level.Level(self.hero, self.depth)
+        self.depth += 1
         self.level.render(self.display)
         self.display.scroll_to(self.hero.sprite.rect)