changeset 459:41ebc538109c

Merge.
author Simon Cross <hodgestar@gmail.com>
date Sat, 07 Sep 2013 15:42:30 +0200
parents fcf9f6edf153 (diff) 0f8945232e54 (current diff)
children 0318738e3b84
files tools/area_editor.py
diffstat 11 files changed, 152 insertions(+), 163 deletions(-) [+]
line wrap: on
line diff
--- a/data/levels/alientunnels	Sat Sep 07 15:39:49 2013 +0200
+++ b/data/levels/alientunnels	Sat Sep 07 15:42:30 2013 +0200
@@ -1,97 +1,70 @@
 base_tile: tiles/alien_tile.png
-enemies: []
-game_objects:
+enemies:
 - args:
-  - [350, 3450]
-  - alientunnels
-  - [300, 3000]
-  - 135
-  classname: Door
-  name: entrance
-- args:
-  - [1050, 3450]
-  - alientunnels
-  - [1150, 3550]
-  - 45
-  classname: Door
-  name: 1to2
+  - [1200, 2200]
+  - [1700, 2000]
+  classname: PatrollingAlien
+  name: alien_1_1
 - args:
-  - [1150, 3550]
-  - alientunnels
-  - [1050, 3450]
-  - 45
-  classname: Door
-  name: 2to1
-- args:
-  - [1850, 3550]
-  - alientunnels
-  - [1950, 3450]
-  - 135
-  classname: Door
-  name: 2to3
+  - [1300, 2100]
+  - [1500, 1900]
+  classname: PatrollingAlien
+  name: alien_1_2
 - args:
-  - [1950, 3450]
-  - alientunnels
-  - [1850, 3550]
-  - 135
-  classname: Door
-  name: 3to2
-- args:
-  - [1950, 2750]
-  - alientunnels
-  - [1850, 2650]
-  - 45
-  classname: Door
-  name: 3to4
+  - [1200, 2300]
+  - [1200, 2100]
+  classname: PatrollingAlien
+  name: alien_1_3
+game_objects:
 - args:
   - [1850, 2650]
   - alientunnels
-  - [1950, 2750]
+  - [1500, 2500]
   - 45
   classname: Door
-  name: 4to3
+  name: entrance
 - args:
   - [1850, 1950]
   - alientunnels
   - [1950, 1850]
   - 135
   classname: Door
-  name: 4to5
+  name: 1to2
 - args:
   - [1950, 1850]
   - alientunnels
   - [1850, 1950]
   - 135
   classname: Door
-  name: 5to4
+  name: 2to1
 - args:
   - [1950, 1150]
   - alientunnels
   - [1850, 1050]
   - 45
   classname: Door
-  name: 5to6
+  name: 2to3
 - args:
   - [1950, 1150]
   - alientunnels
   - [1850, 1050]
   - 45
   classname: Door
-  name: 6to5
+  name: 3to2
 - args:
   - [1150, 1050]
   - alientunnels
   - [1050, 1150]
   - 135
   classname: Door
-  name: 6to7
+  name: 3to4
 - args:
   - [1050, 1150]
   - alientunnels
   - [1150, 1050]
   - 135
   classname: Door
-  name: 7to6
+  name: 4to3
 - args:
   - [350, 1850]
   - alientunnels
@@ -99,39 +72,21 @@
   - 135
   classname: Door
   name: exit
+- args:
+  - [1392, 2536]
+  - - [1392, 2536]
+    - [1252, 2468]
+    - [1266, 2270]
+    - [1504, 2112]
+    - [1812, 2104]
+    - [1960, 2196]
+    - [1896, 2380]
+    - [1688, 2524]
+  classname: AcidFloor
+  name: acid_1
 lines: []
 polygons:
   1:
-  - [1300, 4400]
-  - [1700, 4400]
-  - [2000, 4100]
-  - [2000, 3700]
-  - [1700, 3400]
-  - [1300, 3400]
-  - [1000, 3700]
-  - [1000, 4100]
-  - [1300, 4400]
-  2:
-  - [500, 3600]
-  - [900, 3600]
-  - [1200, 3300]
-  - [1200, 2900]
-  - [900, 2600]
-  - [500, 2600]
-  - [200, 2900]
-  - [200, 3300]
-  - [500, 3600]
-  3:
-  - [2100, 3600]
-  - [2500, 3600]
-  - [2800, 3300]
-  - [2800, 2900]
-  - [2500, 2600]
-  - [2100, 2600]
-  - [1800, 2900]
-  - [1800, 3300]
-  - [2100, 3600]
-  4:
   - [1300, 2800]
   - [1700, 2800]
   - [2000, 2500]
