Пример #1
0
    def init(self):
        #self._tiles = load_tiles(data.filepath('tiles.tga'))
        self._tiles = Level._tiles
        fname = self.fname  # MYNOTE by default fname = none
        if fname == None:
            fname, self.title = levels.LEVELS[
                self.game.
                lcur]  #MYNOTE at start lcur of game = 0 !! fname = filename
            fname = data.filepath(os.path.join('levels', fname))
        else:
            self.title = os.path.basename(self.fname)
        self.data = load_level(
            fname)  #load_level of level file to self.data the file is .tga
        #MYNOTE self.data is the rgb value of map
        #print "running level : "+ self.title
        #agentConnect.init(self)

        #self.images = load_images(data.filepath('images'))
        self.images = Level._images
        img = pygame.Surface((1, 1)).convert_alpha()
        img.fill((0, 0, 0, 0))  #MYNOTE create img that is a 1*1 of black
        self.images[None] = img
        for n in xrange(0, len(self._tiles)):
            self.images[n] = self._tiles[n]

        import tiles
        self._images = []
        for m in xrange(0, IROTATE):  #MYNOTE IROTATE = fixed 64
            r = dict(self.images)
            #for n,i,t in tiles.TANIMATE:
            #n2 = n+(m/t)%i
            #r[n] = self.images[n2]
            for n, incs in tiles.TANIMATE:  #MYNOTE TANIMATE = list for animating an obj
                n2 = n + incs[m % len(incs)]
                r[n] = self.images[n2]
            for n1, n2 in tiles.TREPLACE:
                r[n1] = self.images[n2]
            self._images.append(r)

        self.size = len(self.data[0][0]), len(self.data[0])

        self._bkgr_fname = None
        self.set_bkgr('1.png')
        self.bkgr_scroll = pygame.Rect(0, 0, 1, 1)

        self.view = pygame.Rect(0, 0, SW, SH)  #MYNOTE the screen?
        self.bounds = pygame.Rect(0, 0, self.size[0] * TW, self.size[1] * TH)

        self.sprites = []
        self.player = None
        self.frame = 0
        self.codes = {}

        # initialize all the tiles ...
        self.layer = [[None for x in xrange(0, self.size[0])]
                      for y in xrange(0, self.size[1])]

        for y in xrange(0, self.size[1]):
            l = self.data[0][y]  #MYNOTE data of color r
            for x in xrange(0, self.size[0]):
                n = l[x]  #MYNOTE n is a tile in data matrix
                #n1 = self.data[1][y][x]
                #if n1:
                #print 'warning place background tiles in the foreground',x,y,n1
                #if n == 0: n = n1
                if not n: continue
                tiles.t_put(self, (x, y), n)  #MYNOTE put tile into game.layer
        #MYNOTE if comment this the floor will disappear but character is exist

        for y in xrange(0, self.size[1]):
            l = self.data[2][y]  #MYNOTE data of color b
            for x in xrange(0, self.size[0]):
                n = l[x]
                if not n: continue
                codes.c_init(self, (x, y), n)  #init player and boss
        #MYNOTE print(self.layer) may be the tiles in the screen
        #print(self.layer)

        #just do a loop, just to get things all shined up ..
        self.status = None
        #self.loop() this is not real loop wtf
        self.status = '_first'
        self.player.image = None
        self.player.exploded = 30  # time when player appear effect
Пример #2
0
    def init(self):
        #self._tiles = load_tiles(data.filepath('tiles.tga'))
        self._tiles = Level._tiles
        fname = self.fname
        if fname == None:
            fname, self.title = levels.LEVELS[self.game.lcur]
            fname = data.filepath(os.path.join('levels', fname))
        else:
            self.title = os.path.basename(self.fname)
        self.data = load_level(fname)

        #self.images = load_images(data.filepath('images'))
        self.images = Level._images
        img = pygame.Surface((1, 1)).convert_alpha()
        img.fill((0, 0, 0, 0))
        self.images[None] = img
        for n in xrange(0, len(self._tiles)):
            self.images[n] = self._tiles[n]

        import tiles
        self._images = []
        for m in xrange(0, IROTATE):
            r = dict(self.images)
            #for n,i,t in tiles.TANIMATE:
            #n2 = n+(m/t)%i
            #r[n] = self.images[n2]
            for n, incs in tiles.TANIMATE:
                n2 = n + incs[m % len(incs)]
                r[n] = self.images[n2]
            for n1, n2 in tiles.TREPLACE:
                r[n1] = self.images[n2]
            self._images.append(r)

        self.size = len(self.data[0][0]), len(self.data[0])

        self._bkgr_fname = None
        self.set_bkgr('1.png')
        self.bkgr_scroll = pygame.Rect(0, 0, 1, 1)

        self.view = pygame.Rect(0, 0, SW, SH)
        self.bounds = pygame.Rect(0, 0, self.size[0] * TW, self.size[1] * TH)

        self.sprites = []
        self.player = None
        self.frame = 0
        self.codes = {}

        # initialize all the tiles ...
        self.layer = [[None for x in xrange(0, self.size[0])]
                      for y in xrange(0, self.size[1])]

        for y in xrange(0, self.size[1]):
            l = self.data[0][y]
            for x in xrange(0, self.size[0]):
                n = l[x]
                #n1 = self.data[1][y][x]
                #if n1:
                #print 'warning place background tiles in the foreground',x,y,n1
                #if n == 0: n = n1
                if not n: continue
                tiles.t_put(self, (x, y), n)

        for y in xrange(0, self.size[1]):
            l = self.data[2][y]
            for x in xrange(0, self.size[0]):
                n = l[x]
                if not n: continue
                codes.c_init(self, (x, y), n)

        #just do a loop, just to get things all shined up ..
        self.status = None
        self.loop()
        self.status = '_first'
        self.player.image = None
        self.player.exploded = 30
