def tryMove(self, newX, newY): if (self.isPaused): return False elif (not self.level.bomberman.canMove): return False elif (self.level.bomberman.wallPass and self.level.bomberman.bombPass): if (self.tileAt(newX,newY) == Tile.Concrete): return False elif (self.level.bomberman.wallPass): if (self.tileAt(newX,newY) == Tile.Concrete or self.tileAt(newX,newY) == Tile.Bomb): return False elif (self.level.bomberman.bombPass): if (self.tileAt(newX,newY) == Tile.Concrete or self.tileAt(newX,newY) == Tile.Brick): return False elif (self.tileAt(newX,newY) == Tile.Concrete or self.tileAt(newX,newY) == Tile.Brick or self.tileAt(newX,newY) == Tile.Bomb): return False elif Tile.isEnemy(self.tileAt(newX,newY)): self.death() return False # Pop level at current pos self.popTileAt(self.level.bomberman.curX,self.level.bomberman.curY) # Compute new position self.level.bomberman.curX = newX self.level.bomberman.curY = newY # Check if new pos is powerup if (self.tileAt(self.level.bomberman.curX,self.level.bomberman.curY) == Tile.Powerup): self.popTileAt(newX, newY) self.level.gainPowerUp() # Check if new pos is exit if ((self.tileAt(self.level.bomberman.curX,self.level.bomberman.curY) == Tile.Exit) and self.level.numberEnemies == 0): self.exit() return # IMPORTANT # Set level to new pos self.setTileAt(self.level.bomberman.curX,self.level.bomberman.curY,Tile.Bomberman) # Limit level move speed self.bombermanTriggerCanMove() self.globalTimer.singleShot(self.level.bomberman.speed, self.bombermanTriggerCanMove) return True
def detonateBomb(self): x, y, z = self.level.bombQueue.pop(0) if (self.tileAt(x,y) == Tile.Bomberman): self.popTileAt(x,y) self.popTileAt(x,y) self.setTileAt(x,y,Tile.Bomberman) else: self.popTileAt(x,y) flashList = [] popList = [] killedEnemies = [[] for i in range(self.level.bomberman.rangeOfBombs)] # NORTH for i in range(1,self.level.bomberman.rangeOfBombs+1): modY = y + i if (modY < constant.BOARD_HEIGHT-1): northTile = self.tileAt(x,modY) if (northTile == Tile.Concrete or northTile == Tile.Bomb): break if (Tile.isEmpty(northTile)): flashList.append((x,modY)) if (northTile == Tile.Brick): popList.append((x,modY)) break if (Tile.isEnemy(northTile)): killedEnemies[i-1].append(northTile) self.killEnemy(x, modY) if (Tile.isBomberman(northTile) and not self.level.bomberman.invincible): self.death() break if (Tile.isPowerup(northTile) or Tile.isExit(northTile)): self.level.setChaos() break # SOUTH for i in range(1,self.level.bomberman.rangeOfBombs+1): modY = y - i if (modY < constant.BOARD_HEIGHT-1): southTile = self.tileAt(x,modY) if (southTile == Tile.Concrete or southTile == Tile.Bomb): break if (Tile.isEmpty(southTile)): flashList.append((x,modY)) if (southTile == Tile.Brick): popList.append((x,modY)) break if (Tile.isEnemy(southTile)): killedEnemies[i-1].append(southTile) self.killEnemy(x, modY) if (Tile.isBomberman(southTile) and not self.level.bomberman.invincible): self.death() break if (Tile.isPowerup(southTile) or Tile.isExit(southTile)): self.level.setChaos() break # EAST for i in range(1,self.level.bomberman.rangeOfBombs+1): modX = x + i if (modX < constant.BOARD_WIDTH-1): eastTile = self.tileAt(modX,y) if (eastTile == Tile.Concrete or eastTile == Tile.Bomb): break if (Tile.isEmpty(eastTile)): flashList.append((modX,y)) if (eastTile == Tile.Brick): popList.append((modX,y)) break if (Tile.isEnemy(eastTile)): killedEnemies[i-1].append(eastTile) self.killEnemy(modX, y) if (Tile.isBomberman(eastTile) and not self.level.bomberman.invincible): self.death() break if (Tile.isPowerup(eastTile) or Tile.isExit(eastTile)): self.level.setChaos() break # WEST for i in range(1,self.level.bomberman.rangeOfBombs+1): modX = x - i if (modX < constant.BOARD_WIDTH-1): westTile = self.tileAt(modX,y) if (westTile == Tile.Concrete or westTile == Tile.Bomb): break if (Tile.isEmpty(westTile)): flashList.append((modX,y)) if (westTile == Tile.Brick): popList.append((modX,y)) break if (Tile.isEnemy(westTile)): killedEnemies[i-1].append(westTile) self.killEnemy(modX, y) if (Tile.isBomberman(westTile) and not self.level.bomberman.invincible): self.death() if (Tile.isPowerup(westTile) or Tile.isExit(westTile)): self.level.setChaos() break self.startFlash(flashList) # self.endFlash(flashList) self.destroyTiles(popList) self.updateScore(killedEnemies)