@@ -141,7 +96,7 @@
   - [1000, 2100]
   - [1000, 2500]
   - [1300, 2800]
-  5:
+  2:
   - [500, 2000]
   - [900, 2000]
   - [1200, 1700]
@@ -151,7 +106,7 @@
   - [200, 1300]
   - [200, 1700]
   - [500, 2000]
-  6:
+  3:
   - [2100, 2000]
   - [2500, 2000]
   - [2800, 1700]
@@ -161,7 +116,7 @@
   - [1800, 1300]
   - [1800, 1700]
   - [2100, 2000]
-  7:
+  4:
   - [1300, 1200]
   - [1700, 1200]
   - [2000, 900]
@@ -171,4 +126,5 @@
   - [1000, 500]
   - [1000, 900]
   - [1300, 1200]
-size: [3000, 4600]
+  6: []
+size: [3000, 3000]
--- a/data/levels/sheep	Sat Sep 07 15:39:49 2013 +0200
+++ b/data/levels/sheep	Sat Sep 07 15:42:30 2013 +0200
@@ -14,11 +14,11 @@
   classname: Sheep
 game_objects:
 - args:
-  - [800, 500]
-  - - [700, 450]
-    - [700, 850]
+  - [900, 700]
+  - - [850, 650]
+    - [850, 850]
     - [1150, 850]
-    - [1150, 450]
+    - [1150, 650]
   - 3
   classname: SheepPen
   name: sheep_pen
@@ -27,11 +27,19 @@
   - sheep_pen
   classname: FloorLight
   name: sheep_light
+- args:
+  - [51, 450]
+  - sheep
+  - [100, 450]
+  - 0
+  classname: Door
 lines:
-- - [700, 850]
-  - [700, 450]
-- - [700, 450]
-  - [960, 450]
+- - [850, 650]
+  - [850, 850]
+- - [1000, 650]
+  - [850, 650]
+- - [1100, 650]
+  - [1150, 650]
 polygons:
   1:
   - [50, 50]
--- a/nagslang/__main__.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/__main__.py	Sat Sep 07 15:42:30 2013 +0200
@@ -16,7 +16,7 @@
     pygame.font.init()
     pygame.display.set_mode(SCREEN, pgl.SWSURFACE | pgl.RESIZABLE)
     #pygame.display.set_icon(load_image(...))
-    pygame.display.set_caption('Nagslang')
+    pygame.display.set_caption('Werewolf Sonata')
     sound.init()
 
     screen = pygame.display.get_surface()
--- a/nagslang/constants.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/constants.py	Sat Sep 07 15:42:30 2013 +0200
@@ -5,8 +5,13 @@
 
 DEFAULTS = dict(
     debug=False,
+    shapes=False,
+
     sound=True,
     music=True,
+    # Debug starting position:
+    area=None,
+    point=None,
 )
 
 # Sound constants
--- a/nagslang/enemies.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/enemies.py	Sat Sep 07 15:42:30 2013 +0200
@@ -79,8 +79,8 @@
             self.world.kills += 1
             self.physicser.remove_from_space()
 
-    def set_direction(self, dx, dy):
-        vec = vec_with_length((dx, dy), self.impulse_factor)
+    def set_direction(self, dx, dy, force_factor=1):
+        vec = vec_with_length((dx, dy), self.impulse_factor * force_factor)
         self.angle = vec.angle
         self.physicser.apply_impulse(vec)
 
@@ -125,6 +125,7 @@
     def greedy_move(self, target):
         """Simple greedy path finder"""
         def _calc_step(tp, pp):
+            step = 0
             if (tp < pp):
                 step = max(-1, tp - pp)
             elif (tp > pp):
@@ -321,15 +322,15 @@
     def move(self, result):
         vec = self.range_to_visible_protagonist()
         prot = self.world.protagonist
-        step = None
         if vec is not None:
             if prot.in_human_form() and vec.length < self.human_vision_range:
-                step = vec.int_tuple
+                self.set_direction(vec.x, vec.y, 1.5)
+                return
             if prot.in_wolf_form() and vec.length < self.wolf_vision_range:
-                step = (-vec).int_tuple
-        if step is None:
-            step = self.random_move()
-        self.set_direction(*step)
+                vec = -vec
+                self.set_direction(vec.x, vec.y, 3)
+                return
+        self.set_direction(*self.random_move())
 
     @classmethod
     def requires(cls):
--- a/nagslang/engine.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/engine.py	Sat Sep 07 15:42:30 2013 +0200
@@ -4,6 +4,7 @@
 import pygame.locals as pgl
 
 from nagslang import constants
+from nagslang.options import options
 from nagslang.screens.area import AreaScreen
 from nagslang.events import ScreenChange
 from nagslang.world import World
