def checkMenuClick(data): mouseStatus = pygame.mouse.get_pressed() if Menu.checkRegion(data) == 4 and mouseStatus[0] == 1: print 'menu clicked' if data.mode == 'run': data.mode = 'pause' elif data.mode == 'pause': data.mode = 'run'
def checkNextRound(data): mouseStatus = pygame.mouse.get_pressed() if Menu.checkRegion(data) == 3 and mouseStatus[0] == 1: print ' Next Round !' data.selected = None data.currentPlayer.xPos = data.map.x data.currentPlayer.yPos = data.map.y data.currentPlayer, data.otherPlayer = data.otherPlayer, data.currentPlayer data.currentPlayer.UntCls.nextRound() data.currentPlayer.BldCls.nextRound(data) data.currentPlayer.updateCurrentPopulation() data.currentPlayer.updateCurrentPopulationAvaliable() data.otherPlayer.addResources() data.currentPlayer.drawFogOfWar() data.map.x = data.currentPlayer.xPos data.map.y = data.currentPlayer.yPos
def checkMiniMapScroll(data): mouseStatus = pygame.mouse.get_pressed() mouseRegion = Menu.checkRegion(data) if mouseRegion == 1: mMapx, mMapy = Menu.getMiniMapOrigin() if mouseStatus[0] == 1: DestX, DestY = data.mouseX - 20, data.mouseY-20 data.ViewBox.x = DestX - mMapx data.ViewBox.y = DestY - mMapy if data.ViewBox.x < 0: data.ViewBox.x = 0 if data.ViewBox.x > 128-40: data.ViewBox.x = 128-40 if data.ViewBox.y < 0: data.ViewBox.y = 0 if data.ViewBox.y > 128-40: data.ViewBox.y = 128-40 data.map.x = -(data.ViewBox.x)*24 data.map.y = -(data.ViewBox.y)*24
def mousePressed(data): row, col = mouse2RC(data) mouseStatus = pygame.mouse.get_pressed() mouseRegion = Menu.checkRegion(data) # if in unit selection region if mouseRegion == 0: if mouseStatus[0] == 1: if data.map.board[row][col] == 0: # if the previous selection is a unit, move that unit if possible if isinstance(data.selected,Unit.Unit): if data.selected.canMove: if data.buttonStatus[0] == 1 and data.buildMode == False\ and data.placeMode == False: data.selected.move(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() elif data.selected.canAttack: if data.buttonStatus[1] == 1 and data.buildMode == False\ and data.placeMode == False: print data.selected data.selected.Attack(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() else: data.selected = None elif data.map.board[row][col] == 1: # if the previous selection is a unit, move that unit if possible if isinstance(data.selected,Unit.Unit): if data.selected.canMove and data.selected.AirUnit: if data.buttonStatus[0] == 1 and data.buildMode == False\ and data.placeMode == False: data.selected.move(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() elif data.selected.canAttack: if data.buttonStatus[1] == 1 and data.buildMode == False\ and data.placeMode == False: data.selected.Attack(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() else: data.selected = None elif isinstance(data.map.board[row][col],Unit.Unit): # if the previously selected is a unit, attack if possible, else select the unit if isinstance(data.selected,Unit.Unit): if data.selected.canAttack: if data.buttonStatus[1] == 1 and data.buildMode == False\ and data.placeMode == False: data.selected.Attack(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) elif isinstance(data.map.board[row][col],Building.building): if isinstance(data.selected,Unit.Unit): if data.selected.canAttack: if data.buttonStatus[1] == 1 and data.buildMode == False\ and data.placeMode == False: data.selected.Attack(row,col) data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) else: data.selected = data.map.board[row][col] data.selected.playSound(data.selected.idleSounds) else: data.selected = data.map.board[row][col] elif mouseStatus[2] == 1: data.selected = None if data.buildMode == True: if mouseRegion == 2: data.currentBuildIndex = Menu.getButtonStatus(data) if data.currentBuildIndex != None: data.placeMode = True if data.placeMode == True: if isinstance(data.selected,Unit.Unit): if mouseRegion == 0: mRow, mCol = mouse2RC(data) if data.currentBuildClass.cost <= data.currentPlayer.resources: data.currentBuildClass(mRow,mCol) data.currentPlayer.resources -= data.currentBuildClass.cost data.map.resetFogOfWarBoard(data.currentPlayer.index) data.currentPlayer.drawFogOfWar() else: print 'Not enough minerals' data.currentPlayer.playSound(data.currentPlayer.NoMineralSound) data.currentBuildClass = None data.placeMode = False data.buildMode = False data.currentBuildIndex = None #update the button Status # MUST POST UPDATE, OTHERWISE THE UNITS WONT MOVE Menu.updateButtonStatus(data)