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)