@@ -25,7 +26,14 @@
         starting_area = Level.game_starting_point()[0]
 
         self._world.load()
-        self.change_screen(starting_area)
+        if options.point:
+            x, y = options.point.split(',')
+            point = (int(x), int(y))
+            self._world.protagonist.set_position(point)
+        if options.area:
+            self.change_screen(options.area)
+        else:
+            self.change_screen(starting_area)
         # Dummy resize event, to force us to realise our real size
         # http://stackoverflow.com/q/16442573/8629
         pygame.event.post(pygame.event.Event(pgl.VIDEORESIZE,
--- a/nagslang/options.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/options.py	Sat Sep 07 15:42:30 2013 +0200
@@ -35,6 +35,9 @@
 
     if options.debug:
         parser.add_option('--area', help='Initial area')
+        parser.add_option('--point', help='Initial position x,y')
+        parser.add_option('--shapes', help='Show collision shapes',
+                          action='store_true', default=options.shapes)
 
     opts, _ = parser.parse_args(args)
 
--- a/nagslang/puzzle.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/puzzle.py	Sat Sep 07 15:42:30 2013 +0200
@@ -70,13 +70,21 @@
             collision_types = (COLLISION_TYPE_PLAYER,)
         self._collision_types = collision_types
 
-    def get_colliders(self):
+    def get_interior_colliders(self):
         space = self.game_object.get_space()
         my_shape = self.game_object.get_shape()
         shapes = [shape for shape in space.shapes
                   if shape.collision_type in self._collision_types]
-        return [shape for shape in shapes
-                if my_shape in space.point_query(shape.body.position)]
+        return set(shape for shape in shapes
+                   if my_shape in space.point_query(shape.body.position))
+
+    def get_colliders(self):
+        space = self.game_object.get_space()
+        my_shape = self.game_object.get_shape()
+        shapes = set(shape for shape in space.shape_query(my_shape)
+                     if shape.collision_type in self._collision_types)
+        shapes.update(self.get_interior_colliders())
+        return shapes
 
     def get_state(self):
         return bool(self.get_colliders())
--- a/nagslang/render.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/nagslang/render.py	Sat Sep 07 15:42:30 2013 +0200
@@ -33,7 +33,7 @@
             pymunk.pygame_util.draw(surface, shape)
 
     def render(self, surface):
-        if options.debug:
+        if options.shapes:
             self._render_shape(surface)
 
     def update(self, seconds):
--- a/source/levels/alientunnels.svg	Sat Sep 07 15:39:49 2013 +0200
+++ b/source/levels/alientunnels.svg	Sat Sep 07 15:42:30 2013 +0200
@@ -10,7 +10,7 @@
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    width="3000"
-   height="4600"
+   height="3000"
    id="svg2"
    version="1.1"
    inkscape:version="0.48.4 r9939"
@@ -24,9 +24,9 @@
      borderopacity="1.0"
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
-     inkscape:zoom="0.175"
-     inkscape:cx="1556.0113"
-     inkscape:cy="3201.2529"
+     inkscape:zoom="0.12374369"
+     inkscape:cx="-857.7453"
+     inkscape:cy="2386.4477"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="true"
@@ -54,7 +54,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -62,48 +62,41 @@
      inkscape:label="Layer 1"
      inkscape:groupmode="layer"
      id="layer1"
-     transform="translate(0,3547.6378)">
-    <path
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="m 1300,-3347.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
-       id="path2987"
-       inkscape:connector-curvature="0"
-       sodipodi:nodetypes="ccccccccc" />
-    <path
-       sodipodi:nodetypes="ccccccccc"
-       inkscape:connector-curvature="0"
-       id="path2989"
-       d="m 500,-2547.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
-    <path
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="m 2100,-2547.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
-       id="path2991"
-       inkscape:connector-curvature="0"
-       sodipodi:nodetypes="ccccccccc" />
-    <path
-       sodipodi:nodetypes="ccccccccc"
-       inkscape:connector-curvature="0"
-       id="path2993"
-       d="m 1300,-1747.6378 400,0 300,300 5.7143,400 -305.7143,300 -400,0 -300,-300 0,-400 z"
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
-    <path
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="m 1300,-147.6378 400,0 300,300 -1.4286,401.42857 L 1700,852.3622 l -400,0 -300,-300 0,-400 z"
-       id="path2995"
-       inkscape:connector-curvature="0"
-       sodipodi:nodetypes="ccccccccc" />
-    <path
-       sodipodi:nodetypes="ccccccccc"
-       inkscape:connector-curvature="0"
-       id="path2997"
-       d="m 500,-947.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
-    <path
-       style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="m 2100,-947.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
-       id="path2999"
-       inkscape:connector-curvature="0"
-       sodipodi:nodetypes="ccccccccc" />
+     transform="translate(0,1947.6378)">
+    <g
+       id="g5460"
+       transform="translate(0,1600)">
+      <path
+         sodipodi:nodetypes="ccccccccc"
+         inkscape:connector-curvature="0"
+         id="path2987"
+         d="m 1300,-3347.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
+         style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+         d="m 500,-2547.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
+         id="path2989"
+         inkscape:connector-curvature="0"
+         sodipodi:nodetypes="ccccccccc" />
+      <path
+         sodipodi:nodetypes="ccccccccc"
+         inkscape:connector-curvature="0"
+         id="path2991"
+         d="m 2100,-2547.6378 400,0 300,300 0,400 -300,300 -400,0 -300,-300 0,-400 z"
+         style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+         d="m 1300,-1747.6378 400,0 300,300 5.7143,400 -305.7143,300 -400,0 -300,-300 0,-400 z"
+         id="path2993"
+         inkscape:connector-curvature="0"
+         sodipodi:nodetypes="ccccccccc" />
+      <path
+         sodipodi:nodetypes="ccccccccccccc"
+         transform="translate(0,-3547.6378)"
+         inkscape:connector-curvature="0"
+         id="path5458"
+         d="m 400,1500 100,100 100,0 200,-200 0,-100 -100,-100 200,0 100,100 0,200 -300,300 -200,0 -100,-100 z"
+         style="fill:#00ff00;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    </g>
   </g>
 </svg>
--- a/tools/area_editor.py	Sat Sep 07 15:39:49 2013 +0200
+++ b/tools/area_editor.py	Sat Sep 07 15:42:30 2013 +0200
@@ -126,7 +126,8 @@
         self.lines.append([startpoint, endpoint])
 
     def draw(self, mouse_pos, mouse_poly, filled, draw_cand_line, start_pos,
-             move_point_mode, move_poly_mode, move_point, zoom_factor):
+             move_point_mode, move_poly_mode, move_point, zoom_factor,
+             level_widget):
         self._draw_background(True)
         # Draw polygons as needed for the editor
         line_width = int(2 * zoom_factor)
@@ -168,7 +169,8 @@
             pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist,
                               line_width)
         if draw_cand_line and start_pos and mouse_pos:
