本文整理汇总了Python中spritesheet.spritesheet函数的典型用法代码示例。如果您正苦于以下问题:Python spritesheet函数的具体用法?Python spritesheet怎么用?Python spritesheet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spritesheet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_resources
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)
示例2: __init__
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
示例3: makeSmallMon
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
示例4: load_from_files
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)
示例5: __init__
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
示例6: __init__
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')
示例7: main
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()
示例8: add
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)]
示例9: button
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)
示例10: __init__
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
示例11: get_images
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)]
}
示例12: __init__
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()
示例13: loadTiles
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]
示例14: __int__
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
示例15: connectionMade
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)