def makeTileRect( self, p1, p2 ): curTile = self.processedTiles[self.tileNum] height = curTile.rect.h width = curTile.rect.w floorRect = self.floor.layers[self.currentFloorLayer].rect leftBoundary = min( p2[0], p1[0] )-floorRect.left rightBoundary = max( p2[0], p1[0] )-floorRect.left topBoundary = min( p2[1], p1[1] )-floorRect.top bottomBoundary = max( p2[1], p1[1] )-floorRect.top x1Position, y1Position = gridRound( [ leftBoundary, topBoundary ], width, height, roundToTopLeft=True ) x2Position, y2Position = gridRound( [ rightBoundary, bottomBoundary], width, height, roundToTopLeft=False ) return pygame.Rect( x1Position, y1Position, x2Position-x1Position, y2Position-y1Position )
def update( self, dt, click, clickKey, curMousePos=None ): MenuState.update( self, dt, click, clickKey, curMousePos ) playState = self.menu.playState curMousePos = curMousePos[0]-playState.panX, curMousePos[1]-playState.panY if self.curStart is not None: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos playState.lineVisualiser.devMenuLineGroups = [ [ (self.curStart[0]+playState.panX, self.curStart[1]+playState.panY), (curPoint[0]+playState.panX, curPoint[1]+playState.panY) ] ] playState.lineVisualiser.flush = True playState.lineVisualiser.renderLines = True playState.lineVisualiser.renderPhysicsLines = True playState.lineVisualiser.forceNoRender = True if click is not None: if clickKey is 'mouse1down' and self.curStart is None and self.addingMode: if self.snapToGrid: self.curStart = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: self.curStart = curMousePos elif clickKey is 'mouse1up' and self.addingMode: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos playState.addBoundary( self.curStart, curPoint ) self.curStart = None elif clickKey is 'mouse1up' and self.removingMode: segment = self.selectSegment( curMousePos, 10 ) if segment is not None: playState.removeBoundary( segment ) elif clickKey is 'mouse3down' and self.curStart is None: segmentEndPair = self.selectSegmentEnd( curMousePos, 10 ) if segmentEndPair is not None: playState.removeBoundary( segmentEndPair[0] ) if segmentEndPair[1] is 'a': damnPoint = segmentEndPair[0].b else: damnPoint = segmentEndPair[0].a self.curStart = damnPoint.x, damnPoint.y elif clickKey is 'mouse3up' and self.curStart is not None: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos playState.addBoundary( self.curStart, curPoint ) self.curStart = None
def update( self, dt, click, clickKey, curMousePos=None ): MenuState.update( self, dt, click, clickKey, curMousePos ) playState = self.menu.playState curMousePos = curMousePos[0]-playState.panX, curMousePos[1]-playState.panY if self.snapToGrid: curMousePos = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curMousePos = curMousePos if self.curStart is not None: self.menu.playState.lineVisualiser.devMenuLineGroups = [ [ self.curStart, ( self.curStart[0], curMousePos[1] ) ], [ ( self.curStart[0], curMousePos[1] ), curMousePos ], [ curMousePos, ( curMousePos[0], self.curStart[1] ) ], [ ( curMousePos[0], self.curStart[1] ), self.curStart ] ] self.menu.playState.lineVisualiser.devMenuLineGroups = [ [ (each[0]+playState.panX, each[1]+playState.panY) for each in eachLine ] for eachLine in self.menu.playState.lineVisualiser.devMenuLineGroups ] self.menu.playState.lineVisualiser.flush = True self.menu.playState.lineVisualiser.renderLines = True self.menu.playState.lineVisualiser.renderPhysicsLines = True self.menu.playState.lineVisualiser.forceNoRender = True if click is not None: if clickKey is 'mouse1down' and self.curStart is None: self.curStart = curMousePos elif clickKey is 'mouse1up': #ADD SENSOR HERE destPoint = min( self.curStart[0], curMousePos[0] ), min( self.curStart[1], curMousePos[1] ) w = abs( self.curStart[0] - curMousePos[0] ) h = abs( self.curStart[1] - curMousePos[1] ) if w != 0 or h != 0: destPoint = destPoint[0] + w/2, destPoint[1] + h/2 destGroup = getattr( self.menu.playState, PureSensor.playStateGroup ) PureSensor( pos=destPoint, group=destGroup, width=w, height=h ) self.curStart = None elif clickKey is 'mouse3down': self.curGrabbedSens = self.getPressedSensor( (curMousePos[0]+playState.panX, curMousePos[1]+playState.panY) ) if self.curGrabbedSens is not None: entPos = self.curGrabbedSens.getPosition() self.whereEntWasGrabbed = curMousePos[0] - entPos[0], curMousePos[1] - entPos[1] elif clickKey is 'mouse3up': pickedSensor = self.getPressedSensor( (curMousePos[0]+playState.panX, curMousePos[1]+playState.panY) ) if pickedSensor is not None: if self.removingMode: pickedSensor.kill() self.curGrabbedSens = None self.whereEntWasGrabbed = None elif curMousePos is not None: if self.curGrabbedSens is not None: curEnt = self.curGrabbedSens newPos = curMousePos[0]-self.whereEntWasGrabbed[0], curMousePos[1]-self.whereEntWasGrabbed[1] curEnt.setPosition( newPos )
def update( self, dt, click, clickKey, curMousePos=None ): """Generic update method. The actual Entity-placing happens in here.""" #print len( self.menu.playState.sprites() ) MenuState.update( self, dt, click, clickKey, curMousePos ) self.generateButtons() if click is not None: if clickKey is 'mouse1down': self.curGrabbedEnt = self.getPressedEnt( curMousePos ) if self.curGrabbedEnt is not None: entPos = self.curGrabbedEnt.getPosition() self.whereEntWasGrabbed = curMousePos[0] - entPos[0], curMousePos[1] - entPos[1] if self.gridFill: self.gridFillStart = curMousePos[0]-self.menu.playState.panX, curMousePos[1]-self.menu.playState.panY elif clickKey is 'mouse1up': if self.getPressedEnt( click ) == None and self.curGrabbedEnt == None: classDef = self.processedEnts[self.entNum] destGroup = getattr( self.menu.playState, classDef.playStateGroup ) dest = click[0]-self.menu.playState.panX, click[1]-self.menu.playState.panY if classDef.wbWidth is not None: gridX = classDef.wbWidth gridY = classDef.wbHeight elif classDef.bWidth is not None: gridX = classDef.bWidth gridY = classDef.bHeight else: gridX = classDef.width gridY = classDef.height if not self.gridFill: if self.snapToGrid: dest = gridRound( dest, gridX, gridY ) classDef( dest, vel=[0,0], group=destGroup ) else: xMin = min( self.gridFillStart[0], dest[0] ) xMax = max( self.gridFillStart[0], dest[0] ) yMin = min( self.gridFillStart[1], dest[1] ) yMax = max( self.gridFillStart[1], dest[1] ) xMin, yMin = gridRound( (xMin, yMin), gridX, gridY ) xMax, yMax = gridRound( (xMax, yMax), gridX, gridY, roundToTopLeft=False ) for x in xrange( xMin, xMax, gridX ): for y in xrange( yMin, yMax, gridY ): classDef( (x,y), vel=[0,0], group=destGroup ) self.curGrabbedEnt = None self.whereEntWasGrabbed = None self.gridFillStart = None elif clickKey is 'mouse3up': anEnt = self.getPressedEnt( click ) if anEnt is not None: anEnt.kill() self.whereEntWasGrabbed = None elif curMousePos is not None: if self.curGrabbedEnt is not None: curEnt = self.curGrabbedEnt newPos = curMousePos[0]-self.whereEntWasGrabbed[0], curMousePos[1]-self.whereEntWasGrabbed[1] if self.snapToGrid: if curEnt.wbWidth is not None: newPos = gridRound( newPos, curEnt.wbWidth, curEnt.wbHeight ) elif curEnt.bWidth is not None: newPos = gridRound( newPos, curEnt.bWidth, curEnt.bHeight ) else: newPos = gridRound( newPos, curEnt.width, curEnt.height ) curEnt.setPosition( newPos ) self.lastMouseSpot = curMousePos
def update(self, dt, click, clickKey, curMousePos=None): MenuState.update(self, dt, click, clickKey, curMousePos) playState = self.menu.playState curMousePos = curMousePos[0] - playState.panX, curMousePos[ 1] - playState.panY if self.snapToGrid: curMousePos = gridRound(curMousePos, self.gridX, self.gridY, trueRounding=True) else: curMousePos = curMousePos if self.curStart is not None: self.menu.playState.lineVisualiser.devMenuLineGroups = [ [self.curStart, (self.curStart[0], curMousePos[1])], [(self.curStart[0], curMousePos[1]), curMousePos], [curMousePos, (curMousePos[0], self.curStart[1])], [(curMousePos[0], self.curStart[1]), self.curStart] ] self.menu.playState.lineVisualiser.devMenuLineGroups = [ [(each[0] + playState.panX, each[1] + playState.panY) for each in eachLine] for eachLine in self.menu.playState.lineVisualiser.devMenuLineGroups ] self.menu.playState.lineVisualiser.flush = True self.menu.playState.lineVisualiser.renderLines = True self.menu.playState.lineVisualiser.renderPhysicsLines = True self.menu.playState.lineVisualiser.forceNoRender = True if click is not None: if clickKey is 'mouse1down' and self.curStart is None: self.curStart = curMousePos elif clickKey is 'mouse1up': #ADD SENSOR HERE destPoint = min(self.curStart[0], curMousePos[0]), min(self.curStart[1], curMousePos[1]) w = abs(self.curStart[0] - curMousePos[0]) h = abs(self.curStart[1] - curMousePos[1]) if w != 0 or h != 0: destPoint = destPoint[0] + w / 2, destPoint[1] + h / 2 destGroup = getattr(self.menu.playState, PureSensor.playStateGroup) PureSensor(pos=destPoint, group=destGroup, width=w, height=h) self.curStart = None elif clickKey is 'mouse3down': self.curGrabbedSens = self.getPressedSensor( (curMousePos[0] + playState.panX, curMousePos[1] + playState.panY)) if self.curGrabbedSens is not None: entPos = self.curGrabbedSens.getPosition() self.whereEntWasGrabbed = curMousePos[0] - entPos[ 0], curMousePos[1] - entPos[1] elif clickKey is 'mouse3up': pickedSensor = self.getPressedSensor( (curMousePos[0] + playState.panX, curMousePos[1] + playState.panY)) if pickedSensor is not None: if self.removingMode: pickedSensor.kill() self.curGrabbedSens = None self.whereEntWasGrabbed = None elif curMousePos is not None: if self.curGrabbedSens is not None: curEnt = self.curGrabbedSens newPos = curMousePos[0] - self.whereEntWasGrabbed[ 0], curMousePos[1] - self.whereEntWasGrabbed[1] curEnt.setPosition(newPos)
def update(self, dt, click, clickKey, curMousePos=None): """Generic update method. The actual Entity-placing happens in here.""" #print len( self.menu.playState.sprites() ) MenuState.update(self, dt, click, clickKey, curMousePos) self.generateButtons() if click is not None: if clickKey is 'mouse1down': self.curGrabbedEnt = self.getPressedEnt(curMousePos) if self.curGrabbedEnt is not None: entPos = self.curGrabbedEnt.getPosition() self.whereEntWasGrabbed = curMousePos[0] - entPos[ 0], curMousePos[1] - entPos[1] if self.gridFill: self.gridFillStart = curMousePos[ 0] - self.menu.playState.panX, curMousePos[ 1] - self.menu.playState.panY elif clickKey is 'mouse1up': if self.getPressedEnt( click) == None and self.curGrabbedEnt == None: classDef = self.processedEnts[self.entNum] destGroup = getattr(self.menu.playState, classDef.playStateGroup) dest = click[0] - self.menu.playState.panX, click[ 1] - self.menu.playState.panY if classDef.wbWidth is not None: gridX = classDef.wbWidth gridY = classDef.wbHeight elif classDef.bWidth is not None: gridX = classDef.bWidth gridY = classDef.bHeight else: gridX = classDef.width gridY = classDef.height if not self.gridFill: if self.snapToGrid: dest = gridRound(dest, gridX, gridY) classDef(dest, vel=[0, 0], group=destGroup) else: xMin = min(self.gridFillStart[0], dest[0]) xMax = max(self.gridFillStart[0], dest[0]) yMin = min(self.gridFillStart[1], dest[1]) yMax = max(self.gridFillStart[1], dest[1]) xMin, yMin = gridRound((xMin, yMin), gridX, gridY) xMax, yMax = gridRound((xMax, yMax), gridX, gridY, roundToTopLeft=False) for x in xrange(xMin, xMax, gridX): for y in xrange(yMin, yMax, gridY): classDef((x, y), vel=[0, 0], group=destGroup) self.curGrabbedEnt = None self.whereEntWasGrabbed = None self.gridFillStart = None elif clickKey is 'mouse3up': anEnt = self.getPressedEnt(click) if anEnt is not None: anEnt.kill() self.whereEntWasGrabbed = None elif curMousePos is not None: if self.curGrabbedEnt is not None: curEnt = self.curGrabbedEnt newPos = curMousePos[0] - self.whereEntWasGrabbed[ 0], curMousePos[1] - self.whereEntWasGrabbed[1] if self.snapToGrid: if curEnt.wbWidth is not None: newPos = gridRound(newPos, curEnt.wbWidth, curEnt.wbHeight) elif curEnt.bWidth is not None: newPos = gridRound(newPos, curEnt.bWidth, curEnt.bHeight) else: newPos = gridRound(newPos, curEnt.width, curEnt.height) curEnt.setPosition(newPos) self.lastMouseSpot = curMousePos
def update(self, dt, click, clickKey, curMousePos=None): MenuState.update(self, dt, click, clickKey, curMousePos) playState = self.menu.playState curMousePos = curMousePos[0] - playState.panX, curMousePos[ 1] - playState.panY if self.curStart is not None: if self.snapToGrid: curPoint = gridRound(curMousePos, self.gridX, self.gridY, trueRounding=True) else: curPoint = curMousePos playState.lineVisualiser.devMenuLineGroups = [[ (self.curStart[0] + playState.panX, self.curStart[1] + playState.panY), (curPoint[0] + playState.panX, curPoint[1] + playState.panY) ]] playState.lineVisualiser.flush = True playState.lineVisualiser.renderLines = True playState.lineVisualiser.renderPhysicsLines = True playState.lineVisualiser.forceNoRender = True if click is not None: if clickKey is 'mouse1down' and self.curStart is None and self.addingMode: if self.snapToGrid: self.curStart = gridRound(curMousePos, self.gridX, self.gridY, trueRounding=True) else: self.curStart = curMousePos elif clickKey is 'mouse1up' and self.addingMode: if self.snapToGrid: curPoint = gridRound(curMousePos, self.gridX, self.gridY, trueRounding=True) else: curPoint = curMousePos playState.addBoundary(self.curStart, curPoint) self.curStart = None elif clickKey is 'mouse1up' and self.removingMode: segment = self.selectSegment(curMousePos, 10) if segment is not None: playState.removeBoundary(segment) elif clickKey is 'mouse3down' and self.curStart is None: segmentEndPair = self.selectSegmentEnd(curMousePos, 10) if segmentEndPair is not None: playState.removeBoundary(segmentEndPair[0]) if segmentEndPair[1] is 'a': damnPoint = segmentEndPair[0].b else: damnPoint = segmentEndPair[0].a self.curStart = damnPoint.x, damnPoint.y elif clickKey is 'mouse3up' and self.curStart is not None: if self.snapToGrid: curPoint = gridRound(curMousePos, self.gridX, self.gridY, trueRounding=True) else: curPoint = curMousePos playState.addBoundary(self.curStart, curPoint) self.curStart = None
def update( self, dt, click, clickKey, curMousePos=None ): """Where the actual Tile placing on the Floor happens.""" MenuState.update( self, dt, click, clickKey, curMousePos ) self.menu.playState.lineVisualiser.devMenuLineGroups = [] for eachLayer in self.floor.layers: self.menu.playState.lineVisualiser.devMenuLineGroups.extend( generateListOfLines( eachLayer.rect.topleft, eachLayer.rect.bottomright ) ) if self.startOfBlock is not None: if self.editMode is 0: self.tileFillRect = self.makeTileRect( self.startOfBlock, curMousePos ) p1 = self.floor.layers[self.currentFloorLayer].rect.left+self.tileFillRect.left, self.floor.layers[self.currentFloorLayer].rect.top+self.tileFillRect.top p2 = p1[0]+self.tileFillRect.w, p1[1]+self.tileFillRect.h self.menu.playState.lineVisualiser.devMenuLineGroups.extend( generateListOfLines( p1, p2 ) ) self.menu.playState.lineVisualiser.flush = True elif self.editMode is 1: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos self.menu.playState.lineVisualiser.devMenuLineGroups.extend( generateListOfLines( curPoint, self.startOfBlock ) ) self.menu.playState.lineVisualiser.flush = True else: if self.editMode is 0: curTile = self.processedTiles[self.tileNum] floorRect = self.floor.layers[self.currentFloorLayer].rect displacedPoint = curMousePos[0]-floorRect.left, curMousePos[1]-floorRect.top p1 = gridRound( displacedPoint, self.gridX, self.gridY ) p1 = p1[0]+floorRect.left, p1[1]+floorRect.top p2 = p1[0]+curTile.rect.w, p1[1]+curTile.rect.h self.menu.playState.lineVisualiser.devMenuLineGroups.extend( generateListOfLines( p1, p2 ) ) self.menu.playState.lineVisualiser.flush = True self.menu.playState.lineVisualiser.renderLines = True self.menu.playState.lineVisualiser.forceNoRender = True if click is not None: if clickKey is 'mouse1down': if self.snapToGrid: self.startOfBlock = gridRound( click, self.gridX, self.gridY, trueRounding=True ) else: self.startOfBlock = click elif clickKey is 'mouse1up': if self.editMode is 0: if self.startOfBlock != None: self.floor.writeArea( self.tileNum, self.tileFillRect, layerNum=self.currentFloorLayer, hardBlit=self.hardBlit ) self.startOfBlock = None self.tileFillRect = None elif self.editMode is 1: if self.startOfBlock != None: if self.snapToGrid: curPoint = gridRound( click, self.gridX, self.gridY, trueRounding=True ) else: curPoint = click newSize = ( abs( curPoint[0]-self.startOfBlock[0] ), abs( curPoint[1]-self.startOfBlock[1] ) ) newLayer = FloorLayer( newSize, ( min( curPoint[0], self.startOfBlock[0] ), min( curPoint[1], self.startOfBlock[1] ) ) ) self.floor.layers.append( newLayer ) self.grabPoint = None self.currentlyGrabbedClamp = None elif self.editMode is 2: if self.currentlyGrabbedClamp is None: self.selectFloorLayer( click ) self.currentLayerIsGrabbed = False elif self.editMode is 3: self.deleteFloorLayer( click ) self.startOfBlock = None self.grabPoint = None self.currentlyGrabbedClamp = None elif clickKey is 'mouse3down': if self.editMode is 2: self.currentLayerIsGrabbed = True self.grabPoint = ( click[0]-self.floor.layers[self.currentFloorLayer].rect.x, click[1]-self.floor.layers[self.currentFloorLayer].rect.y ) elif clickKey is 'mouse3up': if self.editMode is 2: self.currentLayerIsGrabbed = False self.grabPoint = None elif curMousePos is not None: if self.currentLayerIsGrabbed and self.grabPoint is not None: if self.snapToGrid: curPoint = gridRound( (curMousePos[0]-self.grabPoint[0], curMousePos[1]-self.grabPoint[1]), self.gridX, self.gridY, trueRounding=True ) else: curPoint = (curMousePos[0]-self.grabPoint[0], curMousePos[1]-self.grabPoint[1]) self.floor.layers[self.currentFloorLayer].rect.topleft = curPoint elif self.currentlyGrabbedClamp == 1: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos nx = curPoint[0]-self.grabPoint[0] ny = curPoint[1]-self.grabPoint[1] self.floor.layers[self.currentFloorLayer].resize( nx-self.topLeftLayerClamp.rect.left, 0, ny-self.topLeftLayerClamp.rect.top, 0 ) elif self.currentlyGrabbedClamp == 2: if self.snapToGrid: curPoint = gridRound( curMousePos, self.gridX, self.gridY, trueRounding=True ) else: curPoint = curMousePos nx = curPoint[0]-self.grabPoint[0] ny = curPoint[1]-self.grabPoint[1] self.floor.layers[self.currentFloorLayer].resize( 0, nx-self.bottomRightLayerClamp.rect.left, 0, ny-self.bottomRightLayerClamp.rect.top ) self.setClamps()