-            endpoint = self.snap_to_grid(mouse_pos)
+            endpoint = level_widget.snap_to_grid(mouse_pos)
+            endpoint = self.point_to_pymunk(endpoint)
             pointlist = [start_pos,
                          self.point_to_pygame(endpoint)]
             pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 1)
@@ -399,18 +401,23 @@
                 # Evil, but faster than good
                 try:
                     l = eval(text)
-                    args.append(' - - %s' % l[0])
-                    for coord in l[1:]:
-                        args.append('   - %s' % coord)
                 except Exception:
                     alert("Invalid polygon %s" % text)
                     self.needs_cleanup = False
                     return None
                 # Check for convexity
-                hull = pymunk.util.convex_hull(l)
-                if hull != l:
+                if not pymunk.util.is_convex(l):
                     alert("Invalid polygon %s - not convex" % text)
                     return None
+                if not pymunk.util.is_clockwise(l):
+                    l.reverse()
+                    if not pymunk.util.is_clockwise(l):
+                        alert("Invalid polygon %s - unable to make clockwise"
+                              % text)
+                        return None
+                args.append(' - - %s' % l[0])
+                for coord in l[1:]:
+                    args.append('   - %s' % coord)
             else:
                 args.append(' - ' + text)
         data = "args:\n" + '\n'.join(args)
@@ -446,8 +453,9 @@
         if not pos:
             return (0, 0)
         # Apply zoom_factor
+        pos = pos[0] + self.pos[0], pos[1] + self.pos[1]
         zoomed = (pos[0] * self._zoom_factor, pos[1] * self._zoom_factor)
-        return int(zoomed[0] + self.pos[0]), int(zoomed[1] + self.pos[1])
+        return int(zoomed[0]), int(zoomed[1])
 
     def _move_view(self, offset):
         new_pos = [self.pos[0] + offset[0], self.pos[1] + offset[1]]
@@ -509,8 +517,7 @@
         level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode,
                                    self._draw_lines, self._start_pos,
                                    self._move_point_mode, self._move_poly_mode,
-                                   self._move_point,
-                                   self._zoom_factor)
+                                   self._move_point, self._zoom_factor, self)
         if self._draw_objects:
             for thing in self.level.drawables:
                 if not isinstance(thing, ne.Enemy):