Changeset 101:b502e732f821


Ignore:
Timestamp:
Apr 4, 2011, 5:34:20 PM (9 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Add ? object-placement-help tiles

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1.json

    r99 r101  
    66    "tiles": [
    77        "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    8         "X{.....................................}X{..............................}X",
     8        "X{.....?...............................}X{..............................}X",
    99        "X...1...................................X................................X",
    10         "X.......................................bXXXd=-->........................X",
     10        "X..?....................................bXXXd=-->........................X",
    1111        "Xd=--------+XXXq.........................................................X",
    1212        "X{..........XXXX.........................................................X",
  • data/levels/level2.json

    r91 r101  
    1111        "X.........<+bXXd=>....<+bXXXXXXXXXXd=>...<+bXXd=>..........XX...........}X",
    1212        "X...........................}XX{...........}bd{...<+bd=>...XXd=>.........X",
    13         "X........pq......pq..........XX............................XX{........<+bX",
     13        "X........pq..?...pq..........XX............................XX{........<+bX",
    1414        "X.....<+bXXXXXXXXXXd=>...<+bXXX.........pq......pq......<+bXX...........}X",
    1515        "X...........}XX{............}XX......<+bXXXXXXXXXXd=>.....}XXd=----->....X",
    16         "X............XX..............XXd=>.........}XX{............XX{...........X",
     16        "X..?.........XX..............XXd=>.........}XX{............XX{...........X",
    1717        "XXXXd=>......XX......<---+bXXXX{.........<+bXX..........<+bXX............X",
    1818        "X{...........XX.............}XX............}XX............}XXd=--->......X",
  • scripts/level-editor

    r92 r101  
    1616
    1717from skaapsteker.constants import SCREEN
    18 from skaapsteker.level import Level
     18from skaapsteker.level import DebugLevel
    1919from skaapsteker.sprites.player import Player
    2020from skaapsteker.widgets.text import Text
     
    2626    screen_surface = pygame.display.get_surface()
    2727    player = Player()
    28     level = Level(levelname, player)
     28    level = DebugLevel(levelname, player)
    2929    level_surface = level.get_surface()
    3030    position = [0, 0]
  • skaapsteker/level.py

    r97 r101  
    11import json
    22
    3 from pygame import Rect, Surface
     3from pygame import Rect, Surface, Color
    44from pygame.sprite import LayeredUpdates
    55from pygame.locals import SRCALPHA, HWSURFACE
    66
    7 from skaapsteker import data
    8 from skaapsteker.constants import Layers
    9 from skaapsteker.sprites import enemies
    10 from skaapsteker.sprites.base import TILE_SIZE, find_sprite, Geography
     7from . import data
     8from .constants import Layers
     9from .sprites import enemies
     10from .sprites.base import TILE_SIZE, find_sprite, Geography
     11from .widgets.text import Text
    1112
    1213
     
    1718        self.tile_factories = {
    1819            '.': lambda pos: None,
     20            '?': lambda pos: None, # Object placement helper
    1921            '-': self.tile_factory('floor.png', True),
    2022            'X': self.tile_factory('solid.png', True, True),
     
    129131    def draw(self, surface):
    130132        self.draw_background(surface)
     133
     134
     135
     136class DebugLevel(Level):
     137    """Used by level-editor"""
     138    def build_tiles(self):
     139        super(DebugLevel, self).build_tiles()
     140        tile_data = self.level_data['tiles']
     141        for y, row in enumerate(tile_data):
     142            for x, char in enumerate(row):
     143                if char == '?':
     144                    self.check_debug_tile(x, y)
     145
     146
     147    def check_debug_tile(self, x, y):
     148        objects = []
     149        objects += self.level_data.get('enemies', [])
     150        objects += self.level_data.get('sprites', [])
     151        if 'player' in self.level_data:
     152            objects.append(self.level_data['player'])
     153
     154        for object_ in objects:
     155            if [x, y] == object_['pos']:
     156                break
     157        else:
     158            tile = self.get_debug_tile(x, y)
     159            print "Debug tile at (%i, %i)" % (x, y)
     160            self.tiles.add(tile)
     161            self.sprites.add(tile)
     162
     163
     164    def get_debug_tile(self, x, y):
     165        surface = Surface((64, 64))
     166        surface.fill(Color('black'))
     167        text = Text("? Tile at\n(%i, %i)" % (x, y), (2, 2), size=14, color='white')
     168        text.draw(surface)
     169        return Geography((x, y), surface.convert_alpha())
Note: See TracChangeset for help on using the changeset viewer.