def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite(self.panel) self.snapToGridButton = SnapToGridButton(self) self.addButton(self.snapToGridButton) self.removeButton = RemoveSensorButton(self) self.addButton(self.removeButton) self.gridButtonSelectionBox = None self.removeButtonSelectionBox = None self.addingMode = True self.removingMode = False self.curGrabbedSens = None self.curStart = None self.gridX = 40 self.gridY = 40 self.snapToGrid = False self.whereEntWasGrabbed = None
def __init__( self, menu, buttonType, sprites=[] ): self.panelImage = loadImage( "filebrowserbackground.png", 2 ) self.panel = StaticImage( self.panelImage, ( 10, 10 ) ) sprites.append( self.panel ) self.backButton = ScrollBackButtonFiles( self ) sprites.append( self.backButton ) self.nextButton = ScrollNextButtonFiles( self ) sprites.append( self.nextButton ) MenuState.__init__( self, menu, sprites, miniMap = False ) self.keyboardEnabled = True self.currentString = "" self.forceUpdate = False self.deleteLastChar = False self.oldString = "" self.boundingArea = pygame.Rect( 26, 26, 670, 496 ) #self.addButton( FileButton( self, self.currentString, ( 40, 30 ) ) ) self.startButtonIndex = 0 self.pageLength = 0 self.fileButtons = [] self.buttonType = buttonType self.generateFileButtons() self.userFont = pygame.font.Font( os.path.join( "data", "fonts", "PD-tarzeau_-_Atari_Small.ttf" ), 24 ) #Carry these sprites over each update. self.carryMeOverSprites = [ self.fileNameLabel ] self.carryMeOverButtons = []
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2 ), (10, 10)) self.addSprite( self.panel ) self.addBoundButton = AddBoundaryButton( self ) self.addButton( self.addBoundButton ) self.removeBoundButton = RemoveBoundaryButton( self ) self.addButton( self.removeBoundButton ) self.snapToGridButton = SnapToGridButton( self ) self.addButton( self.snapToGridButton ) self.buttonSelectionBox = SelectionBox( self.addBoundButton.rect, self ) self.addSprite( self.buttonSelectionBox ) self.gridButtonSelectionBox = None self.addingMode = True self.removingMode = False self.curStart = None tmpGrdRect = self.menu.playState.floor.tileSet.getTiles()[0].image.get_rect() self.gridX, self.gridY = tmpGrdRect.w, tmpGrdRect.h self.snapToGrid = False
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage( "devmenu.png", 2 ), (10, 10)) self.addSprite( self.panel ) self.snapToGridButton = SnapToGridButton( self ) self.addButton( self.snapToGridButton ) self.removeButton = RemoveSensorButton( self ) self.addButton( self.removeButton ) self.gridButtonSelectionBox = None self.removeButtonSelectionBox = None self.addingMode = True self.removingMode = False self.curGrabbedSens = None self.curStart = None self.gridX = 40 self.gridY = 40 self.snapToGrid = False self.whereEntWasGrabbed = None
def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("tageditorbackground.png", 2), (10, 10)) self.addSprite(self.panel) self.plusTagButton = AddTagButton(self) self.addButton(self.plusTagButton) self.subTagButton = SubTagButton(self) self.addButton(self.subTagButton) self.sensorButton = SensorButton(self) self.addButton(self.sensorButton) self.curEnt = None self.keyboardEnabled = True #self.currentString = "" self.deleteLastChar = False #self.oldString = "" self.curTag = None self.tagButtons = [] self.carryMeOverButtons = [ self.plusTagButton, self.subTagButton, self.sensorButton ] self.carryMeOverSprites = [self.panel, self.fileNameLabel ] + self.carryMeOverButtons self.sensorMode = False self.sensorButtonSelectionBox = None
def __init__(self, menu, buttonType, sprites=[]): self.panelImage = loadImage("filebrowserbackground.png", 2) self.panel = StaticImage(self.panelImage, (10, 10)) sprites.append(self.panel) self.backButton = ScrollBackButtonFiles(self) sprites.append(self.backButton) self.nextButton = ScrollNextButtonFiles(self) sprites.append(self.nextButton) MenuState.__init__(self, menu, sprites, miniMap=False) self.keyboardEnabled = True self.currentString = "" self.forceUpdate = False self.deleteLastChar = False self.oldString = "" self.boundingArea = pygame.Rect(26, 26, 670, 496) #self.addButton( FileButton( self, self.currentString, ( 40, 30 ) ) ) self.startButtonIndex = 0 self.pageLength = 0 self.fileButtons = [] self.buttonType = buttonType self.generateFileButtons() self.userFont = pygame.font.Font( os.path.join("data", "fonts", "PD-tarzeau_-_Atari_Small.ttf"), 24) #Carry these sprites over each update. self.carryMeOverSprites = [self.fileNameLabel] self.carryMeOverButtons = []
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage( loadImage( "tageditorbackground.png", 2 ), (10, 10) ) self.addSprite( self.panel ) self.plusTagButton = AddTagButton( self ) self.addButton( self.plusTagButton ) self.subTagButton = SubTagButton( self ) self.addButton( self.subTagButton ) self.sensorButton = SensorButton( self ) self.addButton( self.sensorButton ) self.curEnt = None self.keyboardEnabled = True #self.currentString = "" self.deleteLastChar = False #self.oldString = "" self.curTag = None self.tagButtons = [] self.carryMeOverButtons = [self.plusTagButton, self.subTagButton, self.sensorButton] self.carryMeOverSprites = [self.panel,self.fileNameLabel] + self.carryMeOverButtons self.sensorMode = False self.sensorButtonSelectionBox = None
def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite(self.panel) self.addBoundButton = AddBoundaryButton(self) self.addButton(self.addBoundButton) self.removeBoundButton = RemoveBoundaryButton(self) self.addButton(self.removeBoundButton) self.snapToGridButton = SnapToGridButton(self) self.addButton(self.snapToGridButton) self.buttonSelectionBox = SelectionBox(self.addBoundButton.rect, self) self.addSprite(self.buttonSelectionBox) self.gridButtonSelectionBox = None self.addingMode = True self.removingMode = False self.curStart = None tmpGrdRect = self.menu.playState.floor.tileSet.getTiles( )[0].image.get_rect() self.gridX, self.gridY = tmpGrdRect.w, tmpGrdRect.h self.snapToGrid = False
class SnapToGridButtonFloor( Button ): image = loadImage( "gridbutton.png", 2 ) def __init__( self, menu=None ): Button.__init__( self, None, None, menu ) self.rect = self.image.get_rect() self.rect.topleft = ( 114, 338 ) def push( self, clickKey, click ): if "up" in clickKey: self.parentState.toggleSnapToGrid()
class HardBlitButton( Button ): image = loadImage( "hardblit.png", 2 ) def __init__( self, menu=None ): Button.__init__( self, None, None, menu ) self.rect = self.image.get_rect() self.rect.topleft = ( 73, 370 ) #( 144, 338 ) def push( self, clickKey, click ): if "up" in clickKey: self.parentState.toggleHardBlit()
class SensorButton(Button): image = loadImage("physicsvis.png", 2) def __init__(self, parentState=None): Button.__init__(self, None, None, parentState) self.rect = self.image.get_rect() self.rect.topleft = (90, 370) def push(self, clickKey, click): if "up" in clickKey: self.parentState.toggleSensor()
class RemoveSensorButton(Button): image = loadImage("remove.png", 2) def __init__(self, menu=None): Button.__init__(self, None, None, menu) self.rect = self.image.get_rect() self.rect.topleft = (54, 24) def push(self, clickKey, click): if "up" in clickKey: self.parentState.toggleRemove()
class RemoveFloorButton( Button ): image = loadImage("remove.png", 2 ) def __init__( self, menu=None ): Button.__init__( self, None, None, menu ) self.rect = self.image.get_rect() self.rect.topleft = ( 84, 338 ) def push( self, clickKey, click ): if "up" in clickKey: self.parentState.applySelectionBox( self ) self.parentState.editMode = 3 self.parentState.setClampVisibility( False )
class RedoButton( Button ): """RedoButton class, also pretty obvious what it does.""" image = loadImage("redo.png", 2) def __init__( self, parentState=None ): Button.__init__( self, None, None, parentState ) self.rect = self.image.get_rect() self.rect.topleft = ( 93, 18 ) def push( self, clickKey, click ): if clickKey is 'mouse1up': self.parentState.floor.redoChange()
class GridFillButtonEnt(Button): image = loadImage("gridfillbutton.png", 2) def __init__(self, menu=None): Button.__init__(self, None, None, menu) self.rect = self.image.get_rect() self.rect.topleft = (84, 338) def push(self, clickKey, click): if "up" in clickKey: self.parentState.toggleGridFill()
class AddBoundaryButton(Button): image = loadImage("add.png", 2) def __init__(self, menu=None): Button.__init__(self, None, None, menu) self.rect = self.image.get_rect() self.rect.topleft = (54, 24) def push(self, clickKey, click): if "up" in clickKey: self.parentState.addMode()
class SensorEditButton(Button): image = loadImage("sensoreditbutton.png", 2) rect = image.get_rect() rect.topleft = (24, 144) def __init__(self, menu=None): Button.__init__(self, None, None, menu) def push(self, clickKey, click): if "up" in clickKey: aBoundEditState = SensorEditState(self.parentState.menu) self.parentState.menu.loadMenuState(aBoundEditState)
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 UndoButton( Button ): """UndoButton class, pretty obvious what it does.""" image = loadImage("undo.png", 2) def __init__( self, parentState=None ): Button.__init__( self, None, None, parentState ) self.rect = self.image.get_rect() self.rect.topleft = ( 44, 18 ) def push( self, clickKey, click ): """Call Floor.undoChange() on the playState's floor.""" if "up" in clickKey: self.parentState.floor.undoChange()
class LevelWarp(Entity): scale = 2 width = 16 height = 16 playStateGroup = "levelWarpGroup" setName = "levelwarp" sheetFileName = "block.png" sheet = loadImage(sheetFileName, scale) specialCollision = queueLoad collidable = True solid = False mass = 20 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 LevelWarp.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) #self.shape.collision_type = 1 self.tags["warpKey"] = "prime" self.tags["warpDest"] = "testthingy" self.ignore = set([]) self.collidedWith = set([]) if LevelWarp.instanceSpecificVars is None: LevelWarp.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): Entity.update(self, dt) for each in self.groups()[0].playState.playersGroup: if each.id not in self.collidedWith and each.id in self.ignore: self.ignore.remove(each.id) self.collidedWith = set([])
class FloorEditButton( Button ): """The FloorEditButton class, just creates a Button that invokes FloorEditState on the DevMenu.""" image = loadImage("flooreditbutton.png", 2 ) rect = image.get_rect() rect.topleft = ( 24, 24 ) def __init__( self, parentState=None ): Button.__init__( self, None, None, parentState ) def push( self, clickKey, click ): """Invoke the FloorEditState""" #SWITCH TO FLOOREDIT MENU STATE if "up" in clickKey: aFloorEditState = FloorEditState( self.parentState.menu ) self.parentState.menu.loadMenuState( aFloorEditState )
class EntityEditButton(Button): """EntityEditButton is a Button that appears in the DefaultMenuState.\n"""\ """It merely invokes the EntityEditState MenuState.""" image = loadImage("entityeditbutton.png", 2) rect = image.get_rect() rect.topleft = (24, 44) def __init__(self, menu=None): Button.__init__(self, None, None, menu) def push(self, clickKey, click): """Invokes the EntityEditState MenuState on the parentState's DevMenu.""" if "up" in clickKey: anEntityEditState = EntityEditState(self.parentState.menu) self.parentState.menu.loadMenuState(anEntityEditState)
class SubTagButton(Button): image = loadImage("sub.png", 2) def __init__(self, parentState=None): Button.__init__(self, None, None, parentState) self.rect = self.image.get_rect() self.rect.topleft = (60, 370) def push(self, clickKey, click): if "up" in clickKey: curEnt = self.parentState.curEnt if curEnt is not None: curTag = self.parentState.curTag if curTag is not None: del curEnt.tags[curTag.getKeyValuePair()[0]] self.parentState.getTagButtons()
def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.entNum = 0 self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite(self.panel) self.scrollNextButton = ScrollNextButton(self) self.addButton(self.scrollNextButton) self.scrollBackButton = ScrollBackButton(self) self.addButton(self.scrollBackButton) self.snapToGridButton = SnapToGridButtonEnt(self) self.addButton(self.snapToGridButton) self.gridFillButton = GridFillButtonEnt(self) self.addButton(self.gridFillButton) self.curEntNum = 0 self.xPos = 0 self.yPos = 0 self.tallest = 0 self.processedEnts = [] self.pages = {0: []} self.curPage = 0 self.maxPage = 0 self.generateButtons() self.snapToGrid = False self.gridButtonSelectionBox = None self.gridFill = False self.gridFillButtonSelectionBox = None self.gridFillStart = None self.selectedButton = self.buttons[self.entNum + 4] self.entSelectionBox = SelectionBox(self.selectedButton.rect, self) self.addSprite(self.entSelectionBox) self.curGrabbedEnt = None self.lastMouseSpot = (0, 0) self.whereEntWasGrabbed = None
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.entNum = 0 self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite( self.panel ) self.scrollNextButton = ScrollNextButton( self ) self.addButton( self.scrollNextButton ) self.scrollBackButton = ScrollBackButton( self ) self.addButton( self.scrollBackButton ) self.snapToGridButton = SnapToGridButtonEnt( self ) self.addButton( self.snapToGridButton ) self.gridFillButton = GridFillButtonEnt( self ) self.addButton( self.gridFillButton ) self.curEntNum = 0 self.xPos = 0 self.yPos = 0 self.tallest = 0 self.processedEnts = [] self.pages = {0:[]} self.curPage = 0 self.maxPage = 0 self.generateButtons() self.snapToGrid = False self.gridButtonSelectionBox = None self.gridFill = False self.gridFillButtonSelectionBox = None self.gridFillStart = None self.selectedButton = self.buttons[self.entNum+4] self.entSelectionBox = SelectionBox( self.selectedButton.rect, self ) self.addSprite( self.entSelectionBox ) self.curGrabbedEnt = None self.lastMouseSpot = ( 0, 0 ) self.whereEntWasGrabbed = None
class GenericBlock(Entity): scale = 2 width = 32 height = 32 bWidth = width bHeight = height bdx = 0 bdy = 0 wbWidth = 32 wbHeight = 16 wbdx = 0 wbdy = 16 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "block.png" sheet = loadImage(sheetFileName, scale) specialCollision = None collidable = True solid = True mass = 20 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 GenericBlock.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) if GenericBlock.instanceSpecificVars is None: GenericBlock.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 PhysicsVisButton(Button): image = loadImage("physicsvis.png", 2) def __init__(self, menu=None): Button.__init__(self, None, None, menu) self.rect = self.image.get_rect() self.rect.topleft = (30, 370) self.on = False def push(self, clickKey, click): if "up" in clickKey: if not self.on: self.on = True self.parentState.menu.playState.lineVisualiser.renderLines = True self.parentState.menu.playState.lineVisualiser.renderPhysicsLines = True elif self.on: self.on = False self.parentState.menu.playState.lineVisualiser.forceNoRender = True
class SaveMapButton(Button): """Save the current playState with cPickle.""" image = loadImage("savemapbutton.png", 2) rect = image.get_rect() rect.topleft = (24, 64) def __init__(self, parentState=None): Button.__init__(self, None, None, parentState) def push(self, clickKey, click): """Dump the state to a file""" #SWITCH TO FLOOREDIT MENU STATE #writeObjectToFile( self.parentState.menu.playState, "asdf.pickle" ) if "up" in clickKey: #print self.parentState.menu.playState.floor #dumpPlayState( self.parentState.menu.playState, os.path.join( "data", "maps", "asdf.pickle" ) ) aSaveMapState = SaveMapState(self.parentState.menu) self.parentState.menu.loadMenuState(aSaveMapState)
class PauseStartButton(Button): image = loadImage("pausestart.png", 2) def __init__(self, menu=None): Button.__init__(self, None, None, menu) self.rect = self.image.get_rect() self.rect.topleft = (60, 370) self.on = False def push(self, clickKey, click): if "up" in clickKey: if not self.on: self.on = True elif self.on: self.on = False self.parentState.menu.playState.paused = self.on if self.on: pygame.mixer.pause() else: pygame.mixer.unpause()
class AddTagButton(Button): image = loadImage("add.png", 2) def __init__(self, parentState=None): Button.__init__(self, None, None, parentState) self.rect = self.image.get_rect() self.rect.topleft = (30, 370) def push(self, clickKey, click): if "up" in clickKey: curEnt = self.parentState.curEnt if curEnt is not None: num = len(curEnt.tags) + 1 done = False while not done: if str(num) not in curEnt.tags.keys(): done = True else: num += 1 curEnt.tags[str(num)] = "" self.parentState.getTagButtons()
class Anvil(Entity): width = 32 height = 22 playStateGroup = "genericStuffGroup" setName = "genericstuff" sheetFileName = "anvil.png" sheet = loadImage(sheetFileName, 2) specialCollision = None collidable = True solid = True mass = 2000000000 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 Anvil.instanceSpecificVars is None: attrList = list(self.__dict__.keys()) if Anvil.instanceSpecificVars is None: Anvil.instanceSpecificVars = dict([ (eachKey, eachVal) for eachKey, eachVal in self.__dict__.items() if eachKey not in attrList ]) def update(self, dt): Entity.update(self, dt)
def __init__( self, parentState=None ): Button.__init__( self, loadImage( "bottomrightlayerclamp.png", 2 ), ( 0, 0 ), parentState )
def __init__( self, parentState=None ): Button.__init__( self, loadImage( "forwardarrow.png", 2 ), ( 670, 526 ), parentState )
def __init__( self, parentState=None ): Button.__init__( self, loadImage( "backarrow.png", 2 ), ( 42, 526 ), parentState )
def __init__( self, parentState=None ): Button.__init__( self, loadImage( "forwardarrowsmall.png", 2 ), ( 116, 380 ), parentState )
def __init__( self, parentState=None ): Button.__init__( self, loadImage( "backarrowsmall.png", 2 ), ( 24, 380 ), parentState )
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.buttons = [] self.sprites = [self.fileNameLabel, self.miniMap] self.panel = StaticImage( loadImage( "devmenu.png", 2 ), ( 10, 10 ) ) self.addSprite( self.panel ) self.undoButton = UndoButton( self ) self.addButton( self.undoButton ) self.redoButton = RedoButton( self ) self.addButton( self.redoButton ) self.scrollNextButton = ScrollNextButtonTiles( self ) self.addButton( self.scrollNextButton ) self.scrollBackButton = ScrollBackButtonTiles( self ) self.addButton( self.scrollBackButton ) self.removeFloorButton = RemoveFloorButton( self ) self.addButton( self.removeFloorButton ) self.addFloorButton = AddFloorButton( self ) self.addButton( self.addFloorButton ) self.editFloorButton = EditFloorButton( self ) self.addButton( self.editFloorButton ) self.topLeftLayerClamp = TopLeftLayerClamp( self ) self.bottomRightLayerClamp = BottomRightLayerClamp( self ) self.snapToGridButton = SnapToGridButtonFloor( self ) self.addButton( self.snapToGridButton ) self.hardBlitButton = HardBlitButton( self ) self.addButton( self.hardBlitButton ) #A local copy to prevent excessive look ups. self.floor = self.menu.playState.floor self.currentFloorLayer = 0 self.currentLayerIsGrabbed = False self.grabPoint = None self.snapToGrid = False self.gridButtonSelectionBox = None self.hardBlit = False self.hardBlitSelectionBox = None self.currentlyGrabbedClamp = None #Edit modes are zero for tiles, 1 for creating/editing layers, 2 for select/edit, and 3 for removing self.editMode = 0 self.tileNum = 0 self.tileFillRect = None self.xPos = 0 self.yPos = 0 self.tallest = 0 self.pages = {0:[]} self.curPage = 0 self.processedTiles = [] self.generateButtons() #For the tile placing functionality. self.startOfBlock = None self.tileSelectionBox = SelectionBox( self.pages[self.curPage][0].rect, self ) self.addSprite( self.tileSelectionBox ) self.curSelectedButton = self.pages[self.curPage][0] self.gridX, self.gridY = self.curSelectedButton.rect.w, self.curSelectedButton.rect.h self.setClamps()
def __init__(self, parentState=None): Button.__init__(self, loadImage("backarrowsmall.png", 2), (24, 380), parentState)
def __init__(self, parentState=None): Button.__init__(self, loadImage("forwardarrowsmall.png", 2), (116, 380), parentState)