コード例 #1
0
 def draw(self):
     if self.mongoose != None:
         canvas.remove(self.mongoose)
     if self.hunting:
         if self.direction == LEFT:
             self.locs = [self.locs[0] - inc, self.locs[1]]
             if self.locs[0] < 0:
                 self.die()
         if self.direction == UP:
             self.locs = [self.locs[0], self.locs[1] - inc]
             if self.locs[1] < 0:
                 self.die()
         if self.direction == RIGHT:
             self.locs = [self.locs[0] + inc, self.locs[1]]
             if self.locs[0] >= w:
                 self.die()
         if self.direction == DOWN:
             self.locs = [self.locs[0], self.locs[1] + inc]
             if self.locs[1] >= h:
                 self.die()
         self.mongoose = __new__(
             fabric.Rect({
                 'left': self.locs[0],
                 'top': self.locs[1],
                 'width': inc,
                 'height': inc,
                 'originX': 'left',
                 'originY': 'top',
                 'fill': 'yellow'
             }))
         self.mongoose.hasControls = False
         self.mongoose.evented = False
         self.mongoose.selectable = False
         canvas.add(self.mongoose)
コード例 #2
0
 def update(self):
     canvas.remove(self.snake)
     for t_box in self.tail:
         canvas.remove(t_box)
     self.coords = []
     self.tail = []
     self.past.append(self.loc)
     if self.facing == 1:
         self.loc = (self.loc[0] - inc, self.loc[1])
     elif self.facing == 2:
         self.loc = (self.loc[0], self.loc[1] - inc)
     elif self.facing == 3:
         self.loc = (self.loc[0] + inc, self.loc[1])
     else:
         self.loc = (self.loc[0], self.loc[1] + inc)
     self.snake = __new__(
         fabric.Rect({
             'left': self.loc[0],
             'top': self.loc[1],
             'width': inc,
             'height': inc,
             'originX': 'left',
             'originY': 'top',
             'fill': 'green'
         }))
     self.coords.append(self.loc)
     self.snake.hasControls = False
     tail = []
     for i in range(self.snake_length - 1):
         self.tail.append(
             __new__(
                 fabric.Rect({
                     'left': self.past[len(self.past) - (i + 1)][0],
                     'top': self.past[len(self.past) - (i + 1)][1],
                     'width': inc,
                     'height': inc,
                     'originX': 'left',
                     'originY': 'top',
                     'fill': 'green'
                 })))
         self.coords.append(self.past[len(self.past) - (i + 1)])
     for t_box in self.tail:
         canvas.add(t_box)
         if t_box.left == self.snake.left and t_box.top == self.snake.top:
             alert("You ate yourself! Click OK to continue.")
             self.die()
     canvas.add(self.snake)
コード例 #3
0
 def install(self):  # The sprite holds an image that fabric can display
     self.image = __new__(
         fabric.Rect({
             'width': self.game.scaleX(self.width),
             'height': self.game.scaleY(self.height),
             'originX': 'center',
             'originY': 'center',
             'fill': 'white'
         }))
コード例 #4
0
ファイル: pong.py プロジェクト: pkdevboxy/Transcrypt
 def install(self):  # The sprite holds an image that fabric can display
     self.image = __new__(
         fabric.Rect({
             width: self.game.scaleX(self.width),
             height: self.game.scaleY(self.height),
             originX: 'center',
             originY: 'center',
             fill: 'white'
         }))
コード例 #5
0
    def install(self):  # The sprite holds an image that fabric can display
        red = 0
        green = 255
        blue = 0
        color = (f'rbg({red},{green},{blue})')

        self.image = __new__(
            fabric.Rect({
                'width': self.game.scaleX(self.width),
                'height': self.game.scaleY(self.height),
                'originX': 'center',
                'originY': 'center',
                'fill': 'white'
            }))
コード例 #6
0
 def spawn(self):
     self.loc = (int(Math.random() * w / inc) * inc,
                 int(Math.random() * h / inc) * inc)
     self.apple = __new__(
         fabric.Rect({
             'left': self.loc[0],
             'top': self.loc[1],
             'width': inc,
             'height': inc,
             'originX': 'left',
             'originY': 'top',
             'fill': 'red'
         }))
     self.apple.hasControls = False
     self.apple.evented = False
     self.apple.selectable = False
     canvas.add(self.apple)
コード例 #7
0
 def __init__(self):
     self.alive = True
     self.past = []
     self.tail = []
     self.coords = []
     self.snake_length = 1
     self.loc = (5 * inc, 5 * inc)
     self.snake = __new__(
         fabric.Rect({
             'left': self.loc[0],
             'top': self.loc[1],
             'width': inc,
             'height': inc,
             'originX': 'left',
             'originY': 'top',
             'fill': 'green'
         }))
     self.facing = 3
コード例 #8
0
 def draw_obstacle(self):
     if self.block != None:
         canvas.remove(self.block)
     self.block = __new__(
         fabric.Rect({
             'left': self.locs[0],
             'top': self.locs[1],
             'width': inc,
             'height': inc,
             'originX': 'left',
             'originY': 'top',
             'fill': 'black'
         }))
     self.block.hasControls = False
     self.block.evented = False
     self.block.selectable = False
     canvas.add(self.block)
     self.in_place = True