Exemplo n.º 1
0
	def __init__(self):
		self.runL = []
		self.runR = []
		self.jumpL = None
		self.jumpR = None
		self.duck = None
		self.stop = None
		self.idle = None
		self.flagPole = []
		self.runf = []
		self.jumpf = None
		self.duckf = None
		self.stopf = None
		self.idlef = None
		self.flagPolef = []
		self.runs = []
		self.jumps = None
		self.ducks = None
		self.stops = None
		self.idles = None
		self.flagPoles = []
		self.debris = None
		self.mario = spritesheet.spritesheet("images/characters.gif")
		self.objects = spritesheet.spritesheet("images/tiles.png")
		self.objects1 = spritesheet.spritesheet("images/blocks1.png")
		self.cutImage()
Exemplo n.º 2
0
    def create_resources(self):
        # set image paths
        self.bg_path = os.path.join("images","background.jpg")
        self.dragon_path = os.path.join("images","dragon_red.png")
        self.fire_path = os.path.join("images","fire.png")

        # transparent color for sprite sheets
        ckey = colors.BLACK

        # create dragon frames from sprite sheet
        ss = spritesheet( self.dragon_path )
        self.dragon_frames = []
        self.dragon_frames.append(ss.image_at((0, 160, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((280, 160, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((590, 140, 280, 260),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((880, 180, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((1160, 180, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((1440, 180, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((1760, 180, 280, 240),colorkey=ckey))
        self.dragon_frames.append(ss.image_at((2050, 180, 280, 240),colorkey=ckey))
        self.dragon_frames_flipped = self.generate_flipped_frames(self.dragon_frames)

        # create fire frames from sprite sheet
        ss = spritesheet( self.fire_path )
        self.fire_frames = []
        self.fire_frames.append(ss.image_at((130, 0, 75, 45),colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 45, 75, 45),colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 90, 75, 45),colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 130, 75, 45),colorkey=ckey))
        self.fire_frames_flipped = self.generate_flipped_frames(self.fire_frames)
Exemplo n.º 3
0
    def __init__(self):
        Ss = spritesheet.spritesheet('images/SS.bmp')
        Sss = spritesheet.spritesheet('images/laz.png')

        self.a1 = []
        self.a1.append(Ss.image_at((0, 0, 32, 32)))
        self.a1.append(Ss.image_at((0, 32, 32, 32)))
        self.a2 = []
        self.a2.append(Ss.image_at((0, 32 * 2, 32, 32)))
        self.a2.append(Ss.image_at((0, 32 * 3, 32, 32)))
        self.a3 = []
        self.a3.append(Ss.image_at((0, 32 * 4, 32, 32)))
        self.a3.append(Ss.image_at((0, 32 * 5, 32, 32)))
        self.a4 = []
        self.a4.append(Ss.image_at((0, 32 * 6, 32, 32)))
        self.a4.append(Ss.image_at((0, 32 * 7, 32, 32)))
        self.s1 = []
        self.s1.append(Ss.image_at((0, 32 * 19, 32, 32)))
        self.s1.append(Ss.image_at((0, 32 * 20, 32, 32)))
        self.E1 = []
        self.E1.append(Ss.image_at((0, 32 * 14, 32, 32)))
        self.E1.append(Ss.image_at((0, 32 * 15, 32, 32)))
        self.E1.append(Ss.image_at((0, 32 * 16, 32, 32)))
        self.E1.append(Ss.image_at((0, 32 * 17, 32, 32)))
        self.E1.append(Ss.image_at((0, 32 * 18, 32, 32)))
        self.L1 = []
        self.L1.append(Sss.image_at((0, 0, 32, 32)))
        self.L1.append(Sss.image_at((0, 32, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 2, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 3, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 4, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 5, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 6, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 7, 32, 32)))
        self.L1.append(Sss.image_at((0, 32 * 8, 32, 32)))
Exemplo n.º 4
0
    def connectionMade(self):
        """initialize game, screen, sheets to be displayed, image lists, and callLater function"""
        pygame.init()
        self.screen = pygame.display.set_mode(
            ((self.img_size + 1) * 10, (self.img_size + 1) * 10))
        watersheet = spritesheet("sprites/water.png")
        self.water = watersheet.image_at(
            (50, 50, self.img_size, self.img_size))
        firesheet = spritesheet("sprites/fire.png")
        self.fire = firesheet.image_at((415, 22, self.img_size, self.img_size))
        misssheet = spritesheet("sprites/miss.png")
        self.miss = misssheet.image_at(
            (455, 182, self.img_size, self.img_size))
        boatsheet = spritesheet("sprites/battleships.png")
        self.battleship = boatsheet.image_at((93, 130, self.img_size, 100))
        self.battleship1 = boatsheet.image_at((93, 130, self.img_size, 100))
        self.battleship2 = boatsheet.image_at((249, 128, self.img_size, 67))
        self.battleship3 = boatsheet.image_at((93, 130, self.img_size, 100))
        self.battleship3 = pygame.transform.rotate(self.battleship3, 90)
        self.battleship4 = boatsheet.image_at((249, 128, self.img_size, 67))
        self.battleship4 = pygame.transform.rotate(self.battleship4, 90)
        self.win_image = pygame.image.load("sprites/win.png").convert()
        self.lose_image = pygame.image.load("sprites/lose.png").convert()

        reactor.callLater(.01, self.tick)
Exemplo n.º 5
0
    def __init__(self): 
        
        self.ObsSheet = spritesheet.spritesheet('sprites/Map/obstacle.png')
        self.IconSheet = spritesheet.spritesheet('sprites/Map/life1.png')
        self.testSheet = spritesheet.spritesheet('sprites/Map/test.png')

        self.IconDict = {}
        self.ObsLst = []
Exemplo n.º 6
0
 def __init__(self):
     self.CharacterSpritesheet = sprite.spritesheet('img/characters.gif',
                                                    16)
     self.TilesSpritesheet = sprite.spritesheet('img/tiles.png', 16)
     #sprites
     self.mario = self.CharacterSpritesheet.image_at((276, 44, 16, 16), 4)
     self.sky = self.TilesSpritesheet.image_at((48, 368, 16, 16), 2)
     self.bricks = self.TilesSpritesheet.image_at((16, 0, 16, 16), 2)
     self.ground = self.TilesSpritesheet.image_at((0, 0, 16, 16), 2)
Exemplo n.º 7
0
    def __init__(self, ai_settings, screen):

        # Movement Flags
        self.movingLeft = False
        self.movingRight = False
        self.movingUp = False
        self.movingDown = False

        self.runningcounter = 0

        self.screen = screen

        # The coordinates within the screen for pacman
        self.x = 4
        self.y = 20

        # The Sprite for Inky
        self.clyde_sprite = spritesheet.spritesheet("img/clyde.png")
        self.blue_sprite = spritesheet.spritesheet("img/blueghost.png")

        self.images = self.clyde_sprite.images_at([(0, 0, 24, 24),
                                                   (0, 24, 24, 24),
                                                   (0, 48, 24, 24),
                                                   (0, 72, 24, 24),
                                                   (0, 96, 24, 24),
                                                   (0, 120, 24, 24),
                                                   (0, 144, 24, 24),
                                                   (0, 168, 24, 24)],
                                                  colorkey=(0, 0, 0))

        self.blue_images = self.blue_sprite.images_at([(0, 0, 24, 24),
                                                       (0, 24, 24, 24),
                                                       (0, 48, 24, 24),
                                                       (0, 72, 24, 24),
                                                       (0, 96, 24, 24),
                                                       (0, 120, 24, 24),
                                                       (0, 144, 24, 24),
                                                       (0, 168, 24, 24)],
                                                      colorkey=(0, 0, 0))

        self.image = self.images[0]
        self.rect = self.image.get_rect()

        # ai mode options are "chasing", "running", and "returning"
        self.turnedaround = False

        # Initialize frame counter
        self.framecounter = 0
        self.image_index = 0
        self.framelimit = 5

        self.rect.x = self.x * 32 + 4
        self.rect.y = self.y * 32 + 4

        self.screen_rect = screen.get_rect()
        self.center = (self.rect.centerx, self.rect.centery)
Exemplo n.º 8
0
    def set_images(self):
        os.chdir(os.path.dirname(sys.argv[0]))
        self.player_imgs = spritesheet.make_sprite_array(
            spritesheet.spritesheet('../../../img/cats.png'), 5, 25, 25)
        self.goal_imgs = spritesheet.make_sprite_array(
            spritesheet.spritesheet('../../../img/mouse.png'), 1, 25, 25)
        self.wall_imgs = spritesheet.make_sprite_array(
            spritesheet.spritesheet('../../../img/wall.png'), 1, 25, 25)

        for p in self.players:
            p.img = self.player_imgs[p.team - 1]
        for g in self.goals:
            g.img = self.goal_imgs[0]
        for w in self.walls:
            w.img = self.wall_imgs[0]
Exemplo n.º 9
0
    def __init__(self, path):
        self.sheet = spritesheet.spritesheet('tiles-color.png')
        size = tuple(v * conf.SCALE for v in self.sheet.sheet.get_size())
        self.sheet.sheet = pygame.transform.scale(self.sheet.sheet, size)

        self.empty_tile = pygame.Surface((conf.TILE_SIZE, conf.TILE_SIZE))
        self.empty_tile.fill(pygame.Color('black'))
Exemplo n.º 10
0
    def __init__(self,
                 robot,
                 cbExplode,
                 filename,
                 rect,
                 count,
                 colorkey=BLACK,
                 scale=2):
        super(RobotExplode, self).__init__(cbExplode)
        ss = spritesheet.spritesheet(filename)
        self.images = ss.load_strip(rect, count, colorkey)
        self.frame = 10

        for i in range(count):
            image = self.images[i]
            image.set_colorkey(colorkey)  #black is transparent
            w, h = image.get_size()
            cropped_image = image.subsurface(0, 0, w, h)
            scale_image = pygame.transform.scale(cropped_image,
                                                 (scale * w, scale * h))
            self.images[i] = scale_image

        self.rect = self.images[0].get_rect()
        self.rect.x = robot.rect.x
        self.rect.y = robot.rect.y
        self.setcolor(robot.color)

        self.addpattern("explode", [0, 1, 2])
        self.setpattern("explode")
        Robot.grp.add(self)
Exemplo n.º 11
0
    def __init__(self, screen, x, y):
        self.image = self.load_image(IDLE1)
        self.screen = screen
        self.x = x
        self.y = y
        self.dx = 0
        self.dy = 0
        self.ddx = 0.1
        self.ddy = 0
        self.dx_max = 0.8
        self.dy_max = 0.8
        self.image_w, self.image_h = self.image.get_size()
        self.ss = spritesheet.spritesheet("../assets/sprite_sheet_colors_fixed.png")

        self.rect = self.image.get_rect()
        self.rect.move(self.x, self.y)
        self.rect.topleft = (self.x, self.y)
        self.rect.bottomright = (self.x + self.image_w, self.y + self.image_h)

        self.bottom = pygame.Rect((self.x, (self.y + self.image_h - 5)), (self.image_w, 5))

        # pygame.Rect takes ((start_x, start_y), (width, height))[EXPERIMENTAL]
        self.boundwidth = 5
        self.left = pygame.Rect((self.x, self.y), (self.boundwidth, self.image_h))
        self.right = pygame.Rect((self.x + self.image_w - self.boundwidth, self.y), (self.boundwidth, self.image_h))

        self.alive = True
        self.jumped = False
        self.apex = False  # True if the player has reached the max jump height
        self.jumptimer = 0
        self.direction = "Right"
        self.movetimer = 0
        self.runtimer = 0
        self.onplat = False
Exemplo n.º 12
0
 def loadTileSheet(self, spriteSheetPath, tileHeight, tileWidth):
     self.tileHeight = tileHeight
     self.tileWidth =  tileWidth
     self.newLevel.tileHeight = tileHeight
     self.newLevel.tileWidth = tileWidth
     self.sheet = spritesheet(spriteSheetPath, tileHeight, tileWidth)
     self.tiles = self.sheet.get_tiles()
Exemplo n.º 13
0
    def __init__(self, ai_settings, screen):
        """Initialize the ship and set its starting position."""
        super(Ship, self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # Get ship from sprite sheet and load its image and rect.
        self.ss = spritesheet.spritesheet('images/ship_pixelsheet.png')
        self.ship_image = self.ss.image_at((0, 0, 52, 40), -1)
        # self.ship_images = []
        self.image = self.ship_image
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        self.gf = gf
        # Load the ship image and get its rect.
        # self.image = pygame.image.load('images/ship.bmp')
        # self.rect = self.image.get_rect()

        # Start each new ship at the bottom center of the screen.
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

        # Store a decimal value for the ship's center
        self.center = float(self.rect.centerx)

        # Movement flags
        self.moving_right = False
        self.moving_left = False
Exemplo n.º 14
0
  def load_from_files(self, tileset_name, tilesize):
    import tile
    ss = spritesheet(tileset_name + ".png", tilesize)
    types = None
    names = None
    with open(tileset_name + ".types", 'r') as types_f:
      types = types_f.readlines()
    with open(tileset_name + ".names", 'r') as names_f:
      names = names_f.readlines()

    if types is None:
      raise ValueError("Could not open types definition, {0}.types".format(tileset_name))

    for x, rows in enumerate(izip_longest(types, names)):
      type_row, name_row = rows
      type_row_tmp = type_row.strip().split(',')
      type_row = []
      for i in type_row_tmp:
        typ, sep, num = i.partition("*")
        if sep != "":
          for n in xrange(int(num)):
            type_row.append(getattr(tile, typ.strip()))
        else:
          type_row.append(getattr(tile, typ.strip()))
  
      if name_row is not None:
        name_row = name_row.strip().split(',')
      else:
        name_row = []
      for y, cols in enumerate(izip_longest(type_row, name_row)):
        type_col, name_col = cols
        typ = type_col(ss.image_pos((y, x)))
        self.tiles[x][y] = typ
        if name_col is not None:
          self.aliases[name_col.strip()] = (x, y)
Exemplo n.º 15
0
Arquivo: Index.py Projeto: Nando96/pac
    def __init__(self):
        ss = spritesheet.spritesheet('img/Pac.png')

        self.pacR = []
        self.pacR.append(ss.image_at((0, 0, 32, 32)))
        self.pacR.append(ss.image_at((0, 32, 32, 32)))
        self.pacR.append(ss.image_at((0, 32 * 2, 32, 32)))
        self.pacR.append(ss.image_at((0, 32 * 3, 32, 32)))
        self.pacU = []
        self.pacU.append(ss.image_at((0, 32 * 4, 32, 32)))
        self.pacU.append(ss.image_at((0, 32 * 5, 32, 32)))
        self.pacU.append(ss.image_at((0, 32 * 6, 32, 32)))
        self.pacU.append(ss.image_at((0, 32 * 7, 32, 32)))
        self.pacL = []
        self.pacL.append(ss.image_at((0, 32 * 19, 32, 32)))
        self.pacL.append(ss.image_at((0, 32 * 20, 32, 32)))
        self.pacL.append(ss.image_at((0, 32 * 14, 32, 32)))
        self.pacL.append(ss.image_at((0, 32 * 15, 32, 32)))
        self.pacD = []
        self.pacD.append(ss.image_at((0, 32 * 16, 32, 32)))
        self.pacD.append(ss.image_at((0, 32 * 17, 32, 32)))
        self.pacD.append(ss.image_at((0, 32 * 18, 32, 32)))
        self.pacD.append(ss.image_at((0, 32 * 19, 32, 32)))
        self.dead = []
        self.dead.append(ss.image_at((0, 32 * 20, 32, 32)))
        self.dead.append(ss.image_at((0, 32 * 21, 32, 32)))
        self.dead.append(ss.image_at((0, 32 * 22, 32, 32)))
        self.dead.append(ss.image_at((0, 32 * 23, 32, 32)))
        self.dead.append(ss.image_at((0, 32 * 24, 32, 32)))
        self.dead.append(ss.image_at((0, 32 * 25, 32, 32)))
Exemplo n.º 16
0
    def __init__(self, color, player, filename, rect, count, colorkey=BLACK, scale=2):
        super(Otto ,self).__init__(self.ottocb)
        ss = spritesheet.spritesheet(filename)
        self.images =  ss.load_strip(rect, count, colorkey)
        self.frame = 15
        self.moveTime = 400
        self.timer = pygame.time.get_ticks()

        self.setcolor(color)

        for i in range(count):
            image = self.images[i]
            w,h = image.get_size()
            cropped_image = image.subsurface(0, 0, w, h)
            scale_image = pygame.transform.scale(cropped_image,(scale*w, scale*h))
            self.images[i] = scale_image

        self.rect = self.images[0].get_rect()

        # otto starts at player start position
        self.rect.x = player.start_x
        self.rect.y = player.start_y


        self.addpattern("spawn",[0,1,3,4])
        self.addpattern("otto", [4])
        self.setpattern("spawn")

        self.player = player

        self.step = 0
        self.dir = 2
        self.y = self.rect.y
Exemplo n.º 17
0
def makeSmallMon(name, mType, level=1):
	if mType == "imp":
		mType = 0
	elif mType == "skeleton":
		mType = 1
	elif mType == "wolf":
		mType = 2
	elif mType == "snake":
		mType = 3
	elif mType == "mudman":
		mType = 4
	elif mType == "scorpion":
		mType = 5
	elif mType == "madpriest":
		mType = 6
	else:
		print "not valid"
		mType = 0

	# TODO: make level stuff work here
	monFighter = fighter.Fighter(10,4,4,(1,6),2,0)
	monAI = ai.BasicMonster()
	mon = baseObject.Object(name, spritesheet.spritesheet("monsters.png").load_strip((70 * mType,0,70,70), 1, (195,195,195)),fighter=monFighter, ai=monAI)
	# do any other monster stuff here
	return mon
Exemplo n.º 18
0
 def __init__(self, start:tuple):
     self.x = start[0]
     self.y = start[1]
     ss = spritesheet.spritesheet('PacMan Sprite Sheet.png')
     screen = pygame.display.set_mode((600,400), 0, 32)
     maze = open(mazeFile, "r")
     images = []
Exemplo n.º 19
0
 def __init__(self,
              filename,
              rect,
              count,
              colorkey=None,
              loop=False,
              frames=1):
     """construct a SpriteStripAnim
     
     filename, rect, count, and colorkey are the same arguments used
     by spritesheet.load_strip.
     
     loop is a boolean that, when True, causes the next() method to
     loop. If False, the terminal case raises StopIteration.
     
     frames is the number of ticks to return the same image before
     the iterator advances to the next image.
     """
     self.filename = filename
     ss = spritesheet.spritesheet(filename)
     self.images = ss.load_strip(rect, count, colorkey)
     self.i = 0
     self.loop = loop
     self.frames = frames
     self.f = frames
Exemplo n.º 20
0
    def __init__(self, life, filename, rect, color, colorkey=BLACK, scale=3):
        super(Lives, self).__init__()
        ss = spritesheet.spritesheet(filename)
        image = ss.image_at(rect)
        image.set_colorkey(colorkey)
        w, h = image.get_size()
        cropped_image = image.subsurface(0, 0, w, h)
        scale_image = pygame.transform.scale(cropped_image,
                                             (scale * w, scale * h))
        self.image = scale_image
        self.rect = self.image.get_rect()
        self.life = life

        self.rect.x = SCREEN_WIDTH / 4 + self.rect.width * {
            3: 1,
            4: 2,
            5: 3,
            6: 4,
            7: 5
        }.get(life, 0)
        self.rect.y = SCREEN_HEIGHT - BORDERTHICKNESS - self.rect.height / 2

        self.color = color
        pixelArray = pygame.PixelArray(self.image)
        pixelArray.replace(WHITE, color)
Exemplo n.º 21
0
    def __init__(self, color, direction, x, y, filename, speed=16, count=1, colorkey=BLACK, scale=2):
        super(Bullet, self).__init__()
        ss = spritesheet.spritesheet(filename)

        IMG_DICT = {"W": (0, 0 ,6, 1), "E": (0, 0, 6, 1), "N": (24, 0, 1, 6), "S": (24, 0, 1, 6),
                    "NE": (16, 0, 6, 6), "SE": (8, 0, 6, 6), "NW": (8, 0, 6, 6), "SW": (16, 0, 6, 6)}

        if direction in IMG_DICT:
            self.images.append(ss.image_at(IMG_DICT[direction]))

        #self.images =  ss.load_strip(rect, count, colorkey)
        self.direction = direction
        self.speed = speed

        image = self.images[0]
        w, h = image.get_size()
        cropped_image = image.subsurface(0, 0, w, h)
        scale_image = pygame.transform.scale(cropped_image, (scale*w, scale*h))
        self.images[0] = scale_image

        self.image = self.images[0]
        self.rect = self.image.get_rect()

        self.setcolor(color)

        self.rect.x = x
        self.rect.y = y
        self.addpattern('bullet', [0])
        self.setpattern('bullet')
Exemplo n.º 22
0
    def __init__(self, name, team, controls):
        super().__init__()
        logger.debug("Creating player.")
        self.name = name
        self.team = team
        self.controls = controls
        self.pos = vector.Vector(self.team.node.pos.x, self.team.node.pos.y)
        self.node = None
        self.node_cooldown = 0
        self.node_pickup = 0
        self.node_ready = True
        self.direction = 0

        tile_size = 32
        offsets = [
            (tile_size * 0, tile_size * 0),
            (tile_size * 3, tile_size * 0),
            (tile_size * 6, tile_size * 0),
            (tile_size * 9, tile_size * 0),
            (tile_size * 0, tile_size * 4),
            (tile_size * 3, tile_size * 4),
            (tile_size * 6, tile_size * 4),
            (tile_size * 9, tile_size * 4),
        ]

        offset = offsets[random.randint(0, len(offsets) - 1)]
        logger.debug(f"offset is {offset}")

        sheet = spritesheet.spritesheet(
            os.path.join('server', 'resources', 'player.png'))
        super().add_sprite("up", sheet,
                           (offset[0] + 0 * tile_size,
                            offset[1] + 3 * tile_size, tile_size, tile_size))
        super().add_sprite("down", sheet,
                           (offset[0] + 0 * tile_size,
                            offset[1] + 0 * tile_size, tile_size, tile_size))
        super().add_sprite("left", sheet,
                           (offset[0] + 0 * tile_size,
                            offset[1] + 1 * tile_size, tile_size, tile_size))
        super().add_sprite("right", sheet,
                           (offset[0] + 0 * tile_size,
                            offset[1] + 2 * tile_size, tile_size, tile_size))
        super().add_sprites("walking_up", sheet,
                            (offset[0] + 0 * tile_size,
                             offset[1] + 3 * tile_size, tile_size, tile_size),
                            3, (tile_size, 0))
        super().add_sprites("walking_down", sheet,
                            (offset[0] + 0 * tile_size,
                             offset[1] + 0 * tile_size, tile_size, tile_size),
                            3, (tile_size, 0))
        super().add_sprites("walking_left", sheet,
                            (offset[0] + 0 * tile_size,
                             offset[1] + 1 * tile_size, tile_size, tile_size),
                            3, (tile_size, 0))
        super().add_sprites("walking_right", sheet,
                            (offset[0] + 0 * tile_size,
                             offset[1] + 2 * tile_size, tile_size, tile_size),
                            3, (tile_size, 0))
        super().set_sprite("down")
Exemplo n.º 23
0
def main():
	# Init pygame
	pygame.init()
	screen = pygame.display.set_mode((WIDTH, HEIGHT))
	pygame.display.set_caption('Rice Rocks')
	
	# Load the graphics
	ship_info = ImageInfo([45, 45], [90, 90], 35)
	ship_sheet = spritesheet.spritesheet('art/double_ship.png')
	ship_images = ship_sheet.images_at(((0, 0, 90, 90),(90, 0, 90,90)), colorkey=(255, 255, 255))

	# Load the sounds
	# Make em global first though
	global ship_thrust_sound
	soundtrack = load_sound('music.ogg')
	missile_sound = load_sound('shoot.wav')
	ship_thrust_sound = load_sound('thrust.wav')
	ship_thrust_sound.set_volume(0.05)
	explosion_sound = load_sound('explode.wav')
	
	# Init the ship and other objects
	my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_images, ship_info)
	
	# Draw the background
	background = load_image('nebula_blue.f2014.png')
	#screen.blit(background, (0,0))
	pygame.display.flip()
	
	# Init game objects
	clock = pygame.time.Clock()

	# Game loop
	while 1:
		clock.tick(60)
		# Event listener
		for event in pygame.event.get():
			if event.type == QUIT:
				return
			# Register key handlers
			if event.type == KEYDOWN and event.key == K_RIGHT:
				my_ship.turn(-5)
			if event.type == KEYDOWN and event.key == K_LEFT:
				my_ship.turn(5)
			if event.type == KEYDOWN and event.key == K_UP:
				my_ship.move(True)
			if event.type == KEYUP and event.key == K_UP:
				my_ship.move(False)
			if event.type == KEYUP and event.key == K_RIGHT:
				my_ship.turn(0)
			if event.type == KEYUP and event.key == K_LEFT:
				my_ship.turn(0)
		# Update everything
		my_ship.update()
		
		# Draw everything
		screen.blit(background, (0,0))
		my_ship.draw(screen)
		pygame.display.flip()
Exemplo n.º 24
0
Arquivo: main.py Projeto: johnfn/ld22
  def add(file_name):
    if file_name in TileSheet.sheets:
      return

    new_sheet = spritesheet.spritesheet(file_name)
    width, height = dimensions = new_sheet.sheet.get_size()
    TileSheet.sheets[file_name] =\
     [[new_sheet.image_at((x, y, TILE_SIZE, TILE_SIZE), colorkey=(255,255,255))\
       for y in range(0, height, TILE_SIZE)] for x in range(0, width, TILE_SIZE)]
Exemplo n.º 25
0
Arquivo: main.py Projeto: johnfn/ld22
    def add(file_name):
        if file_name in TileSheet.sheets:
            return

        new_sheet = spritesheet.spritesheet(file_name)
        width, height = dimensions = new_sheet.sheet.get_size()
        TileSheet.sheets[file_name] =\
         [[new_sheet.image_at((x, y, TILE_SIZE, TILE_SIZE), colorkey=(255,255,255))\
           for y in range(0, height, TILE_SIZE)] for x in range(0, width, TILE_SIZE)]
Exemplo n.º 26
0
 def LoadSprites(self, Lib):
     omitVal = (7, 103, 51)
     for Name in Lib:
         tup_coor = Lib[Name]
         filename = 'sprites/Luffy/' + Name + '.png'
         sheet = spritesheet.spritesheet(filename)
         tups = ((i[0], i[1], i[2] - i[0], i[3]) for i in tup_coor)
         array = sheet.images_at(tups, colorkey=omitVal)
         self.Database.update({Name: array})
Exemplo n.º 27
0
    def __init__(self, filename, width, height):
        pygame.sprite.Sprite.__init__(self)

        self._position = [0, 0]
        self._spritesheet = spritesheet.spritesheet(filename)
        self._frames = self._spritesheet.load_all((0, 0, width, height),
                                                  ALPHA_COLOUR)

        self._current_frame_index = 0
        self.update_frame()
Exemplo n.º 28
0
	def button(self,filename,string,rect1,rect2,toCoords):
	
		tempSheet = spritesheet.spritesheet(filename)
		
		tempButton = Button()
		tempButton.setString(string)
		tempButton.setOffButton(tempSheet.image_at(rect1))
		tempButton.setOnButton(tempSheet.image_at(rect2))
		tempButton.setCoords(toCoords)
		self.buttons.append(tempButton)
Exemplo n.º 29
0
def main(kard_list):
    print(os.getcwd())
    """ A játék inicializálása és a f˝ociklus futtatása. """
    pygame.init()  # El˝okészíti a pygame modult a használatra.

    # Egy felület és a hozzá tartozó ablak elkészítése.
    # A set_mode (szélesség, magasság) értékpárt vár.
    fo_felulet = pygame.display.set_mode((960, 480))

    playingCards = spritesheet.spritesheet(
        os.path.join(image_path, 'playingCards.png'))

    # Sprite is 16x16 pixels at location 0,0 in the file...
    sor = 0
    oszlop = 0
    kartya_szel = 139
    kartya_mag = 189
    kartya_kep = playingCards.image_at(
        (sor * 140, oszlop * 190, kartya_szel, kartya_mag))
    kartya_kepek = []

    for i in range(6):
        for j in range(10):
            if j > 3:
                if i <= 4:
                    kartya_kepek.append(
                        playingCards.image_at(
                            (i * 140, j * 190, kartya_szel, kartya_mag)))
            else:
                kartya_kepek.append(
                    playingCards.image_at(
                        (i * 140, j * 190, kartya_szel, kartya_mag)))

    del kartya_kepek[-1]

    while True:

        # Billenty˝uzet, egér, joystick, stb. események figyelése.
        esemeny = pygame.event.poll()
        if esemeny.type == pygame.QUIT:  # Rákattintottak az ablakbezárás gombra?
            break  # Kilépés a ciklusból

        # Minden egyes képkockánál teljesen el˝oröl kezdve rajzoljuk újra a képet:
        # El˝oször mindent háttérszínnel töltünk ki.
        fo_felulet.fill((0, 200, 255))

        # Átmásoljuk a képünket a felület (x, y) pontjára.
        for (i, index) in enumerate(kard_list):
            fo_felulet.blit(kartya_kepek[index], ((10 + i * kartya_szel), 50))

        # Most, hogy mindent megrajzoltunk, kirakjuk a képerny˝ore!
        pygame.display.flip()

    pygame.quit()
Exemplo n.º 30
0
 def __init__(self, ship, background):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.img = spritesheet.spritesheet('images/bullet.png').imgat(
         [0, 0, 7, 12], colorkey=-1)
     self.pos_x = ship.pos_x + ship.curr_img.get_rect().centerx - 4
     self.pos_y = ship.pos_y
     self.speed = 10
     self.rect = self.img.get_rect()
     self.sound = pygame.mixer.Sound('sounds/laser.wav')
     self.sound.play()
Exemplo n.º 31
0
	def __init__(self, x, y, size, ssheet_path):
		self.pos = Vector(x, y)
		self.destpos = Vector(x, y)
		self.velocity = Vector(0, 0)
		self.speed = 5
		self.size = size
		self.ssheet = spritesheet.spritesheet(ssheet_path)
		self.set_direction('down')
		self.health = 100
		self.items = []
		self.idle = True
Exemplo n.º 32
0
 def get_images(self):
     Sheet = spritesheet('imgs/sheet.png')
     return {
         'PlayerImg': Sheet.image_at((0, 0, 32, 32), -1),
         'PlayerFiring': Sheet.image_at((32, 0, 32, 32), -1),
         'RedShip': Sheet.image_at((0, 32, 32, 32), -1),
         'GreenShip': Sheet.image_at((0, 64, 32, 32), -1),
         'GoodShot': Sheet.image_at((64, 0, 32, 32), -1),
         'BadShot': Sheet.image_at((64, 32, 32, 32), -1),
         'ExplodeList': [Sheet.image_at((i * 32, 96, 32, 32), -1) for i in (0, 1, 2, 3, 2, 3, 4)]
     }
Exemplo n.º 33
0
 def __init__(self, ship, background):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.img = spritesheet.spritesheet(
         'images/bullet.png').imgat([0, 0, 7, 12], colorkey=-1)
     self.pos_x = ship.pos_x + ship.curr_img.get_rect().centerx - 4
     self.pos_y = ship.pos_y
     self.speed = 10
     self.rect = self.img.get_rect()
     self.sound = pygame.mixer.Sound('sounds/laser.wav')
     self.sound.play()
Exemplo n.º 34
0
    def __init__(self, manager, engine, map_name, entrance_name):
        self._manager = manager
        self.finished = False
        self._engine = engine

        # Load images for UI
        self._ui_spritesheet = spritesheet.spritesheet('ui.png')
        self._ui_images = self._ui_spritesheet.load_all(
            (0, 0, DEFAULT_SPRITE_WIDTH, DEFAULT_SPRITE_HEIGHT), ALPHA_COLOUR)

        # Load the map
        self.load_map(map_name, entrance_name, self._engine.screen.get_size())
Exemplo n.º 35
0
 def __init__(self, background, rect):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.master_img = spritesheet.spritesheet('images/explosion.gif')
     self.sprite_pos = [[64 * x + 1, 64 * y + 1, 64, 64] for y in range(4)
                        for x in range(3)]
     self.imgs = self.master_img.imgsat(self.sprite_pos, colorkey=(0, 0, 0))
     self.img_idx = 0
     self.rect = rect
     self.curr_img = self.imgs[self.img_idx]
     self.sound = pygame.mixer.Sound('sounds/explosion.wav')
     self.sound.play()
Exemplo n.º 36
0
    def __init__(self):  # this gets called when a Bat object is instantiated
        super(Bat, self).__init__()
        ss = spritesheet.spritesheet('assets/bat-ss.png')
        # the frames for the sprite!
        self.frames = ss.load_strip((0, 0, 75, 13), numframes, 0)

        self.idx = 0  # create an idx member variable to reference the frame
        self.incr = 0  # create a variable to pace the sprite animation
        self.frame_period = 200  # set frames to update at this period
        self.image = self.frames[self.idx]
        self.rect = pygame.Rect(
            100, 175, 75, 13)  # defines an area sixe 75x13 at pos (100,175)
Exemplo n.º 37
0
	def loadTiles(self):
		ss = spritesheet.spritesheet('img/tiles.png')
		TileTypesData = [
			("wasteland", ["clean", "salvage", "housing", "factory"], ss.tileImg(4,9)),
			("plains", ["farm", "housing", "factory"], ss.tileImg(1,1)),
			("lake", ["fish", "water"], ss.tileImg(3,7)),
			("forest", ["chop", "hunt"], ss.tileImg(6,1))
		]

		self.bgTile = ss.tileImg(4,9)

		self.TileTypesList = [TileType(name, workAvailKeys, image) for name, workAvailKeys, image in TileTypesData]
Exemplo n.º 38
0
    def set_font_images(self, xy):

        self.tss = spritesheet.spritesheet('text_med_tileset.png')
        self.sss = spritesheet.spritesheet('score_tileset.png')

        self.number_image_list = []
        self.letter_image_dict = {}
        self.point_image_dict = {}

        for number in range(10):
            self.number_image_list.append(
                self.tss.image_at((number * xy, 0, xy, xy),
                                  colorkey=(0, 0, 0)))

        letter_row = 1
        letter_count = 0
        for letter in [chr(x) for x in range(ord('a'), ord('z') + 1)]:
            if letter_count == 10:
                letter_row += 1
                letter_count = 0
            self.letter_image_dict[letter] = self.tss.image_at(
                (letter_count * xy, letter_row * xy, xy, xy),
                colorkey=(0, 0, 0))
            letter_count += 1
        self.letter_image_dict['dash'] = self.tss.image_at(
            (6 * xy, 3 * xy, xy, xy), colorkey=(0, 0, 0))
        self.letter_image_dict['by'] = self.tss.image_at(
            (7 * xy, 3 * xy, xy, xy), colorkey=(0, 0, 0))
        self.letter_image_dict['cop'] = self.tss.image_at(
            (8 * xy, 3 * xy, xy, xy), colorkey=(0, 0, 0))
        self.letter_image_dict['exc'] = self.tss.image_at(
            (9 * xy, 3 * xy, xy, xy), colorkey=(0, 0, 0))

        score_count = 0
        for number in [0, 1, 2, 4, 5, 8]:
            self.point_image_dict[number] = self.sss.image_at(
                (score_count * 4, 0, 4, 8), colorkey=(0, 0, 0))
            score_count += 1
        self.point_image_dict['1UP'] = self.sss.image_at(
            (score_count * 4, 0, 16, 8), colorkey=(0, 0, 0))
Exemplo n.º 39
0
    def create_resources(self):
        # set image paths
        self.bg_path = os.path.join("images", "background.jpg")
        self.dragon_path = os.path.join("images", "dragon_red.png")
        self.fire_path = os.path.join("images", "fire.png")

        # transparent color for sprite sheets
        ckey = colors.BLACK

        # create dragon frames from sprite sheet
        ss = spritesheet(self.dragon_path)
        self.dragon_frames = []
        self.dragon_frames.append(
            ss.image_at((0, 160, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((280, 160, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((590, 140, 280, 260), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((880, 180, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((1160, 180, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((1440, 180, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((1760, 180, 280, 240), colorkey=ckey))
        self.dragon_frames.append(
            ss.image_at((2050, 180, 280, 240), colorkey=ckey))
        self.dragon_frames_flipped = self.generate_flipped_frames(
            self.dragon_frames)

        # create fire frames from sprite sheet
        ss = spritesheet(self.fire_path)
        self.fire_frames = []
        self.fire_frames.append(ss.image_at((130, 0, 75, 45), colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 45, 75, 45), colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 90, 75, 45), colorkey=ckey))
        self.fire_frames.append(ss.image_at((130, 130, 75, 45), colorkey=ckey))
        self.fire_frames_flipped = self.generate_flipped_frames(
            self.fire_frames)
    def __int__(self, filename, rect, count, colorkey=None, loop=False, frames=1):
        """
        Constructor for the sprite strip animation obejct

        Args:
            filename(String): the file being processed
            rect(tuple): the rectangle object represented as a tuple of coordinates
            count(int): the number of images in the strip
            colorkey(tuple): color value ('None' by default)
            loop(boolean): indicates whether strip is iterative
            frames(int):
        """
        self.filename = filename
        ss = spritesheet.spritesheet(filename)
        self.images = ss.load_strip(rect, count, colorkey)
        self.i = 0
        self.loop = loop
        self.frames = frames
        self.f = frames

        def iter(self):
            """
            Resets values of frames and iterator; returns self
            """
            self.i = 0
            self.f = self.frames
            return self

        def next(self):
            """
            Returns an image object for each frame in the sprite strip

            Raises:
                StopIteration
            """
            if self.i >= len(self.images):
                if not self.loop:
                    raise StopIteration
                else:
                    self.i = 0

                image = self.images[self.i]
                self.f -= 1

                if self.f == 0:
                    self.i += 1
                    self.f = self.frames
                return image

        def __add__(self, ss):
            self.images.extend(ss.images)
            return self
Exemplo n.º 41
0
    def __init__(self,
                 color,
                 cbRobot,
                 player,
                 grid,
                 pillars,
                 walls,
                 imagefiles,
                 rect,
                 count,
                 frame=5,
                 colorkey=BLACK,
                 scale=2):
        super(Robot, self).__init__()
        ss = spritesheet.spritesheet(imagefiles['robot'])
        self.images = ss.load_strip(rect, count, colorkey)
        self.frameupdate = self.frame = frame
        self.cbRobot = cbRobot
        self.imagefiles = imagefiles
        self.active = False
        self.pillars = pillars
        self.cellX = 0
        self.cellY = 0
        self.grid = grid

        for i in range(count):
            image = self.images[i]
            image.set_colorkey(colorkey, RLEACCEL)
            w, h = image.get_size()
            cropped_image = image.subsurface(0, 0, w, h)
            scale_image = pygame.transform.scale(cropped_image,
                                                 (scale * w, scale * h))
            self.images[i] = scale_image

        self.setcolor(color)

        self.rect = self.images[0].get_rect()

        self.addpattern("roving_eye", [0, 1, 2, 1, 0, 5, 4, 5])
        self.addpattern("east", [7, 6, 6])
        self.addpattern("south", [0, 8, 0, 9])
        self.addpattern("west", [10, 11, 11])
        self.addpattern("north", [12, 13, 12, 14])
        self.setpattern("roving_eye")

        self.reset(walls, grid)
        self.player = player

        self.timer = pygame.time.get_ticks()
        self.cooldown = 600
        Robot.grp.add(self)
        Robot.robotcnt += 1
Exemplo n.º 42
0
 def __init__(self, location, *groups):
     super(Coin, self).__init__(*groups)
     self.bss = spritesheet.spritesheet('block_tileset.png')
     self.image_list = (self.bss.image_at((48, 16, 16, 16), colorkey=-1),
                        self.bss.image_at((64, 16, 16, 16), colorkey=-1),
                        self.bss.image_at((80, 16, 16, 16), colorkey=-1),
                        self.bss.image_at((96, 16, 16, 16), colorkey=-1))
     self.image = self.image_list[0]
     self.rect = pygame.rect.Rect(location, self.image.get_size())
     self.initial_py = location[1]
     self.initial_px = location[0]
     self.n = 0
     self.point_n = 0
Exemplo n.º 43
0
 def __init__(self, background, rect):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.master_img = spritesheet.spritesheet('images/explosion.gif')
     self.sprite_pos = [[64 * x + 1, 64 * y + 1, 64, 64]
                        for y in range(4) for x in range(3)]
     self.imgs = self.master_img.imgsat(
         self.sprite_pos, colorkey=(0, 0, 0))
     self.img_idx = 0
     self.rect = rect
     self.curr_img = self.imgs[self.img_idx]
     self.sound = pygame.mixer.Sound('sounds/explosion.wav')
     self.sound.play()
Exemplo n.º 44
0
	def connectionMade(self):
		"""initialize game, screen, sheets to be displayed, image lists, and callLater function"""
		pygame.init()
		self.screen = pygame.display.set_mode(((self.img_size+1)*10, (self.img_size+1)*10))
		watersheet = spritesheet("sprites/water.png")
		self.water = watersheet.image_at((50, 50, self.img_size, self.img_size))
		firesheet = spritesheet("sprites/fire.png")
		self.fire = firesheet.image_at((415, 22, self.img_size, self.img_size))
		misssheet = spritesheet("sprites/miss.png")
		self.miss = misssheet.image_at((455, 182, self.img_size, self.img_size))
		boatsheet = spritesheet("sprites/battleships.png")
		self.battleship = boatsheet.image_at((93, 130, self.img_size, 100))
                self.battleship1 = boatsheet.image_at((93, 130, self.img_size, 100))
                self.battleship2 = boatsheet.image_at((249, 128, self.img_size, 67))
                self.battleship3 = boatsheet.image_at((93, 130, self.img_size, 100))
                self.battleship3 = pygame.transform.rotate(self.battleship3, 90)
                self.battleship4 = boatsheet.image_at((249, 128, self.img_size, 67))
                self.battleship4 = pygame.transform.rotate(self.battleship4, 90)
		self.win_image = pygame.image.load("sprites/win.png").convert()
		self.lose_image = pygame.image.load("sprites/lose.png").convert()
		
		reactor.callLater(.01,self.tick)
Exemplo n.º 45
0
def setupDisplay():
    #Create a window of the speicified height and width.
    display = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT),
                                      pygame.FULLSCREEN)
    pygame.display.set_caption('Pac-Man demonstration')
    background1 = pygame.image.load(BACKGROUNDFILE1).convert()
    background2 = pygame.image.load(BACKGROUNDFILE2).convert()

    #Create the spritesheet using the spritesheet class.
    gameSprites = spritesheet.spritesheet("GeneralSprites.png")

    #Create a new font object of the default pygame font, and with the specified font size.
    gamefont = pygame.font.Font(None, FONTSIZE)
    return (display, gamefont, (background1, background2), gameSprites)
Exemplo n.º 46
0
 def __init__(self, background, pos_y=-50):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.master_img = spritesheet.spritesheet('images/enemy2.bmp')
     self.sprite_pos = [[24 * x, 0, 25, 25] for x in range(4)]
     self.imgs = self.master_img.imgsat(self.sprite_pos, colorkey=-1)
     self.imgs = [pygame.transform.scale(x, (30, 30)) for x in self.imgs]
     self.img_idx = 0
     self.curr_img = self.imgs[self.img_idx]
     self.rect = self.curr_img.get_rect()
     self.pos_x = random.randint(
         0, self.background.get_width() - self.rect.width)
     self.pos_y = pos_y
     self.speed = 3 + random.random()
Exemplo n.º 47
0
    def load_image(cls, name, rects, colorkey=None):
        if type(name) is not str:
            raise TypeError

        fullname = Asset.resource_path(os.path.join(Asset.data_dir, name))
        ss = spritesheet.spritesheet(fullname)
        images = None
        try:
            images = ss.images_at(rects, colorkey=colorkey)
        except pygame.error:
            print ('Cannot load image:', fullname)
            raise SystemExit(str(geterror()))

        return images
Exemplo n.º 48
0
 def __init__(self, background):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.fname = 'images/rock%d.png' % random.randint(1, 6)
     self.sprite = spritesheet.spritesheet(self.fname)
     self.size = self.sprite.get_size()
     self.img = pygame.transform.rotate(
         self.sprite.imgat([0, 0, self.size[0], self.size[1]],
                           colorkey=-1), random.randint(0, 360))
     self.pos_x = random.randint(
         0, self.background.get_width() - self.img.get_width())
     self.pos_y = -50
     self.speed = 1 + random.random()
     self.rect = self.img.get_rect()
Exemplo n.º 49
0
 def spritemaker(self,workspace,infile,scale,colorkey,rects,direction,anim):
     spritesheeter = spritesheet.spritesheet(workspace+infile)
     self.sprite_lib[anim+" right"] = []
     self.sprite_lib[anim+" left"] = []
     for rect in rects[anim]:
         sprite = spritesheeter.image_at(rect,colorkey)
         if scale is not None:
             sprite = pygame.transform.scale(sprite,scale)
         if direction == "left":
             flip = "right"
         else:
             flip = "left"
         self.sprite_lib[anim+" "+direction].append(sprite)
         self.sprite_lib[anim+" "+flip].append(pygame.transform.flip(sprite,True,False))
Exemplo n.º 50
0
    def __init__(self, x=0, y=0, name="Smiley"):
        pygame.sprite.Sprite.__init__(self)
        ss = spritesheet.spritesheet("img/asprite.bmp")
        self.image = ss.image_at((0, 0, 32, 32), -1)
        screen = pygame.display.get_surface()
        self.area = screen.get_rect()
        # 		self.speed = 10
        self.owner = []
        self.x = x
        self.y = y
        self.name = name
        self.rect = pygame.Rect(x * 32, y * 32, 32, 32)

        self.selected = False
Exemplo n.º 51
0
    def __init__(self, filename, position, world_dim, size, ssinfo, fps, *groups):

        ''' Initializes the player sprite '''
        ss = spritesheet.spritesheet(filename)
        startx,starty,rows,cols,width,height,bufferwidth,bufferheight = ssinfo
        self.images = []
	self.images = self.spritesheetToImages(ss,startx, starty, rows, cols,width,height,bufferwidth,bufferheight)
        self.image = self.images[0]
        self.originalimage = self.image
        self.image = pygame.transform.scale(self.image, size)
        self.i = 0
        self.maxi = len(self.images)
        self.ticks = fps/self.maxi
        self.ticki = 0
        self.fps = fps
Exemplo n.º 52
0
	def __init__(self,center,pointA,pointB,surfaceRect,imageRect,sideToRemove,filename):
	
		self.filename = filename
		self.imageRect = pygame.Rect(imageRect)
		spriteSheetImage = spritesheet(filename)
		self.image = spriteSheetImage.image_at(imageRect)
		width = 1
		closed = True
		self.tup = (center,pointA,pointB)
		self.colorA = Color("black")
		
		#self.points = [self.transCenter(center),self.transPointA(pointA),self.transPointB(pointB)]
		#self.surfaceRect = pygame.Rect(0,0,surfaceRect.width,surfaceRect.height)
		#print "surfaceRect.width is: ",surfaceRect.width
		#print "surfaceRect.height is: ",surfaceRect.height
		
		#self.surface = pygame.Surface((surfaceRect.width,surfaceRect.height))
		self.surface = pygame.Surface(self.tranSurfaceRect(center,pointA,pointB))
		self.surface.fill(Color("white"))
		self.surfaceRect = self.surface.get_rect()
		
		tempCenter = self.convertPoint(center,pointA,pointB,center)
		tempPointA = self.convertPoint(center,pointA,pointB,pointA)
		tempPointB = self.convertPoint(center,pointA,pointB,pointB)	
		
		valX = self.smallestX(center,pointA,pointB)
		valY = self.smallestY(center,pointA,pointB)
		self.transLocVar = (valX,valY) 
		
		pygame.draw.lines(
		self.surface,
		Color("black"),
		closed,
		[tempCenter,tempPointA,tempPointB],
		width
		)
		
		
		# print "the surface width is: ",self.surface.get_width()
		# print "the surface height is: ",self.surface.get_height()	

		# print "center is: ",tempCenter
		# print "pointA is: ",tempPointA
		# print "pointB is: ",tempPointB
		
		self.makeSheet3()
		#self.removeSide("top") # starts at the top and goes down (0 to height) 
		self.removeSide(sideToRemove) #starts at the bottom (height) and goes to zero 
Exemplo n.º 53
0
def load_images(sheet):
	global image, cursor
	image = []
	ss = spritesheet.spritesheet(sheet)
	
	# cycles through the pixels in the spritesheet. not very
	# good method as I don't check if there is any more pixels, 
	# I just assume that the sheet is 128x128. 
	# Order of for y and for x is important: We want to load the images
	# from row to row (left to right), not column to column (up and down).
	for y in range(0, 128, 16): # cycle through the rows
		for x in range(0, 128, 16): # cycle through tiles in the row 
			image.append(ss.image_at((x, y, 16, 16)))
	
	# Set our custom cursor to an image in the spritesheet
	cursor = pygame.transform.scale(image[2], (16, 16))
Exemplo n.º 54
0
 def loading(self):
     #make spritesheet
     self.ss=spritesheet.spritesheet("sprites/spritesheet.bmp")
     #render the background
     self.background = self.level.render(self.ss)
     self.background.set_colorkey((255, 255, 255))
     pygame.display.set_caption('PixelBuild')
     self.character=self.ss.image_at(pygame.rect.Rect(96,64, 32, 32), colorkey = (255, 255, 255))
     self.carrying = self.ss.image_at(pygame.rect.Rect(0,512, 32, 32), colorkey = (255, 255, 255))
     #Create The Backgound
     self.background.blit(self.character, (400, 300))
     self.screen.blit(self.background, (-100, -100))
     self.clock = pygame.time.Clock()
     pygame.display.flip()
     #ss.image_at(pygame.Rect(32, 96, 32, 32))
     self.monsters=[]
     monsternum=25
     if self.level.monsters=={}:
         for mon in range(monsternum):
             self.monsters.append(Monster(ss.image_at(pygame.rect.Rect(96, 288, 32, 32), colorkey = (255, 255, 255)), 5, [random.randint(10, 1280), random.randint(10, 1280)], level))
         del(mon)
     else:
         for mon in self.level.monsters:
             self.monsters.append(Monster(self.ss.image_at(pygame.rect.Rect(96, 288, 32, 32), colorkey = (255, 255, 255)), 5, [int(self.level.monsters[mon]["x"]), int(self.level.monsters[mon]["y"])], self.level))
         del(mon)
     self.defaultmap=open("default.map", "r").read()
     self.xoffset=0
     self.yoffset=0
     self.selected=""
     self.monsterspeed=7
     self.monsterdirection=random.randint(0,4)
     self.inv=['1', '2', '3', '4', '5', '6','7', '8', '9','0', 'q', 'b', 't', 'i', 'd', 'g', 'tr', 'w', "wf"]
     self.invcount=[100, 100,100, 100,100, 100, 100,100, 100,100, 100,0, 0, 0, 1, 0, 5, 0, 0]
     self.currentselected=1
     self.currentselectednum=self.invcount[self.currentselected-1]
     self.playerx=400
     self.playery=300
     self.chunk=(0,0,0,0)
     pygame.key.set_repeat(1,25)
     self.background = self.level.render(self.ss)
     self.background.set_colorkey((255, 255, 255))
     self.currentbox=pygame.Surface((48, 64))
     self.currentbox.fill((255,255,255))
     self.running=True
     self.dead=False
     self.update()
Exemplo n.º 55
0
	def input(self):
		events = pygame.event.get()
		for e in events:
			if e.type == pygame.QUIT:
				pygame.quit()
			elif e.type == pygame.KEYDOWN:
				# cheat code stuff
				if e.key == self.cheat[self.index]:
					self.index += 1
				else:
					self.index = 0
				if self.index == len(self.cheat):
					print "cheat code activated"
					c.team[0].sprites = spritesheet.spritesheet("FF1.png").load_strip((0,280,70,70), 7, (195,195,195))
					self.index = 0
					self.owner.pop()

				# normal input stuff
				if e.key == pygame.K_UP:
					sounds.cursor_move.play()
					self.cursor_loc -= 1
					if self.cursor_loc < 0:
						self.cursor_loc = len(self.cur_node.children) - 1

				elif e.key == pygame.K_DOWN:
					sounds.cursor_move.play()
					self.cursor_loc += 1
					if self.cursor_loc > len(self.cur_node.children) - 1:
						self.cursor_loc = 0

				elif e.key == pygame.K_RETURN:
#					sounds.cursor_select.play()
					if len(self.cur_node.children[self.cursor_loc].children) > 0: # if has children
						sounds.cursor_select.play()
						self.cur_node = self.cur_node.children[self.cursor_loc]
						self.cursor_loc = 0
					else: 
						#self.cur_node.children[self.cursor_loc].choice() # do choice
						# do stuff to pass information here
						self.pop_pass = self.cur_node.children[self.cursor_loc].choice
						self.owner.pop() # exit menu

				elif e.key == pygame.K_BACKSPACE:
					self.cur_node = self.cur_node.parent
					self.cursor_loc = 0
Exemplo n.º 56
0
 def on_init(self):
     pygame.init()
     self._display_surf = pygame.display.set_mode((287,510), pygame.HWSURFACE)
     pygame.display.set_caption("Annoying Bird 0.5")
     self._running = True
     self.ss = spritesheet.spritesheet("Flappy-Graphics.bmp")
     self.numbers = self.ss.images_at([(276,647,11,13), (276,665,11,13), (276,699,11,13), (276,717,11,13), (276,751,11,13), (276,769,11,13), (276,803,11,13), (276,821,11,13), (276,855,11,13), (276,873,11,13)], colorkey =(255,255,255))
     self.background = self.ss.image_at((0, 0, 287, 510))
     self.score = 0
     self.numberRect = self.numbers[0].get_rect().move(125, 30)
     self.flappy = flappy.flappy(self.ss)
     self.tube = tube.tube(self.ss)
     self.ground = ground.ground(self.ss)
     self.menu = True
     self.title = pygame.image.load("Menu.bmp")
     pygame.mixer.init()
     pygame.mixer.music.load("TOP.ogg") 
     pygame.mixer.music.set_volume(1.0)
Exemplo n.º 57
0
    def __init__(self, life, filename, rect, color, colorkey=BLACK, scale=3):
        super(Lives,self).__init__()
        ss = spritesheet.spritesheet(filename)
        image =  ss.image_at(rect)
        image.set_colorkey(colorkey)
        w,h = image.get_size()
        cropped_image = image.subsurface(0,0,w,h)
        scale_image = pygame.transform.scale(cropped_image,(scale*w,scale*h))
        self.image = scale_image
        self.rect = self.image.get_rect()
        self.life = life

        self.rect.x = SCREEN_WIDTH/4 + self.rect.width*{3:1, 4:2, 5:3, 6:4, 7:5}.get(life,0)
        self.rect.y = SCREEN_HEIGHT - BORDERTHICKNESS - self.rect.height/2

        self.color = color
        pixelArray = pygame.PixelArray(self.image)
        pixelArray.replace(WHITE,color)
Exemplo n.º 58
0
 def __init__(self, filename, rect, count, colorkey=None, loop=False, frames=1):
     """construct a SpriteStripAnim
     
     filename, rect, count, and colorkey are the same arguments used
     by spritesheet.load_strip.
     
     loop is a boolean that, when True, causes the next() method to
     loop. If False, the terminal case raises StopIteration.
     
     frames is the number of ticks to return the same image before
     the iterator advances to the next image.
     """
     self.filename = filename
     ss = spritesheet.spritesheet(filename)
     self.images = ss.load_strip(rect, count, colorkey)
     self.i = 0
     self.loop = loop
     self.frames = frames
     self.f = frames
Exemplo n.º 59
0
 def __init__(self, background):
     pygame.sprite.Sprite.__init__(self)
     self.background = background
     self.master_img = spritesheet.spritesheet('images/spaceship.png')
     self.sprite_pos = [[42 * x, y, 40, 43]
                        for x in range(3) for y in [43, 89]]
     self.sprite_imgs = self.master_img.imgsat(self.sprite_pos, colorkey=-1)
     self.left_imgs = self.sprite_imgs[0:2]
     self.center_imgs = self.sprite_imgs[2:4]
     self.right_imgs = self.sprite_imgs[4:6]
     self.img_idx = 0
     self.curr_img = self.center_imgs[self.img_idx]
     self.pos_x = self.background.get_rect().centerx
     self.pos_y = self.background.get_rect().bottom-50
     self.speed = 10
     self.rect = pygame.Rect(
         self.pos_x, self.pos_y,
         self.curr_img.get_width(),
         self.curr_img.get_height())