class Map(Entity): width = 640 height = 440 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "map.png" sheet = loadImageNoAlpha(sheetFileName) instanceSpecificVars = None notEditable = True collidable = False def __init__(self, group=None, **kwargs): Entity.__init__(self, (80, 80), [0, 0], None, group, pygame.Rect(0, 0, self.width, self.height), animated=False, **kwargs) if Map.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) if Map.instanceSpecificVars is None: Map.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): Entity.update(self, dt)
class Phone(Entity): width = 18 height = 18 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "phone.png" sheet = loadImageNoAlpha(sheetFileName, 2) specialCollision = None scale = 2 instanceSpecificVars = None def __init__(self, pos=[0, 0], vel=[0, 0], group=None, **kwargs): Entity.__init__(self, pos, [0, 0], None, group, pygame.Rect(0, 0, self.width, self.height), animated=False, **kwargs) if Phone.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) if Phone.instanceSpecificVars is None: Phone.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): Entity.update(self, dt)
class Chair(Entity): width = 24 height = 46 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "chair.png" colourKey = pygame.Color(255, 0, 255) sheet = loadImageNoAlpha(sheetFileName, 2) sheet.set_colorkey(colourKey) specialCollision = None collidable = True solid = True mass = 9e9 scale = 2 wbdx = 0 wbdy = 34 wbWidth = 24 wbHeight = 6 instanceSpecificVars = None forceUseRect = True def __init__(self, pos=[0, 0], vel=[0, 0], group=None, **kwargs): Entity.__init__(self, pos, [0, 0], None, group, pygame.Rect(0, 0, self.width, self.height), animated=True, **kwargs) self.animations['left'] = {'fps': 1, 'frames': [3]} self.animations['right'] = {'fps': 1, 'frames': [1]} self.animations['forward'] = {'fps': 1, 'frames': [0]} self.animations['backward'] = {'fps': 1, 'frames': [2]} self.changeAnimation('left') if Chair.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) self.oldTag = 'left' self.tags['direction'] = 'left' if Chair.instanceSpecificVars is None: Chair.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): curTag = self.tags.get('direction') if curTag != self.oldTag and curTag in ('left', 'right', 'forward', 'backward'): self.changeAnimation(curTag) self.oldTag = curTag Entity.update(self, dt)
class Toilet(Entity): width = 16 height = 21 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "toilet.png" colourKey = pygame.Color(255, 0, 255) sheet = loadImageNoAlpha(sheetFileName, 2) sheet.set_colorkey(colourKey) specialCollision = None collidable = False scale = 2 instanceSpecificVars = None frameRects = [ pygame.Rect(0, 0, 32, 42), pygame.Rect(32, 0, 32, 42), pygame.Rect(64, 0, 22, 42), pygame.Rect(86, 0, 22, 42) ] def __init__(self, pos=[0, 0], vel=[0, 0], group=None, **kwargs): Entity.__init__(self, pos, [0, 0], None, group, pygame.Rect(0, 0, self.width, self.height), animated=True, **kwargs) self.animations['left'] = {'fps': 1, 'frames': [0]} self.animations['right'] = {'fps': 1, 'frames': [1]} self.animations['forward'] = {'fps': 1, 'frames': [3]} self.animations['backward'] = {'fps': 1, 'frames': [4]} self.changeAnimation('left') if Toilet.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) self.oldTag = 'left' self.tags['direction'] = 'left' if Toilet.instanceSpecificVars is None: Toilet.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): curTag = self.tags.get('direction') if curTag != self.oldTag and curTag in ('left', 'right', 'forward', 'backward'): self.changeAnimation(curTag) self.oldTag = curTag Entity.update(self, dt)
def makeUnpicklable( self, playState ): if self.alpha: self.sheet = loadImage( self.sheetFileName, self.scale ) else: self.sheet = loadImageNoAlpha( self.sheetFileName, self.scale ) if self.colourKey is not None: self.colourKey = pygame.Color( self.colourKey[0], self.colourKey[1], self.colourKey[2] ) self.sheet.set_colorkey( self.colourKey ) self.rect = pygame.Rect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] ) self.createFrames() self.image = self.frames[ self.curAnimation['frames'][self.frame] ] self.playStateRef = weakref.ref( playState )
class City( Entity ): width = 20 height = 20 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "city.png" sheet = loadImageNoAlpha( sheetFileName ) colourKey = pygame.Color(255, 0, 255) sheet.set_colorkey(colourKey) instanceSpecificVars = None notEditable = True collidable = True solid = False specialCollision = queueCollideWithCity def __init__( self, pos, group=None, **kwargs ): Entity.__init__( self, pos, [0,0], None, group, pygame.Rect( 0, 0, self.width, self.height ), animated=True, **kwargs ) self.animations["online"] = { 'fps':1, 'frames':[0] } self.animations["offline"] = { 'fps':1, 'frames':[1] } self.destructionSound = group.playState.soundManager.getSound( "destruction.wav" ) self.explosionSound = group.playState.soundManager.getSound( "explosion.wav" ) #self.explosionSound.set_volume(0.2) if City.instanceSpecificVars is None: attrList = list( self.__dict__.keys() ) self.destroyed = False if City.instanceSpecificVars is None: City.instanceSpecificVars = dict( [ ( eachKey, eachVal ) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ] ) def destroy( self ): playState = self.playStateRef() self.destructionSound.play(priority=1) self.explosionSound.play(priority=1) playState.gameLogicManager.__class__.shakeAmp += 5 if self.destroyed: return None self.changeAnimation("offline") pop = playState.gameLogicManager.population cityCount = len( [ each for each in playState.gameLogicManager.cities if not each.destroyed ] ) if cityCount == 1: playState.gameLogicManager.adjustPopulation( -pop ) else: playState.gameLogicManager.adjustPopulation( -int(pop*((0.9+0.2*random.random())/cityCount)) ) self.destroyed = True def update( self, dt ): Entity.update( self, dt )
class Laser( Entity ): width = 20 height = 20 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "laser.png" sheet = loadImageNoAlpha( sheetFileName ) colourKey = pygame.Color(255, 0, 255) sheet.set_colorkey(colourKey) instanceSpecificVars = None notEditable = True collidable = True solid = False specialCollision = queueCollideWithLaser def __init__( self, pos, group=None, **kwargs ): Entity.__init__( self, pos, [0,0], None, group, pygame.Rect( 0, 0, self.width, self.height ), animated=True, **kwargs ) self.animations["online"] = { 'fps':1, 'frames':[0] } self.animations["offline"] = { 'fps':1, 'frames':[1] } self.destructionSound = group.playState.soundManager.getSound( "destruction.wav" ) self.explosionSound = group.playState.soundManager.getSound( "explosion.wav" ) #self.explosionSound.set_volume(0.2) if Laser.instanceSpecificVars is None: attrList = list( self.__dict__.keys() ) self.ammo = 8 self.coolDown = 0.0 self.destroyed = False if Laser.instanceSpecificVars is None: Laser.instanceSpecificVars = dict( [ ( eachKey, eachVal ) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ] ) def destroy( self ): self.changeAnimation("offline") self.ammo = 0 self.playStateRef().gameLogicManager.generateAmmoHud() self.destructionSound.play(priority=1) self.explosionSound.play(priority=1) playState = self.playStateRef() playState.gameLogicManager.__class__.shakeAmp += 5 self.destroyed = True def update( self, dt ): self.coolDown -= dt Entity.update( self, dt )
def __init__( self, playState, text, box=None ): sheet = loadImageNoAlpha( self.sheetFileName ) self.originFrames = splitFrames( sheet, (32, 32) ) if box is None: w, h = getResolution() box = pygame.Rect( (0, (7.0/12)*h), (w, (5.0/12)*h ) ) img = pygame.Surface( (box.w, box.h) ).convert() #img.fill( pygame.Color( 0, 0, 0, 0 ) ) for x in range( 32, box.w, 32 ): img.blit( self.originFrames[1], (x, 0) ) img.blit( self.originFrames[7], (x, box.h-32) ) for y in range( 32, box.h, 32 ): img.blit( self.originFrames[3], (0, y) ) img.blit( self.originFrames[5], (box.w-32, y) ) for x in range( box.x+32, box.w+box.x-32, 32 ): for y in range( 32, box.h-32, 32 ): img.blit( self.originFrames[4], (x,y) ) img.blit( self.originFrames[0], ( 0, 0 ) ) img.blit( self.originFrames[2], (box.w-32, 0) ) img.blit( self.originFrames[6], (0, box.h-32) ) img.blit( self.originFrames[8], (box.w-32, box.h-32) ) wLimit = box.w-64 subStrings = [] lastIndex = 0 for eachIndex in range( len( text ) ): eachSub = text[lastIndex:eachIndex] if text[eachIndex] == "\n": subStrings.append( eachSub ) lastIndex = eachIndex + 1 elif self.font.size( eachSub )[0] > wLimit: subStrings.append( eachSub[:-1] ) lastIndex = eachIndex - 1 elif eachIndex == ( len( text ) - 1 ): subStrings.append( eachSub+text[-1] ) if len( subStrings ) is 0: subStrings = [ text ] curIndex = 0 curY = 32 while curY < box.h-32 and curIndex < len( subStrings ): eachImg = self.font.render( subStrings[curIndex], True, pygame.Color( 0, 0, 0 ) ) img.blit( eachImg, ( 32, curY ) ) curY += eachImg.get_height() curIndex += 1 HudElement.__init__( self, playState, box.topleft, img, False ) self.image.set_colorkey( self.colourKey ) self.dying = False self.removed = False self.removeTime = 0.5 self.removeTimer = 0.0 self.borning = True self.bornTime = 0.25 self.bornTimer = 0.0
def __init__(self, pos, playState): sheet = loadImageNoAlpha("bolt.png") colourKey = pygame.Color(255, 0, 255) sheet.set_colorkey(colourKey) HudElement.__init__(self, playState, pos, sheet, False)
def __init__( self, pos, playState ): sheet = loadImageNoAlpha("bolt.png") colourKey = pygame.Color(255, 0, 255) sheet.set_colorkey(colourKey) HudElement.__init__( self, playState, pos, sheet, False )
def __init__(self, playState, text, box=None): sheet = loadImageNoAlpha(self.sheetFileName) self.originFrames = splitFrames(sheet, (32, 32)) if box is None: w, h = getResolution() box = pygame.Rect((0, (7.0 / 12) * h), (w, (5.0 / 12) * h)) img = pygame.Surface((box.w, box.h)).convert() #img.fill( pygame.Color( 0, 0, 0, 0 ) ) for x in range(32, box.w, 32): img.blit(self.originFrames[1], (x, 0)) img.blit(self.originFrames[7], (x, box.h - 32)) for y in range(32, box.h, 32): img.blit(self.originFrames[3], (0, y)) img.blit(self.originFrames[5], (box.w - 32, y)) for x in range(box.x + 32, box.w + box.x - 32, 32): for y in range(32, box.h - 32, 32): img.blit(self.originFrames[4], (x, y)) img.blit(self.originFrames[0], (0, 0)) img.blit(self.originFrames[2], (box.w - 32, 0)) img.blit(self.originFrames[6], (0, box.h - 32)) img.blit(self.originFrames[8], (box.w - 32, box.h - 32)) wLimit = box.w - 64 subStrings = [] lastIndex = 0 for eachIndex in range(len(text)): eachSub = text[lastIndex:eachIndex] if text[eachIndex] == "\n": subStrings.append(eachSub) lastIndex = eachIndex + 1 elif self.font.size(eachSub)[0] > wLimit: subStrings.append(eachSub[:-1]) lastIndex = eachIndex - 1 elif eachIndex == (len(text) - 1): subStrings.append(eachSub + text[-1]) if len(subStrings) is 0: subStrings = [text] curIndex = 0 curY = 32 while curY < box.h - 32 and curIndex < len(subStrings): eachImg = self.font.render(subStrings[curIndex], True, pygame.Color(0, 0, 0)) img.blit(eachImg, (32, curY)) curY += eachImg.get_height() curIndex += 1 HudElement.__init__(self, playState, box.topleft, img, False) self.image.set_colorkey(self.colourKey) self.dying = False self.removed = False self.removeTime = 0.5 self.removeTimer = 0.0 self.borning = True self.bornTime = 0.25 self.bornTimer = 0.0