本文整理汇总了Python中Level.Level.addObstacles方法的典型用法代码示例。如果您正苦于以下问题:Python Level.addObstacles方法的具体用法?Python Level.addObstacles怎么用?Python Level.addObstacles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level.Level
的用法示例。
在下文中一共展示了Level.addObstacles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import addObstacles [as 别名]
class TanksField:
def __init__(self, canvas, nrtanks = 1):
self.canvas = canvas
self.bullets = []
self.bulletSpeed = 10
self.tanks = []
self.tanks_map = {}
self.width = int(self.canvas['width'])
self.height = int(self.canvas['height'])
self.createLevel()
self.createTanks(nrtanks)
self.level_running = True
def createLevel(self):
self.level = Level(self)
self.level.addObstacles([(2,3),(3,2),(3,3),(3,4),(3,5),(4,1),(4,2),(4,3),(4,4),(5,2),
(7,7),(8,7),(9,7),(7,8),(8,8),(9,8),(7,9),(8,9),(8,10),(9,9),(9,10),(9,11),(10,8),(10,9),(10,10),(10,11),(11,9),(11,10),(11,11),
(11,0),(12,0),(12,1),(13,0),(13,1),(13,2),(13,3),(14,0),(14,1),(14,2),(14,3),(15,0),(15,1),(15,2),(16,0),(16,1),(16,2),(17,0),(17,1),(18,0),(19,0),(19,1),
(17,7),(17,8),(16,6),(16,7),(16,8),(15,8),(15,9)])
def createTanks(self,nrtanks):
self.team_counts = [0,0]
data = {}
#Controlled player
data["tankLength"] = 20
data["tankWidth"] = 14
data["cannonLength"] = 20
data["cannonFront"] = 3
data["cannonBack"] = 8
data["x"] = 30
data["y"] = 30
data["angle"] = Math.pi*1.75
data["moveSpeed"] = 3
data["rotateSpeed"] = 3
data["cannonSpeed"] = 4
data["health"] = 80
data["damage"] = 10
data["reloadTime"] = 0.5
data["team"] = 0
data['color-fill'] = "DarkOliveGreen4"
self.player = PlayerTank(self, data)
self.tanks.append(self.player)
self.tanks_map[self.player.getImage()] = self.player
self.team_counts[data["team"]] += 1
#AI
if nrtanks != 0 :
#1
data["x"] = self.width - 30
data["y"] = self.height - 30
data["angle"] = Math.pi*0.75
data["team"] = 1
data['color-fill'] = "cornsilk4"
enemy = AITank(self, data)
self.tanks.append(enemy)
self.tanks_map[enemy.getImage()] = enemy
self.team_counts[data["team"]] += 1
if nrtanks > 1 :
#2
data["x"] = self.width - 75
data["y"] = 75
data["angle"] = 3*Math.pi/2
enemy = AITank(self, data)
self.tanks.append(enemy)
self.tanks_map[enemy.getImage()] = enemy
self.team_2_count += 1
self.team_counts[data["team"]] += 1
#End
self.canvas.tag_raise("cannon")
self.canvas.tag_raise("health")
def update(self, delta):
for tank in self.tanks: tank.update(delta)
for bullet in self.bullets: bullet.update()
self.tankCollision()
self.bulletCollision()
for tank in self.tanks : tank.draw()
for bullet in self.bullets: bullet.draw()
#check if game over
if self.level_running :
for c in self.team_counts :
if c == 0 :
self.level_running = False
def addBullet(self, x, y, team, direction, damage, radius):
self.bullets.append(Bullet(x, y, team, self.bulletSpeed, direction, damage, radius, self.canvas))
def bulletCollision(self):
for bullet in self.bullets :
x = bullet.getX()
y = bullet.getY()
radius = bullet.getRadius()
#.........这里部分代码省略.........