本文整理汇总了Python中spritesheet.spritesheet函数的典型用法代码示例。如果您正苦于以下问题:Python spritesheet函数的具体用法?Python spritesheet怎么用?Python spritesheet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spritesheet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:king1600,项目名称:CanYouLive,代码行数:30,代码来源:main.py
示例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
开发者ID:flyingthing,项目名称:PyBerzerk,代码行数:33,代码来源:otto.py
示例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
开发者ID:cgibbs,项目名称:DerivativeFantasy,代码行数:25,代码来源:monsters.py
示例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)
开发者ID:alexkarpandrus,项目名称:clonermon,代码行数:35,代码来源:tile.py
示例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
开发者ID:nchen24,项目名称:superninjaboy,代码行数:34,代码来源:Player_n.py
示例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')
开发者ID:flyingthing,项目名称:PyBerzerk,代码行数:29,代码来源:bullet.py
示例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()
开发者ID:rszalski,项目名称:pygame-ricerocks-clone,代码行数:58,代码来源:main.py
示例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)]
开发者ID:johnfn,项目名称:ld22,代码行数:9,代码来源:main.py
示例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)
开发者ID:MichaelHaendler,项目名称:python_video_game1,代码行数:10,代码来源:item2.py
示例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
开发者ID:pepebecker,项目名称:python-game,代码行数:11,代码来源:player.py
示例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)]
}
开发者ID:StickOnGit,项目名称:space-frunks,代码行数:11,代码来源:levelscene.py
示例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()
开发者ID:neocortex,项目名称:space-cruise,代码行数:11,代码来源:entities.py
示例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]
开发者ID:derektumolo,项目名称:Apoc,代码行数:12,代码来源:maps.py
示例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
开发者ID:silvaDominic,项目名称:Asteroids-2.0,代码行数:52,代码来源:sprite_strip_animation.py
示例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)
开发者ID:jdumford,项目名称:cse30332FinalProject,代码行数:22,代码来源:player2.py
示例16: spritemaker
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))
开发者ID:higurekon,项目名称:GameProject,代码行数:14,代码来源:test_main3.py
示例17: __init__
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
开发者ID:derektumolo,项目名称:Apoc,代码行数:14,代码来源:units.py
示例18: load_image
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
开发者ID:IrwinKwan,项目名称:ld27_tsts,代码行数:14,代码来源:asset.py
示例19: __init__
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
开发者ID:ahoover64,项目名称:Ethilidia,代码行数:15,代码来源:animationsprite.py
示例20: __init__
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
开发者ID:MichaelHaendler,项目名称:python_video_game1,代码行数:48,代码来源:SingleTri.py
注:本文中的spritesheet.spritesheet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论