def __init__(self, tv, tile_pos, sequence=None, layer='animations'): # Create the first frame if sequence is None: sequence = self.SEQUENCE self.iter = iter(sequence) self.layer = layer Sprite.__init__(self, self.iter.next(), tv.tile_to_view(tile_pos)) tv.sprites.append(self, layer=self.layer)
def __init__(self, image_name, tv, cost=None): self._font = pygame.font.SysFont('Vera', 20, bold=True) image = imagecache.load_image(image_name, ["sprite_cursor"]) if cost is not None: image = self._apply_text(image, str(cost)) # Create the sprite somewhere far off screen Sprite.__init__(self, image, (-1000, -1000)) self._tv = tv
def __init__(self, g): self.image = g.images['inventory'][0].subsurface((4 * 32, 7 * 32, 32, 32)) Sprite.__init__(self, self.image, Rect(0,0,32,32)) self.orginalimage = self.image self.init_position(g) self.rect.x = random.randint(0, g.view.w) + g.view.x self.g = g self.groups = g.string2groups('shot') self.rotateamount = random.randint(-3, 3) self.rotatecounter = 0 g.sprites.append(self) g.removeOnLeave.append(self)
def __init__(self, g, pos, name): # texture for the avatar self.image = pygame.Surface((32,32), SRCALPHA) Sprite.__init__(self, self.image, Rect(0,0,32,32)) # you may want to override this g.removeOnLeave.append(self) self.groups = g.string2groups('shot') self.g = g self.rect.x,self.rect.y = pos[0],pos[1] # meh hack self._rect.x,self._rect.y = self.rect.x,self.rect.y self.startrect = Rect(pos[0], pos[1], 32,32) self.name = name g.sprites.append(self) hitSoundFile = os.path.join("effects", "exp1.wav") self.destryoed = pygame.mixer.Sound(hitSoundFile)
def __init__(self, tile_pos, gameboard): # load images self._image_left = imagecache.load_image(self.IMAGE_FILE) self._image_right = imagecache.load_image(self.IMAGE_FILE, ("right_facing", )) # Create the animal somewhere far off screen Sprite.__init__(self, self._image_left, (-1000, -1000)) self.image_left = self._image_left.copy() self.image_right = self._image_right.copy() if hasattr(tile_pos, 'to_tile_tuple'): self.pos = tile_pos else: self.pos = Position(tile_pos[0], tile_pos[1], 0) self.equipment = [] self.accoutrements = [] self.abode = None self.facing = 'left' self.gameboard = gameboard
def __init__(self, g, t): g.clayer[t.ty][t.tx] = 0 self.rect = Rect(t.rect.x + 16 - g.view.x, t.rect.y - g.view.y, 32, 32) Sprite.__init__(self, g.images["player"], self.rect) self.renderoffset = (-13, 0) # must be called after sprite init g.sprites.append(self) g.removeOnLeave.append(self) self.groups = g.string2groups("player") g.player = self g.infobox = 0 self.orginalImage = self.image hitSoundFile = os.path.join("effects", "hit.wav") self.hitSound = pygame.mixer.Sound(hitSoundFile) hitSoundFile = os.path.join("effects", "ground.wav") self.hitground = pygame.mixer.Sound(hitSoundFile) hitSoundFile = os.path.join("effects", "jump.wav") self.jumpsound = pygame.mixer.Sound(hitSoundFile) if g.loadPosition != None: pop = g.tile_to_screen(g.loadPosition) self.rect.x = pop[0] + g.view.x self.rect.y = pop[1] + g.view.y g.loadPosition = None self.g = g self.health = g.saveData["health"] self.healthmax = g.saveData["healthmax"] self._rect.x, self._rect.y = self.rect.x, self.rect.y self.jumping = 0 self.rect.width = 8 # place the camera on the player if not g.intermission: if self.rect.x > g.view.width: g.view.x = self.rect.x - g.view.width / 2 if self.rect.y > g.view.height: g.view.y = self.rect.y - g.view.height / 2
def __init__(self, pos, gameboard): """Initial image, tile vid position, size and tile number for building.""" self._set_images() self.pos = pos self.gameboard = gameboard self.size = self.SIZE self.tile_no = self.TILE_NO self._buy_price = self.BUY_PRICE self._sell_price = self.SELL_PRICE self._repair_price = getattr(self, 'REPAIR_PRICE', None) self._sun_on = True self._font = pygame.font.SysFont('Vera', 30, bold=True) self._font_image = pygame.Surface( self.images['fixed']['day'].get_size(), flags=SRCALPHA) self._font_image.fill((0, 0, 0, 0)) self._broken = False self._predators = [] self._floors = [] if self.FLOORS: for f, z in enumerate(self.FLOORS): places = [] for j in range(self.size[1]): row = [] for i in range(self.size[0]): row.append(Place(self, (i, j, z))) places.append(row) floor = Floor("Floor %s" % (f + 1, ), places) self._floors.append(floor) # 0: the main image # 1: above, -1: below self.draw_stack = {"main": (0, self.images['fixed']['day'])} # Create the building somewhere far off screen Sprite.__init__(self, self.images['fixed']['day'], (-1000, -1000))
def __init__(self, g, name, pos = (0,0)): spawnonce = 0 # texture for the avatar self.orginalimg = g.images['inventory'][0].subsurface((0, 0, 32, 32)) self.image = self.orginalimg self.extraimg = None if name == 'save': # save self.orginalimg = g.images['inventory'][0].subsurface((4 * 32, 0, 32, 32)) self.image = self.orginalimg self.savetimer = 0 activateSoundFile = os.path.join("effects", "save.wav") self.savesound = pygame.mixer.Sound(activateSoundFile) elif name == 'health': # health one up self.orginalimg = g.images['inventory'][0].subsurface((0, 2*32, 32, 32)) self.image = self.orginalimg # increase Max Health. Many of these. elif name.find('healthincrease', 0) == 0: self.orginalimg = g.images['inventory'][0].subsurface((1*32, 3*32, 32, 32)) self.image = self.orginalimg self.open = 0 self.displaymsg = 0 elif name == 'shot2': # a green shot that comes from birds. -2 self.orginalimg = g.images['inventory'][0].subsurface((2 * 32, 2*32, 32, 32)) self.image = self.orginalimg sprimg = g.images['inventory'][0].subsurface((3 * 32, 2*32, 32, 32)) self.extraimg = Sprite(sprimg, Rect(0,0,32,32)) g.sprites.append(self.extraimg) g.removeOnLeave.append(self.extraimg) self.max_bullet = 3 # max bullets for shot1 elif name == 'shot4': # blue shot from monsters self.orginalimg = g.images['inventory'][0].subsurface((2 * 32, 2*32, 32, 32)) self.image = self.orginalimg sprimg = g.images['inventory'][0].subsurface((5 * 32, 2*32, 32, 32)) self.extraimg = Sprite(sprimg, Rect(0,0,32,32)) g.sprites.append(self.extraimg) g.removeOnLeave.append(self.extraimg) self.max_bullet = 4 # max bullets for shot1 elif name == 'shot7': # eletric shot from monsters self.orginalimg = g.images['inventory'][0].subsurface((2 * 32, 2*32, 32, 32)) self.image = self.orginalimg sprimg = g.images['inventory'][0].subsurface((0, 7*32, 32, 32)) self.extraimg = Sprite(sprimg, Rect(0,0,32,32)) g.sprites.append(self.extraimg) g.removeOnLeave.append(self.extraimg) self.max_bullet = 5 # max bullets for shot1 elif name == 'switch': self.orginalimg = g.images['inventory'][0].subsurface((3*32, 3*32, 32, 32)) self.image = self.orginalimg self.open = 0 self.displaymsg = 0 self.pulled = pygame.mixer.Sound(os.path.join("effects", "switch.wav")) elif name == 'spike': self.orginalimg = g.images['inventory'][0].subsurface((0, 3*32, 32, 32)) self.image = self.orginalimg self.timerloop = 200 self.timer = random.randint(0, self.timerloop) elif name == 'aspike': self.orginalimg = g.images['inventory'][0].subsurface((4*32, 10*32, 32, 32)) self.image = self.orginalimg elif name == 'arms': self.orginalimg = g.images['inventory'][0].subsurface((2*32, 4*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 elif name == 'sprinkler': self.image = g.images['inventory'][0].subsurface((3*32, 4*32, 32, 32)) self.on = 0 self.timer = 0 elif name == 'clonevat': self.orginalimg = pygame.image.load(os.path.join("textures", "clonevats.png")).convert_alpha() elif name == 'plane': self.orginalimg = pygame.image.load(os.path.join("textures", "plane.png")).convert_alpha() elif name == 'flutterbox': self.orginalimg = g.images['inventory'][0].subsurface((7*32, 4*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 elif name == 'flutterswitch': self.orginalimg = g.images['inventory'][0].subsurface((0, 5*32, 32, 32)) self.image = self.orginalimg elif name == 'fish0': self.orginalimg = pygame.image.load(os.path.join("textures", "fish0.png")).convert_alpha() elif name == 'fish1': self.orginalimg = pygame.image.load(os.path.join("textures", "fish1.png")).convert_alpha() elif name == 'skyberry': self.orginalimg = g.images['inventory'][0].subsurface((3*32, 5*32, 8, 8)) self.image = self.orginalimg self.rotate_timer = 0 self.xvel = float(random.randint(-20, 20)) self.rotate_amount = self.xvel / 2 self.gravity = 3.0 self.canget = 1 elif name == 'newspaper': self.gotten = 0 self.orginalimg = g.images['inventory'][0].subsurface((0, 10*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 elif name == 'drawingwater': # (6, 19) ( 192 536 + 64 ) self.orginalimg = g.images['inventory'][0].subsurface((1*32, 10*32, 32, 32)) print 'drawingwater' elif name == 'waterfall': # (6, 19) ( 192 536 + 64 ) self.orginalimg1 = g.images['inventory'][0].subsurface((2*32, 10*32, 32, 32)) self.orginalimg2 = g.images['inventory'][0].subsurface((3*32, 10*32, 32, 32)) elif name == 'coin': self.orginalimg = g.images['inventory'][0].subsurface((6*32, 10*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 elif name == 'jailkey': self.orginalimg = g.images['inventory'][0].subsurface((5*32, 10*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 elif name == 'tape': # imas backup tape self.orginalimg = g.images['inventory'][0].subsurface((7*32, 10*32, 32, 32)) self.image = self.orginalimg spawnonce = 1 Sprite.__init__(self, self.image, Rect(pos[0],pos[1],32,32)) self.rect.x,self.rect.y = pos[0],pos[1] self._rect.x,self._rect.y = self.rect.x,self.rect.y g.sprites.append(self) self.groups = g.string2groups('inventory') self.g = g if name == 'microwave' or spawnonce: # spawn once items if 'i_' + name in g.saveData: g.sprites.remove(self) print 'found i_' + name elif name.find('healthincrease', 0) == 0: # open once if 'i_' + name in g.saveData: self.open = 1 self.name = name g.removeOnLeave.append(self) # small skyberry if name == 'skyberry': self.rect.width,self.rect.height = 8,8
def __init__(self, file, avatar, g, type = None): #load the image tileTexture = os.path.join("textures", file) self.orginalImage = pygame.image.load(tileTexture) self.orginalImage = self.orginalImage.convert_alpha() # texture for the avatar tileTexture = os.path.join("textures", avatar) self.orginalAvatar = pygame.image.load(tileTexture) # fox = 96 x 64 # set the sprite image if type == 'fox': self.image = self.orginalImage.subsurface((0, 0, 96, 64)) self.attacking = 0 self.timer = 0 self.jumping = 0 # ai bull shit self.health = 15 self.jumpvec = 0 self.healthmax = 15 tileTexture = os.path.join("effects", "shoot1.wav") self.hitme = pygame.mixer.Sound(tileTexture) self.teleport = pygame.mixer.Sound(os.path.join("effects", "teleport1.wav")) self.lastframehidden = -1 elif type == 'mushroom': self.secondImage = pygame.image.load(os.path.join("textures", "mushroomhit.png")) self.image = self.orginalImage.subsurface((0, 0, 256, 256)) self.attacking = 0 self.timer = 0 self.jumping = 0 # ai bull shit self.health = 60 self.healthmax = 60 self.dead = 0 tileTexture = os.path.join("effects", "critter5.wav") self.hitme = pygame.mixer.Sound(tileTexture) self.exp2 = pygame.mixer.Sound(os.path.join("effects", "exp2.wav")) self.squirt = pygame.mixer.Sound(os.path.join("effects", "squirt.wav")) self.squirt2 = pygame.mixer.Sound(os.path.join("effects", "squirt2.wav")) elif type == 'doctor': self.squirt = pygame.mixer.Sound(os.path.join("effects", "squirt3.wav")) self.hitme = pygame.mixer.Sound(os.path.join("effects", "cry.wav")) self.attack = pygame.mixer.Sound(os.path.join("effects", "doctor.wav")) self.imagea = pygame.image.load(os.path.join("textures", "monster3a.png")) self.imageb = pygame.image.load(os.path.join("textures", "monster3b.png")) self.imagec = pygame.image.load(os.path.join("textures", "monster3c.png")) self.imaged = pygame.image.load(os.path.join("textures", "monster3d.png")) self.imagee = pygame.image.load(os.path.join("textures", "monster3e.png")) self.imagef = pygame.image.load(os.path.join("textures", "monster3f.png")) self.imageg = pygame.image.load(os.path.join("textures", "monster3g.png")) self.imageh = pygame.image.load(os.path.join("textures", "monster3h.png")) self.imagei = pygame.image.load(os.path.join("textures", "monster3i.png")) self.imagej = pygame.image.load(os.path.join("textures", "monster3j.png")) self.imagek = pygame.image.load(os.path.join("textures", "monster3k.png")) self.imagel = pygame.image.load(os.path.join("textures", "monster3l.png")) self.image = self.orginalImage.subsurface((0, 0, 256, 256)) self.attacking = 0 self.timer = 0 self.jumping = 0 # ai bull shit self.health = 130 # ha oh man that's a nasty fight lol self.healthmax = 130 self.dead = 0 self.dx = 0.0 self.attackright = 0 self.attackleft = 0 self.cache_image = 0 self.spawnedspecialnurse = 0 self.image = pygame.Surface((256, 256), SRCALPHA) self.image.blit(self.imagel, (0,0)) self.image.blit(self.imageg, (0,0)) # normal tracks self.image.blit(self.imagec, (0,0)) self.image.blit(self.imagea, (0,0)) self.image.blit(self.imaged, (0,0)) self.image.blit(self.imageb, (0,0)) elif type == 'robot': self.timer = 0 self.image = self.orginalImage.subsurface((0, 0, 32, 32)) self.health = 100 self.healthmax = 100 elif type == 'backup': self.walktimer = 0 self.dy = 0.0 self.timer = 0 self.image = self.orginalImage.subsurface((0, 0, 32, 32)) self.health = 100 self.healthmax = 100 self.dead = 0 elif type == 'boat': self.image = self.orginalImage.subsurface((0, 0, 64, 32)) else: self.image = self.orginalImage.subsurface((0, 0, 32, 32)) Sprite.__init__(self, self.image, Rect(0,0,32,32)) self.type = type if type == 'fox': self.rect.width = 96 self.rect.height = 64 elif type == 'doctor': self.rect.width = 256 self.rect.height = 256 elif type == 'boat': self.rect.width = 32 self.rect.height = 64 self.dontwalk = 0 g.sprites.append(self) g.removeOnLeave.append(self) self.groups = g.string2groups('character') self.g = g self.direction = 1
def __init__(self, g, name, pos, mymsg = ''): # texture for the avatar self.image = g.images['inventory'][0].subsurface((0, 0, 0, 0)) Sprite.__init__(self, self.image, Rect(0,0,32,32)) self.groups = g.string2groups('shot') self.g = g self.rect.x,self.rect.y = pos[0],pos[1] self._rect.x,self._rect.y = self.rect.x,self.rect.y self.name = name if name == 'explosion': self.keep_alive = 4 elif name == 'shot': g.exp4.play() elif name == 'health': self.healthchange = 0 self.keep_alive = 30 self.rect.x += 5 self.rect.y -= 15 elif name == 'msg': self.keep_alive = 20 self.image = self.g.font.render(mymsg,1,(0,255,0)) self.rect.x += self.image.get_rect().x / 2 self.rect.y -= 15 elif name == 'snow': self.keep_alive = 15 self.image = g.images['inventory'][0].subsurface((1 * 32, 4 * 32, 32, 32)) self.mvrectx = random.randint(-2, 2) self.mvrecty = random.randint(0, 2) elif name == 'water': self.keep_alive = 15 self.image = g.images['inventory'][0].subsurface((4 * 32, 4 * 32, 32, 32)) self.mvrectx = float(random.randint(-4, 4)) / 4 self.mvrecty = float(random.randint(5, 6)) / 3 self.floatx = float(self.rect.x) self.floaty = float(self.rect.y) elif name == 'bubble': self.image = g.images['inventory'][0].subsurface((6 * 32, 4 * 32, 32, 32)) self.keep_alive = 60 self.startx = pos[0] self.timer = random.randint(0, 30) elif name == 'lift': self.image = g.images['inventory'][0].subsurface((2 * 32, 5 * 32, 32, 32)) elif name == 'leaf' or self.name == 'dirt': self.image = g.images['inventory'][0].subsurface((5 * 32, 8 * 32, 32, 32)) self.orginalimage = self.image self.rotationAmount = float(random.randint(-5, 5)) self.vecx = float(random.randint(-2, 2)) self.vecy = float(random.randint(-6, 2)) self.keep_alive = 25 if self.name == 'dirt': self.image = g.images['inventory'][0].subsurface((5 * 32, 7 * 32, 32, 32)) self.orginalimage = self.image elif name == 'foxentrance': Effect(g, 'leaf', pos) Effect(g, 'leaf', pos) Effect(g, 'leaf', pos) Effect(g, 'leaf', pos) Effect(g, 'dirt', pos) Effect(g, 'dirt', pos) Effect(g, 'dirt', pos) Effect(g, 'dirt', pos) self.keep_alive = 0 if name == 'explosion0': self.keep_alive = 7 self.image = g.images['inventory'][0].subsurface((0 * 32, 11 * 32, 32, 32)) g.exp3.play() if name == 'explosion1': self.keep_alive = 4 self.image = g.images['inventory'][0].subsurface((4 * 32, 11 * 32, 32, 32)) g.exp5.play() g.sprites.append(self)
def __init__(self, g, direction, pos, type, owner = 'player'): # texture for the avatar self.orginalimg = g.images['inventory'][0].subsurface((7 * 32, 0, 32, 32)) self.image = g.images['inventory'][0].subsurface((0, 0, 0, 0)) Sprite.__init__(self, self.image, Rect(0,0,8,16)) g.sprites.append(self) g.removeOnLeave.append(self) g.bullets.append(self) self.groups = g.string2groups('player') self.g = g self.direction = direction self.rect.x,self.rect.y = pos[0],pos[1] # meh hack self._rect.x,self._rect.y = self.rect.x,self.rect.y # bullshit hacks. self.type = type self.rect.width = 8 self.rect.height = 8 self.owner = owner if owner == 'player': mkstr = type+'_lvl' if mkstr in g.saveData: if g.saveData[mkstr] > 10: self.level = 1 if g.saveData[mkstr] > 20: self.level = 2 if type == 'shot1': g.shootSound1.play() elif type == 'shot3': # fox spray bullet g.shootSound3.play() self.orginalimg = g.images['inventory'][0].subsurface((5 * 32, 2*32, 32, 32)) self.speed = 15 self.keep_alive = 8 self.damage = 1 self.reload = 10 self.yvel = random.randint(-2, 2) #elif type == 'shot4': # monster shot elif type == 'shot5': # mushroom monster shot (spawns green slime, or explodes) self.orginalimg = g.images['inventory'][0].subsurface((1 * 32, 7*32, 32, 32)) #self.image = self.orginalimg self.speed = 0 self.keep_alive = 200 self.damage = 2 self.rect.height = 10 self.yvel = float(random.randint(-6, 0)) self.xvel = float(random.randint(-4, 4)) self.rebound = self.rebound_spawner elif type == 'shot6': # doctor spawns nurses self.orginalimg = g.images['inventory'][0].subsurface((6 * 32, 6*32, 32, 32)) #self.image = self.orginalimg self.speed = 0 self.keep_alive = 200 self.damage = 2 self.rect.height = 10 self.yvel = float(random.randint(-6, 0)) self.xvel = float(random.randint(-5, 5)) self.rebound = self.rebound_spawner elif type == 'shot7': # an eletrical shot self.orginalimg = g.images['inventory'][0].subsurface((1 * 32, 7*32, 32, 32)) #self.image = self.orginalimg self.speed = 12 self.keep_alive = 18 self.damage = 5 + self.level self.reload = 12 - self.level g.shootSound5.play() elif type == 'shot8': # an eletrical shot self.orginalimg = g.images['inventory'][0].subsurface((7 * 32, 9*32, 32, 32)) #self.image = self.orginalimg self.speed = 13 self.keep_alive = 100 self.damage = 5 + self.level self.reload = 12 - self.level g.shootSound5.play() self.renderoffset = (-16, -20)