Пример #3
0
 def init(self):
     #self._tiles = load_tiles(data.filepath('tiles.tga'))
     self._tiles = Level._tiles
     fname = self.fname
     if fname == None:
         fname,self.title = levels.LEVELS[self.game.lcur]
         fname = data.filepath(os.path.join('levels',fname))
     else:
         self.title = os.path.basename(self.fname)
     self.data = load_level(fname)
     
     #self.images = load_images(data.filepath('images'))
     self.images = Level._images
     img = pygame.Surface((1,1)).convert_alpha()
     img.fill((0,0,0,0))
     self.images[None] = img
     for n in xrange(0,len(self._tiles)): self.images[n] = self._tiles[n]
     
     import tiles
     self._images = []
     for m in xrange(0,IROTATE):
         r = dict(self.images)
         #for n,i,t in tiles.TANIMATE:
             #n2 = n+(m/t)%i
             #r[n] = self.images[n2]
         for n,incs in tiles.TANIMATE:
             n2 = n+incs[m%len(incs)]
             r[n] = self.images[n2]
         for n1,n2 in tiles.TREPLACE:
             r[n1] = self.images[n2]
         self._images.append(r)
     
     self.size = len(self.data[0][0]),len(self.data[0])
     
     self._bkgr_fname = None
     self.set_bkgr('1.png')
     self.bkgr_scroll = pygame.Rect(0,0,1,1)
     
     self.view = pygame.Rect(0,0,SW,SH)
     self.bounds = pygame.Rect(0,0,self.size[0]*TW,self.size[1]*TH)
     
     self.sprites = []
     self.player = None
     self.frame = 0
     self.codes = {}
     
     # initialize all the tiles ...
     self.layer = [[None for x in xrange(0,self.size[0])] for y in xrange(0,self.size[1])]
      
     for y in xrange(0,self.size[1]):
         l = self.data[0][y]
         for x in xrange(0,self.size[0]):
             n = l[x]
             #n1 = self.data[1][y][x]
             #if n1:
                 #print 'warning place background tiles in the foreground',x,y,n1
                 #if n == 0: n = n1
             if not n: continue
             tiles.t_put(self,(x,y),n)
     
     for y in xrange(0,self.size[1]):
         l = self.data[2][y]
         for x in xrange(0,self.size[0]):
             n = l[x]
             if not n: continue
             codes.c_init(self,(x,y),n)
             
     #just do a loop, just to get things all shined up ..
     self.status = None
     self.loop()
     self.status = '_first'
     self.player.image = None
     self.player.exploded = 30
Пример #4
0
    def init(self):
        self._tiles = Level._tiles
        fname = self.fname
        if fname is None:
            fname, self.title = levels.LEVELS[self.game.lcur]
            fname = data.filepath(os.path.join('levels', fname))
        else:
            self.title = os.path.basename(self.fname)
        fg, bg, codes_data = load_level(fname)

        self.images = Level._images
        self.images[None] = pygame.Surface((1, 1), pygame.SRCALPHA)

        import tiles
        self.tile_animation = []
        for m in xrange(IROTATE):
            r = list(self._tiles)
            for n, incs in tiles.TANIMATE:
                n2 = n + incs[m % len(incs)]
                r[n] = self._tiles[n2]
            for n1, n2 in tiles.TREPLACE:
                r[n1] = self._tiles[n2]
            self.tile_animation.append(r)

        self.size = len(bg[0]), len(bg)

        self._bkgr_fname = None
        self.set_bkgr('1.png')
        self.bkgr_scroll = pygame.Rect(0, 0, 1, 1)

        self.view = pygame.Rect(0, 0, SW, SH)
        self.bounds = pygame.Rect(0, 0, self.size[0] * TW, self.size[1] * TH)

        self.sprites = []
        self.player = None
        self.frame = 0
        self.codes = {}
        self.codes_data = codes_data

        # initialize all the tiles ...
        self.layer = [[None] * self.size[0] for y in xrange(self.size[1])]
        self.drawfg = [[0] * self.size[0] for y in xrange(self.size[1])]

        # Create a surface containing solely the immutable background.
        # Part of this surface is drawn onto the screen using one blit call,
        # followed by the mutable tiles, drawn using one blit call per tile.
        # See tiles.TIMMUTABLE for the full definition of 'immutable'.
        self.bg2 = pygame.Surface((self.size[0] * TW, self.size[1] * TH),
                                  pygame.SRCALPHA)
        rw, rh = xrange(self.size[0]), xrange(self.size[1])
        for y in rh:
            fg_row, bg_row, codes_row = fg[y], bg[y], codes_data[y]
            for x in rw:
                fg_tile, bg_tile, codes_tile = fg_row[x], bg_row[x], codes_row[
                    x]
                if bg_tile != 0:
                    self.bg2.blit(self._tiles[bg_tile], (x * TW, y * TH))
                if fg_tile != 0:
                    tiles.t_put(self, (x, y), fg_tile)
                    if fg_tile in tiles.TIMMUTABLE:
                        self.bg2.blit(self._tiles[fg_tile], (x * TW, y * TH))
                        self.drawfg[y][x] = 0
                if codes_tile != 0:
                    codes.c_init(self, (x, y), codes_tile)

        # just do a loop, just to get things all shined up ..
        self.status = None
        self.loop()
        self.status = '_first'
        self.player.image = None
        self.player.exploded = 30